openbgpd-8.8/m4/libtool.m4100644 001750 001750 00001057216 14751151135 0011136# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # 2006, 2007, 2008, 2009, 2010, 2011 Free Software # Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. m4_define([_LT_COPYING], [dnl # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # 2006, 2007, 2008, 2009, 2010, 2011 Free Software # Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is part of GNU Libtool. # # GNU Libtool 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 of # the License, or (at your option) any later version. # # As a special exception to the GNU General Public License, # if you distribute this file as part of a program or library that # is built using GNU Libtool, you may include this file under the # same distribution terms that you use for the rest of that program. # # GNU Libtool 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. # # You should have received a copy of the GNU General Public License # along with GNU Libtool; see the file COPYING. If not, a copy # can be downloaded from http://www.gnu.org/licenses/gpl.html, or # obtained by writing to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ]) # serial 57 LT_INIT # LT_PREREQ(VERSION) # ------------------ # Complain and exit if this libtool version is less that VERSION. m4_defun([LT_PREREQ], [m4_if(m4_version_compare(m4_defn([LT_PACKAGE_VERSION]), [$1]), -1, [m4_default([$3], [m4_fatal([Libtool version $1 or higher is required], 63)])], [$2])]) # _LT_CHECK_BUILDDIR # ------------------ # Complain if the absolute build directory name contains unusual characters m4_defun([_LT_CHECK_BUILDDIR], [case `pwd` in *\ * | *\ *) AC_MSG_WARN([Libtool does not cope well with whitespace in `pwd`]) ;; esac ]) # LT_INIT([OPTIONS]) # ------------------ AC_DEFUN([LT_INIT], [AC_PREREQ([2.58])dnl We use AC_INCLUDES_DEFAULT AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl AC_BEFORE([$0], [LT_LANG])dnl AC_BEFORE([$0], [LT_OUTPUT])dnl AC_BEFORE([$0], [LTDL_INIT])dnl m4_require([_LT_CHECK_BUILDDIR])dnl dnl Autoconf doesn't catch unexpanded LT_ macros by default: m4_pattern_forbid([^_?LT_[A-Z_]+$])dnl m4_pattern_allow([^(_LT_EOF|LT_DLGLOBAL|LT_DLLAZY_OR_NOW|LT_MULTI_MODULE)$])dnl dnl aclocal doesn't pull ltoptions.m4, ltsugar.m4, or ltversion.m4 dnl unless we require an AC_DEFUNed macro: AC_REQUIRE([LTOPTIONS_VERSION])dnl AC_REQUIRE([LTSUGAR_VERSION])dnl AC_REQUIRE([LTVERSION_VERSION])dnl AC_REQUIRE([LTOBSOLETE_VERSION])dnl m4_require([_LT_PROG_LTMAIN])dnl _LT_SHELL_INIT([SHELL=${CONFIG_SHELL-/bin/sh}]) dnl Parse OPTIONS _LT_SET_OPTIONS([$0], [$1]) # This can be used to rebuild libtool when needed LIBTOOL_DEPS="$ltmain" # Always use our own libtool. LIBTOOL='$(SHELL) $(top_builddir)/libtool' AC_SUBST(LIBTOOL)dnl _LT_SETUP # Only expand once: m4_define([LT_INIT]) ])# LT_INIT # Old names: AU_ALIAS([AC_PROG_LIBTOOL], [LT_INIT]) AU_ALIAS([AM_PROG_LIBTOOL], [LT_INIT]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_PROG_LIBTOOL], []) dnl AC_DEFUN([AM_PROG_LIBTOOL], []) # _LT_CC_BASENAME(CC) # ------------------- # Calculate cc_basename. Skip known compiler wrappers and cross-prefix. m4_defun([_LT_CC_BASENAME], [for cc_temp in $1""; do case $cc_temp in compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;; distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;; \-*) ;; *) break;; esac done cc_basename=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` ]) # _LT_FILEUTILS_DEFAULTS # ---------------------- # It is okay to use these file commands and assume they have been set # sensibly after `m4_require([_LT_FILEUTILS_DEFAULTS])'. m4_defun([_LT_FILEUTILS_DEFAULTS], [: ${CP="cp -f"} : ${MV="mv -f"} : ${RM="rm -f"} ])# _LT_FILEUTILS_DEFAULTS # _LT_SETUP # --------- m4_defun([_LT_SETUP], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl AC_REQUIRE([_LT_PREPARE_SED_QUOTE_VARS])dnl AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH])dnl _LT_DECL([], [PATH_SEPARATOR], [1], [The PATH separator for the build system])dnl dnl _LT_DECL([], [host_alias], [0], [The host system])dnl _LT_DECL([], [host], [0])dnl _LT_DECL([], [host_os], [0])dnl dnl _LT_DECL([], [build_alias], [0], [The build system])dnl _LT_DECL([], [build], [0])dnl _LT_DECL([], [build_os], [0])dnl dnl AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([LT_PATH_LD])dnl AC_REQUIRE([LT_PATH_NM])dnl dnl AC_REQUIRE([AC_PROG_LN_S])dnl test -z "$LN_S" && LN_S="ln -s" _LT_DECL([], [LN_S], [1], [Whether we need soft or hard links])dnl dnl AC_REQUIRE([LT_CMD_MAX_LEN])dnl _LT_DECL([objext], [ac_objext], [0], [Object file suffix (normally "o")])dnl _LT_DECL([], [exeext], [0], [Executable file suffix (normally "")])dnl dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_CHECK_SHELL_FEATURES])dnl m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl m4_require([_LT_CMD_RELOAD])dnl m4_require([_LT_CHECK_MAGIC_METHOD])dnl m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl m4_require([_LT_CMD_OLD_ARCHIVE])dnl m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl m4_require([_LT_WITH_SYSROOT])dnl _LT_CONFIG_LIBTOOL_INIT([ # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes INIT. if test -n "\${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi ]) if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi _LT_CHECK_OBJDIR m4_require([_LT_TAG_COMPILER])dnl case $host_os in aix3*) # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi ;; esac # Global variables: ofile=libtool can_build_shared=yes # All known linkers require a `.a' archive for static linking (except MSVC, # which needs '.lib'). libext=a with_gnu_ld="$lt_cv_prog_gnu_ld" old_CC="$CC" old_CFLAGS="$CFLAGS" # Set sane defaults for various variables test -z "$CC" && CC=cc test -z "$LTCC" && LTCC=$CC test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS test -z "$LD" && LD=ld test -z "$ac_objext" && ac_objext=o _LT_CC_BASENAME([$compiler]) # Only perform the check for file, if the check method requires it test -z "$MAGIC_CMD" && MAGIC_CMD=file case $deplibs_check_method in file_magic*) if test "$file_magic_cmd" = '$MAGIC_CMD'; then _LT_PATH_MAGIC fi ;; esac # Use C for the default configuration in the libtool script LT_SUPPORTED_TAG([CC]) _LT_LANG_C_CONFIG _LT_LANG_DEFAULT_CONFIG _LT_CONFIG_COMMANDS ])# _LT_SETUP # _LT_PREPARE_SED_QUOTE_VARS # -------------------------- # Define a few sed substitution that help us do robust quoting. m4_defun([_LT_PREPARE_SED_QUOTE_VARS], [# Backslashify metacharacters that are still active within # double-quoted strings. sed_quote_subst='s/\([["`$\\]]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\([["`\\]]\)/\\\1/g' # Sed substitution to delay expansion of an escaped shell variable in a # double_quote_subst'ed string. delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' # Sed substitution to delay expansion of an escaped single quote. delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' # Sed substitution to avoid accidental globbing in evaled expressions no_glob_subst='s/\*/\\\*/g' ]) # _LT_PROG_LTMAIN # --------------- # Note that this code is called both from `configure', and `config.status' # now that we use AC_CONFIG_COMMANDS to generate libtool. Notably, # `config.status' has no value for ac_aux_dir unless we are using Automake, # so we pass a copy along to make sure it has a sensible value anyway. m4_defun([_LT_PROG_LTMAIN], [m4_ifdef([AC_REQUIRE_AUX_FILE], [AC_REQUIRE_AUX_FILE([ltmain.sh])])dnl _LT_CONFIG_LIBTOOL_INIT([ac_aux_dir='$ac_aux_dir']) ltmain="$ac_aux_dir/ltmain.sh" ])# _LT_PROG_LTMAIN ## ------------------------------------- ## ## Accumulate code for creating libtool. ## ## ------------------------------------- ## # So that we can recreate a full libtool script including additional # tags, we accumulate the chunks of code to send to AC_CONFIG_COMMANDS # in macros and then make a single call at the end using the `libtool' # label. # _LT_CONFIG_LIBTOOL_INIT([INIT-COMMANDS]) # ---------------------------------------- # Register INIT-COMMANDS to be passed to AC_CONFIG_COMMANDS later. m4_define([_LT_CONFIG_LIBTOOL_INIT], [m4_ifval([$1], [m4_append([_LT_OUTPUT_LIBTOOL_INIT], [$1 ])])]) # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_INIT]) # _LT_CONFIG_LIBTOOL([COMMANDS]) # ------------------------------ # Register COMMANDS to be passed to AC_CONFIG_COMMANDS later. m4_define([_LT_CONFIG_LIBTOOL], [m4_ifval([$1], [m4_append([_LT_OUTPUT_LIBTOOL_COMMANDS], [$1 ])])]) # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS]) # _LT_CONFIG_SAVE_COMMANDS([COMMANDS], [INIT_COMMANDS]) # ----------------------------------------------------- m4_defun([_LT_CONFIG_SAVE_COMMANDS], [_LT_CONFIG_LIBTOOL([$1]) _LT_CONFIG_LIBTOOL_INIT([$2]) ]) # _LT_FORMAT_COMMENT([COMMENT]) # ----------------------------- # Add leading comment marks to the start of each line, and a trailing # full-stop to the whole comment if one is not present already. m4_define([_LT_FORMAT_COMMENT], [m4_ifval([$1], [ m4_bpatsubst([m4_bpatsubst([$1], [^ *], [# ])], [['`$\]], [\\\&])]m4_bmatch([$1], [[!?.]$], [], [.]) )]) ## ------------------------ ## ## FIXME: Eliminate VARNAME ## ## ------------------------ ## # _LT_DECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION], [IS-TAGGED?]) # ------------------------------------------------------------------- # CONFIGNAME is the name given to the value in the libtool script. # VARNAME is the (base) name used in the configure script. # VALUE may be 0, 1 or 2 for a computed quote escaped value based on # VARNAME. Any other value will be used directly. m4_define([_LT_DECL], [lt_if_append_uniq([lt_decl_varnames], [$2], [, ], [lt_dict_add_subkey([lt_decl_dict], [$2], [libtool_name], [m4_ifval([$1], [$1], [$2])]) lt_dict_add_subkey([lt_decl_dict], [$2], [value], [$3]) m4_ifval([$4], [lt_dict_add_subkey([lt_decl_dict], [$2], [description], [$4])]) lt_dict_add_subkey([lt_decl_dict], [$2], [tagged?], [m4_ifval([$5], [yes], [no])])]) ]) # _LT_TAGDECL([CONFIGNAME], VARNAME, VALUE, [DESCRIPTION]) # -------------------------------------------------------- m4_define([_LT_TAGDECL], [_LT_DECL([$1], [$2], [$3], [$4], [yes])]) # lt_decl_tag_varnames([SEPARATOR], [VARNAME1...]) # ------------------------------------------------ m4_define([lt_decl_tag_varnames], [_lt_decl_filter([tagged?], [yes], $@)]) # _lt_decl_filter(SUBKEY, VALUE, [SEPARATOR], [VARNAME1..]) # --------------------------------------------------------- m4_define([_lt_decl_filter], [m4_case([$#], [0], [m4_fatal([$0: too few arguments: $#])], [1], [m4_fatal([$0: too few arguments: $#: $1])], [2], [lt_dict_filter([lt_decl_dict], [$1], [$2], [], lt_decl_varnames)], [3], [lt_dict_filter([lt_decl_dict], [$1], [$2], [$3], lt_decl_varnames)], [lt_dict_filter([lt_decl_dict], $@)])[]dnl ]) # lt_decl_quote_varnames([SEPARATOR], [VARNAME1...]) # -------------------------------------------------- m4_define([lt_decl_quote_varnames], [_lt_decl_filter([value], [1], $@)]) # lt_decl_dquote_varnames([SEPARATOR], [VARNAME1...]) # --------------------------------------------------- m4_define([lt_decl_dquote_varnames], [_lt_decl_filter([value], [2], $@)]) # lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...]) # --------------------------------------------------- m4_define([lt_decl_varnames_tagged], [m4_assert([$# <= 2])dnl _$0(m4_quote(m4_default([$1], [[, ]])), m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]), m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))]) m4_define([_lt_decl_varnames_tagged], [m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])]) # lt_decl_all_varnames([SEPARATOR], [VARNAME1...]) # ------------------------------------------------ m4_define([lt_decl_all_varnames], [_$0(m4_quote(m4_default([$1], [[, ]])), m4_if([$2], [], m4_quote(lt_decl_varnames), m4_quote(m4_shift($@))))[]dnl ]) m4_define([_lt_decl_all_varnames], [lt_join($@, lt_decl_varnames_tagged([$1], lt_decl_tag_varnames([[, ]], m4_shift($@))))dnl ]) # _LT_CONFIG_STATUS_DECLARE([VARNAME]) # ------------------------------------ # Quote a variable value, and forward it to `config.status' so that its # declaration there will have the same value as in `configure'. VARNAME # must have a single quote delimited value for this to work. m4_define([_LT_CONFIG_STATUS_DECLARE], [$1='`$ECHO "$][$1" | $SED "$delay_single_quote_subst"`']) # _LT_CONFIG_STATUS_DECLARATIONS # ------------------------------ # We delimit libtool config variables with single quotes, so when # we write them to config.status, we have to be sure to quote all # embedded single quotes properly. In configure, this macro expands # each variable declared with _LT_DECL (and _LT_TAGDECL) into: # # ='`$ECHO "$" | $SED "$delay_single_quote_subst"`' m4_defun([_LT_CONFIG_STATUS_DECLARATIONS], [m4_foreach([_lt_var], m4_quote(lt_decl_all_varnames), [m4_n([_LT_CONFIG_STATUS_DECLARE(_lt_var)])])]) # _LT_LIBTOOL_TAGS # ---------------- # Output comment and list of tags supported by the script m4_defun([_LT_LIBTOOL_TAGS], [_LT_FORMAT_COMMENT([The names of the tagged configurations supported by this script])dnl available_tags="_LT_TAGS"dnl ]) # _LT_LIBTOOL_DECLARE(VARNAME, [TAG]) # ----------------------------------- # Extract the dictionary values for VARNAME (optionally with TAG) and # expand to a commented shell variable setting: # # # Some comment about what VAR is for. # visible_name=$lt_internal_name m4_define([_LT_LIBTOOL_DECLARE], [_LT_FORMAT_COMMENT(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [description])))[]dnl m4_pushdef([_libtool_name], m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [libtool_name])))[]dnl m4_case(m4_quote(lt_dict_fetch([lt_decl_dict], [$1], [value])), [0], [_libtool_name=[$]$1], [1], [_libtool_name=$lt_[]$1], [2], [_libtool_name=$lt_[]$1], [_libtool_name=lt_dict_fetch([lt_decl_dict], [$1], [value])])[]dnl m4_ifval([$2], [_$2])[]m4_popdef([_libtool_name])[]dnl ]) # _LT_LIBTOOL_CONFIG_VARS # ----------------------- # Produce commented declarations of non-tagged libtool config variables # suitable for insertion in the LIBTOOL CONFIG section of the `libtool' # script. Tagged libtool config variables (even for the LIBTOOL CONFIG # section) are produced by _LT_LIBTOOL_TAG_VARS. m4_defun([_LT_LIBTOOL_CONFIG_VARS], [m4_foreach([_lt_var], m4_quote(_lt_decl_filter([tagged?], [no], [], lt_decl_varnames)), [m4_n([_LT_LIBTOOL_DECLARE(_lt_var)])])]) # _LT_LIBTOOL_TAG_VARS(TAG) # ------------------------- m4_define([_LT_LIBTOOL_TAG_VARS], [m4_foreach([_lt_var], m4_quote(lt_decl_tag_varnames), [m4_n([_LT_LIBTOOL_DECLARE(_lt_var, [$1])])])]) # _LT_TAGVAR(VARNAME, [TAGNAME]) # ------------------------------ m4_define([_LT_TAGVAR], [m4_ifval([$2], [$1_$2], [$1])]) # _LT_CONFIG_COMMANDS # ------------------- # Send accumulated output to $CONFIG_STATUS. Thanks to the lists of # variables for single and double quote escaping we saved from calls # to _LT_DECL, we can put quote escaped variables declarations # into `config.status', and then the shell code to quote escape them in # for loops in `config.status'. Finally, any additional code accumulated # from calls to _LT_CONFIG_LIBTOOL_INIT is expanded. m4_defun([_LT_CONFIG_COMMANDS], [AC_PROVIDE_IFELSE([LT_OUTPUT], dnl If the libtool generation code has been placed in $CONFIG_LT, dnl instead of duplicating it all over again into config.status, dnl then we will have config.status run $CONFIG_LT later, so it dnl needs to know what name is stored there: [AC_CONFIG_COMMANDS([libtool], [$SHELL $CONFIG_LT || AS_EXIT(1)], [CONFIG_LT='$CONFIG_LT'])], dnl If the libtool generation code is destined for config.status, dnl expand the accumulated commands and init code now: [AC_CONFIG_COMMANDS([libtool], [_LT_OUTPUT_LIBTOOL_COMMANDS], [_LT_OUTPUT_LIBTOOL_COMMANDS_INIT])]) ])#_LT_CONFIG_COMMANDS # Initialize. m4_define([_LT_OUTPUT_LIBTOOL_COMMANDS_INIT], [ # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH sed_quote_subst='$sed_quote_subst' double_quote_subst='$double_quote_subst' delay_variable_subst='$delay_variable_subst' _LT_CONFIG_STATUS_DECLARATIONS LTCC='$LTCC' LTCFLAGS='$LTCFLAGS' compiler='$compiler_DEFAULT' # A function that is used when there is no print builtin or printf. func_fallback_echo () { eval 'cat <<_LTECHO_EOF \$[]1 _LTECHO_EOF' } # Quote evaled strings. for var in lt_decl_all_varnames([[ \ ]], lt_decl_quote_varnames); do case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in *[[\\\\\\\`\\"\\\$]]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done # Double-quote double-evaled strings. for var in lt_decl_all_varnames([[ \ ]], lt_decl_dquote_varnames); do case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in *[[\\\\\\\`\\"\\\$]]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done _LT_OUTPUT_LIBTOOL_INIT ]) # _LT_GENERATED_FILE_INIT(FILE, [COMMENT]) # ------------------------------------ # Generate a child script FILE with all initialization necessary to # reuse the environment learned by the parent script, and make the # file executable. If COMMENT is supplied, it is inserted after the # `#!' sequence but before initialization text begins. After this # macro, additional text can be appended to FILE to form the body of # the child script. The macro ends with non-zero status if the # file could not be fully written (such as if the disk is full). m4_ifdef([AS_INIT_GENERATED], [m4_defun([_LT_GENERATED_FILE_INIT],[AS_INIT_GENERATED($@)])], [m4_defun([_LT_GENERATED_FILE_INIT], [m4_require([AS_PREPARE])]dnl [m4_pushdef([AS_MESSAGE_LOG_FD])]dnl [lt_write_fail=0 cat >$1 <<_ASEOF || lt_write_fail=1 #! $SHELL # Generated by $as_me. $2 SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$1 <<\_ASEOF || lt_write_fail=1 AS_SHELL_SANITIZE _AS_PREPARE exec AS_MESSAGE_FD>&1 _ASEOF test $lt_write_fail = 0 && chmod +x $1[]dnl m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT # LT_OUTPUT # --------- # This macro allows early generation of the libtool script (before # AC_OUTPUT is called), incase it is used in configure for compilation # tests. AC_DEFUN([LT_OUTPUT], [: ${CONFIG_LT=./config.lt} AC_MSG_NOTICE([creating $CONFIG_LT]) _LT_GENERATED_FILE_INIT(["$CONFIG_LT"], [# Run this file to recreate a libtool stub with the current configuration.]) cat >>"$CONFIG_LT" <<\_LTEOF lt_cl_silent=false exec AS_MESSAGE_LOG_FD>>config.log { echo AS_BOX([Running $as_me.]) } >&AS_MESSAGE_LOG_FD lt_cl_help="\ \`$as_me' creates a local libtool stub from the current configuration, for use in further configure time tests before the real libtool is generated. Usage: $[0] [[OPTIONS]] -h, --help print this help, then exit -V, --version print version number, then exit -q, --quiet do not print progress messages -d, --debug don't remove temporary files Report bugs to ." lt_cl_version="\ m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) configured by $[0], generated by m4_PACKAGE_STRING. Copyright (C) 2011 Free Software Foundation, Inc. This config.lt script is free software; the Free Software Foundation gives unlimited permision to copy, distribute and modify it." while test $[#] != 0 do case $[1] in --version | --v* | -V ) echo "$lt_cl_version"; exit 0 ;; --help | --h* | -h ) echo "$lt_cl_help"; exit 0 ;; --debug | --d* | -d ) debug=: ;; --quiet | --q* | --silent | --s* | -q ) lt_cl_silent=: ;; -*) AC_MSG_ERROR([unrecognized option: $[1] Try \`$[0] --help' for more information.]) ;; *) AC_MSG_ERROR([unrecognized argument: $[1] Try \`$[0] --help' for more information.]) ;; esac shift done if $lt_cl_silent; then exec AS_MESSAGE_FD>/dev/null fi _LTEOF cat >>"$CONFIG_LT" <<_LTEOF _LT_OUTPUT_LIBTOOL_COMMANDS_INIT _LTEOF cat >>"$CONFIG_LT" <<\_LTEOF AC_MSG_NOTICE([creating $ofile]) _LT_OUTPUT_LIBTOOL_COMMANDS AS_EXIT(0) _LTEOF chmod +x "$CONFIG_LT" # configure is writing to config.log, but config.lt does its own redirection, # appending to config.log, which fails on DOS, as config.log is still kept # open by configure. Here we exec the FD to /dev/null, effectively closing # config.log, so it can be properly (re)opened and appended to by config.lt. lt_cl_success=: test "$silent" = yes && lt_config_lt_args="$lt_config_lt_args --quiet" exec AS_MESSAGE_LOG_FD>/dev/null $SHELL "$CONFIG_LT" $lt_config_lt_args || lt_cl_success=false exec AS_MESSAGE_LOG_FD>>config.log $lt_cl_success || AS_EXIT(1) ])# LT_OUTPUT # _LT_CONFIG(TAG) # --------------- # If TAG is the built-in tag, create an initial libtool script with a # default configuration from the untagged config vars. Otherwise add code # to config.status for appending the configuration named by TAG from the # matching tagged config vars. m4_defun([_LT_CONFIG], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl _LT_CONFIG_SAVE_COMMANDS([ m4_define([_LT_TAG], m4_if([$1], [], [C], [$1]))dnl m4_if(_LT_TAG, [C], [ # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes. if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi cfgfile="${ofile}T" trap "$RM \"$cfgfile\"; exit 1" 1 2 15 $RM "$cfgfile" cat <<_LT_EOF >> "$cfgfile" #! $SHELL # `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. # Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION # Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # _LT_COPYING _LT_LIBTOOL_TAGS # ### BEGIN LIBTOOL CONFIG _LT_LIBTOOL_CONFIG_VARS _LT_LIBTOOL_TAG_VARS # ### END LIBTOOL CONFIG _LT_EOF case $host_os in aix3*) cat <<\_LT_EOF >> "$cfgfile" # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi _LT_EOF ;; esac _LT_PROG_LTMAIN # We use sed instead of cat because bash on DJGPP gets confused if # if finds mixed CR/LF and LF-only lines. Since sed operates in # text mode, it properly converts lines to CR/LF. This bash problem # is reportedly fixed, but why not run on old versions too? sed '$q' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) _LT_PROG_REPLACE_SHELLFNS mv -f "$cfgfile" "$ofile" || (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") chmod +x "$ofile" ], [cat <<_LT_EOF >> "$ofile" dnl Unfortunately we have to use $1 here, since _LT_TAG is not expanded dnl in a comment (ie after a #). # ### BEGIN LIBTOOL TAG CONFIG: $1 _LT_LIBTOOL_TAG_VARS(_LT_TAG) # ### END LIBTOOL TAG CONFIG: $1 _LT_EOF ])dnl /m4_if ], [m4_if([$1], [], [ PACKAGE='$PACKAGE' VERSION='$VERSION' TIMESTAMP='$TIMESTAMP' RM='$RM' ofile='$ofile'], []) ])dnl /_LT_CONFIG_SAVE_COMMANDS ])# _LT_CONFIG # LT_SUPPORTED_TAG(TAG) # --------------------- # Trace this macro to discover what tags are supported by the libtool # --tag option, using: # autoconf --trace 'LT_SUPPORTED_TAG:$1' AC_DEFUN([LT_SUPPORTED_TAG], []) # C support is built-in for now m4_define([_LT_LANG_C_enabled], []) m4_define([_LT_TAGS], []) # LT_LANG(LANG) # ------------- # Enable libtool support for the given language if not already enabled. AC_DEFUN([LT_LANG], [AC_BEFORE([$0], [LT_OUTPUT])dnl m4_case([$1], [C], [_LT_LANG(C)], [C++], [_LT_LANG(CXX)], [Go], [_LT_LANG(GO)], [Java], [_LT_LANG(GCJ)], [Fortran 77], [_LT_LANG(F77)], [Fortran], [_LT_LANG(FC)], [Windows Resource], [_LT_LANG(RC)], [m4_ifdef([_LT_LANG_]$1[_CONFIG], [_LT_LANG($1)], [m4_fatal([$0: unsupported language: "$1"])])])dnl ])# LT_LANG # _LT_LANG(LANGNAME) # ------------------ m4_defun([_LT_LANG], [m4_ifdef([_LT_LANG_]$1[_enabled], [], [LT_SUPPORTED_TAG([$1])dnl m4_append([_LT_TAGS], [$1 ])dnl m4_define([_LT_LANG_]$1[_enabled], [])dnl _LT_LANG_$1_CONFIG($1)])dnl ])# _LT_LANG m4_ifndef([AC_PROG_GO], [ ############################################################ # NOTE: This macro has been submitted for inclusion into # # GNU Autoconf as AC_PROG_GO. When it is available in # # a released version of Autoconf we should remove this # # macro and use it instead. # ############################################################ m4_defun([AC_PROG_GO], [AC_LANG_PUSH(Go)dnl AC_ARG_VAR([GOC], [Go compiler command])dnl AC_ARG_VAR([GOFLAGS], [Go compiler flags])dnl _AC_ARG_VAR_LDFLAGS()dnl AC_CHECK_TOOL(GOC, gccgo) if test -z "$GOC"; then if test -n "$ac_tool_prefix"; then AC_CHECK_PROG(GOC, [${ac_tool_prefix}gccgo], [${ac_tool_prefix}gccgo]) fi fi if test -z "$GOC"; then AC_CHECK_PROG(GOC, gccgo, gccgo, false) fi ])#m4_defun ])#m4_ifndef # _LT_LANG_DEFAULT_CONFIG # ----------------------- m4_defun([_LT_LANG_DEFAULT_CONFIG], [AC_PROVIDE_IFELSE([AC_PROG_CXX], [LT_LANG(CXX)], [m4_define([AC_PROG_CXX], defn([AC_PROG_CXX])[LT_LANG(CXX)])]) AC_PROVIDE_IFELSE([AC_PROG_F77], [LT_LANG(F77)], [m4_define([AC_PROG_F77], defn([AC_PROG_F77])[LT_LANG(F77)])]) AC_PROVIDE_IFELSE([AC_PROG_FC], [LT_LANG(FC)], [m4_define([AC_PROG_FC], defn([AC_PROG_FC])[LT_LANG(FC)])]) dnl The call to [A][M_PROG_GCJ] is quoted like that to stop aclocal dnl pulling things in needlessly. AC_PROVIDE_IFELSE([AC_PROG_GCJ], [LT_LANG(GCJ)], [AC_PROVIDE_IFELSE([A][M_PROG_GCJ], [LT_LANG(GCJ)], [AC_PROVIDE_IFELSE([LT_PROG_GCJ], [LT_LANG(GCJ)], [m4_ifdef([AC_PROG_GCJ], [m4_define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[LT_LANG(GCJ)])]) m4_ifdef([A][M_PROG_GCJ], [m4_define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[LT_LANG(GCJ)])]) m4_ifdef([LT_PROG_GCJ], [m4_define([LT_PROG_GCJ], defn([LT_PROG_GCJ])[LT_LANG(GCJ)])])])])]) AC_PROVIDE_IFELSE([AC_PROG_GO], [LT_LANG(GO)], [m4_define([AC_PROG_GO], defn([AC_PROG_GO])[LT_LANG(GO)])]) AC_PROVIDE_IFELSE([LT_PROG_RC], [LT_LANG(RC)], [m4_define([LT_PROG_RC], defn([LT_PROG_RC])[LT_LANG(RC)])]) ])# _LT_LANG_DEFAULT_CONFIG # Obsolete macros: AU_DEFUN([AC_LIBTOOL_CXX], [LT_LANG(C++)]) AU_DEFUN([AC_LIBTOOL_F77], [LT_LANG(Fortran 77)]) AU_DEFUN([AC_LIBTOOL_FC], [LT_LANG(Fortran)]) AU_DEFUN([AC_LIBTOOL_GCJ], [LT_LANG(Java)]) AU_DEFUN([AC_LIBTOOL_RC], [LT_LANG(Windows Resource)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_CXX], []) dnl AC_DEFUN([AC_LIBTOOL_F77], []) dnl AC_DEFUN([AC_LIBTOOL_FC], []) dnl AC_DEFUN([AC_LIBTOOL_GCJ], []) dnl AC_DEFUN([AC_LIBTOOL_RC], []) # _LT_TAG_COMPILER # ---------------- m4_defun([_LT_TAG_COMPILER], [AC_REQUIRE([AC_PROG_CC])dnl _LT_DECL([LTCC], [CC], [1], [A C compiler])dnl _LT_DECL([LTCFLAGS], [CFLAGS], [1], [LTCC compiler flags])dnl _LT_TAGDECL([CC], [compiler], [1], [A language specific compiler])dnl _LT_TAGDECL([with_gcc], [GCC], [0], [Is the compiler the GNU compiler?])dnl # If no C compiler was specified, use CC. LTCC=${LTCC-"$CC"} # If no C compiler flags were specified, use CFLAGS. LTCFLAGS=${LTCFLAGS-"$CFLAGS"} # Allow CC to be a program name with arguments. compiler=$CC ])# _LT_TAG_COMPILER # _LT_COMPILER_BOILERPLATE # ------------------------ # Check for compiler boilerplate output or warnings with # the simple compiler test code. m4_defun([_LT_COMPILER_BOILERPLATE], [m4_require([_LT_DECL_SED])dnl ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" >conftest.$ac_ext eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_compiler_boilerplate=`cat conftest.err` $RM conftest* ])# _LT_COMPILER_BOILERPLATE # _LT_LINKER_BOILERPLATE # ---------------------- # Check for linker boilerplate output or warnings with # the simple link test code. m4_defun([_LT_LINKER_BOILERPLATE], [m4_require([_LT_DECL_SED])dnl ac_outfile=conftest.$ac_objext echo "$lt_simple_link_test_code" >conftest.$ac_ext eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_linker_boilerplate=`cat conftest.err` $RM -r conftest* ])# _LT_LINKER_BOILERPLATE # _LT_REQUIRED_DARWIN_CHECKS # ------------------------- m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ case $host_os in rhapsody* | darwin*) AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:]) AC_CHECK_TOOL([NMEDIT], [nmedit], [:]) AC_CHECK_TOOL([LIPO], [lipo], [:]) AC_CHECK_TOOL([OTOOL], [otool], [:]) AC_CHECK_TOOL([OTOOL64], [otool64], [:]) _LT_DECL([], [DSYMUTIL], [1], [Tool to manipulate archived DWARF debug symbol files on Mac OS X]) _LT_DECL([], [NMEDIT], [1], [Tool to change global to local symbols on Mac OS X]) _LT_DECL([], [LIPO], [1], [Tool to manipulate fat objects and archives on Mac OS X]) _LT_DECL([], [OTOOL], [1], [ldd/readelf like tool for Mach-O binaries on Mac OS X]) _LT_DECL([], [OTOOL64], [1], [ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4]) AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod], [lt_cv_apple_cc_single_mod=no if test -z "${LT_MULTI_MODULE}"; then # By default we will add the -single_module flag. You can override # by either setting the environment variable LT_MULTI_MODULE # non-empty at configure time, or by adding -multi_module to the # link flags. rm -rf libconftest.dylib* echo "int foo(void){return 1;}" > conftest.c echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c 2>conftest.err _lt_result=$? # If there is a non-empty error log, and "single_module" # appears in it, assume the flag caused a linker warning if test -s conftest.err && $GREP single_module conftest.err; then cat conftest.err >&AS_MESSAGE_LOG_FD # Otherwise, if the output was created with a 0 exit code from # the compiler, it worked. elif test -f libconftest.dylib && test $_lt_result -eq 0; then lt_cv_apple_cc_single_mod=yes else cat conftest.err >&AS_MESSAGE_LOG_FD fi rm -rf libconftest.dylib* rm -f conftest.* fi]) AC_CACHE_CHECK([for -exported_symbols_list linker flag], [lt_cv_ld_exported_symbols_list], [lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [lt_cv_ld_exported_symbols_list=yes], [lt_cv_ld_exported_symbols_list=no]) LDFLAGS="$save_LDFLAGS" ]) AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load], [lt_cv_ld_force_load=no cat > conftest.c << _LT_EOF int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD cat > conftest.c << _LT_EOF int main() { return 0;} _LT_EOF echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err _lt_result=$? if test -s conftest.err && $GREP force_load conftest.err; then cat conftest.err >&AS_MESSAGE_LOG_FD elif test -f conftest && test $_lt_result -eq 0 && $GREP forced_load conftest >/dev/null 2>&1 ; then lt_cv_ld_force_load=yes else cat conftest.err >&AS_MESSAGE_LOG_FD fi rm -f conftest.err libconftest.a conftest conftest.c rm -rf conftest.dSYM ]) case $host_os in rhapsody* | darwin1.[[012]]) _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; darwin1.*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; darwin*) # darwin 5.x on # if running on 10.5 or later, the deployment target defaults # to the OS version, if on x86, and 10.4, the deployment # target defaults to 10.4. Don't you love it? case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; 10.[[012]]*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; 10.*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; esac ;; esac if test "$lt_cv_apple_cc_single_mod" = "yes"; then _lt_dar_single_mod='$single_module' fi if test "$lt_cv_ld_exported_symbols_list" = "yes"; then _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' else _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' fi if test "$DSYMUTIL" != ":" && test "$lt_cv_ld_force_load" = "no"; then _lt_dsymutil='~$DSYMUTIL $lib || :' else _lt_dsymutil= fi ;; esac ]) # _LT_DARWIN_LINKER_FEATURES([TAG]) # --------------------------------- # Checks for linker and compiler features on darwin m4_defun([_LT_DARWIN_LINKER_FEATURES], [ m4_require([_LT_REQUIRED_DARWIN_CHECKS]) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported if test "$lt_cv_ld_force_load" = "yes"; then _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience ${wl}-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' m4_case([$1], [F77], [_LT_TAGVAR(compiler_needs_object, $1)=yes], [FC], [_LT_TAGVAR(compiler_needs_object, $1)=yes]) else _LT_TAGVAR(whole_archive_flag_spec, $1)='' fi _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined" case $cc_basename in ifort*) _lt_dar_can_shared=yes ;; *) _lt_dar_can_shared=$GCC ;; esac if test "$_lt_dar_can_shared" = "yes"; then output_verbose_link_cmd=func_echo_all _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" m4_if([$1], [CXX], [ if test "$lt_cv_apple_cc_single_mod" != "yes"; then _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}" _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}" fi ],[]) else _LT_TAGVAR(ld_shlibs, $1)=no fi ]) # _LT_SYS_MODULE_PATH_AIX([TAGNAME]) # ---------------------------------- # Links a minimal program and checks the executable # for the system default hardcoded library path. In most cases, # this is /usr/lib:/lib, but when the MPI compilers are used # the location of the communication and MPI libs are included too. # If we don't find anything, use the default library path according # to the aix ld manual. # Store the results from the different compilers for each TAGNAME. # Allow to override them for all tags through lt_cv_aix_libpath. m4_defun([_LT_SYS_MODULE_PATH_AIX], [m4_require([_LT_DECL_SED])dnl if test "${lt_cv_aix_libpath+set}" = set; then aix_libpath=$lt_cv_aix_libpath else AC_CACHE_VAL([_LT_TAGVAR([lt_cv_aix_libpath_], [$1])], [AC_LINK_IFELSE([AC_LANG_PROGRAM],[ lt_aix_libpath_sed='[ /Import File Strings/,/^$/ { /^0/ { s/^0 *\([^ ]*\) *$/\1/ p } }]' _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` # Check for a 64-bit object if we didn't find anything. if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then _LT_TAGVAR([lt_cv_aix_libpath_], [$1])=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi],[]) if test -z "$_LT_TAGVAR([lt_cv_aix_libpath_], [$1])"; then _LT_TAGVAR([lt_cv_aix_libpath_], [$1])="/usr/lib:/lib" fi ]) aix_libpath=$_LT_TAGVAR([lt_cv_aix_libpath_], [$1]) fi ])# _LT_SYS_MODULE_PATH_AIX # _LT_SHELL_INIT(ARG) # ------------------- m4_define([_LT_SHELL_INIT], [m4_divert_text([M4SH-INIT], [$1 ])])# _LT_SHELL_INIT # _LT_PROG_ECHO_BACKSLASH # ----------------------- # Find how we can fake an echo command that does not interpret backslash. # In particular, with Autoconf 2.60 or later we add some code to the start # of the generated configure script which will find a shell with a builtin # printf (which we can use as an echo command). m4_defun([_LT_PROG_ECHO_BACKSLASH], [ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO AC_MSG_CHECKING([how to print strings]) # Test print first, because it will be a builtin if present. if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then ECHO='print -r --' elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then ECHO='printf %s\n' else # Use this function as a fallback that always works. func_fallback_echo () { eval 'cat <<_LTECHO_EOF $[]1 _LTECHO_EOF' } ECHO='func_fallback_echo' fi # func_echo_all arg... # Invoke $ECHO with all args, space-separated. func_echo_all () { $ECHO "$*" } case "$ECHO" in printf*) AC_MSG_RESULT([printf]) ;; print*) AC_MSG_RESULT([print -r]) ;; *) AC_MSG_RESULT([cat]) ;; esac m4_ifdef([_AS_DETECT_SUGGESTED], [_AS_DETECT_SUGGESTED([ test -n "${ZSH_VERSION+set}${BASH_VERSION+set}" || ( ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO PATH=/empty FPATH=/empty; export PATH FPATH test "X`printf %s $ECHO`" = "X$ECHO" \ || test "X`print -r -- $ECHO`" = "X$ECHO" )])]) _LT_DECL([], [SHELL], [1], [Shell to use when invoking shell scripts]) _LT_DECL([], [ECHO], [1], [An echo program that protects backslashes]) ])# _LT_PROG_ECHO_BACKSLASH # _LT_WITH_SYSROOT # ---------------- AC_DEFUN([_LT_WITH_SYSROOT], [AC_MSG_CHECKING([for sysroot]) AC_ARG_WITH([sysroot], [ --with-sysroot[=DIR] Search for dependent libraries within DIR (or the compiler's sysroot if not specified).], [], [with_sysroot=no]) dnl lt_sysroot will always be passed unquoted. We quote it here dnl in case the user passed a directory name. lt_sysroot= case ${with_sysroot} in #( yes) if test "$GCC" = yes; then lt_sysroot=`$CC --print-sysroot 2>/dev/null` fi ;; #( /*) lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` ;; #( no|'') ;; #( *) AC_MSG_RESULT([${with_sysroot}]) AC_MSG_ERROR([The sysroot must be an absolute path.]) ;; esac AC_MSG_RESULT([${lt_sysroot:-no}]) _LT_DECL([], [lt_sysroot], [0], [The root where to search for ]dnl [dependent libraries, and in which our libraries should be installed.])]) # _LT_ENABLE_LOCK # --------------- m4_defun([_LT_ENABLE_LOCK], [AC_ARG_ENABLE([libtool-lock], [AS_HELP_STRING([--disable-libtool-lock], [avoid locking (might break parallel builds)])]) test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes # Some flags need to be propagated to the compiler or linker for good # libtool support. case $host in ia64-*-hpux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `/usr/bin/file conftest.$ac_objext` in *ELF-32*) HPUX_IA64_MODE="32" ;; *ELF-64*) HPUX_IA64_MODE="64" ;; esac fi rm -rf conftest* ;; *-*-irix6*) # Find out which ABI we are using. echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then if test "$lt_cv_prog_gnu_ld" = yes; then case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -melf32bsmip" ;; *N32*) LD="${LD-ld} -melf32bmipn32" ;; *64-bit*) LD="${LD-ld} -melf64bmip" ;; esac else case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; *N32*) LD="${LD-ld} -n32" ;; *64-bit*) LD="${LD-ld} -64" ;; esac fi fi rm -rf conftest* ;; x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `/usr/bin/file conftest.o` in *32-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_i386" ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" ;; s390x-*linux*) LD="${LD-ld} -m elf_s390" ;; sparc64-*linux*) LD="${LD-ld} -m elf32_sparc" ;; esac ;; *64-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_x86_64_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_x86_64" ;; ppc*-*linux*|powerpc*-*linux*) LD="${LD-ld} -m elf64ppc" ;; s390*-*linux*|s390*-*tpf*) LD="${LD-ld} -m elf64_s390" ;; sparc*-*linux*) LD="${LD-ld} -m elf64_sparc" ;; esac ;; esac fi rm -rf conftest* ;; *-*-sco3.2v5*) # On SCO OpenServer 5, we need -belf to get full-featured binaries. SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -belf" AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf, [AC_LANG_PUSH(C) AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no]) AC_LANG_POP]) if test x"$lt_cv_cc_needs_belf" != x"yes"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS="$SAVE_CFLAGS" fi ;; *-*solaris*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then case `/usr/bin/file conftest.o` in *64-bit*) case $lt_cv_prog_gnu_ld in yes*) case $host in i?86-*-solaris*) LD="${LD-ld} -m elf_x86_64" ;; sparc*-*-solaris*) LD="${LD-ld} -m elf64_sparc" ;; esac # GNU ld 2.21 introduced _sol2 emulations. Use them if available. if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then LD="${LD-ld}_sol2" fi ;; *) if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then LD="${LD-ld} -64" fi ;; esac ;; esac fi rm -rf conftest* ;; esac need_locks="$enable_libtool_lock" ])# _LT_ENABLE_LOCK # _LT_PROG_AR # ----------- m4_defun([_LT_PROG_AR], [AC_CHECK_TOOLS(AR, [ar], false) : ${AR=ar} : ${AR_FLAGS=cru} _LT_DECL([], [AR], [1], [The archiver]) _LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file], [lt_cv_ar_at_file=no AC_COMPILE_IFELSE([AC_LANG_PROGRAM], [echo conftest.$ac_objext > conftest.lst lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&AS_MESSAGE_LOG_FD' AC_TRY_EVAL([lt_ar_try]) if test "$ac_status" -eq 0; then # Ensure the archiver fails upon bogus file names. rm -f conftest.$ac_objext libconftest.a AC_TRY_EVAL([lt_ar_try]) if test "$ac_status" -ne 0; then lt_cv_ar_at_file=@ fi fi rm -f conftest.* libconftest.a ]) ]) if test "x$lt_cv_ar_at_file" = xno; then archiver_list_spec= else archiver_list_spec=$lt_cv_ar_at_file fi _LT_DECL([], [archiver_list_spec], [1], [How to feed a file listing to the archiver]) ])# _LT_PROG_AR # _LT_CMD_OLD_ARCHIVE # ------------------- m4_defun([_LT_CMD_OLD_ARCHIVE], [_LT_PROG_AR AC_CHECK_TOOL(STRIP, strip, :) test -z "$STRIP" && STRIP=: _LT_DECL([], [STRIP], [1], [A symbol stripping program]) AC_CHECK_TOOL(RANLIB, ranlib, :) test -z "$RANLIB" && RANLIB=: _LT_DECL([], [RANLIB], [1], [Commands used to install an old-style archive]) # Determine commands to create old-style static archives. old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' old_postinstall_cmds='chmod 644 $oldlib' old_postuninstall_cmds= if test -n "$RANLIB"; then case $host_os in openbsd*) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" ;; *) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" ;; esac old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" fi case $host_os in darwin*) lock_old_archive_extraction=yes ;; *) lock_old_archive_extraction=no ;; esac _LT_DECL([], [old_postinstall_cmds], [2]) _LT_DECL([], [old_postuninstall_cmds], [2]) _LT_TAGDECL([], [old_archive_cmds], [2], [Commands used to build an old-style archive]) _LT_DECL([], [lock_old_archive_extraction], [0], [Whether to use a lock for old archive extraction]) ])# _LT_CMD_OLD_ARCHIVE # _LT_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, # [OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE]) # ---------------------------------------------------------------- # Check whether the given compiler option works AC_DEFUN([_LT_COMPILER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_SED])dnl AC_CACHE_CHECK([$1], [$2], [$2=no m4_if([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4]) echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="$3" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. # The option is referenced via a variable to avoid confusing sed. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&AS_MESSAGE_LOG_FD echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then $2=yes fi fi $RM conftest* ]) if test x"[$]$2" = xyes; then m4_if([$5], , :, [$5]) else m4_if([$6], , :, [$6]) fi ])# _LT_COMPILER_OPTION # Old name: AU_ALIAS([AC_LIBTOOL_COMPILER_OPTION], [_LT_COMPILER_OPTION]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION], []) # _LT_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS, # [ACTION-SUCCESS], [ACTION-FAILURE]) # ---------------------------------------------------- # Check whether the given linker option works AC_DEFUN([_LT_LINKER_OPTION], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_SED])dnl AC_CACHE_CHECK([$1], [$2], [$2=no save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS $3" echo "$lt_simple_link_test_code" > conftest.$ac_ext if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then # The linker can only warn and ignore the option if not recognized # So say no if there are warnings if test -s conftest.err; then # Append any errors to the config.log. cat conftest.err 1>&AS_MESSAGE_LOG_FD $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if diff conftest.exp conftest.er2 >/dev/null; then $2=yes fi else $2=yes fi fi $RM -r conftest* LDFLAGS="$save_LDFLAGS" ]) if test x"[$]$2" = xyes; then m4_if([$4], , :, [$4]) else m4_if([$5], , :, [$5]) fi ])# _LT_LINKER_OPTION # Old name: AU_ALIAS([AC_LIBTOOL_LINKER_OPTION], [_LT_LINKER_OPTION]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_LINKER_OPTION], []) # LT_CMD_MAX_LEN #--------------- AC_DEFUN([LT_CMD_MAX_LEN], [AC_REQUIRE([AC_CANONICAL_HOST])dnl # find the maximum length of command line arguments AC_MSG_CHECKING([the maximum length of command line arguments]) AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl i=0 teststring="ABCD" case $build_os in msdosdjgpp*) # On DJGPP, this test can blow up pretty badly due to problems in libc # (any single argument exceeding 2000 bytes causes a buffer overrun # during glob expansion). Even if it were fixed, the result of this # check would be larger than it should be. lt_cv_sys_max_cmd_len=12288; # 12K is about right ;; gnu*) # Under GNU Hurd, this test is not required because there is # no limit to the length of command line arguments. # Libtool will interpret -1 as no limit whatsoever lt_cv_sys_max_cmd_len=-1; ;; cygwin* | mingw* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, # you end up with a "frozen" computer, even though with patience # the test eventually succeeds (with a max line length of 256k). # Instead, let's just punt: use the minimum linelength reported by # all of the supported platforms: 8192 (on NT/2K/XP). lt_cv_sys_max_cmd_len=8192; ;; mint*) # On MiNT this can take a long time and run out of memory. lt_cv_sys_max_cmd_len=8192; ;; amigaos*) # On AmigaOS with pdksh, this test takes hours, literally. # So we just punt and use a minimum line length of 8192. lt_cv_sys_max_cmd_len=8192; ;; netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) # This has been around since 386BSD, at least. Likely further. if test -x /sbin/sysctl; then lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` elif test -x /usr/sbin/sysctl; then lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` else lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs fi # And add a safety zone lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` ;; interix*) # We know the value 262144 and hardcode it with a safety zone (like BSD) lt_cv_sys_max_cmd_len=196608 ;; os2*) # The test takes a long time on OS/2. lt_cv_sys_max_cmd_len=8192 ;; osf*) # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not # nice to cause kernel panics so lets avoid the loop below. # First set a reasonable default. lt_cv_sys_max_cmd_len=16384 # if test -x /sbin/sysconfig; then case `/sbin/sysconfig -q proc exec_disable_arg_limit` in *1*) lt_cv_sys_max_cmd_len=-1 ;; esac fi ;; sco3.2v5*) lt_cv_sys_max_cmd_len=102400 ;; sysv5* | sco5v6* | sysv4.2uw2*) kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` if test -n "$kargmax"; then lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` else lt_cv_sys_max_cmd_len=32768 fi ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` if test -n "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else # Make teststring a little bigger before we do anything with it. # a 1K string should be a reasonable start. for i in 1 2 3 4 5 6 7 8 ; do teststring=$teststring$teststring done SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} # If test is not a shell built-in, we'll probably end up computing a # maximum length that is only half of the actual maximum length, but # we can't tell. while { test "X"`env echo "$teststring$teststring" 2>/dev/null` \ = "X$teststring$teststring"; } >/dev/null 2>&1 && test $i != 17 # 1/2 MB should be enough do i=`expr $i + 1` teststring=$teststring$teststring done # Only check the string length outside the loop. lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` teststring= # Add a significant safety factor because C++ compilers can tack on # massive amounts of additional arguments before passing them to the # linker. It appears as though 1/2 is a usable value. lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` fi ;; esac ]) if test -n $lt_cv_sys_max_cmd_len ; then AC_MSG_RESULT($lt_cv_sys_max_cmd_len) else AC_MSG_RESULT(none) fi max_cmd_len=$lt_cv_sys_max_cmd_len _LT_DECL([], [max_cmd_len], [0], [What is the maximum length of a command?]) ])# LT_CMD_MAX_LEN # Old name: AU_ALIAS([AC_LIBTOOL_SYS_MAX_CMD_LEN], [LT_CMD_MAX_LEN]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN], []) # _LT_HEADER_DLFCN # ---------------- m4_defun([_LT_HEADER_DLFCN], [AC_CHECK_HEADERS([dlfcn.h], [], [], [AC_INCLUDES_DEFAULT])dnl ])# _LT_HEADER_DLFCN # _LT_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE, # ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING) # ---------------------------------------------------------------- m4_defun([_LT_TRY_DLOPEN_SELF], [m4_require([_LT_HEADER_DLFCN])dnl if test "$cross_compiling" = yes; then : [$4] else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF [#line $LINENO "configure" #include "confdefs.h" #if HAVE_DLFCN_H #include #endif #include #ifdef RTLD_GLOBAL # define LT_DLGLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL # define LT_DLGLOBAL DL_GLOBAL # else # define LT_DLGLOBAL 0 # endif #endif /* We may have to define LT_DLLAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_DLLAZY_OR_NOW # ifdef RTLD_LAZY # define LT_DLLAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY # define LT_DLLAZY_OR_NOW DL_LAZY # else # ifdef RTLD_NOW # define LT_DLLAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW # define LT_DLLAZY_OR_NOW DL_NOW # else # define LT_DLLAZY_OR_NOW 0 # endif # endif # endif # endif #endif /* When -fvisbility=hidden is used, assume the code has been annotated correspondingly for the symbols needed. */ #if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) int fnord () __attribute__((visibility("default"))); #endif int fnord () { return 42; } int main () { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; if (self) { if (dlsym (self,"fnord")) status = $lt_dlno_uscore; else { if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; else puts (dlerror ()); } /* dlclose (self); */ } else puts (dlerror ()); return status; }] _LT_EOF if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null lt_status=$? case x$lt_status in x$lt_dlno_uscore) $1 ;; x$lt_dlneed_uscore) $2 ;; x$lt_dlunknown|x*) $3 ;; esac else : # compilation failed $3 fi fi rm -fr conftest* ])# _LT_TRY_DLOPEN_SELF # LT_SYS_DLOPEN_SELF # ------------------ AC_DEFUN([LT_SYS_DLOPEN_SELF], [m4_require([_LT_HEADER_DLFCN])dnl if test "x$enable_dlopen" != xyes; then enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown else lt_cv_dlopen=no lt_cv_dlopen_libs= case $host_os in beos*) lt_cv_dlopen="load_add_on" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ;; mingw* | pw32* | cegcc*) lt_cv_dlopen="LoadLibrary" lt_cv_dlopen_libs= ;; cygwin*) lt_cv_dlopen="dlopen" lt_cv_dlopen_libs= ;; darwin*) # if libdl is installed we need to link against it AC_CHECK_LIB([dl], [dlopen], [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[ lt_cv_dlopen="dyld" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ]) ;; *) AC_CHECK_FUNC([shl_load], [lt_cv_dlopen="shl_load"], [AC_CHECK_LIB([dld], [shl_load], [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"], [AC_CHECK_FUNC([dlopen], [lt_cv_dlopen="dlopen"], [AC_CHECK_LIB([dl], [dlopen], [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"], [AC_CHECK_LIB([svld], [dlopen], [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"], [AC_CHECK_LIB([dld], [dld_link], [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"]) ]) ]) ]) ]) ]) ;; esac if test "x$lt_cv_dlopen" != xno; then enable_dlopen=yes else enable_dlopen=no fi case $lt_cv_dlopen in dlopen) save_CPPFLAGS="$CPPFLAGS" test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" save_LDFLAGS="$LDFLAGS" wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" save_LIBS="$LIBS" LIBS="$lt_cv_dlopen_libs $LIBS" AC_CACHE_CHECK([whether a program can dlopen itself], lt_cv_dlopen_self, [dnl _LT_TRY_DLOPEN_SELF( lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes, lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross) ]) if test "x$lt_cv_dlopen_self" = xyes; then wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" AC_CACHE_CHECK([whether a statically linked program can dlopen itself], lt_cv_dlopen_self_static, [dnl _LT_TRY_DLOPEN_SELF( lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=no, lt_cv_dlopen_self_static=cross) ]) fi CPPFLAGS="$save_CPPFLAGS" LDFLAGS="$save_LDFLAGS" LIBS="$save_LIBS" ;; esac case $lt_cv_dlopen_self in yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; *) enable_dlopen_self=unknown ;; esac case $lt_cv_dlopen_self_static in yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; *) enable_dlopen_self_static=unknown ;; esac fi _LT_DECL([dlopen_support], [enable_dlopen], [0], [Whether dlopen is supported]) _LT_DECL([dlopen_self], [enable_dlopen_self], [0], [Whether dlopen of programs is supported]) _LT_DECL([dlopen_self_static], [enable_dlopen_self_static], [0], [Whether dlopen of statically linked programs is supported]) ])# LT_SYS_DLOPEN_SELF # Old name: AU_ALIAS([AC_LIBTOOL_DLOPEN_SELF], [LT_SYS_DLOPEN_SELF]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF], []) # _LT_COMPILER_C_O([TAGNAME]) # --------------------------- # Check to see if options -c and -o are simultaneously supported by compiler. # This macro does not hard code the compiler like AC_PROG_CC_C_O. m4_defun([_LT_COMPILER_C_O], [m4_require([_LT_DECL_SED])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_TAG_COMPILER])dnl AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext], [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)], [_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no $RM -r conftest 2>/dev/null mkdir conftest cd conftest mkdir out echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-o out/conftest2.$ac_objext" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&AS_MESSAGE_LOG_FD echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes fi fi chmod u+w . 2>&AS_MESSAGE_LOG_FD $RM conftest* # SGI C++ compiler will create directory out/ii_files/ for # template instantiation test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files $RM out/* && rmdir out cd .. $RM -r conftest $RM conftest* ]) _LT_TAGDECL([compiler_c_o], [lt_cv_prog_compiler_c_o], [1], [Does compiler simultaneously support -c and -o options?]) ])# _LT_COMPILER_C_O # _LT_COMPILER_FILE_LOCKS([TAGNAME]) # ---------------------------------- # Check to see if we can do hard links to lock some files if needed m4_defun([_LT_COMPILER_FILE_LOCKS], [m4_require([_LT_ENABLE_LOCK])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl _LT_COMPILER_C_O([$1]) hard_links="nottested" if test "$_LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then # do not overwrite the value of need_locks provided by the user AC_MSG_CHECKING([if we can lock with hard links]) hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no AC_MSG_RESULT([$hard_links]) if test "$hard_links" = no; then AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe]) need_locks=warn fi else need_locks=no fi _LT_DECL([], [need_locks], [1], [Must we lock files when doing compilation?]) ])# _LT_COMPILER_FILE_LOCKS # _LT_CHECK_OBJDIR # ---------------- m4_defun([_LT_CHECK_OBJDIR], [AC_CACHE_CHECK([for objdir], [lt_cv_objdir], [rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then lt_cv_objdir=.libs else # MS-DOS does not allow filenames that begin with a dot. lt_cv_objdir=_libs fi rmdir .libs 2>/dev/null]) objdir=$lt_cv_objdir _LT_DECL([], [objdir], [0], [The name of the directory that contains temporary libtool files])dnl m4_pattern_allow([LT_OBJDIR])dnl AC_DEFINE_UNQUOTED(LT_OBJDIR, "$lt_cv_objdir/", [Define to the sub-directory in which libtool stores uninstalled libraries.]) ])# _LT_CHECK_OBJDIR # _LT_LINKER_HARDCODE_LIBPATH([TAGNAME]) # -------------------------------------- # Check hardcoding attributes. m4_defun([_LT_LINKER_HARDCODE_LIBPATH], [AC_MSG_CHECKING([how to hardcode library paths into programs]) _LT_TAGVAR(hardcode_action, $1)= if test -n "$_LT_TAGVAR(hardcode_libdir_flag_spec, $1)" || test -n "$_LT_TAGVAR(runpath_var, $1)" || test "X$_LT_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then # We can hardcode non-existent directories. if test "$_LT_TAGVAR(hardcode_direct, $1)" != no && # If the only mechanism to avoid hardcoding is shlibpath_var, we # have to relink, otherwise we might link with an installed library # when we should be linking with a yet-to-be-installed one ## test "$_LT_TAGVAR(hardcode_shlibpath_var, $1)" != no && test "$_LT_TAGVAR(hardcode_minus_L, $1)" != no; then # Linking always hardcodes the temporary library directory. _LT_TAGVAR(hardcode_action, $1)=relink else # We can link without hardcoding, and we can hardcode nonexisting dirs. _LT_TAGVAR(hardcode_action, $1)=immediate fi else # We cannot hardcode anything, or else we can only hardcode existing # directories. _LT_TAGVAR(hardcode_action, $1)=unsupported fi AC_MSG_RESULT([$_LT_TAGVAR(hardcode_action, $1)]) if test "$_LT_TAGVAR(hardcode_action, $1)" = relink || test "$_LT_TAGVAR(inherit_rpath, $1)" = yes; then # Fast installation is not supported enable_fast_install=no elif test "$shlibpath_overrides_runpath" = yes || test "$enable_shared" = no; then # Fast installation is not necessary enable_fast_install=needless fi _LT_TAGDECL([], [hardcode_action], [0], [How to hardcode a shared library path into an executable]) ])# _LT_LINKER_HARDCODE_LIBPATH # _LT_CMD_STRIPLIB # ---------------- m4_defun([_LT_CMD_STRIPLIB], [m4_require([_LT_DECL_EGREP]) striplib= old_striplib= AC_MSG_CHECKING([whether stripping libraries is possible]) if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" test -z "$striplib" && striplib="$STRIP --strip-unneeded" AC_MSG_RESULT([yes]) else # FIXME - insert some real tests, host_os isn't really good enough case $host_os in darwin*) if test -n "$STRIP" ; then striplib="$STRIP -x" old_striplib="$STRIP -S" AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) fi ;; *) AC_MSG_RESULT([no]) ;; esac fi _LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) _LT_DECL([], [striplib], [1]) ])# _LT_CMD_STRIPLIB # _LT_SYS_DYNAMIC_LINKER([TAG]) # ----------------------------- # PORTME Fill in your ld.so characteristics m4_defun([_LT_SYS_DYNAMIC_LINKER], [AC_REQUIRE([AC_CANONICAL_HOST])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_OBJDUMP])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_CHECK_SHELL_FEATURES])dnl AC_MSG_CHECKING([dynamic linker characteristics]) m4_if([$1], [], [ if test "$GCC" = yes; then case $host_os in darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; *) lt_awk_arg="/^libraries:/" ;; esac case $host_os in mingw* | cegcc*) lt_sed_strip_eq="s,=\([[A-Za-z]]:\),\1,g" ;; *) lt_sed_strip_eq="s,=/,/,g" ;; esac lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` case $lt_search_path_spec in *\;*) # if the path contains ";" then we assume it to be the separator # otherwise default to the standard path separator (i.e. ":") - it is # assumed that no part of a normal pathname contains ";" but that should # okay in the real world where ";" in dirpaths is itself problematic. lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` ;; *) lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` ;; esac # Ok, now we have the path, separated by spaces, we can step through it # and add multilib dir if necessary. lt_tmp_lt_search_path_spec= lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` for lt_sys_path in $lt_search_path_spec; do if test -d "$lt_sys_path/$lt_multi_os_dir"; then lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" else test -d "$lt_sys_path" && \ lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" fi done lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' BEGIN {RS=" "; FS="/|\n";} { lt_foo=""; lt_count=0; for (lt_i = NF; lt_i > 0; lt_i--) { if ($lt_i != "" && $lt_i != ".") { if ($lt_i == "..") { lt_count++; } else { if (lt_count == 0) { lt_foo="/" $lt_i lt_foo; } else { lt_count--; } } } } if (lt_foo != "") { lt_freq[[lt_foo]]++; } if (lt_freq[[lt_foo]] == 1) { print lt_foo; } }'` # AWK program above erroneously prepends '/' to C:/dos/paths # for these hosts. case $host_os in mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ $SED 's,/\([[A-Za-z]]:\),\1,g'` ;; esac sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` else sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" fi]) library_names_spec= libname_spec='lib$name' soname_spec= shrext_cmds=".so" postinstall_cmds= postuninstall_cmds= finish_cmds= finish_eval= shlibpath_var= shlibpath_overrides_runpath=unknown version_type=none dynamic_linker="$host_os ld.so" sys_lib_dlsearch_path_spec="/lib /usr/lib" need_lib_prefix=unknown hardcode_into_libs=no # when you set need_version to no, make sure it does not cause -set_version # flags to be left without arguments need_version=unknown case $host_os in aix3*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' shlibpath_var=LIBPATH # AIX 3 has no versioning support, so we append a major version to the name. soname_spec='${libname}${release}${shared_ext}$major' ;; aix[[4-9]]*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no hardcode_into_libs=yes if test "$host_cpu" = ia64; then # AIX 5 supports IA64 library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH else # With GCC up to 2.95.x, collect2 would create an import file # for dependence libraries. The import file would start with # the line `#! .'. This would cause the generated library to # depend on `.', always an invalid library. This was fixed in # development snapshots of GCC prior to 3.0. case $host_os in aix4 | aix4.[[01]] | aix4.[[01]].*) if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' echo ' yes ' echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then : else can_build_shared=no fi ;; esac # AIX (on Power*) has no versioning support, so currently we can not hardcode correct # soname into executable. Probably we can add versioning support to # collect2, so additional links can be useful in future. if test "$aix_use_runtimelinking" = yes; then # If using run time linking (on AIX 4.2 or later) use lib.so # instead of lib.a to let people know that these are not # typical AIX shared libraries. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' else # We preserve .a as extension for shared libraries through AIX4.2 # and later when we are not doing run time linking. library_names_spec='${libname}${release}.a $libname.a' soname_spec='${libname}${release}${shared_ext}$major' fi shlibpath_var=LIBPATH fi ;; amigaos*) case $host_cpu in powerpc) # Since July 2007 AmigaOS4 officially supports .so libraries. # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' ;; m68k) library_names_spec='$libname.ixlibrary $libname.a' # Create ${libname}_ixlibrary.a entries in /sys/libs. finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' ;; esac ;; beos*) library_names_spec='${libname}${shared_ext}' dynamic_linker="$host_os ld.so" shlibpath_var=LIBRARY_PATH ;; bsdi[[45]]*) version_type=linux # correct to gnu/linux during the next big refactor need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" # the default ld.so.conf also contains /usr/contrib/lib and # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow # libtool to hard-code these into programs ;; cygwin* | mingw* | pw32* | cegcc*) version_type=windows shrext_cmds=".dll" need_version=no need_lib_prefix=no case $GCC,$cc_basename in yes,*) # gcc library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds postinstall_cmds='base_file=`basename \${file}`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname~ chmod a+x \$dldir/$dlname~ if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' m4_if([$1], [],[ sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) ;; mingw* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' ;; esac dynamic_linker='Win32 ld.exe' ;; *,cl*) # Native MSVC libname_spec='$name' soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}' library_names_spec='${libname}.dll.lib' case $build_os in mingw*) sys_lib_search_path_spec= lt_save_ifs=$IFS IFS=';' for lt_path in $LIB do IFS=$lt_save_ifs # Let DOS variable expansion print the short 8.3 style file name. lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" done IFS=$lt_save_ifs # Convert to MSYS style. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` ;; cygwin*) # Convert to unix form, then to dos form, then back to unix form # but this time dos style (no spaces!) so that the unix form looks # like /cygdrive/c/PROGRA~1:/cygdr... sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` ;; *) sys_lib_search_path_spec="$LIB" if $ECHO "$sys_lib_search_path_spec" | [$GREP ';[c-zC-Z]:/' >/dev/null]; then # It is most probably a Windows format PATH. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` else sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` fi # FIXME: find the short name or the path components, as spaces are # common. (e.g. "Program Files" -> "PROGRA~1") ;; esac # DLL is installed to $(libdir)/../bin by postinstall_cmds postinstall_cmds='base_file=`basename \${file}`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes dynamic_linker='Win32 link.exe' ;; *) # Assume MSVC wrapper library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib' dynamic_linker='Win32 ld.exe' ;; esac # FIXME: first we should search . and the directory the executable is in shlibpath_var=PATH ;; darwin* | rhapsody*) dynamic_linker="$host_os dyld" version_type=darwin need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' soname_spec='${libname}${release}${major}$shared_ext' shlibpath_overrides_runpath=yes shlibpath_var=DYLD_LIBRARY_PATH shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' m4_if([$1], [],[ sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' ;; dgux*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; freebsd* | dragonfly*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then objformat=`/usr/bin/objformat` else case $host_os in freebsd[[23]].*) objformat=aout ;; *) objformat=elf ;; esac fi version_type=freebsd-$objformat case $version_type in freebsd-elf*) library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' need_version=no need_lib_prefix=no ;; freebsd-*) library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' need_version=yes ;; esac shlibpath_var=LD_LIBRARY_PATH case $host_os in freebsd2.*) shlibpath_overrides_runpath=yes ;; freebsd3.[[01]]* | freebsdelf3.[[01]]*) shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \ freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1) shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; *) # from 4.6 on, and DragonFly shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; esac ;; gnu*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; haiku*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no dynamic_linker="$host_os runtime_loader" library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LIBRARY_PATH shlibpath_overrides_runpath=yes sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' hardcode_into_libs=yes ;; hpux9* | hpux10* | hpux11*) # Give a soname corresponding to the major version so that dld.sl refuses to # link against other versions. version_type=sunos need_lib_prefix=no need_version=no case $host_cpu in ia64*) shrext_cmds='.so' hardcode_into_libs=yes dynamic_linker="$host_os dld.so" shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' if test "X$HPUX_IA64_MODE" = X32; then sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" else sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" fi sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; hppa*64*) shrext_cmds='.sl' hardcode_into_libs=yes dynamic_linker="$host_os dld.sl" shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; *) shrext_cmds='.sl' dynamic_linker="$host_os dld.sl" shlibpath_var=SHLIB_PATH shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' ;; esac # HP-UX runs *really* slowly unless shared libraries are mode 555, ... postinstall_cmds='chmod 555 $lib' # or fails outright, so override atomically: install_override_mode=555 ;; interix[[3-9]]*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; irix5* | irix6* | nonstopux*) case $host_os in nonstopux*) version_type=nonstopux ;; *) if test "$lt_cv_prog_gnu_ld" = yes; then version_type=linux # correct to gnu/linux during the next big refactor else version_type=irix fi ;; esac need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' case $host_os in irix5* | nonstopux*) libsuff= shlibsuff= ;; *) case $LD in # libtool.m4 will add one of these switches to LD *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= libmagic=32-bit;; *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 libmagic=N32;; *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 libmagic=64-bit;; *) libsuff= shlibsuff= libmagic=never-match;; esac ;; esac shlibpath_var=LD_LIBRARY${shlibsuff}_PATH shlibpath_overrides_runpath=no sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" hardcode_into_libs=yes ;; # No shared lib support for Linux oldld, aout, or coff. linux*oldld* | linux*aout* | linux*coff*) dynamic_linker=no ;; # This must be glibc/ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH AC_CACHE_VAL([lt_cv_shlibpath_overrides_runpath], [lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir eval "libdir=/foo; wl=\"$_LT_TAGVAR(lt_prog_compiler_wl, $1)\"; \ LDFLAGS=\"\$LDFLAGS $_LT_TAGVAR(hardcode_libdir_flag_spec, $1)\"" AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])], [AS_IF([ ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null], [lt_cv_shlibpath_overrides_runpath=yes])]) LDFLAGS=$save_LDFLAGS libdir=$save_libdir ]) shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath # This implies no fast_install, which is unacceptable. # Some rework will be needed to allow for fast_install # before this can be enabled. hardcode_into_libs=yes # Append ld.so.conf contents to the search path if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on # powerpc, because MkLinux only supported shared libraries with the # GNU dynamic linker. Since this was broken with cross compilers, # most powerpc-linux boxes support dynamic linking these days and # people can always --disable-shared, the test was removed, and we # assume the GNU/Linux dynamic linker is in use. dynamic_linker='GNU/Linux ld.so' ;; netbsd*) version_type=sunos need_lib_prefix=no need_version=no if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' dynamic_linker='NetBSD (a.out) ld.so' else library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='NetBSD ld.elf_so' fi shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; newsos6) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes ;; *nto* | *qnx*) version_type=qnx need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='ldqnx.so' ;; openbsd*) version_type=sunos sys_lib_dlsearch_path_spec="/usr/lib" need_lib_prefix=no # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. case $host_os in openbsd3.3 | openbsd3.3.*) need_version=yes ;; *) need_version=no ;; esac library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' shlibpath_var=LD_LIBRARY_PATH if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then case $host_os in openbsd2.[[89]] | openbsd2.[[89]].*) shlibpath_overrides_runpath=no ;; *) shlibpath_overrides_runpath=yes ;; esac else shlibpath_overrides_runpath=yes fi ;; os2*) libname_spec='$name' shrext_cmds=".dll" need_lib_prefix=no library_names_spec='$libname${shared_ext} $libname.a' dynamic_linker='OS/2 ld.exe' shlibpath_var=LIBPATH ;; osf3* | osf4* | osf5*) version_type=osf need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" ;; rdos*) dynamic_linker=no ;; solaris*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes # ldd complains unless libraries are executable postinstall_cmds='chmod +x $lib' ;; sunos4*) version_type=sunos library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes if test "$with_gnu_ld" = yes; then need_lib_prefix=no fi need_version=yes ;; sysv4 | sysv4.3*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH case $host_vendor in sni) shlibpath_overrides_runpath=no need_lib_prefix=no runpath_var=LD_RUN_PATH ;; siemens) need_lib_prefix=no ;; motorola) need_lib_prefix=no need_version=no shlibpath_overrides_runpath=no sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' ;; esac ;; sysv4*MP*) if test -d /usr/nec ;then version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' soname_spec='$libname${shared_ext}.$major' shlibpath_var=LD_LIBRARY_PATH fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) version_type=freebsd-elf need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes if test "$with_gnu_ld" = yes; then sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' else sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' case $host_os in sco3.2v5*) sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" ;; esac fi sys_lib_dlsearch_path_spec='/usr/lib' ;; tpf*) # TPF is a cross-target only. Preferred cross-host = GNU/Linux. version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; uts4*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; *) dynamic_linker=no ;; esac AC_MSG_RESULT([$dynamic_linker]) test "$dynamic_linker" = no && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" if test "$GCC" = yes; then variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" fi if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" fi if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" fi _LT_DECL([], [variables_saved_for_relink], [1], [Variables whose values should be saved in libtool wrapper scripts and restored at link time]) _LT_DECL([], [need_lib_prefix], [0], [Do we need the "lib" prefix for modules?]) _LT_DECL([], [need_version], [0], [Do we need a version for libraries?]) _LT_DECL([], [version_type], [0], [Library versioning type]) _LT_DECL([], [runpath_var], [0], [Shared library runtime path variable]) _LT_DECL([], [shlibpath_var], [0],[Shared library path variable]) _LT_DECL([], [shlibpath_overrides_runpath], [0], [Is shlibpath searched before the hard-coded library search path?]) _LT_DECL([], [libname_spec], [1], [Format of library name prefix]) _LT_DECL([], [library_names_spec], [1], [[List of archive names. First name is the real one, the rest are links. The last name is the one that the linker finds with -lNAME]]) _LT_DECL([], [soname_spec], [1], [[The coded name of the library, if different from the real name]]) _LT_DECL([], [install_override_mode], [1], [Permission mode override for installation of shared libraries]) _LT_DECL([], [postinstall_cmds], [2], [Command to use after installation of a shared archive]) _LT_DECL([], [postuninstall_cmds], [2], [Command to use after uninstallation of a shared archive]) _LT_DECL([], [finish_cmds], [2], [Commands used to finish a libtool library installation in a directory]) _LT_DECL([], [finish_eval], [1], [[As "finish_cmds", except a single script fragment to be evaled but not shown]]) _LT_DECL([], [hardcode_into_libs], [0], [Whether we should hardcode library paths into libraries]) _LT_DECL([], [sys_lib_search_path_spec], [2], [Compile-time system search path for libraries]) _LT_DECL([], [sys_lib_dlsearch_path_spec], [2], [Run-time system search path for libraries]) ])# _LT_SYS_DYNAMIC_LINKER # _LT_PATH_TOOL_PREFIX(TOOL) # -------------------------- # find a file program which can recognize shared library AC_DEFUN([_LT_PATH_TOOL_PREFIX], [m4_require([_LT_DECL_EGREP])dnl AC_MSG_CHECKING([for $1]) AC_CACHE_VAL(lt_cv_path_MAGIC_CMD, [case $MAGIC_CMD in [[\\/*] | ?:[\\/]*]) lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. ;; *) lt_save_MAGIC_CMD="$MAGIC_CMD" lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR dnl $ac_dummy forces splitting on constant user-supplied paths. dnl POSIX.2 word splitting is done only on the output of word expansions, dnl not every word. This closes a longstanding sh security hole. ac_dummy="m4_if([$2], , $PATH, [$2])" for ac_dir in $ac_dummy; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$1; then lt_cv_path_MAGIC_CMD="$ac_dir/$1" if test -n "$file_magic_test_file"; then case $deplibs_check_method in "file_magic "*) file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | $EGREP "$file_magic_regex" > /dev/null; then : else cat <<_LT_EOF 1>&2 *** Warning: the command libtool uses to detect shared libraries, *** $file_magic_cmd, produces output that libtool cannot recognize. *** The result is that libtool may fail to recognize shared libraries *** as such. This will affect the creation of libtool libraries that *** depend on shared libraries, but programs linked with such libtool *** libraries will work regardless of this problem. Nevertheless, you *** may want to report the problem to your system manager and/or to *** bug-libtool@gnu.org _LT_EOF fi ;; esac fi break fi done IFS="$lt_save_ifs" MAGIC_CMD="$lt_save_MAGIC_CMD" ;; esac]) MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if test -n "$MAGIC_CMD"; then AC_MSG_RESULT($MAGIC_CMD) else AC_MSG_RESULT(no) fi _LT_DECL([], [MAGIC_CMD], [0], [Used to examine libraries when file_magic_cmd begins with "file"])dnl ])# _LT_PATH_TOOL_PREFIX # Old name: AU_ALIAS([AC_PATH_TOOL_PREFIX], [_LT_PATH_TOOL_PREFIX]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_PATH_TOOL_PREFIX], []) # _LT_PATH_MAGIC # -------------- # find a file program which can recognize a shared library m4_defun([_LT_PATH_MAGIC], [_LT_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH) if test -z "$lt_cv_path_MAGIC_CMD"; then if test -n "$ac_tool_prefix"; then _LT_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH) else MAGIC_CMD=: fi fi ])# _LT_PATH_MAGIC # LT_PATH_LD # ---------- # find the pathname to the GNU or non-GNU linker AC_DEFUN([LT_PATH_LD], [AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_PROG_ECHO_BACKSLASH])dnl AC_ARG_WITH([gnu-ld], [AS_HELP_STRING([--with-gnu-ld], [assume the C compiler uses GNU ld @<:@default=no@:>@])], [test "$withval" = no || with_gnu_ld=yes], [with_gnu_ld=no])dnl ac_prog=ld if test "$GCC" = yes; then # Check if gcc -print-prog-name=ld gives a path. AC_MSG_CHECKING([for ld used by $CC]) case $host in *-*-mingw*) # gcc leaves a trailing carriage return which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; esac case $ac_prog in # Accept absolute paths. [[\\/]]* | ?:[[\\/]]*) re_direlt='/[[^/]][[^/]]*/\.\./' # Canonicalize the pathname of ld ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; "") # If it fails, then pretend we aren't using GCC. ac_prog=ld ;; *) # If it is relative, then search for the first ld in PATH. with_gnu_ld=unknown ;; esac elif test "$with_gnu_ld" = yes; then AC_MSG_CHECKING([for GNU ld]) else AC_MSG_CHECKING([for non-GNU ld]) fi AC_CACHE_VAL(lt_cv_path_LD, [if test -z "$LD"; then lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then lt_cv_path_LD="$ac_dir/$ac_prog" # Check to see if the program is GNU ld. I'd rather use --version, # but apparently some variants of GNU ld only accept -v. # Break only if it was the GNU/non-GNU ld that we prefer. case `"$lt_cv_path_LD" -v 2>&1 &1 /dev/null 2>&1; then lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' else # Keep this pattern in sync with the one in func_win32_libid. lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' lt_cv_file_magic_cmd='$OBJDUMP -f' fi ;; cegcc*) # use the weaker test based on 'objdump'. See mingw*. lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' lt_cv_file_magic_cmd='$OBJDUMP -f' ;; darwin* | rhapsody*) lt_cv_deplibs_check_method=pass_all ;; freebsd* | dragonfly*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then case $host_cpu in i*86 ) # Not sure whether the presence of OpenBSD here was a mistake. # Let's accept both of them until this is cleared up. lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` ;; esac else lt_cv_deplibs_check_method=pass_all fi ;; gnu*) lt_cv_deplibs_check_method=pass_all ;; haiku*) lt_cv_deplibs_check_method=pass_all ;; hpux10.20* | hpux11*) lt_cv_file_magic_cmd=/usr/bin/file case $host_cpu in ia64*) lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so ;; hppa*64*) [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]'] lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl ;; *) lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]]\.[[0-9]]) shared library' lt_cv_file_magic_test_file=/usr/lib/libc.sl ;; esac ;; interix[[3-9]]*) # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$' ;; irix5* | irix6* | nonstopux*) case $LD in *-32|*"-32 ") libmagic=32-bit;; *-n32|*"-n32 ") libmagic=N32;; *-64|*"-64 ") libmagic=64-bit;; *) libmagic=never-match;; esac lt_cv_deplibs_check_method=pass_all ;; # This must be glibc/ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) lt_cv_deplibs_check_method=pass_all ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$' fi ;; newos6*) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=/usr/lib/libnls.so ;; *nto* | *qnx*) lt_cv_deplibs_check_method=pass_all ;; openbsd*) if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$' fi ;; osf3* | osf4* | osf5*) lt_cv_deplibs_check_method=pass_all ;; rdos*) lt_cv_deplibs_check_method=pass_all ;; solaris*) lt_cv_deplibs_check_method=pass_all ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) lt_cv_deplibs_check_method=pass_all ;; sysv4 | sysv4.3*) case $host_vendor in motorola) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]' lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` ;; ncr) lt_cv_deplibs_check_method=pass_all ;; sequent) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )' ;; sni) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib" lt_cv_file_magic_test_file=/lib/libc.so ;; siemens) lt_cv_deplibs_check_method=pass_all ;; pc) lt_cv_deplibs_check_method=pass_all ;; esac ;; tpf*) lt_cv_deplibs_check_method=pass_all ;; esac ]) file_magic_glob= want_nocaseglob=no if test "$build" = "$host"; then case $host_os in mingw* | pw32*) if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then want_nocaseglob=yes else file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[[\1]]\/[[\1]]\/g;/g"` fi ;; esac fi file_magic_cmd=$lt_cv_file_magic_cmd deplibs_check_method=$lt_cv_deplibs_check_method test -z "$deplibs_check_method" && deplibs_check_method=unknown _LT_DECL([], [deplibs_check_method], [1], [Method to check whether dependent libraries are shared objects]) _LT_DECL([], [file_magic_cmd], [1], [Command to use when deplibs_check_method = "file_magic"]) _LT_DECL([], [file_magic_glob], [1], [How to find potential files when deplibs_check_method = "file_magic"]) _LT_DECL([], [want_nocaseglob], [1], [Find potential files using nocaseglob when deplibs_check_method = "file_magic"]) ])# _LT_CHECK_MAGIC_METHOD # LT_PATH_NM # ---------- # find the pathname to a BSD- or MS-compatible name lister AC_DEFUN([LT_PATH_NM], [AC_REQUIRE([AC_PROG_CC])dnl AC_CACHE_CHECK([for BSD- or MS-compatible name lister (nm)], lt_cv_path_NM, [if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM="$NM" else lt_nm_to_check="${ac_tool_prefix}nm" if test -n "$ac_tool_prefix" && test "$build" = "$host"; then lt_nm_to_check="$lt_nm_to_check nm" fi for lt_tmp_nm in $lt_nm_to_check; do lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. tmp_nm="$ac_dir/$lt_tmp_nm" if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then # Check to see if the nm accepts a BSD-compat flag. # Adding the `sed 1q' prevents false positives on HP-UX, which says: # nm: unknown option "B" ignored # Tru64's nm complains that /dev/null is an invalid object file case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in */dev/null* | *'Invalid file or object type'*) lt_cv_path_NM="$tmp_nm -B" break ;; *) case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in */dev/null*) lt_cv_path_NM="$tmp_nm -p" break ;; *) lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but continue # so that we can try to find one that supports BSD flags ;; esac ;; esac fi done IFS="$lt_save_ifs" done : ${lt_cv_path_NM=no} fi]) if test "$lt_cv_path_NM" != "no"; then NM="$lt_cv_path_NM" else # Didn't find any BSD compatible name lister, look for dumpbin. if test -n "$DUMPBIN"; then : # Let the user override the test. else AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :) case `$DUMPBIN -symbols /dev/null 2>&1 | sed '1q'` in *COFF*) DUMPBIN="$DUMPBIN -symbols" ;; *) DUMPBIN=: ;; esac fi AC_SUBST([DUMPBIN]) if test "$DUMPBIN" != ":"; then NM="$DUMPBIN" fi fi test -z "$NM" && NM=nm AC_SUBST([NM]) _LT_DECL([], [NM], [1], [A BSD- or MS-compatible name lister])dnl AC_CACHE_CHECK([the name lister ($NM) interface], [lt_cv_nm_interface], [lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&AS_MESSAGE_LOG_FD) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&AS_MESSAGE_LOG_FD (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&AS_MESSAGE_LOG_FD) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&AS_MESSAGE_LOG_FD (eval echo "\"\$as_me:$LINENO: output\"" >&AS_MESSAGE_LOG_FD) cat conftest.out >&AS_MESSAGE_LOG_FD if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" fi rm -f conftest*]) ])# LT_PATH_NM # Old names: AU_ALIAS([AM_PROG_NM], [LT_PATH_NM]) AU_ALIAS([AC_PROG_NM], [LT_PATH_NM]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_PROG_NM], []) dnl AC_DEFUN([AC_PROG_NM], []) # _LT_CHECK_SHAREDLIB_FROM_LINKLIB # -------------------------------- # how to determine the name of the shared library # associated with a specific link library. # -- PORTME fill in with the dynamic library characteristics m4_defun([_LT_CHECK_SHAREDLIB_FROM_LINKLIB], [m4_require([_LT_DECL_EGREP]) m4_require([_LT_DECL_OBJDUMP]) m4_require([_LT_DECL_DLLTOOL]) AC_CACHE_CHECK([how to associate runtime and link libraries], lt_cv_sharedlib_from_linklib_cmd, [lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in cygwin* | mingw* | pw32* | cegcc*) # two different shell functions defined in ltmain.sh # decide which to use based on capabilities of $DLLTOOL case `$DLLTOOL --help 2>&1` in *--identify-strict*) lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib ;; *) lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback ;; esac ;; *) # fallback: assume linklib IS sharedlib lt_cv_sharedlib_from_linklib_cmd="$ECHO" ;; esac ]) sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO _LT_DECL([], [sharedlib_from_linklib_cmd], [1], [Command to associate shared and link libraries]) ])# _LT_CHECK_SHAREDLIB_FROM_LINKLIB # _LT_PATH_MANIFEST_TOOL # ---------------------- # locate the manifest tool m4_defun([_LT_PATH_MANIFEST_TOOL], [AC_CHECK_TOOL(MANIFEST_TOOL, mt, :) test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_mainfest_tool], [lt_cv_path_mainfest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out cat conftest.err >&AS_MESSAGE_LOG_FD if $GREP 'Manifest Tool' conftest.out > /dev/null; then lt_cv_path_mainfest_tool=yes fi rm -f conftest*]) if test "x$lt_cv_path_mainfest_tool" != xyes; then MANIFEST_TOOL=: fi _LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl ])# _LT_PATH_MANIFEST_TOOL # LT_LIB_M # -------- # check for math library AC_DEFUN([LT_LIB_M], [AC_REQUIRE([AC_CANONICAL_HOST])dnl LIBM= case $host in *-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) # These system don't have libm, or don't need it ;; *-ncr-sysv4.3*) AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw") AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm") ;; *) AC_CHECK_LIB(m, cos, LIBM="-lm") ;; esac AC_SUBST([LIBM]) ])# LT_LIB_M # Old name: AU_ALIAS([AC_CHECK_LIBM], [LT_LIB_M]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_CHECK_LIBM], []) # _LT_COMPILER_NO_RTTI([TAGNAME]) # ------------------------------- m4_defun([_LT_COMPILER_NO_RTTI], [m4_require([_LT_TAG_COMPILER])dnl _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= if test "$GCC" = yes; then case $cc_basename in nvcc*) _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -Xcompiler -fno-builtin' ;; *) _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' ;; esac _LT_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions], lt_cv_prog_compiler_rtti_exceptions, [-fno-rtti -fno-exceptions], [], [_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"]) fi _LT_TAGDECL([no_builtin_flag], [lt_prog_compiler_no_builtin_flag], [1], [Compiler flag to turn off builtin functions]) ])# _LT_COMPILER_NO_RTTI # _LT_CMD_GLOBAL_SYMBOLS # ---------------------- m4_defun([_LT_CMD_GLOBAL_SYMBOLS], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_PROG_CC])dnl AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([LT_PATH_NM])dnl AC_REQUIRE([LT_PATH_LD])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_TAG_COMPILER])dnl # Check for command to grab the raw symbol name followed by C symbol from nm. AC_MSG_CHECKING([command to parse $NM output from $compiler object]) AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe], [ # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] # Character class describing NM global symbol codes. symcode='[[BCDEGRST]]' # Regexp to match symbols that can be accessed directly from C. sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)' # Define system-specific variables. case $host_os in aix*) symcode='[[BCDT]]' ;; cygwin* | mingw* | pw32* | cegcc*) symcode='[[ABCDGISTW]]' ;; hpux*) if test "$host_cpu" = ia64; then symcode='[[ABCDEGRST]]' fi ;; irix* | nonstopux*) symcode='[[BCDEGRST]]' ;; osf*) symcode='[[BCDEGQRST]]' ;; solaris*) symcode='[[BDRT]]' ;; sco3.2v5*) symcode='[[DT]]' ;; sysv4.2uw2*) symcode='[[DT]]' ;; sysv5* | sco5v6* | unixware* | OpenUNIX*) symcode='[[ABDT]]' ;; sysv4) symcode='[[DFNSTU]]' ;; esac # If we're using GNU nm, then use its standard symbol codes. case `$NM -V 2>&1` in *GNU* | *'with BFD'*) symcode='[[ABCDGIRSTW]]' ;; esac # Transform an extracted symbol line into a proper C declaration. # Some systems (esp. on ia64) link data and code symbols differently, # so use this general approach. lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" # Transform an extracted symbol line into symbol name and symbol address lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\)[[ ]]*$/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p'" lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([[^ ]]*\)[[ ]]*$/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \(lib[[^ ]]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/ {\"lib\2\", (void *) \&\2},/p'" # Handle CRLF in mingw tool chain opt_cr= case $build_os in mingw*) opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp ;; esac # Try without a prefix underscore, then with it. for ac_symprfx in "" "_"; do # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. symxfrm="\\1 $ac_symprfx\\2 \\2" # Write the raw and C identifiers. if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Fake it for dumpbin and say T for any non-static function # and D for any global variable. # Also find C++ and __fastcall symbols from MSVC++, # which start with @ or ?. lt_cv_sys_global_symbol_pipe="$AWK ['"\ " {last_section=section; section=\$ 3};"\ " /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ " /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ " \$ 0!~/External *\|/{next};"\ " / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ " {if(hide[section]) next};"\ " {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ " {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ " s[1]~/^[@?]/{print s[1], s[1]; next};"\ " s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ " ' prfx=^$ac_symprfx]" else lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" fi lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" # Check to see that the pipe works correctly. pipe_works=no rm -f conftest* cat > conftest.$ac_ext <<_LT_EOF #ifdef __cplusplus extern "C" { #endif char nm_test_var; void nm_test_func(void); void nm_test_func(void){} #ifdef __cplusplus } #endif int main(){nm_test_var='a';nm_test_func();return(0);} _LT_EOF if AC_TRY_EVAL(ac_compile); then # Now try to grab the symbols. nlist=conftest.nm if AC_TRY_EVAL(NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" else rm -f "$nlist"T fi # Make sure that we snagged all the symbols we need. if $GREP ' nm_test_var$' "$nlist" >/dev/null; then if $GREP ' nm_test_func$' "$nlist" >/dev/null; then cat <<_LT_EOF > conftest.$ac_ext /* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) /* DATA imports from DLLs on WIN32 con't be const, because runtime relocations are performed -- see ld's documentation on pseudo-relocs. */ # define LT@&t@_DLSYM_CONST #elif defined(__osf__) /* This system does not cope well with relocations in const data. */ # define LT@&t@_DLSYM_CONST #else # define LT@&t@_DLSYM_CONST const #endif #ifdef __cplusplus extern "C" { #endif _LT_EOF # Now generate the symbol file. eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' cat <<_LT_EOF >> conftest.$ac_ext /* The mapping between symbol names and symbols. */ LT@&t@_DLSYM_CONST struct { const char *name; void *address; } lt__PROGRAM__LTX_preloaded_symbols[[]] = { { "@PROGRAM@", (void *) 0 }, _LT_EOF $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext cat <<\_LT_EOF >> conftest.$ac_ext {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt__PROGRAM__LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif _LT_EOF # Now try linking the two files. mv conftest.$ac_objext conftstm.$ac_objext lt_globsym_save_LIBS=$LIBS lt_globsym_save_CFLAGS=$CFLAGS LIBS="conftstm.$ac_objext" CFLAGS="$CFLAGS$_LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)" if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then pipe_works=yes fi LIBS=$lt_globsym_save_LIBS CFLAGS=$lt_globsym_save_CFLAGS else echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD fi else echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD fi else echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD fi else echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD cat conftest.$ac_ext >&5 fi rm -rf conftest* conftst* # Do not use the global_symbol_pipe unless it works. if test "$pipe_works" = yes; then break else lt_cv_sys_global_symbol_pipe= fi done ]) if test -z "$lt_cv_sys_global_symbol_pipe"; then lt_cv_sys_global_symbol_to_cdecl= fi if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then AC_MSG_RESULT(failed) else AC_MSG_RESULT(ok) fi # Response file support. if test "$lt_cv_nm_interface" = "MS dumpbin"; then nm_file_list_spec='@' elif $NM --help 2>/dev/null | grep '[[@]]FILE' >/dev/null; then nm_file_list_spec='@' fi _LT_DECL([global_symbol_pipe], [lt_cv_sys_global_symbol_pipe], [1], [Take the output of nm and produce a listing of raw symbols and C names]) _LT_DECL([global_symbol_to_cdecl], [lt_cv_sys_global_symbol_to_cdecl], [1], [Transform the output of nm in a proper C declaration]) _LT_DECL([global_symbol_to_c_name_address], [lt_cv_sys_global_symbol_to_c_name_address], [1], [Transform the output of nm in a C name address pair]) _LT_DECL([global_symbol_to_c_name_address_lib_prefix], [lt_cv_sys_global_symbol_to_c_name_address_lib_prefix], [1], [Transform the output of nm in a C name address pair when lib prefix is needed]) _LT_DECL([], [nm_file_list_spec], [1], [Specify filename containing input files for $NM]) ]) # _LT_CMD_GLOBAL_SYMBOLS # _LT_COMPILER_PIC([TAGNAME]) # --------------------------- m4_defun([_LT_COMPILER_PIC], [m4_require([_LT_TAG_COMPILER])dnl _LT_TAGVAR(lt_prog_compiler_wl, $1)= _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)= m4_if([$1], [CXX], [ # C++ specific cases for pic, static, wl, etc. if test "$GXX" = yes; then _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' case $host_os in aix*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the `-m68020' flag to GCC prevents building anything better, # like `-m68040'. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' ;; *djgpp*) # DJGPP does not support shared libraries at all _LT_TAGVAR(lt_prog_compiler_pic, $1)= ;; haiku*) # PIC is the default for Haiku. # The "-static" flag exists, but is broken. _LT_TAGVAR(lt_prog_compiler_static, $1)= ;; interix[[3-9]]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic fi ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac else case $host_os in aix[[4-9]]*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' else _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' fi ;; chorus*) case $cc_basename in cxch68*) # Green Hills C++ Compiler # _LT_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a" ;; esac ;; mingw* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; dgux*) case $cc_basename in ec++*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' ;; ghcx*) # Green Hills C++ Compiler _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; *) ;; esac ;; freebsd* | dragonfly*) # FreeBSD uses GNU C++ ;; hpux9* | hpux10* | hpux11*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' if test "$host_cpu" != ia64; then _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' fi ;; aCC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' ;; esac ;; *) ;; esac ;; interix*) # This is c89, which is MS Visual C++ (no shared libs) # Anyone wants to do a port? ;; irix5* | irix6* | nonstopux*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' # CC pic flag -KPIC is the default. ;; *) ;; esac ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in KCC*) # KAI C++ Compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; ecpc* ) # old Intel C++ for x86_64 which still supported -KPIC. _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; icpc* ) # Intel C++, used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; pgCC* | pgcpp*) # Portland Group C++ compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; cxx*) # Compaq C++ # Make sure the PIC flag is empty. It appears that all Alpha # Linux and Compaq Tru64 Unix objects are PIC. _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; xlc* | xlC* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL 8.0, 9.0 on PPC and BlueGene _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; esac ;; esac ;; lynxos*) ;; m88k*) ;; mvs*) case $cc_basename in cxx*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall' ;; *) ;; esac ;; netbsd*) ;; *qnx* | *nto*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; osf3* | osf4* | osf5*) case $cc_basename in KCC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,' ;; RCC*) # Rational C++ 2.4.1 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; cxx*) # Digital/Compaq C++ _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # Make sure the PIC flag is empty. It appears that all Alpha # Linux and Compaq Tru64 Unix objects are PIC. _LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; *) ;; esac ;; psos*) ;; solaris*) case $cc_basename in CC* | sunCC*) # Sun C++ 4.2, 5.x and Centerline C++ _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; gcx*) # Green Hills C++ Compiler _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' ;; *) ;; esac ;; sunos4*) case $cc_basename in CC*) # Sun C++ 4.x _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; lcc*) # Lucid _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' ;; *) ;; esac ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) case $cc_basename in CC*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; esac ;; tandem*) case $cc_basename in NCC*) # NonStop-UX NCC 3.20 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' ;; *) ;; esac ;; vxworks*) ;; *) _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; esac fi ], [ if test "$GCC" = yes; then _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' case $host_os in aix*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the `-m68020' flag to GCC prevents building anything better, # like `-m68040'. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common' ;; haiku*) # PIC is the default for Haiku. # The "-static" flag exists, but is broken. _LT_TAGVAR(lt_prog_compiler_static, $1)= ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac ;; interix[[3-9]]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; msdosdjgpp*) # Just because we use GCC doesn't mean we suddenly get shared libraries # on systems that don't support them. _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no enable_shared=no ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic fi ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' ;; esac case $cc_basename in nvcc*) # Cuda Compiler Driver 2.2 _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Xlinker ' if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then _LT_TAGVAR(lt_prog_compiler_pic, $1)="-Xcompiler $_LT_TAGVAR(lt_prog_compiler_pic, $1)" fi ;; esac else # PORTME Check for flag to pass linker flags through the system compiler. case $host_os in aix*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' else _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp' fi ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], [_LT_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT']) ;; hpux9* | hpux10* | hpux11*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but # not for PA HP-UX. case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)='+Z' ;; esac # Is there a better lt_prog_compiler_static that works with the bundled CC? _LT_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive' ;; irix5* | irix6* | nonstopux*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # PIC (with -KPIC) is the default. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in # old Intel for x86_64 which still supported -KPIC. ecc*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; # Lahey Fortran 8.1. lf95*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='--shared' _LT_TAGVAR(lt_prog_compiler_static, $1)='--static' ;; nagfor*) # NAG Fortran compiler _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,-Wl,,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) # Portland Group compilers (*not* the Pentium gcc compiler, # which looks to be a dead project) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; ccc*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # All Alpha code is PIC. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; xl* | bgxl* | bgf* | mpixl*) # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-qpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*) # Sun Fortran 8.3 passes all unrecognized flags to the linker _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='' ;; *Sun\ F* | *Sun*Fortran*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' ;; *Sun\ C*) # Sun C 5.9 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' ;; *Intel*\ [[CF]]*Compiler*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; *Portland\ Group*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fpic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; esac ;; esac ;; newsos6) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC -shared' ;; osf3* | osf4* | osf5*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' # All OSF/1 code is PIC. _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; rdos*) _LT_TAGVAR(lt_prog_compiler_static, $1)='-non_shared' ;; solaris*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' case $cc_basename in f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';; *) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';; esac ;; sunos4*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-PIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; sysv4 | sysv4.2uw2* | sysv4.3*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; sysv4*MP*) if test -d /usr/nec ;then _LT_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' fi ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; unicos*) _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; uts4*) _LT_TAGVAR(lt_prog_compiler_pic, $1)='-pic' _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic' ;; *) _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no ;; esac fi ]) case $host_os in # For platforms which do not support PIC, -DPIC is meaningless: *djgpp*) _LT_TAGVAR(lt_prog_compiler_pic, $1)= ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])" ;; esac AC_CACHE_CHECK([for $compiler option to produce PIC], [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)], [_LT_TAGVAR(lt_cv_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_prog_compiler_pic, $1)]) _LT_TAGVAR(lt_prog_compiler_pic, $1)=$_LT_TAGVAR(lt_cv_prog_compiler_pic, $1) # # Check to make sure the PIC flag actually works. # if test -n "$_LT_TAGVAR(lt_prog_compiler_pic, $1)"; then _LT_COMPILER_OPTION([if $compiler PIC flag $_LT_TAGVAR(lt_prog_compiler_pic, $1) works], [_LT_TAGVAR(lt_cv_prog_compiler_pic_works, $1)], [$_LT_TAGVAR(lt_prog_compiler_pic, $1)@&t@m4_if([$1],[],[ -DPIC],[m4_if([$1],[CXX],[ -DPIC],[])])], [], [case $_LT_TAGVAR(lt_prog_compiler_pic, $1) in "" | " "*) ;; *) _LT_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_TAGVAR(lt_prog_compiler_pic, $1)" ;; esac], [_LT_TAGVAR(lt_prog_compiler_pic, $1)= _LT_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no]) fi _LT_TAGDECL([pic_flag], [lt_prog_compiler_pic], [1], [Additional compiler flags for building library objects]) _LT_TAGDECL([wl], [lt_prog_compiler_wl], [1], [How to pass a linker flag through the compiler]) # # Check to make sure the static flag actually works. # wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_TAGVAR(lt_prog_compiler_static, $1)\" _LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works], _LT_TAGVAR(lt_cv_prog_compiler_static_works, $1), $lt_tmp_static_flag, [], [_LT_TAGVAR(lt_prog_compiler_static, $1)=]) _LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1], [Compiler flag to prevent dynamic linking]) ])# _LT_COMPILER_PIC # _LT_LINKER_SHLIBS([TAGNAME]) # ---------------------------- # See if the linker supports building shared libraries. m4_defun([_LT_LINKER_SHLIBS], [AC_REQUIRE([LT_PATH_LD])dnl AC_REQUIRE([LT_PATH_NM])dnl m4_require([_LT_PATH_MANIFEST_TOOL])dnl m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_DECL_SED])dnl m4_require([_LT_CMD_GLOBAL_SYMBOLS])dnl m4_require([_LT_TAG_COMPILER])dnl AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) m4_if([$1], [CXX], [ _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] case $host_os in aix[[4-9]]*) # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to AIX nm, but means don't demangle with GNU nm # Also, AIX nm treats weak defined symbols like other global defined # symbols, whereas GNU nm marks them as "W". if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' else _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' fi ;; pw32*) _LT_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds" ;; cygwin* | mingw* | cegcc*) case $cc_basename in cl*) _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] ;; esac ;; *) _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' ;; esac ], [ runpath_var= _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_cmds, $1)= _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(compiler_needs_object, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(old_archive_from_new_cmds, $1)= _LT_TAGVAR(old_archive_from_expsyms_cmds, $1)= _LT_TAGVAR(thread_safe_flag_spec, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= # include_expsyms should be a list of space-separated symbols to be *always* # included in the symbol list _LT_TAGVAR(include_expsyms, $1)= # exclude_expsyms can be an extended regexp of symbols to exclude # it will be wrapped by ` (' and `)$', so one must not match beginning or # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', # as well as any symbol that contains `d'. _LT_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*'] # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out # platforms (ab)use it in PIC code, but their linkers get confused if # the symbol is explicitly referenced. Since portable code cannot # rely on this symbol name, it's probably fine to never include it in # preloaded symbol tables. # Exclude shared library initialization/finalization symbols. dnl Note also adjust exclude_expsyms for C++ above. extract_expsyms_cmds= case $host_os in cygwin* | mingw* | pw32* | cegcc*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. if test "$GCC" != yes; then with_gnu_ld=no fi ;; interix*) # we just hope/assume this is gcc and not c89 (= MSVC++) with_gnu_ld=yes ;; openbsd*) with_gnu_ld=no ;; esac _LT_TAGVAR(ld_shlibs, $1)=yes # On some targets, GNU ld is compatible enough with the native linker # that we're better off using the native interface for both. lt_use_gnu_ld_interface=no if test "$with_gnu_ld" = yes; then case $host_os in aix*) # The AIX port of GNU ld has always aspired to compatibility # with the native linker. However, as the warning in the GNU ld # block says, versions before 2.19.5* couldn't really create working # shared libraries, regardless of the interface used. case `$LD -v 2>&1` in *\ \(GNU\ Binutils\)\ 2.19.5*) ;; *\ \(GNU\ Binutils\)\ 2.[[2-9]]*) ;; *\ \(GNU\ Binutils\)\ [[3-9]]*) ;; *) lt_use_gnu_ld_interface=yes ;; esac ;; *) lt_use_gnu_ld_interface=yes ;; esac fi if test "$lt_use_gnu_ld_interface" = yes; then # If archive_cmds runs LD, not CC, wlarc should be empty wlarc='${wl}' # Set some defaults for GNU ld with shared library support. These # are reset later if shared libraries are not supported. Putting them # here allows them to be overridden if necessary. runpath_var=LD_RUN_PATH _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' # ancient GNU ld didn't support --whole-archive et. al. if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' else _LT_TAGVAR(whole_archive_flag_spec, $1)= fi supports_anon_versioning=no case `$LD -v 2>&1` in *GNU\ gold*) supports_anon_versioning=yes ;; *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... *\ 2.11.*) ;; # other 2.11 versions *) supports_anon_versioning=yes ;; esac # See if GNU ld supports shared libraries. case $host_os in aix[[3-9]]*) # On AIX/PPC, the GNU linker is very broken if test "$host_cpu" != ia64; then _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: the GNU linker, at least up to release 2.19, is reported *** to be unable to reliably create shared libraries on AIX. *** Therefore, libtool is disabling shared libraries support. If you *** really care for shared libraries, you may want to install binutils *** 2.20 or above, or modify your PATH so that a non-GNU linker is found. *** You will then need to restart the configuration process. _LT_EOF fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='' ;; m68k) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; cygwin* | mingw* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-all-symbols' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.* //'\'' | sort | uniq > $export_symbols' _LT_TAGVAR(exclude_expsyms, $1)=['[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname'] if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file (1st line # is EXPORTS), use it as is; otherwise, prepend... _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; haiku*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(link_all_deplibs, $1)=yes ;; interix[[3-9]]*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) tmp_diet=no if test "$host_os" = linux-dietlibc; then case $cc_basename in diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) esac fi if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ && test "$tmp_diet" = no then tmp_addflag=' $pic_flag' tmp_sharedflag='-shared' case $cc_basename,$host_cpu in pgcc*) # Portland Group C compiler _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag' ;; pgf77* | pgf90* | pgf95* | pgfortran*) # Portland Group f77 and f90 compilers _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag -Mnomain' ;; ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 tmp_addflag=' -i_dynamic' ;; efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 tmp_addflag=' -i_dynamic -nofor_main' ;; ifc* | ifort*) # Intel Fortran compiler tmp_addflag=' -nofor_main' ;; lf95*) # Lahey Fortran 8.1 _LT_TAGVAR(whole_archive_flag_spec, $1)= tmp_sharedflag='--shared' ;; xl[[cC]]* | bgxl[[cC]]* | mpixl[[cC]]*) # IBM XL C 8.0 on PPC (deal with xlf below) tmp_sharedflag='-qmkshrobj' tmp_addflag= ;; nvcc*) # Cuda Compiler Driver 2.2 _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes ;; esac case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C 5.9 _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes tmp_sharedflag='-G' ;; *Sun\ F*) # Sun Fortran 8.3 tmp_sharedflag='-G' ;; esac _LT_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' if test "x$supports_anon_versioning" = xyes; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' fi case $cc_basename in xlf* | bgf* | bgxlf* | mpixlf*) # IBM XL Fortran 10.1 on PPC cannot create shared libs itself _LT_TAGVAR(whole_archive_flag_spec, $1)='--whole-archive$convenience --no-whole-archive' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' if test "x$supports_anon_versioning" = xyes; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' fi ;; esac else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' fi ;; solaris*) if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: The releases 2.8.* of the GNU linker cannot reliably *** create shared libraries on Solaris systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.9.1 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) case `$LD -v 2>&1` in *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*) _LT_TAGVAR(ld_shlibs, $1)=no cat <<_LT_EOF 1>&2 *** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not *** reliably create shared libraries on SCO systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.16.91.0.3 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF ;; *) # For security reasons, it is highly recommended that you always # use absolute paths for naming shared libraries, and exclude the # DT_RUNPATH tag from executables and libraries. But doing so # requires that you compile everything twice, which is a pain. if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; sunos4*) _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' wlarc= _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac if test "$_LT_TAGVAR(ld_shlibs, $1)" = no; then runpath_var= _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= fi else # PORTME fill in a description of your system's linker (not GNU ld) case $host_os in aix3*) _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes _LT_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' # Note: this linker hardcodes the directories in LIBPATH if there # are no directories specified by -L. _LT_TAGVAR(hardcode_minus_L, $1)=yes if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then # Neither direct hardcoding nor static linking is supported with a # broken collect2. _LT_TAGVAR(hardcode_direct, $1)=unsupported fi ;; aix[[4-9]]*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag="" else # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to AIX nm, but means don't demangle with GNU nm # Also, AIX nm treats weak defined symbols like other global # defined symbols, whereas GNU nm marks them as "W". if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' else _LT_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && ([substr](\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) for ld_flag in $LDFLAGS; do if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then aix_use_runtimelinking=yes break fi done ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. _LT_TAGVAR(archive_cmds, $1)='' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' if test "$GCC" = yes; then case $host_os in aix4.[[012]]|aix4.[[012]].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`${CC} -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 _LT_TAGVAR(hardcode_direct, $1)=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)= fi ;; esac shared_flag='-shared' if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi else # not using gcc if test "$host_cpu" = ia64; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test "$aix_use_runtimelinking" = yes; then shared_flag='${wl}-G' else shared_flag='${wl}-bM:SRE' fi fi fi _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to export. _LT_TAGVAR(always_export_symbols, $1)=yes if test "$aix_use_runtimelinking" = yes; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. _LT_TAGVAR(allow_undefined_flag, $1)='-berok' # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" else if test "$host_cpu" = ia64; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' if test "$with_gnu_ld" = yes; then # We only use this code for GNU lds that support --whole-archive. _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' else # Exported symbols can be pulled into shared objects from archives _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' fi _LT_TAGVAR(archive_cmds_need_lc, $1)=yes # This is similar to how AIX traditionally builds its shared libraries. _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' fi fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='' ;; m68k) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac ;; bsdi[[45]]*) _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic ;; cygwin* | mingw* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. case $cc_basename in cl*) # Native MSVC _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=".dll" # FIXME: Setting linknames here is a bad hack. _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames=' _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then sed -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp; else sed -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp; fi~ $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ linknames=' # The linker will not automatically build a static lib if we build a DLL. # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' _LT_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1,DATA/'\'' | $SED -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols' # Don't use ranlib _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ lt_tool_outputfile="@TOOL_OUTPUT@"~ case $lt_outputfile in *.exe|*.EXE) ;; *) lt_outputfile="$lt_outputfile.exe" lt_tool_outputfile="$lt_tool_outputfile.exe" ;; esac~ if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; $RM "$lt_outputfile.manifest"; fi' ;; *) # Assume MSVC wrapper _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=".dll" # FIXME: Setting linknames here is a bad hack. _LT_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' # The linker will automatically build a .lib file if we build a DLL. _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' # FIXME: Should let the user specify the lib program. _LT_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes ;; esac ;; darwin* | rhapsody*) _LT_DARWIN_LINKER_FEATURES($1) ;; dgux*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor # support. Future versions do this automatically, but an explicit c++rt0.o # does not break anything, and helps significantly (at the cost of a little # extra space). freebsd2.2*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # Unfortunately, older versions of FreeBSD 2 do not have this feature. freebsd2.*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; # FreeBSD 3 and greater uses gcc -shared to do shared libraries. freebsd* | dragonfly*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; hpux9*) if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' else _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_direct, $1)=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' ;; hpux10*) if test "$GCC" = yes && test "$with_gnu_ld" = no; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' fi if test "$with_gnu_ld" = no; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes fi ;; hpux11*) if test "$GCC" = yes && test "$with_gnu_ld" = no; then case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;; esac else case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) m4_if($1, [], [ # Older versions of the 11.00 compiler do not understand -b yet # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) _LT_LINKER_OPTION([if $CC understands -b], _LT_TAGVAR(lt_cv_prog_compiler__b, $1), [-b], [_LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'], [_LT_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'])], [_LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags']) ;; esac fi if test "$with_gnu_ld" = no; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: case $host_cpu in hppa*64*|ia64*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. _LT_TAGVAR(hardcode_minus_L, $1)=yes ;; esac fi ;; irix5* | irix6* | nonstopux*) if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' # Try to use the -exported_symbol ld option, if it does not # work, assume that -exports_file does not work either and # implicitly export all symbols. # This should be the same for all languages, so no per-tag cache variable. AC_CACHE_CHECK([whether the $host_os linker accepts -exported_symbol], [lt_cv_irix_exported_symbol], [save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" AC_LINK_IFELSE( [AC_LANG_SOURCE( [AC_LANG_CASE([C], [[int foo (void) { return 0; }]], [C++], [[int foo (void) { return 0; }]], [Fortran 77], [[ subroutine foo end]], [Fortran], [[ subroutine foo end]])])], [lt_cv_irix_exported_symbol=yes], [lt_cv_irix_exported_symbol=no]) LDFLAGS="$save_LDFLAGS"]) if test "$lt_cv_irix_exported_symbol" = yes; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' fi else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(inherit_rpath, $1)=yes _LT_TAGVAR(link_all_deplibs, $1)=yes ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else _LT_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; newsos6) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *nto* | *qnx*) ;; openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=yes if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' else case $host_os in openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*) _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' ;; esac fi else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; os2*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(archive_cmds, $1)='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~echo DATA >> $output_objdir/$libname.def~echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' ;; osf3*) if test "$GCC" = yes; then _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' else _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: ;; osf4* | osf5*) # as osf3* with the addition of -msym flag if test "$GCC" = yes; then _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $pic_flag $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' else _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' # Both c and cxx compiler support -rpath directly _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' fi _LT_TAGVAR(archive_cmds_need_lc, $1)='no' _LT_TAGVAR(hardcode_libdir_separator, $1)=: ;; solaris*) _LT_TAGVAR(no_undefined_flag, $1)=' -z defs' if test "$GCC" = yes; then wlarc='${wl}' _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' else case `$CC -V 2>&1` in *"Compilers 5.0"*) wlarc='' _LT_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' ;; *) wlarc='${wl}' _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' ;; esac fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands `-z linker_flag'. GCC discards it without `$wl', # but is careful enough not to reorder. # Supported since Solaris 2.6 (maybe 2.5.1?) if test "$GCC" = yes; then _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' else _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' fi ;; esac _LT_TAGVAR(link_all_deplibs, $1)=yes ;; sunos4*) if test "x$host_vendor" = xsequent; then # Use $CC to link under sequent, because it throws in some extra .o # files that make .init and .fini sections work. _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; sysv4) case $host_vendor in sni) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=yes # is this really true??? ;; siemens) ## LD is ld it makes a PLAMLIB ## CC just makes a GrossModule. _LT_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs' _LT_TAGVAR(hardcode_direct, $1)=no ;; motorola) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie ;; esac runpath_var='LD_RUN_PATH' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; sysv4.3*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport' ;; sysv4*MP*) if test -d /usr/nec; then _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var=LD_RUN_PATH hardcode_runpath_var=yes _LT_TAGVAR(ld_shlibs, $1)=yes fi ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We can NOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; uts4*) _LT_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(ld_shlibs, $1)=no ;; esac if test x$host_vendor = xsni; then case $host in sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Blargedynsym' ;; esac fi fi ]) AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no _LT_TAGVAR(with_gnu_ld, $1)=$with_gnu_ld _LT_DECL([], [libext], [0], [Old archive suffix (normally "a")])dnl _LT_DECL([], [shrext_cmds], [1], [Shared library suffix (normally ".so")])dnl _LT_DECL([], [extract_expsyms_cmds], [2], [The commands to extract the exported symbol list from a shared archive]) # # Do we need to explicitly link libc? # case "x$_LT_TAGVAR(archive_cmds_need_lc, $1)" in x|xyes) # Assume -lc should be added _LT_TAGVAR(archive_cmds_need_lc, $1)=yes if test "$enable_shared" = yes && test "$GCC" = yes; then case $_LT_TAGVAR(archive_cmds, $1) in *'~'*) # FIXME: we may have to deal with multi-command sequences. ;; '$CC '*) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. AC_CACHE_CHECK([whether -lc should be explicitly linked in], [lt_cv_]_LT_TAGVAR(archive_cmds_need_lc, $1), [$RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if AC_TRY_EVAL(ac_compile) 2>conftest.err; then soname=conftest lib=conftest libobjs=conftest.$ac_objext deplibs= wl=$_LT_TAGVAR(lt_prog_compiler_wl, $1) pic_flag=$_LT_TAGVAR(lt_prog_compiler_pic, $1) compiler_flags=-v linker_flags=-v verstring= output_objdir=. libname=conftest lt_save_allow_undefined_flag=$_LT_TAGVAR(allow_undefined_flag, $1) _LT_TAGVAR(allow_undefined_flag, $1)= if AC_TRY_EVAL(_LT_TAGVAR(archive_cmds, $1) 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) then lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=no else lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1)=yes fi _LT_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag else cat conftest.err 1>&5 fi $RM conftest* ]) _LT_TAGVAR(archive_cmds_need_lc, $1)=$lt_cv_[]_LT_TAGVAR(archive_cmds_need_lc, $1) ;; esac fi ;; esac _LT_TAGDECL([build_libtool_need_lc], [archive_cmds_need_lc], [0], [Whether or not to add -lc for building shared libraries]) _LT_TAGDECL([allow_libtool_libs_with_static_runtimes], [enable_shared_with_static_runtimes], [0], [Whether or not to disallow shared libs when runtime libs are static]) _LT_TAGDECL([], [export_dynamic_flag_spec], [1], [Compiler flag to allow reflexive dlopens]) _LT_TAGDECL([], [whole_archive_flag_spec], [1], [Compiler flag to generate shared objects directly from archives]) _LT_TAGDECL([], [compiler_needs_object], [1], [Whether the compiler copes with passing no objects directly]) _LT_TAGDECL([], [old_archive_from_new_cmds], [2], [Create an old-style archive from a shared archive]) _LT_TAGDECL([], [old_archive_from_expsyms_cmds], [2], [Create a temporary old-style archive to link instead of a shared archive]) _LT_TAGDECL([], [archive_cmds], [2], [Commands used to build a shared archive]) _LT_TAGDECL([], [archive_expsym_cmds], [2]) _LT_TAGDECL([], [module_cmds], [2], [Commands used to build a loadable module if different from building a shared archive.]) _LT_TAGDECL([], [module_expsym_cmds], [2]) _LT_TAGDECL([], [with_gnu_ld], [1], [Whether we are building with GNU ld or not]) _LT_TAGDECL([], [allow_undefined_flag], [1], [Flag that allows shared libraries with undefined symbols to be built]) _LT_TAGDECL([], [no_undefined_flag], [1], [Flag that enforces no undefined symbols]) _LT_TAGDECL([], [hardcode_libdir_flag_spec], [1], [Flag to hardcode $libdir into a binary during linking. This must work even if $libdir does not exist]) _LT_TAGDECL([], [hardcode_libdir_separator], [1], [Whether we need a single "-rpath" flag with a separated argument]) _LT_TAGDECL([], [hardcode_direct], [0], [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_direct_absolute], [0], [Set to "yes" if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the resulting binary and the resulting library dependency is "absolute", i.e impossible to change by setting ${shlibpath_var} if the library is relocated]) _LT_TAGDECL([], [hardcode_minus_L], [0], [Set to "yes" if using the -LDIR flag during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_shlibpath_var], [0], [Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into the resulting binary]) _LT_TAGDECL([], [hardcode_automatic], [0], [Set to "yes" if building a shared library automatically hardcodes DIR into the library and all subsequent libraries and executables linked against it]) _LT_TAGDECL([], [inherit_rpath], [0], [Set to yes if linker adds runtime paths of dependent libraries to runtime path list]) _LT_TAGDECL([], [link_all_deplibs], [0], [Whether libtool must link a program against all its dependency libraries]) _LT_TAGDECL([], [always_export_symbols], [0], [Set to "yes" if exported symbols are required]) _LT_TAGDECL([], [export_symbols_cmds], [2], [The commands to list exported symbols]) _LT_TAGDECL([], [exclude_expsyms], [1], [Symbols that should not be listed in the preloaded symbols]) _LT_TAGDECL([], [include_expsyms], [1], [Symbols that must always be exported]) _LT_TAGDECL([], [prelink_cmds], [2], [Commands necessary for linking programs (against libraries) with templates]) _LT_TAGDECL([], [postlink_cmds], [2], [Commands necessary for finishing linking programs]) _LT_TAGDECL([], [file_list_spec], [1], [Specify filename containing input files]) dnl FIXME: Not yet implemented dnl _LT_TAGDECL([], [thread_safe_flag_spec], [1], dnl [Compiler flag to generate thread safe objects]) ])# _LT_LINKER_SHLIBS # _LT_LANG_C_CONFIG([TAG]) # ------------------------ # Ensure that the configuration variables for a C compiler are suitably # defined. These variables are subsequently used by _LT_CONFIG to write # the compiler configuration to `libtool'. m4_defun([_LT_LANG_C_CONFIG], [m4_require([_LT_DECL_EGREP])dnl lt_save_CC="$CC" AC_LANG_PUSH(C) # Source file extension for C test sources. ac_ext=c # Object file extension for compiled C test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(){return(0);}' _LT_TAG_COMPILER # Save the default compiler, since it gets overwritten when the other # tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. compiler_DEFAULT=$CC # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) LT_SYS_DLOPEN_SELF _LT_CMD_STRIPLIB # Report which library types will actually be built AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_CONFIG($1) fi AC_LANG_POP CC="$lt_save_CC" ])# _LT_LANG_C_CONFIG # _LT_LANG_CXX_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for a C++ compiler are suitably # defined. These variables are subsequently used by _LT_CONFIG to write # the compiler configuration to `libtool'. m4_defun([_LT_LANG_CXX_CONFIG], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_DECL_EGREP])dnl m4_require([_LT_PATH_MANIFEST_TOOL])dnl if test -n "$CXX" && ( test "X$CXX" != "Xno" && ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) || (test "X$CXX" != "Xg++"))) ; then AC_PROG_CXXCPP else _lt_caught_CXX_error=yes fi AC_LANG_PUSH(C++) _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(compiler_needs_object, $1)=no _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for C++ test sources. ac_ext=cpp # Object file extension for compiled C++ test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the CXX compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test "$_lt_caught_CXX_error" != yes; then # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_CFLAGS=$CFLAGS lt_save_LD=$LD lt_save_GCC=$GCC GCC=$GXX lt_save_with_gnu_ld=$with_gnu_ld lt_save_path_LD=$lt_cv_path_LD if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx else $as_unset lt_cv_prog_gnu_ld fi if test -n "${lt_cv_path_LDCXX+set}"; then lt_cv_path_LD=$lt_cv_path_LDCXX else $as_unset lt_cv_path_LD fi test -z "${LDCXX+set}" || LD=$LDCXX CC=${CXX-"c++"} CFLAGS=$CXXFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) if test -n "$compiler"; then # We don't want -fno-exception when compiling C++ code, so set the # no_builtin_flag separately if test "$GXX" = yes; then _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin' else _LT_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)= fi if test "$GXX" = yes; then # Set up default GNU C++ configuration LT_PATH_LD # Check if GNU C++ uses GNU ld as the underlying linker, since the # archiving commands below assume that GNU ld is being used. if test "$with_gnu_ld" = yes; then _LT_TAGVAR(archive_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC $pic_flag -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' # If archive_cmds runs LD, not CC, wlarc should be empty # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to # investigate it a little bit more. (MM) wlarc='${wl}' # ancient GNU ld didn't support --whole-archive et. al. if eval "`$CC -print-prog-name=ld` --help 2>&1" | $GREP 'no-whole-archive' > /dev/null; then _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' else _LT_TAGVAR(whole_archive_flag_spec, $1)= fi else with_gnu_ld=no wlarc= # A generic and very simple default shared library creation # command for GNU C++ for the case where it uses the native # linker, instead of GNU ld. If possible, this setting should # overridden to take advantage of the native linker features on # the platform it is being used on. _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else GXX=no with_gnu_ld=no wlarc= fi # PORTME: fill in a description of your system's C++ link characteristics AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries]) _LT_TAGVAR(ld_shlibs, $1)=yes case $host_os in aix3*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aix[[4-9]]*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag="" else aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*) for ld_flag in $LDFLAGS; do case $ld_flag in *-brtl*) aix_use_runtimelinking=yes break ;; esac done ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. _LT_TAGVAR(archive_cmds, $1)='' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(file_list_spec, $1)='${wl}-f,' if test "$GXX" = yes; then case $host_os in aix4.[[012]]|aix4.[[012]].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`${CC} -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 _LT_TAGVAR(hardcode_direct, $1)=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking _LT_TAGVAR(hardcode_minus_L, $1)=yes _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)= fi esac shared_flag='-shared' if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi else # not using gcc if test "$host_cpu" = ia64; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test "$aix_use_runtimelinking" = yes; then shared_flag='${wl}-G' else shared_flag='${wl}-bM:SRE' fi fi fi _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to # export. _LT_TAGVAR(always_export_symbols, $1)=yes if test "$aix_use_runtimelinking" = yes; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. _LT_TAGVAR(allow_undefined_flag, $1)='-berok' # Determine the default libpath from the value encoded in an empty # executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" else if test "$host_cpu" = ia64; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib' _LT_TAGVAR(allow_undefined_flag, $1)="-z nodefs" _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. _LT_SYS_MODULE_PATH_AIX([$1]) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok' _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok' if test "$with_gnu_ld" = yes; then # We only use this code for GNU lds that support --whole-archive. _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' else # Exported symbols can be pulled into shared objects from archives _LT_TAGVAR(whole_archive_flag_spec, $1)='$convenience' fi _LT_TAGVAR(archive_cmds_need_lc, $1)=yes # This is similar to how AIX traditionally builds its shared # libraries. _LT_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' fi fi ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME _LT_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; chorus*) case $cc_basename in *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; cygwin* | mingw* | pw32* | cegcc*) case $GXX,$cc_basename in ,cl* | no,cl*) # Native MSVC # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes _LT_TAGVAR(file_list_spec, $1)='@' # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=".dll" # FIXME: Setting linknames here is a bad hack. _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames=' _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then $SED -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp; else $SED -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp; fi~ $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ linknames=' # The linker will not automatically build a static lib if we build a DLL. # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes # Don't use ranlib _LT_TAGVAR(old_postinstall_cmds, $1)='chmod 644 $oldlib' _LT_TAGVAR(postlink_cmds, $1)='lt_outputfile="@OUTPUT@"~ lt_tool_outputfile="@TOOL_OUTPUT@"~ case $lt_outputfile in *.exe|*.EXE) ;; *) lt_outputfile="$lt_outputfile.exe" lt_tool_outputfile="$lt_tool_outputfile.exe" ;; esac~ func_to_tool_file "$lt_outputfile"~ if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; $RM "$lt_outputfile.manifest"; fi' ;; *) # g++ # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-all-symbols' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file (1st line # is EXPORTS), use it as is; otherwise, prepend... _LT_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; darwin* | rhapsody*) _LT_DARWIN_LINKER_FEATURES($1) ;; dgux*) case $cc_basename in ec++*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; ghcx*) # Green Hills C++ Compiler # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; freebsd2.*) # C++ shared libraries reported to be fairly broken before # switch to ELF _LT_TAGVAR(ld_shlibs, $1)=no ;; freebsd-elf*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; freebsd* | dragonfly*) # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF # conventions _LT_TAGVAR(ld_shlibs, $1)=yes ;; gnu*) ;; haiku*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(link_all_deplibs, $1)=yes ;; hpux9*) _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, # but as the default # location of the library. case $cc_basename in CC*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aCC*) _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test "$GXX" = yes; then _LT_TAGVAR(archive_cmds, $1)='$RM $output_objdir/$soname~$CC -shared -nostdlib $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; hpux10*|hpux11*) if test $with_gnu_ld = no; then _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: case $host_cpu in hppa*64*|ia64*) ;; *) _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' ;; esac fi case $host_cpu in hppa*64*|ia64*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no ;; *) _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH, # but as the default # location of the library. ;; esac case $cc_basename in CC*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; aCC*) case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; esac # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test "$GXX" = yes; then if test $with_gnu_ld = no; then case $host_cpu in hppa*64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; ia64*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' ;; esac fi else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; interix[[3-9]]*) _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; irix5* | irix6*) case $cc_basename in CC*) # SGI C++ _LT_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' # Archives containing C++ object files must be created using # "CC -ar", where "CC" is the IRIX C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs' ;; *) if test "$GXX" = yes; then if test "$with_gnu_ld" = no; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' else _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` -o $lib' fi fi _LT_TAGVAR(link_all_deplibs, $1)=yes ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: _LT_TAGVAR(inherit_rpath, $1)=yes ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in KCC*) # Kuck and Associates, Inc. (KAI) C++ Compiler # KCC will only create a shared library if the output file # ends with ".so" (or ".sl" for HP-UX), so rename the library # to its proper name (with version) after linking. _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | $GREP "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' # Archives containing C++ object files must be created using # "CC -Bstatic", where "CC" is the KAI C++ compiler. _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; icpc* | ecpc* ) # Intel C++ with_gnu_ld=yes # version 8.0 and above of icpc choke on multiply defined symbols # if we add $predep_objects and $postdep_objects, however 7.1 and # earlier do not add the objects themselves. case `$CC -V 2>&1` in *"Version 7."*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' ;; *) # Version 8.0 or newer tmp_idyn= case $host_cpu in ia64*) tmp_idyn=' -i_dynamic';; esac _LT_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' ;; esac _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive' ;; pgCC* | pgcpp*) # Portland Group C++ compiler case `$CC -V` in *pgCC\ [[1-5]].* | *pgcpp\ [[1-5]].*) _LT_TAGVAR(prelink_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~ compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"' _LT_TAGVAR(old_archive_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~ $AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~ $RANLIB $oldlib' _LT_TAGVAR(archive_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='tpldir=Template.dir~ rm -rf $tpldir~ $CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~ $CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' ;; *) # Version 6 and above use weak symbols _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib' ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' ;; cxx*) # Compaq C++ _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib ${wl}-retain-symbols-file $wl$export_symbols' runpath_var=LD_RUN_PATH _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "X$list" | $Xsed' ;; xl* | mpixl* | bgxl*) # IBM XL 8.0 on PPC, with GNU ld _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic' _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' if test "x$supports_anon_versioning" = xyes; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC -qmkshrobj $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' fi ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes # Not sure whether something based on # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 # would be better. output_verbose_link_cmd='func_echo_all' # Archives containing C++ object files must be created using # "CC -xar", where "CC" is the Sun C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' ;; esac ;; esac ;; lynxos*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; m88k*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; mvs*) case $cc_basename in cxx*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then _LT_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags' wlarc= _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no fi # Workaround some broken pre-1.5 toolchains output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"' ;; *nto* | *qnx*) _LT_TAGVAR(ld_shlibs, $1)=yes ;; openbsd2*) # C++ shared libraries are fairly broken _LT_TAGVAR(ld_shlibs, $1)=no ;; openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=yes _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib' _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E' _LT_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' fi output_verbose_link_cmd=func_echo_all else _LT_TAGVAR(ld_shlibs, $1)=no fi ;; osf3* | osf4* | osf5*) case $cc_basename in KCC*) # Kuck and Associates, Inc. (KAI) C++ Compiler # KCC will only create a shared library if the output file # ends with ".so" (or ".sl" for HP-UX), so rename the library # to its proper name (with version) after linking. _LT_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo "$lib" | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Archives containing C++ object files must be created using # the KAI C++ compiler. case $host in osf3*) _LT_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs' ;; *) _LT_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs' ;; esac ;; RCC*) # Rational C++ 2.4.1 # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; cxx*) case $host in osf3*) _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && func_echo_all "${wl}-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' ;; *) _LT_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*' _LT_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~ echo "-hidden">> $lib.exp~ $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname ${wl}-input ${wl}$lib.exp `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~ $RM $lib.exp' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir' ;; esac _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. # # There doesn't appear to be a way to prevent this compiler from # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP "ld" | $GREP -v "ld:"`; templist=`func_echo_all "$templist" | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test "$GXX" = yes && test "$with_gnu_ld" = no; then _LT_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*' case $host in osf3*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' ;; esac _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=: # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no fi ;; esac ;; psos*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; sunos4*) case $cc_basename in CC*) # Sun C++ 4.x # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; lcc*) # Lucid # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; solaris*) case $cc_basename in CC* | sunCC*) # Sun C++ 4.2, 5.x and Centerline C++ _LT_TAGVAR(archive_cmds_need_lc,$1)=yes _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' _LT_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G${allow_undefined_flag} ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_shlibpath_var, $1)=no case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands `-z linker_flag'. # Supported since Solaris 2.6 (maybe 2.5.1?) _LT_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract' ;; esac _LT_TAGVAR(link_all_deplibs, $1)=yes output_verbose_link_cmd='func_echo_all' # Archives containing C++ object files must be created using # "CC -xar", where "CC" is the Sun C++ compiler. This is # necessary to make sure instantiated templates are included # in the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs' ;; gcx*) # Green Hills C++ Compiler _LT_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' # The C++ compiler must be used to create the archive. _LT_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs' ;; *) # GNU C++ compiler with Solaris linker if test "$GXX" = yes && test "$with_gnu_ld" = no; then _LT_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs' if $CC --version | $GREP -v '^2\.7' > /dev/null; then _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared $pic_flag -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' else # g++ 2.7 appears to require `-G' NOT `-shared' on this # platform. _LT_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib' _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$RM $lib.exp' # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir' case $host_os in solaris2.[[0-5]] | solaris2.[[0-5]].*) ;; *) _LT_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' ;; esac fi ;; esac ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*) _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no runpath_var='LD_RUN_PATH' case $cc_basename in CC*) _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; esac ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We can NOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. _LT_TAGVAR(no_undefined_flag, $1)='${wl}-z,text' _LT_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs' _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(hardcode_shlibpath_var, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R,$libdir' _LT_TAGVAR(hardcode_libdir_separator, $1)=':' _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport' runpath_var='LD_RUN_PATH' case $cc_basename in CC*) _LT_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(old_archive_cmds, $1)='$CC -Tprelink_objects $oldobjs~ '"$_LT_TAGVAR(old_archive_cmds, $1)" _LT_TAGVAR(reload_cmds, $1)='$CC -Tprelink_objects $reload_objs~ '"$_LT_TAGVAR(reload_cmds, $1)" ;; *) _LT_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' ;; esac ;; tandem*) case $cc_basename in NCC*) # NonStop-UX NCC 3.20 # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac ;; vxworks*) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; *) # FIXME: insert proper C++ library support _LT_TAGVAR(ld_shlibs, $1)=no ;; esac AC_MSG_RESULT([$_LT_TAGVAR(ld_shlibs, $1)]) test "$_LT_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no _LT_TAGVAR(GCC, $1)="$GXX" _LT_TAGVAR(LD, $1)="$LD" ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_SYS_HIDDEN_LIBDEPS($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS LDCXX=$LD LD=$lt_save_LD GCC=$lt_save_GCC with_gnu_ld=$lt_save_with_gnu_ld lt_cv_path_LDCXX=$lt_cv_path_LD lt_cv_path_LD=$lt_save_path_LD lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld fi # test "$_lt_caught_CXX_error" != yes AC_LANG_POP ])# _LT_LANG_CXX_CONFIG # _LT_FUNC_STRIPNAME_CNF # ---------------------- # func_stripname_cnf prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). # # This function is identical to the (non-XSI) version of func_stripname, # except this one can be used by m4 code that may be executed by configure, # rather than the libtool script. m4_defun([_LT_FUNC_STRIPNAME_CNF],[dnl AC_REQUIRE([_LT_DECL_SED]) AC_REQUIRE([_LT_PROG_ECHO_BACKSLASH]) func_stripname_cnf () { case ${2} in .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%\\\\${2}\$%%"`;; *) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;; esac } # func_stripname_cnf ])# _LT_FUNC_STRIPNAME_CNF # _LT_SYS_HIDDEN_LIBDEPS([TAGNAME]) # --------------------------------- # Figure out "hidden" library dependencies from verbose # compiler output when linking a shared library. # Parse the compiler output and extract the necessary # objects, libraries and library flags. m4_defun([_LT_SYS_HIDDEN_LIBDEPS], [m4_require([_LT_FILEUTILS_DEFAULTS])dnl AC_REQUIRE([_LT_FUNC_STRIPNAME_CNF])dnl # Dependencies to place before and after the object being linked: _LT_TAGVAR(predep_objects, $1)= _LT_TAGVAR(postdep_objects, $1)= _LT_TAGVAR(predeps, $1)= _LT_TAGVAR(postdeps, $1)= _LT_TAGVAR(compiler_lib_search_path, $1)= dnl we can't use the lt_simple_compile_test_code here, dnl because it contains code intended for an executable, dnl not a library. It's possible we should let each dnl tag define a new lt_????_link_test_code variable, dnl but it's only used here... m4_if([$1], [], [cat > conftest.$ac_ext <<_LT_EOF int a; void foo (void) { a = 0; } _LT_EOF ], [$1], [CXX], [cat > conftest.$ac_ext <<_LT_EOF class Foo { public: Foo (void) { a = 0; } private: int a; }; _LT_EOF ], [$1], [F77], [cat > conftest.$ac_ext <<_LT_EOF subroutine foo implicit none integer*4 a a=0 return end _LT_EOF ], [$1], [FC], [cat > conftest.$ac_ext <<_LT_EOF subroutine foo implicit none integer a a=0 return end _LT_EOF ], [$1], [GCJ], [cat > conftest.$ac_ext <<_LT_EOF public class foo { private int a; public void bar (void) { a = 0; } }; _LT_EOF ], [$1], [GO], [cat > conftest.$ac_ext <<_LT_EOF package foo func foo() { } _LT_EOF ]) _lt_libdeps_save_CFLAGS=$CFLAGS case "$CC $CFLAGS " in #( *\ -flto*\ *) CFLAGS="$CFLAGS -fno-lto" ;; *\ -fwhopr*\ *) CFLAGS="$CFLAGS -fno-whopr" ;; *\ -fuse-linker-plugin*\ *) CFLAGS="$CFLAGS -fno-use-linker-plugin" ;; esac dnl Parse the compiler output and extract the necessary dnl objects, libraries and library flags. if AC_TRY_EVAL(ac_compile); then # Parse the compiler output and extract the necessary # objects, libraries and library flags. # Sentinel used to keep track of whether or not we are before # the conftest object file. pre_test_object_deps_done=no for p in `eval "$output_verbose_link_cmd"`; do case ${prev}${p} in -L* | -R* | -l*) # Some compilers place space between "-{L,R}" and the path. # Remove the space. if test $p = "-L" || test $p = "-R"; then prev=$p continue fi # Expand the sysroot to ease extracting the directories later. if test -z "$prev"; then case $p in -L*) func_stripname_cnf '-L' '' "$p"; prev=-L; p=$func_stripname_result ;; -R*) func_stripname_cnf '-R' '' "$p"; prev=-R; p=$func_stripname_result ;; -l*) func_stripname_cnf '-l' '' "$p"; prev=-l; p=$func_stripname_result ;; esac fi case $p in =*) func_stripname_cnf '=' '' "$p"; p=$lt_sysroot$func_stripname_result ;; esac if test "$pre_test_object_deps_done" = no; then case ${prev} in -L | -R) # Internal compiler library paths should come after those # provided the user. The postdeps already come after the # user supplied libs so there is no need to process them. if test -z "$_LT_TAGVAR(compiler_lib_search_path, $1)"; then _LT_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}" else _LT_TAGVAR(compiler_lib_search_path, $1)="${_LT_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}" fi ;; # The "-l" case would never come before the object being # linked, so don't bother handling this case. esac else if test -z "$_LT_TAGVAR(postdeps, $1)"; then _LT_TAGVAR(postdeps, $1)="${prev}${p}" else _LT_TAGVAR(postdeps, $1)="${_LT_TAGVAR(postdeps, $1)} ${prev}${p}" fi fi prev= ;; *.lto.$objext) ;; # Ignore GCC LTO objects *.$objext) # This assumes that the test object file only shows up # once in the compiler output. if test "$p" = "conftest.$objext"; then pre_test_object_deps_done=yes continue fi if test "$pre_test_object_deps_done" = no; then if test -z "$_LT_TAGVAR(predep_objects, $1)"; then _LT_TAGVAR(predep_objects, $1)="$p" else _LT_TAGVAR(predep_objects, $1)="$_LT_TAGVAR(predep_objects, $1) $p" fi else if test -z "$_LT_TAGVAR(postdep_objects, $1)"; then _LT_TAGVAR(postdep_objects, $1)="$p" else _LT_TAGVAR(postdep_objects, $1)="$_LT_TAGVAR(postdep_objects, $1) $p" fi fi ;; *) ;; # Ignore the rest. esac done # Clean up. rm -f a.out a.exe else echo "libtool.m4: error: problem compiling $1 test program" fi $RM -f confest.$objext CFLAGS=$_lt_libdeps_save_CFLAGS # PORTME: override above test on systems where it is broken m4_if([$1], [CXX], [case $host_os in interix[[3-9]]*) # Interix 3.5 installs completely hosed .la files for C++, so rather than # hack all around it, let's just trust "g++" to DTRT. _LT_TAGVAR(predep_objects,$1)= _LT_TAGVAR(postdep_objects,$1)= _LT_TAGVAR(postdeps,$1)= ;; linux*) case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C++ 5.9 # The more standards-conforming stlport4 library is # incompatible with the Cstd library. Avoid specifying # it if it's in CXXFLAGS. Ignore libCrun as # -library=stlport4 depends on it. case " $CXX $CXXFLAGS " in *" -library=stlport4 "*) solaris_use_stlport4=yes ;; esac if test "$solaris_use_stlport4" != yes; then _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' fi ;; esac ;; solaris*) case $cc_basename in CC* | sunCC*) # The more standards-conforming stlport4 library is # incompatible with the Cstd library. Avoid specifying # it if it's in CXXFLAGS. Ignore libCrun as # -library=stlport4 depends on it. case " $CXX $CXXFLAGS " in *" -library=stlport4 "*) solaris_use_stlport4=yes ;; esac # Adding this requires a known-good setup of shared libraries for # Sun compiler versions before 5.6, else PIC objects from an old # archive will be linked into the output, leading to subtle bugs. if test "$solaris_use_stlport4" != yes; then _LT_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun' fi ;; esac ;; esac ]) case " $_LT_TAGVAR(postdeps, $1) " in *" -lc "*) _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; esac _LT_TAGVAR(compiler_lib_search_dirs, $1)= if test -n "${_LT_TAGVAR(compiler_lib_search_path, $1)}"; then _LT_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'` fi _LT_TAGDECL([], [compiler_lib_search_dirs], [1], [The directories searched by this compiler when creating a shared library]) _LT_TAGDECL([], [predep_objects], [1], [Dependencies to place before and after the objects being linked to create a shared library]) _LT_TAGDECL([], [postdep_objects], [1]) _LT_TAGDECL([], [predeps], [1]) _LT_TAGDECL([], [postdeps], [1]) _LT_TAGDECL([], [compiler_lib_search_path], [1], [The library search path used internally by the compiler when linking a shared library]) ])# _LT_SYS_HIDDEN_LIBDEPS # _LT_LANG_F77_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for a Fortran 77 compiler are # suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_F77_CONFIG], [AC_LANG_PUSH(Fortran 77) if test -z "$F77" || test "X$F77" = "Xno"; then _lt_disable_F77=yes fi _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for f77 test sources. ac_ext=f # Object file extension for compiled f77 test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the F77 compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test "$_lt_disable_F77" != yes; then # Code to be used in simple compile tests lt_simple_compile_test_code="\ subroutine t return end " # Code to be used in simple link tests lt_simple_link_test_code="\ program t end " # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC="$CC" lt_save_GCC=$GCC lt_save_CFLAGS=$CFLAGS CC=${F77-"f77"} CFLAGS=$FFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) GCC=$G77 if test -n "$compiler"; then AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_TAGVAR(GCC, $1)="$G77" _LT_TAGVAR(LD, $1)="$LD" ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" GCC=$lt_save_GCC CC="$lt_save_CC" CFLAGS="$lt_save_CFLAGS" fi # test "$_lt_disable_F77" != yes AC_LANG_POP ])# _LT_LANG_F77_CONFIG # _LT_LANG_FC_CONFIG([TAG]) # ------------------------- # Ensure that the configuration variables for a Fortran compiler are # suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_FC_CONFIG], [AC_LANG_PUSH(Fortran) if test -z "$FC" || test "X$FC" = "Xno"; then _lt_disable_FC=yes fi _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(allow_undefined_flag, $1)= _LT_TAGVAR(always_export_symbols, $1)=no _LT_TAGVAR(archive_expsym_cmds, $1)= _LT_TAGVAR(export_dynamic_flag_spec, $1)= _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_direct_absolute, $1)=no _LT_TAGVAR(hardcode_libdir_flag_spec, $1)= _LT_TAGVAR(hardcode_libdir_separator, $1)= _LT_TAGVAR(hardcode_minus_L, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=no _LT_TAGVAR(inherit_rpath, $1)=no _LT_TAGVAR(module_cmds, $1)= _LT_TAGVAR(module_expsym_cmds, $1)= _LT_TAGVAR(link_all_deplibs, $1)=unknown _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds _LT_TAGVAR(no_undefined_flag, $1)= _LT_TAGVAR(whole_archive_flag_spec, $1)= _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=no # Source file extension for fc test sources. ac_ext=${ac_fc_srcext-f} # Object file extension for compiled fc test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # No sense in running all these tests if we already determined that # the FC compiler isn't working. Some variables (like enable_shared) # are currently assumed to apply to all compilers on this platform, # and will be corrupted by setting them based on a non-working compiler. if test "$_lt_disable_FC" != yes; then # Code to be used in simple compile tests lt_simple_compile_test_code="\ subroutine t return end " # Code to be used in simple link tests lt_simple_link_test_code="\ program t end " # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC="$CC" lt_save_GCC=$GCC lt_save_CFLAGS=$CFLAGS CC=${FC-"f95"} CFLAGS=$FCFLAGS compiler=$CC GCC=$ac_cv_fc_compiler_gnu _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) if test -n "$compiler"; then AC_MSG_CHECKING([if libtool supports shared libraries]) AC_MSG_RESULT([$can_build_shared]) AC_MSG_CHECKING([whether to build shared libraries]) test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[[4-9]]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac AC_MSG_RESULT([$enable_shared]) AC_MSG_CHECKING([whether to build static libraries]) # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes AC_MSG_RESULT([$enable_static]) _LT_TAGVAR(GCC, $1)="$ac_cv_fc_compiler_gnu" _LT_TAGVAR(LD, $1)="$LD" ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... _LT_SYS_HIDDEN_LIBDEPS($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_SYS_DYNAMIC_LINKER($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi # test -n "$compiler" GCC=$lt_save_GCC CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS fi # test "$_lt_disable_FC" != yes AC_LANG_POP ])# _LT_LANG_FC_CONFIG # _LT_LANG_GCJ_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for the GNU Java Compiler compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_GCJ_CONFIG], [AC_REQUIRE([LT_PROG_GCJ])dnl AC_LANG_SAVE # Source file extension for Java test sources. ac_ext=java # Object file extension for compiled Java test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="class foo {}" # Code to be used in simple link tests lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_CFLAGS=$CFLAGS lt_save_GCC=$GCC GCC=yes CC=${GCJ-"gcj"} CFLAGS=$GCJFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_TAGVAR(LD, $1)="$LD" _LT_CC_BASENAME([$compiler]) # GCJ did not exist at the time GCC didn't implicitly link libc in. _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi AC_LANG_RESTORE GCC=$lt_save_GCC CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS ])# _LT_LANG_GCJ_CONFIG # _LT_LANG_GO_CONFIG([TAG]) # -------------------------- # Ensure that the configuration variables for the GNU Go compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_GO_CONFIG], [AC_REQUIRE([LT_PROG_GO])dnl AC_LANG_SAVE # Source file extension for Go test sources. ac_ext=go # Object file extension for compiled Go test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="package main; func main() { }" # Code to be used in simple link tests lt_simple_link_test_code='package main; func main() { }' # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC=$CC lt_save_CFLAGS=$CFLAGS lt_save_GCC=$GCC GCC=yes CC=${GOC-"gccgo"} CFLAGS=$GOFLAGS compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_TAGVAR(LD, $1)="$LD" _LT_CC_BASENAME([$compiler]) # Go did not exist at the time GCC didn't implicitly link libc in. _LT_TAGVAR(archive_cmds_need_lc, $1)=no _LT_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds _LT_TAGVAR(reload_flag, $1)=$reload_flag _LT_TAGVAR(reload_cmds, $1)=$reload_cmds ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then _LT_COMPILER_NO_RTTI($1) _LT_COMPILER_PIC($1) _LT_COMPILER_C_O($1) _LT_COMPILER_FILE_LOCKS($1) _LT_LINKER_SHLIBS($1) _LT_LINKER_HARDCODE_LIBPATH($1) _LT_CONFIG($1) fi AC_LANG_RESTORE GCC=$lt_save_GCC CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS ])# _LT_LANG_GO_CONFIG # _LT_LANG_RC_CONFIG([TAG]) # ------------------------- # Ensure that the configuration variables for the Windows resource compiler # are suitably defined. These variables are subsequently used by _LT_CONFIG # to write the compiler configuration to `libtool'. m4_defun([_LT_LANG_RC_CONFIG], [AC_REQUIRE([LT_PROG_RC])dnl AC_LANG_SAVE # Source file extension for RC test sources. ac_ext=rc # Object file extension for compiled RC test sources. objext=o _LT_TAGVAR(objext, $1)=$objext # Code to be used in simple compile tests lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }' # Code to be used in simple link tests lt_simple_link_test_code="$lt_simple_compile_test_code" # ltmain only uses $CC for tagged configurations so make sure $CC is set. _LT_TAG_COMPILER # save warnings/boilerplate of simple test code _LT_COMPILER_BOILERPLATE _LT_LINKER_BOILERPLATE # Allow CC to be a program name with arguments. lt_save_CC="$CC" lt_save_CFLAGS=$CFLAGS lt_save_GCC=$GCC GCC= CC=${RC-"windres"} CFLAGS= compiler=$CC _LT_TAGVAR(compiler, $1)=$CC _LT_CC_BASENAME([$compiler]) _LT_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes if test -n "$compiler"; then : _LT_CONFIG($1) fi GCC=$lt_save_GCC AC_LANG_RESTORE CC=$lt_save_CC CFLAGS=$lt_save_CFLAGS ])# _LT_LANG_RC_CONFIG # LT_PROG_GCJ # ----------- AC_DEFUN([LT_PROG_GCJ], [m4_ifdef([AC_PROG_GCJ], [AC_PROG_GCJ], [m4_ifdef([A][M_PROG_GCJ], [A][M_PROG_GCJ], [AC_CHECK_TOOL(GCJ, gcj,) test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2" AC_SUBST(GCJFLAGS)])])[]dnl ]) # Old name: AU_ALIAS([LT_AC_PROG_GCJ], [LT_PROG_GCJ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_GCJ], []) # LT_PROG_GO # ---------- AC_DEFUN([LT_PROG_GO], [AC_CHECK_TOOL(GOC, gccgo,) ]) # LT_PROG_RC # ---------- AC_DEFUN([LT_PROG_RC], [AC_CHECK_TOOL(RC, windres,) ]) # Old name: AU_ALIAS([LT_AC_PROG_RC], [LT_PROG_RC]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_RC], []) # _LT_DECL_EGREP # -------------- # If we don't have a new enough Autoconf to choose the best grep # available, choose the one first in the user's PATH. m4_defun([_LT_DECL_EGREP], [AC_REQUIRE([AC_PROG_EGREP])dnl AC_REQUIRE([AC_PROG_FGREP])dnl test -z "$GREP" && GREP=grep _LT_DECL([], [GREP], [1], [A grep program that handles long lines]) _LT_DECL([], [EGREP], [1], [An ERE matcher]) _LT_DECL([], [FGREP], [1], [A literal string matcher]) dnl Non-bleeding-edge autoconf doesn't subst GREP, so do it here too AC_SUBST([GREP]) ]) # _LT_DECL_OBJDUMP # -------------- # If we don't have a new enough Autoconf to choose the best objdump # available, choose the one first in the user's PATH. m4_defun([_LT_DECL_OBJDUMP], [AC_CHECK_TOOL(OBJDUMP, objdump, false) test -z "$OBJDUMP" && OBJDUMP=objdump _LT_DECL([], [OBJDUMP], [1], [An object symbol dumper]) AC_SUBST([OBJDUMP]) ]) # _LT_DECL_DLLTOOL # ---------------- # Ensure DLLTOOL variable is set. m4_defun([_LT_DECL_DLLTOOL], [AC_CHECK_TOOL(DLLTOOL, dlltool, false) test -z "$DLLTOOL" && DLLTOOL=dlltool _LT_DECL([], [DLLTOOL], [1], [DLL creation program]) AC_SUBST([DLLTOOL]) ]) # _LT_DECL_SED # ------------ # Check for a fully-functional sed program, that truncates # as few characters as possible. Prefer GNU sed if found. m4_defun([_LT_DECL_SED], [AC_PROG_SED test -z "$SED" && SED=sed Xsed="$SED -e 1s/^X//" _LT_DECL([], [SED], [1], [A sed program that does not truncate output]) _LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], [Sed that helps us avoid accidentally triggering echo(1) options like -n]) ])# _LT_DECL_SED m4_ifndef([AC_PROG_SED], [ ############################################################ # NOTE: This macro has been submitted for inclusion into # # GNU Autoconf as AC_PROG_SED. When it is available in # # a released version of Autoconf we should remove this # # macro and use it instead. # ############################################################ m4_defun([AC_PROG_SED], [AC_MSG_CHECKING([for a sed that does not truncate output]) AC_CACHE_VAL(lt_cv_path_SED, [# Loop through the user's path and test for sed and gsed. # Then use that list of sed's as ones to test for truncation. as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for lt_ac_prog in sed gsed; do for ac_exec_ext in '' $ac_executable_extensions; do if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" fi done done done IFS=$as_save_IFS lt_ac_max=0 lt_ac_count=0 # Add /usr/xpg4/bin/sed as it is typically found on Solaris # along with /bin/sed that truncates output. for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do test ! -f $lt_ac_sed && continue cat /dev/null > conftest.in lt_ac_count=0 echo $ECHO_N "0123456789$ECHO_C" >conftest.in # Check for GNU sed and select it if it is found. if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then lt_cv_path_SED=$lt_ac_sed break fi while true; do cat conftest.in conftest.in >conftest.tmp mv conftest.tmp conftest.in cp conftest.in conftest.nl echo >>conftest.nl $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break cmp -s conftest.out conftest.nl || break # 10000 chars as input seems more than enough test $lt_ac_count -gt 10 && break lt_ac_count=`expr $lt_ac_count + 1` if test $lt_ac_count -gt $lt_ac_max; then lt_ac_max=$lt_ac_count lt_cv_path_SED=$lt_ac_sed fi done done ]) SED=$lt_cv_path_SED AC_SUBST([SED]) AC_MSG_RESULT([$SED]) ])#AC_PROG_SED ])#m4_ifndef # Old name: AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_SED], []) # _LT_CHECK_SHELL_FEATURES # ------------------------ # Find out whether the shell is Bourne or XSI compatible, # or has some other useful features. m4_defun([_LT_CHECK_SHELL_FEATURES], [AC_MSG_CHECKING([whether the shell understands some XSI constructs]) # Try some XSI features xsi_shell=no ( _lt_dummy="a/b/c" test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \ = c,a/b,b/c, \ && eval 'test $(( 1 + 1 )) -eq 2 \ && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ && xsi_shell=yes AC_MSG_RESULT([$xsi_shell]) _LT_CONFIG_LIBTOOL_INIT([xsi_shell='$xsi_shell']) AC_MSG_CHECKING([whether the shell understands "+="]) lt_shell_append=no ( foo=bar; set foo baz; eval "$[1]+=\$[2]" && test "$foo" = barbaz ) \ >/dev/null 2>&1 \ && lt_shell_append=yes AC_MSG_RESULT([$lt_shell_append]) _LT_CONFIG_LIBTOOL_INIT([lt_shell_append='$lt_shell_append']) if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then lt_unset=unset else lt_unset=false fi _LT_DECL([], [lt_unset], [0], [whether the shell understands "unset"])dnl # test EBCDIC or ASCII case `echo X|tr X '\101'` in A) # ASCII based system # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr lt_SP2NL='tr \040 \012' lt_NL2SP='tr \015\012 \040\040' ;; *) # EBCDIC based system lt_SP2NL='tr \100 \n' lt_NL2SP='tr \r\n \100\100' ;; esac _LT_DECL([SP2NL], [lt_SP2NL], [1], [turn spaces into newlines])dnl _LT_DECL([NL2SP], [lt_NL2SP], [1], [turn newlines into spaces])dnl ])# _LT_CHECK_SHELL_FEATURES # _LT_PROG_FUNCTION_REPLACE (FUNCNAME, REPLACEMENT-BODY) # ------------------------------------------------------ # In `$cfgfile', look for function FUNCNAME delimited by `^FUNCNAME ()$' and # '^} FUNCNAME ', and replace its body with REPLACEMENT-BODY. m4_defun([_LT_PROG_FUNCTION_REPLACE], [dnl { sed -e '/^$1 ()$/,/^} # $1 /c\ $1 ()\ {\ m4_bpatsubsts([$2], [$], [\\], [^\([ ]\)], [\\\1]) } # Extended-shell $1 implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: ]) # _LT_PROG_REPLACE_SHELLFNS # ------------------------- # Replace existing portable implementations of several shell functions with # equivalent extended shell implementations where those features are available.. m4_defun([_LT_PROG_REPLACE_SHELLFNS], [if test x"$xsi_shell" = xyes; then _LT_PROG_FUNCTION_REPLACE([func_dirname], [dnl case ${1} in */*) func_dirname_result="${1%/*}${2}" ;; * ) func_dirname_result="${3}" ;; esac]) _LT_PROG_FUNCTION_REPLACE([func_basename], [dnl func_basename_result="${1##*/}"]) _LT_PROG_FUNCTION_REPLACE([func_dirname_and_basename], [dnl case ${1} in */*) func_dirname_result="${1%/*}${2}" ;; * ) func_dirname_result="${3}" ;; esac func_basename_result="${1##*/}"]) _LT_PROG_FUNCTION_REPLACE([func_stripname], [dnl # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are # positional parameters, so assign one to ordinary parameter first. func_stripname_result=${3} func_stripname_result=${func_stripname_result#"${1}"} func_stripname_result=${func_stripname_result%"${2}"}]) _LT_PROG_FUNCTION_REPLACE([func_split_long_opt], [dnl func_split_long_opt_name=${1%%=*} func_split_long_opt_arg=${1#*=}]) _LT_PROG_FUNCTION_REPLACE([func_split_short_opt], [dnl func_split_short_opt_arg=${1#??} func_split_short_opt_name=${1%"$func_split_short_opt_arg"}]) _LT_PROG_FUNCTION_REPLACE([func_lo2o], [dnl case ${1} in *.lo) func_lo2o_result=${1%.lo}.${objext} ;; *) func_lo2o_result=${1} ;; esac]) _LT_PROG_FUNCTION_REPLACE([func_xform], [ func_xform_result=${1%.*}.lo]) _LT_PROG_FUNCTION_REPLACE([func_arith], [ func_arith_result=$(( $[*] ))]) _LT_PROG_FUNCTION_REPLACE([func_len], [ func_len_result=${#1}]) fi if test x"$lt_shell_append" = xyes; then _LT_PROG_FUNCTION_REPLACE([func_append], [ eval "${1}+=\\${2}"]) _LT_PROG_FUNCTION_REPLACE([func_append_quoted], [dnl func_quote_for_eval "${2}" dnl m4 expansion turns \\\\ into \\, and then the shell eval turns that into \ eval "${1}+=\\\\ \\$func_quote_for_eval_result"]) # Save a `func_append' function call where possible by direct use of '+=' sed -e 's%func_append \([[a-zA-Z_]]\{1,\}\) "%\1+="%g' $cfgfile > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: else # Save a `func_append' function call even when '+=' is not available sed -e 's%func_append \([[a-zA-Z_]]\{1,\}\) "%\1="$\1%g' $cfgfile > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: fi if test x"$_lt_function_replace_fail" = x":"; then AC_MSG_WARN([Unable to substitute extended shell functions in $ofile]) fi ]) # _LT_PATH_CONVERSION_FUNCTIONS # ----------------------------- # Determine which file name conversion functions should be used by # func_to_host_file (and, implicitly, by func_to_host_path). These are needed # for certain cross-compile configurations and native mingw. m4_defun([_LT_PATH_CONVERSION_FUNCTIONS], [AC_REQUIRE([AC_CANONICAL_HOST])dnl AC_REQUIRE([AC_CANONICAL_BUILD])dnl AC_MSG_CHECKING([how to convert $build file names to $host format]) AC_CACHE_VAL(lt_cv_to_host_file_cmd, [case $host in *-*-mingw* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 ;; *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 ;; * ) # otherwise, assume *nix lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 ;; esac ;; *-*-cygwin* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin ;; *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_noop ;; * ) # otherwise, assume *nix lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin ;; esac ;; * ) # unhandled hosts (and "normal" native builds) lt_cv_to_host_file_cmd=func_convert_file_noop ;; esac ]) to_host_file_cmd=$lt_cv_to_host_file_cmd AC_MSG_RESULT([$lt_cv_to_host_file_cmd]) _LT_DECL([to_host_file_cmd], [lt_cv_to_host_file_cmd], [0], [convert $build file names to $host format])dnl AC_MSG_CHECKING([how to convert $build file names to toolchain format]) AC_CACHE_VAL(lt_cv_to_tool_file_cmd, [#assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in *-*-mingw* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 ;; esac ;; esac ]) to_tool_file_cmd=$lt_cv_to_tool_file_cmd AC_MSG_RESULT([$lt_cv_to_tool_file_cmd]) _LT_DECL([to_tool_file_cmd], [lt_cv_to_tool_file_cmd], [0], [convert $build files to toolchain format])dnl ])# _LT_PATH_CONVERSION_FUNCTIONS openbgpd-8.8/m4/ltoptions.m4100644 001750 001750 00000030073 14751151135 0011514# Helper functions for option handling. -*- Autoconf -*- # # Copyright (C) 2004, 2005, 2007, 2008, 2009 Free Software Foundation, # Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 7 ltoptions.m4 # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) # _LT_MANGLE_OPTION(MACRO-NAME, OPTION-NAME) # ------------------------------------------ m4_define([_LT_MANGLE_OPTION], [[_LT_OPTION_]m4_bpatsubst($1__$2, [[^a-zA-Z0-9_]], [_])]) # _LT_SET_OPTION(MACRO-NAME, OPTION-NAME) # --------------------------------------- # Set option OPTION-NAME for macro MACRO-NAME, and if there is a # matching handler defined, dispatch to it. Other OPTION-NAMEs are # saved as a flag. m4_define([_LT_SET_OPTION], [m4_define(_LT_MANGLE_OPTION([$1], [$2]))dnl m4_ifdef(_LT_MANGLE_DEFUN([$1], [$2]), _LT_MANGLE_DEFUN([$1], [$2]), [m4_warning([Unknown $1 option `$2'])])[]dnl ]) # _LT_IF_OPTION(MACRO-NAME, OPTION-NAME, IF-SET, [IF-NOT-SET]) # ------------------------------------------------------------ # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. m4_define([_LT_IF_OPTION], [m4_ifdef(_LT_MANGLE_OPTION([$1], [$2]), [$3], [$4])]) # _LT_UNLESS_OPTIONS(MACRO-NAME, OPTION-LIST, IF-NOT-SET) # ------------------------------------------------------- # Execute IF-NOT-SET unless all options in OPTION-LIST for MACRO-NAME # are set. m4_define([_LT_UNLESS_OPTIONS], [m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), [m4_ifdef(_LT_MANGLE_OPTION([$1], _LT_Option), [m4_define([$0_found])])])[]dnl m4_ifdef([$0_found], [m4_undefine([$0_found])], [$3 ])[]dnl ]) # _LT_SET_OPTIONS(MACRO-NAME, OPTION-LIST) # ---------------------------------------- # OPTION-LIST is a space-separated list of Libtool options associated # with MACRO-NAME. If any OPTION has a matching handler declared with # LT_OPTION_DEFINE, dispatch to that macro; otherwise complain about # the unknown option and exit. m4_defun([_LT_SET_OPTIONS], [# Set options m4_foreach([_LT_Option], m4_split(m4_normalize([$2])), [_LT_SET_OPTION([$1], _LT_Option)]) m4_if([$1],[LT_INIT],[ dnl dnl Simply set some default values (i.e off) if boolean options were not dnl specified: _LT_UNLESS_OPTIONS([LT_INIT], [dlopen], [enable_dlopen=no ]) _LT_UNLESS_OPTIONS([LT_INIT], [win32-dll], [enable_win32_dll=no ]) dnl dnl If no reference was made to various pairs of opposing options, then dnl we run the default mode handler for the pair. For example, if neither dnl `shared' nor `disable-shared' was passed, we enable building of shared dnl archives by default: _LT_UNLESS_OPTIONS([LT_INIT], [shared disable-shared], [_LT_ENABLE_SHARED]) _LT_UNLESS_OPTIONS([LT_INIT], [static disable-static], [_LT_ENABLE_STATIC]) _LT_UNLESS_OPTIONS([LT_INIT], [pic-only no-pic], [_LT_WITH_PIC]) _LT_UNLESS_OPTIONS([LT_INIT], [fast-install disable-fast-install], [_LT_ENABLE_FAST_INSTALL]) ]) ])# _LT_SET_OPTIONS ## --------------------------------- ## ## Macros to handle LT_INIT options. ## ## --------------------------------- ## # _LT_MANGLE_DEFUN(MACRO-NAME, OPTION-NAME) # ----------------------------------------- m4_define([_LT_MANGLE_DEFUN], [[_LT_OPTION_DEFUN_]m4_bpatsubst(m4_toupper([$1__$2]), [[^A-Z0-9_]], [_])]) # LT_OPTION_DEFINE(MACRO-NAME, OPTION-NAME, CODE) # ----------------------------------------------- m4_define([LT_OPTION_DEFINE], [m4_define(_LT_MANGLE_DEFUN([$1], [$2]), [$3])[]dnl ])# LT_OPTION_DEFINE # dlopen # ------ LT_OPTION_DEFINE([LT_INIT], [dlopen], [enable_dlopen=yes ]) AU_DEFUN([AC_LIBTOOL_DLOPEN], [_LT_SET_OPTION([LT_INIT], [dlopen]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `dlopen' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_DLOPEN], []) # win32-dll # --------- # Declare package support for building win32 dll's. LT_OPTION_DEFINE([LT_INIT], [win32-dll], [enable_win32_dll=yes case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) AC_CHECK_TOOL(AS, as, false) AC_CHECK_TOOL(DLLTOOL, dlltool, false) AC_CHECK_TOOL(OBJDUMP, objdump, false) ;; esac test -z "$AS" && AS=as _LT_DECL([], [AS], [1], [Assembler program])dnl test -z "$DLLTOOL" && DLLTOOL=dlltool _LT_DECL([], [DLLTOOL], [1], [DLL creation program])dnl test -z "$OBJDUMP" && OBJDUMP=objdump _LT_DECL([], [OBJDUMP], [1], [Object dumper program])dnl ])# win32-dll AU_DEFUN([AC_LIBTOOL_WIN32_DLL], [AC_REQUIRE([AC_CANONICAL_HOST])dnl _LT_SET_OPTION([LT_INIT], [win32-dll]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `win32-dll' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_WIN32_DLL], []) # _LT_ENABLE_SHARED([DEFAULT]) # ---------------------------- # implement the --enable-shared flag, and supports the `shared' and # `disable-shared' LT_INIT options. # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. m4_define([_LT_ENABLE_SHARED], [m4_define([_LT_ENABLE_SHARED_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([shared], [AS_HELP_STRING([--enable-shared@<:@=PKGS@:>@], [build shared libraries @<:@default=]_LT_ENABLE_SHARED_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; no) enable_shared=no ;; *) enable_shared=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_shared=yes fi done IFS="$lt_save_ifs" ;; esac], [enable_shared=]_LT_ENABLE_SHARED_DEFAULT) _LT_DECL([build_libtool_libs], [enable_shared], [0], [Whether or not to build shared libraries]) ])# _LT_ENABLE_SHARED LT_OPTION_DEFINE([LT_INIT], [shared], [_LT_ENABLE_SHARED([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-shared], [_LT_ENABLE_SHARED([no])]) # Old names: AC_DEFUN([AC_ENABLE_SHARED], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[shared]) ]) AC_DEFUN([AC_DISABLE_SHARED], [_LT_SET_OPTION([LT_INIT], [disable-shared]) ]) AU_DEFUN([AM_ENABLE_SHARED], [AC_ENABLE_SHARED($@)]) AU_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_ENABLE_SHARED], []) dnl AC_DEFUN([AM_DISABLE_SHARED], []) # _LT_ENABLE_STATIC([DEFAULT]) # ---------------------------- # implement the --enable-static flag, and support the `static' and # `disable-static' LT_INIT options. # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. m4_define([_LT_ENABLE_STATIC], [m4_define([_LT_ENABLE_STATIC_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([static], [AS_HELP_STRING([--enable-static@<:@=PKGS@:>@], [build static libraries @<:@default=]_LT_ENABLE_STATIC_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; no) enable_static=no ;; *) enable_static=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_static=yes fi done IFS="$lt_save_ifs" ;; esac], [enable_static=]_LT_ENABLE_STATIC_DEFAULT) _LT_DECL([build_old_libs], [enable_static], [0], [Whether or not to build static libraries]) ])# _LT_ENABLE_STATIC LT_OPTION_DEFINE([LT_INIT], [static], [_LT_ENABLE_STATIC([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-static], [_LT_ENABLE_STATIC([no])]) # Old names: AC_DEFUN([AC_ENABLE_STATIC], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[static]) ]) AC_DEFUN([AC_DISABLE_STATIC], [_LT_SET_OPTION([LT_INIT], [disable-static]) ]) AU_DEFUN([AM_ENABLE_STATIC], [AC_ENABLE_STATIC($@)]) AU_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AM_ENABLE_STATIC], []) dnl AC_DEFUN([AM_DISABLE_STATIC], []) # _LT_ENABLE_FAST_INSTALL([DEFAULT]) # ---------------------------------- # implement the --enable-fast-install flag, and support the `fast-install' # and `disable-fast-install' LT_INIT options. # DEFAULT is either `yes' or `no'. If omitted, it defaults to `yes'. m4_define([_LT_ENABLE_FAST_INSTALL], [m4_define([_LT_ENABLE_FAST_INSTALL_DEFAULT], [m4_if($1, no, no, yes)])dnl AC_ARG_ENABLE([fast-install], [AS_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@], [optimize for fast installation @<:@default=]_LT_ENABLE_FAST_INSTALL_DEFAULT[@:>@])], [p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; no) enable_fast_install=no ;; *) enable_fast_install=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_fast_install=yes fi done IFS="$lt_save_ifs" ;; esac], [enable_fast_install=]_LT_ENABLE_FAST_INSTALL_DEFAULT) _LT_DECL([fast_install], [enable_fast_install], [0], [Whether or not to optimize for fast installation])dnl ])# _LT_ENABLE_FAST_INSTALL LT_OPTION_DEFINE([LT_INIT], [fast-install], [_LT_ENABLE_FAST_INSTALL([yes])]) LT_OPTION_DEFINE([LT_INIT], [disable-fast-install], [_LT_ENABLE_FAST_INSTALL([no])]) # Old names: AU_DEFUN([AC_ENABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], m4_if([$1], [no], [disable-])[fast-install]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `fast-install' option into LT_INIT's first parameter.]) ]) AU_DEFUN([AC_DISABLE_FAST_INSTALL], [_LT_SET_OPTION([LT_INIT], [disable-fast-install]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `disable-fast-install' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_ENABLE_FAST_INSTALL], []) dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) # _LT_WITH_PIC([MODE]) # -------------------- # implement the --with-pic flag, and support the `pic-only' and `no-pic' # LT_INIT options. # MODE is either `yes' or `no'. If omitted, it defaults to `both'. m4_define([_LT_WITH_PIC], [AC_ARG_WITH([pic], [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@], [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], [lt_p=${PACKAGE-default} case $withval in yes|no) pic_mode=$withval ;; *) pic_mode=default # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for lt_pkg in $withval; do IFS="$lt_save_ifs" if test "X$lt_pkg" = "X$lt_p"; then pic_mode=yes fi done IFS="$lt_save_ifs" ;; esac], [pic_mode=default]) test -z "$pic_mode" && pic_mode=m4_default([$1], [default]) _LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl ])# _LT_WITH_PIC LT_OPTION_DEFINE([LT_INIT], [pic-only], [_LT_WITH_PIC([yes])]) LT_OPTION_DEFINE([LT_INIT], [no-pic], [_LT_WITH_PIC([no])]) # Old name: AU_DEFUN([AC_LIBTOOL_PICMODE], [_LT_SET_OPTION([LT_INIT], [pic-only]) AC_DIAGNOSE([obsolete], [$0: Remove this warning and the call to _LT_SET_OPTION when you put the `pic-only' option into LT_INIT's first parameter.]) ]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([AC_LIBTOOL_PICMODE], []) ## ----------------- ## ## LTDL_INIT Options ## ## ----------------- ## m4_define([_LTDL_MODE], []) LT_OPTION_DEFINE([LTDL_INIT], [nonrecursive], [m4_define([_LTDL_MODE], [nonrecursive])]) LT_OPTION_DEFINE([LTDL_INIT], [recursive], [m4_define([_LTDL_MODE], [recursive])]) LT_OPTION_DEFINE([LTDL_INIT], [subproject], [m4_define([_LTDL_MODE], [subproject])]) m4_define([_LTDL_TYPE], []) LT_OPTION_DEFINE([LTDL_INIT], [installable], [m4_define([_LTDL_TYPE], [installable])]) LT_OPTION_DEFINE([LTDL_INIT], [convenience], [m4_define([_LTDL_TYPE], [convenience])]) openbgpd-8.8/m4/ltsugar.m4100644 001750 001750 00000010424 14751151135 0011140# ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- # # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 6 ltsugar.m4 # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) # lt_join(SEP, ARG1, [ARG2...]) # ----------------------------- # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their # associated separator. # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier # versions in m4sugar had bugs. m4_define([lt_join], [m4_if([$#], [1], [], [$#], [2], [[$2]], [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) m4_define([_lt_join], [m4_if([$#$2], [2], [], [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) # lt_car(LIST) # lt_cdr(LIST) # ------------ # Manipulate m4 lists. # These macros are necessary as long as will still need to support # Autoconf-2.59 which quotes differently. m4_define([lt_car], [[$1]]) m4_define([lt_cdr], [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], [$#], 1, [], [m4_dquote(m4_shift($@))])]) m4_define([lt_unquote], $1) # lt_append(MACRO-NAME, STRING, [SEPARATOR]) # ------------------------------------------ # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. # Note that neither SEPARATOR nor STRING are expanded; they are appended # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). # No SEPARATOR is output if MACRO-NAME was previously undefined (different # than defined and empty). # # This macro is needed until we can rely on Autoconf 2.62, since earlier # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. m4_define([lt_append], [m4_define([$1], m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) # ---------------------------------------------------------- # Produce a SEP delimited list of all paired combinations of elements of # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list # has the form PREFIXmINFIXSUFFIXn. # Needed until we can rely on m4_combine added in Autoconf 2.62. m4_define([lt_combine], [m4_if(m4_eval([$# > 3]), [1], [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl [[m4_foreach([_Lt_prefix], [$2], [m4_foreach([_Lt_suffix], ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) # ----------------------------------------------------------------------- # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. m4_define([lt_if_append_uniq], [m4_ifdef([$1], [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], [lt_append([$1], [$2], [$3])$4], [$5])], [lt_append([$1], [$2], [$3])$4])]) # lt_dict_add(DICT, KEY, VALUE) # ----------------------------- m4_define([lt_dict_add], [m4_define([$1($2)], [$3])]) # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) # -------------------------------------------- m4_define([lt_dict_add_subkey], [m4_define([$1($2:$3)], [$4])]) # lt_dict_fetch(DICT, KEY, [SUBKEY]) # ---------------------------------- m4_define([lt_dict_fetch], [m4_ifval([$3], m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) # ----------------------------------------------------------------- m4_define([lt_if_dict_fetch], [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], [$5], [$6])]) # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) # -------------------------------------------------------------- m4_define([lt_dict_filter], [m4_if([$5], [], [], [lt_join(m4_quote(m4_default([$4], [[, ]])), lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl ]) openbgpd-8.8/m4/ltversion.m4100644 001750 001750 00000001262 14751151135 0011504# ltversion.m4 -- version numbers -*- Autoconf -*- # # Copyright (C) 2004 Free Software Foundation, Inc. # Written by Scott James Remnant, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # @configure_input@ # serial 3337 ltversion.m4 # This file is part of GNU Libtool m4_define([LT_PACKAGE_VERSION], [2.4.2]) m4_define([LT_PACKAGE_REVISION], [1.3337]) AC_DEFUN([LTVERSION_VERSION], [macro_version='2.4.2' macro_revision='1.3337' _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_revision, 0) ]) openbgpd-8.8/m4/lt~obsolete.m4100644 001750 001750 00000013756 14751151135 0012044# lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- # # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. # Written by Scott James Remnant, 2004. # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # serial 5 lt~obsolete.m4 # These exist entirely to fool aclocal when bootstrapping libtool. # # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) # which have later been changed to m4_define as they aren't part of the # exported API, or moved to Autoconf or Automake where they belong. # # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us # using a macro with the same name in our local m4/libtool.m4 it'll # pull the old libtool.m4 in (it doesn't see our shiny new m4_define # and doesn't know about Autoconf macros at all.) # # So we provide this file, which has a silly filename so it's always # included after everything else. This provides aclocal with the # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything # because those macros already exist, or will be overwritten later. # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. # # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. # Yes, that means every name once taken will need to remain here until # we give up compatibility with versions before 1.7, at which point # we need to keep only those names which we still refer to. # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) openbgpd-8.8/Makefile.am100644 001750 001750 00000003225 14453465372 0010744# # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. SUBDIRS = include compat src/bgpd src/bgpctl if BUILD_BGPLGD SUBDIRS += src/bgplgd endif ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = README.md LICENSE VERSION bgpd.conf install-data-hook: @if [ ! -d "$(DESTDIR)$(runstatedir)" ]; then \ $(INSTALL) -m 755 -d "$(DESTDIR)$(runstatedir)"; \ fi @if [ X"$(wwwrunstatedir)" != X -a ! -d "$(DESTDIR)$(wwwrunstatedir)" ]; then \ $(INSTALL) -m 755 -d "$(DESTDIR)$(wwwrunstatedir)"; \ fi @if [ ! -d "$(DESTDIR)$(sysconfdir)" ]; then \ $(INSTALL) -m 755 -d "$(DESTDIR)$(sysconfdir)"; \ fi @if [ ! -f "$(DESTDIR)$(sysconfdir)/bgpd.conf" ]; then \ $(INSTALL) -m 644 "$(srcdir)/bgpd.conf" "$(DESTDIR)$(sysconfdir)/bgpd.conf"; \ else \ echo; \ echo " $(DESTDIR)$(sysconfdir)/bgpd.conf already exists, install will not overwrite"; \ fi uninstall-local: @if cmp -s "$(DESTDIR)$(sysconfdir)/bgpd.conf" "$(srcdir)/bgpd.conf"; then \ rm -f "$(DESTDIR)$(sysconfdir)/bgpd.conf"; \ fi openbgpd-8.8/configure100755 001750 001750 00001720505 14751151137 0010617#! /bin/sh # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.72 for OpenBGPD 8.8. # # # Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation, # Inc. # # # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case e in #( e) case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac ;; esac fi # Reset variables that may have inherited troublesome values from # the environment. # IFS needs to be set, to space, tab, and newline, in precisely that order. # (If _AS_PATH_WALK were called with IFS unset, it would have the # side effect of setting IFS to empty, thus disabling word splitting.) # Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl IFS=" "" $as_nl" PS1='$ ' PS2='> ' PS4='+ ' # Ensure predictable behavior from utilities with locale-dependent output. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # We cannot yet rely on "unset" to work, but we need these variables # to be unset--not just set to an empty or harmless value--now, to # avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct # also avoids known problems related to "unset" and subshell syntax # in other old shells (e.g. bash 2.01 and pdksh 5.2.14). for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH do eval test \${$as_var+y} \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done # Ensure that fds 0, 1, and 2 are open. if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. if ${PATH_SEPARATOR+false} :; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as 'sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then _as_can_reexec=no; export _as_can_reexec; # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed 'exec'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case e in #( e) case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( *) : ;; esac ;; esac fi " as_required="as_fn_return () { (exit \$1); } as_fn_success () { as_fn_return 0; } as_fn_failure () { as_fn_return 1; } as_fn_ret_success () { return 0; } as_fn_ret_failure () { return 1; } exitcode=0 as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } if ( set x; as_fn_ret_success y && test x = \"\$1\" ) then : else case e in #( e) exitcode=1; echo positional parameters were not saved. ;; esac fi test x\$exitcode = x0 || exit 1 blah=\$(echo \$(echo blah)) test x\"\$blah\" = xblah || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && test \"x\`expr \$as_lineno_1'\$as_run' + 1\`\" = \"x\$as_lineno_2'\$as_run'\"' || exit 1 test \$(( 1 + 1 )) = 2 || exit 1 test -n \"\${ZSH_VERSION+set}\${BASH_VERSION+set}\" || ( ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO ECHO=\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO\$ECHO PATH=/empty FPATH=/empty; export PATH FPATH test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1" if (eval "$as_required") 2>/dev/null then : as_have_required=yes else case e in #( e) as_have_required=no ;; esac fi if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null then : else case e in #( e) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. as_shell=$as_dir$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null then : CONFIG_SHELL=$as_shell as_have_required=yes if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null then : break 2 fi fi done;; esac as_found=false done IFS=$as_save_IFS if $as_found then : else case e in #( e) if { test -f "$SHELL" || test -f "$SHELL.exe"; } && as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null then : CONFIG_SHELL=$SHELL as_have_required=yes fi ;; esac fi if test "x$CONFIG_SHELL" != x then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also # works around shells that cannot unset nonexistent variables. # Preserve -v and -x to the replacement shell. BASH_ENV=/dev/null ENV=/dev/null (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV case $- in # (((( *v*x* | *x*v* ) as_opts=-vx ;; *v* ) as_opts=-v ;; *x* ) as_opts=-x ;; * ) as_opts= ;; esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed 'exec'. printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi if test x$as_have_required = xno then : printf "%s\n" "$0: This script requires a shell more modern than all" printf "%s\n" "$0: the shells that I found on your system." if test ${ZSH_VERSION+y} ; then printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." else printf "%s\n" "$0: Please tell bug-autoconf@gnu.org about your system, $0: including any error possibly output before this $0: message. Then install a modern shell, or manually run $0: the script under such a shell if you do have one." fi exit 1 fi ;; esac fi fi SHELL=${CONFIG_SHELL-/bin/sh} export SHELL # Unset more variables known to interfere with behavior of common tools. CLICOLOR_FORCE= GREP_OPTIONS= unset CLICOLOR_FORCE GREP_OPTIONS ## --------------------- ## ## M4sh Shell Functions. ## ## --------------------- ## # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null then : eval 'as_fn_append () { eval $1+=\$2 }' else case e in #( e) as_fn_append () { eval $1=\$$1\$2 } ;; esac fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null then : eval 'as_fn_arith () { as_val=$(( $* )) }' else case e in #( e) as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } ;; esac fi # as_fn_arith # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits as_lineno_1=$LINENO as_lineno_1a=$LINENO as_lineno_2=$LINENO as_lineno_2a=$LINENO eval 'test "x$as_lineno_1'$as_run'" != "x$as_lineno_2'$as_run'" && test "x`expr $as_lineno_1'$as_run' + 1`" = "x$as_lineno_2'$as_run'"' || { # Blame Lee E. McMahon (1931-1989) for sed's syntax. :-) sed -n ' p /[$]LINENO/= ' <$as_myself | sed ' t clear :clear s/[$]LINENO.*/&-/ t lineno b :lineno N :loop s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ t loop s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall # in an infinite loop. This has already happened in practice. _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). . "./$as_me.lineno" # Exit status is that of the last command. exit } # Determine whether it's possible to make 'echo' print without a newline. # These variables are no longer used directly by Autoconf, but are AC_SUBSTed # for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac # For backward compatibility with old third-party macros, we provide # the shell variables $as_echo and $as_echo_n. New code should use # AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. as_echo='printf %s\n' as_echo_n='printf %s' rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable. # In both cases, we have to default to 'cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated # Sed expression to map a string onto a valid variable name. as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g" as_tr_sh="eval sed '$as_sed_sh'" # deprecated SHELL=${CONFIG_SHELL-/bin/sh} test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. # hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` # # Initializations. # ac_default_prefix=/usr/local ac_clean_files= ac_config_libobj_dir=. LIBOBJS= cross_compiling=no subdirs= MFLAGS= MAKEFLAGS= # Identity of this package. PACKAGE_NAME='OpenBGPD' PACKAGE_TARNAME='openbgpd' PACKAGE_VERSION='8.8' PACKAGE_STRING='OpenBGPD 8.8' PACKAGE_BUGREPORT='' PACKAGE_URL='' # Factoring default headers for most tests. ac_includes_default="\ #include #ifdef HAVE_STDIO_H # include #endif #ifdef HAVE_STDLIB_H # include #endif #ifdef HAVE_STRING_H # include #endif #ifdef HAVE_INTTYPES_H # include #endif #ifdef HAVE_STDINT_H # include #endif #ifdef HAVE_STRINGS_H # include #endif #ifdef HAVE_SYS_TYPES_H # include #endif #ifdef HAVE_SYS_STAT_H # include #endif #ifdef HAVE_UNISTD_H # include #endif" ac_header_c_list= ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS LIBOBJS AM_LDFLAGS AM_CFLAGS DISABLE_FIB_FALSE DISABLE_FIB_TRUE BUILD_BGPLGD_FALSE BUILD_BGPLGD_TRUE wwwrunstatedir WWW_USER BGPLGD_USER BGPD_USER HAVE_SETFIB_FALSE HAVE_SETFIB_TRUE HAVE_LINUX_TCPMD5_FALSE HAVE_LINUX_TCPMD5_TRUE HAVE_ARC4RANDOM_FALSE HAVE_ARC4RANDOM_TRUE HAVE_PFTABLE_FALSE HAVE_PFTABLE_TRUE HAVE_MNL_FALSE HAVE_MNL_TRUE HAVE_FMT_SCALED_FALSE HAVE_FMT_SCALED_TRUE HAVE_INET_NET_PTON_FALSE HAVE_INET_NET_PTON_TRUE BROKEN_STRNVIS_FALSE BROKEN_STRNVIS_TRUE HAVE_STRNVIS_FALSE HAVE_STRNVIS_TRUE HAVE_GETRTABLE_FALSE HAVE_GETRTABLE_TRUE HAVE_GETDTABLECOUNT_FALSE HAVE_GETDTABLECOUNT_TRUE HAVE_UNVEIL_FALSE HAVE_UNVEIL_TRUE HAVE_PLEDGE_FALSE HAVE_PLEDGE_TRUE HAVE_SYSCONF_FALSE HAVE_SYSCONF_TRUE HAVE_STRTONUM_FALSE HAVE_STRTONUM_TRUE HAVE_STRLCPY_FALSE HAVE_STRLCPY_TRUE HAVE_STRLCAT_FALSE HAVE_STRLCAT_TRUE HAVE_SETPROCTITLE_FALSE HAVE_SETPROCTITLE_TRUE HAVE_SETRESUID_FALSE HAVE_SETRESUID_TRUE HAVE_SETRESGID_FALSE HAVE_SETRESGID_TRUE HAVE_SETGROUPS_FALSE HAVE_SETGROUPS_TRUE HAVE_RECALLOCARRAY_FALSE HAVE_RECALLOCARRAY_TRUE HAVE_REALLOCARRAY_FALSE HAVE_REALLOCARRAY_TRUE HAVE_POLL_FALSE HAVE_POLL_TRUE HAVE_MEMMEM_FALSE HAVE_MEMMEM_TRUE HAVE_MD5_FALSE HAVE_MD5_TRUE HAVE_IMSG_FALSE HAVE_IMSG_TRUE HAVE_GETENTROPY_FALSE HAVE_GETENTROPY_TRUE HAVE_FREEZERO_FALSE HAVE_FREEZERO_TRUE HAVE_EXPLICIT_BZERO_FALSE HAVE_EXPLICIT_BZERO_TRUE HAVE_CLOCK_GETTIME_FALSE HAVE_CLOCK_GETTIME_TRUE HAVE_CLOCK_GETRES_FALSE HAVE_CLOCK_GETRES_TRUE HAVE_CLOSEFROM_FALSE HAVE_CLOSEFROM_TRUE HAVE_ASPRINTF_FALSE HAVE_ASPRINTF_TRUE YFLAGS YACC OTOOL64 OTOOL LIPO NMEDIT DSYMUTIL MANIFEST_TOOL RANLIB ac_ct_AR AR DLLTOOL OBJDUMP LN_S NM ac_ct_DUMPBIN DUMPBIN LD FGREP EGREP GREP LIBTOOL SED HOST_SOLARIS_FALSE HOST_SOLARIS_TRUE HOST_OPENBSD_FALSE HOST_OPENBSD_TRUE HOST_NETBSD_FALSE HOST_NETBSD_TRUE HOST_LINUX_FALSE HOST_LINUX_TRUE HOST_FREEBSD_FALSE HOST_FREEBSD_TRUE HOST_DARWIN_FALSE HOST_DARWIN_TRUE am__fastdepCC_FALSE am__fastdepCC_TRUE CCDEPMODE am__nodep AMDEPBACKSLASH AMDEP_FALSE AMDEP_TRUE am__include DEPDIR OBJEXT EXEEXT ac_ct_CC CPPFLAGS LDFLAGS CFLAGS CC AM_BACKSLASH AM_DEFAULT_VERBOSITY AM_DEFAULT_V AM_V CSCOPE ETAGS CTAGS am__untar am__tar AMTAR am__leading_dot SET_MAKE AWK mkdir_p MKDIR_P INSTALL_STRIP_PROGRAM STRIP install_sh MAKEINFO AUTOHEADER AUTOMAKE AUTOCONF ACLOCAL VERSION PACKAGE CYGPATH_W am__isrc INSTALL_DATA INSTALL_SCRIPT INSTALL_PROGRAM host_os host_vendor host_cpu host build_os build_vendor build_cpu build target_alias host_alias build_alias LIBS ECHO_T ECHO_N ECHO_C DEFS mandir localedir libdir psdir pdfdir dvidir htmldir infodir docdir oldincludedir includedir runstatedir localstatedir sharedstatedir sysconfdir datadir datarootdir libexecdir sbindir bindir program_transform_name prefix exec_prefix PACKAGE_URL PACKAGE_BUGREPORT PACKAGE_STRING PACKAGE_VERSION PACKAGE_TARNAME PACKAGE_NAME PATH_SEPARATOR SHELL am__quote' ac_subst_files='' ac_user_opts=' enable_option_checking enable_silent_rules enable_dependency_tracking enable_shared enable_static with_pic enable_fast_install with_gnu_ld with_sysroot enable_libtool_lock enable_bgplgd enable_fib_support enable_warnings with_event with_event_cflags with_event_ldflags with_privsep_user with_bgplgd_user with_www_user with_wwwrunstatedir with_runstatedir ' ac_precious_vars='build_alias host_alias target_alias CC CFLAGS LDFLAGS LIBS CPPFLAGS YACC YFLAGS' # Initialize some variables set by options. ac_init_help= ac_init_version=false ac_unrecognized_opts= ac_unrecognized_sep= # The variables have the same names as the options, with # dashes changed to underlines. cache_file=/dev/null exec_prefix=NONE no_create= no_recursion= prefix=NONE program_prefix=NONE program_suffix=NONE program_transform_name=s,x,x, silent= site= srcdir= verbose= x_includes=NONE x_libraries=NONE # Installation directory options. # These are left unexpanded so users can "make install exec_prefix=/foo" # and all the variables that are supposed to be based on exec_prefix # by default will actually change. # Use braces instead of parens because sh, perl, etc. also accept them. # (The list follows the same order as the GNU Coding Standards.) bindir='${exec_prefix}/bin' sbindir='${exec_prefix}/sbin' libexecdir='${exec_prefix}/libexec' datarootdir='${prefix}/share' datadir='${datarootdir}' sysconfdir='${prefix}/etc' sharedstatedir='${prefix}/com' localstatedir='${prefix}/var' runstatedir='${localstatedir}/run' includedir='${prefix}/include' oldincludedir='/usr/include' docdir='${datarootdir}/doc/${PACKAGE_TARNAME}' infodir='${datarootdir}/info' htmldir='${docdir}' dvidir='${docdir}' pdfdir='${docdir}' psdir='${docdir}' libdir='${exec_prefix}/lib' localedir='${datarootdir}/locale' mandir='${datarootdir}/man' ac_prev= ac_dashdash= for ac_option do # If the previous option needs an argument, assign it. if test -n "$ac_prev"; then eval $ac_prev=\$ac_option ac_prev= continue fi case $ac_option in *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; *=) ac_optarg= ;; *) ac_optarg=yes ;; esac case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; -bindir | --bindir | --bindi | --bind | --bin | --bi) ac_prev=bindir ;; -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) bindir=$ac_optarg ;; -build | --build | --buil | --bui | --bu) ac_prev=build_alias ;; -build=* | --build=* | --buil=* | --bui=* | --bu=*) build_alias=$ac_optarg ;; -cache-file | --cache-file | --cache-fil | --cache-fi \ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) ac_prev=cache_file ;; -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) cache_file=$ac_optarg ;; --config-cache | -C) cache_file=config.cache ;; -datadir | --datadir | --datadi | --datad) ac_prev=datadir ;; -datadir=* | --datadir=* | --datadi=* | --datad=*) datadir=$ac_optarg ;; -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ | --dataroo | --dataro | --datar) ac_prev=datarootdir ;; -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) datarootdir=$ac_optarg ;; -disable-* | --disable-*) ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--disable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=no ;; -docdir | --docdir | --docdi | --doc | --do) ac_prev=docdir ;; -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) docdir=$ac_optarg ;; -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) ac_prev=dvidir ;; -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) dvidir=$ac_optarg ;; -enable-* | --enable-*) ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid feature name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--enable-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval enable_$ac_useropt=\$ac_optarg ;; -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ | --exec | --exe | --ex) ac_prev=exec_prefix ;; -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ | --exec=* | --exe=* | --ex=*) exec_prefix=$ac_optarg ;; -gas | --gas | --ga | --g) # Obsolete; use --with-gas. with_gas=yes ;; -help | --help | --hel | --he | -h) ac_init_help=long ;; -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) ac_init_help=recursive ;; -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) ac_init_help=short ;; -host | --host | --hos | --ho) ac_prev=host_alias ;; -host=* | --host=* | --hos=* | --ho=*) host_alias=$ac_optarg ;; -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) ac_prev=htmldir ;; -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ | --ht=*) htmldir=$ac_optarg ;; -includedir | --includedir | --includedi | --included | --include \ | --includ | --inclu | --incl | --inc) ac_prev=includedir ;; -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ | --includ=* | --inclu=* | --incl=* | --inc=*) includedir=$ac_optarg ;; -infodir | --infodir | --infodi | --infod | --info | --inf) ac_prev=infodir ;; -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) infodir=$ac_optarg ;; -libdir | --libdir | --libdi | --libd) ac_prev=libdir ;; -libdir=* | --libdir=* | --libdi=* | --libd=*) libdir=$ac_optarg ;; -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ | --libexe | --libex | --libe) ac_prev=libexecdir ;; -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ | --libexe=* | --libex=* | --libe=*) libexecdir=$ac_optarg ;; -localedir | --localedir | --localedi | --localed | --locale) ac_prev=localedir ;; -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) localedir=$ac_optarg ;; -localstatedir | --localstatedir | --localstatedi | --localstated \ | --localstate | --localstat | --localsta | --localst | --locals) ac_prev=localstatedir ;; -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) localstatedir=$ac_optarg ;; -mandir | --mandir | --mandi | --mand | --man | --ma | --m) ac_prev=mandir ;; -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) mandir=$ac_optarg ;; -nfp | --nfp | --nf) # Obsolete; use --without-fp. with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c | -n) no_create=yes ;; -no-recursion | --no-recursion | --no-recursio | --no-recursi \ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) no_recursion=yes ;; -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ | --oldin | --oldi | --old | --ol | --o) ac_prev=oldincludedir ;; -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) oldincludedir=$ac_optarg ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) ac_prev=prefix ;; -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) prefix=$ac_optarg ;; -program-prefix | --program-prefix | --program-prefi | --program-pref \ | --program-pre | --program-pr | --program-p) ac_prev=program_prefix ;; -program-prefix=* | --program-prefix=* | --program-prefi=* \ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) program_prefix=$ac_optarg ;; -program-suffix | --program-suffix | --program-suffi | --program-suff \ | --program-suf | --program-su | --program-s) ac_prev=program_suffix ;; -program-suffix=* | --program-suffix=* | --program-suffi=* \ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) program_suffix=$ac_optarg ;; -program-transform-name | --program-transform-name \ | --program-transform-nam | --program-transform-na \ | --program-transform-n | --program-transform- \ | --program-transform | --program-transfor \ | --program-transfo | --program-transf \ | --program-trans | --program-tran \ | --progr-tra | --program-tr | --program-t) ac_prev=program_transform_name ;; -program-transform-name=* | --program-transform-name=* \ | --program-transform-nam=* | --program-transform-na=* \ | --program-transform-n=* | --program-transform-=* \ | --program-transform=* | --program-transfor=* \ | --program-transfo=* | --program-transf=* \ | --program-trans=* | --program-tran=* \ | --progr-tra=* | --program-tr=* | --program-t=*) program_transform_name=$ac_optarg ;; -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) ac_prev=pdfdir ;; -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) pdfdir=$ac_optarg ;; -psdir | --psdir | --psdi | --psd | --ps) ac_prev=psdir ;; -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) psdir=$ac_optarg ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) silent=yes ;; -runstatedir | --runstatedir | --runstatedi | --runstated \ | --runstate | --runstat | --runsta | --runst | --runs \ | --run | --ru | --r) ac_prev=runstatedir ;; -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \ | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \ | --run=* | --ru=* | --r=*) runstatedir=$ac_optarg ;; -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) ac_prev=sbindir ;; -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ | --sbi=* | --sb=*) sbindir=$ac_optarg ;; -sharedstatedir | --sharedstatedir | --sharedstatedi \ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ | --sharedst | --shareds | --shared | --share | --shar \ | --sha | --sh) ac_prev=sharedstatedir ;; -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ | --sha=* | --sh=*) sharedstatedir=$ac_optarg ;; -site | --site | --sit) ac_prev=site ;; -site=* | --site=* | --sit=*) site=$ac_optarg ;; -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) srcdir=$ac_optarg ;; -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ | --syscon | --sysco | --sysc | --sys | --sy) ac_prev=sysconfdir ;; -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) sysconfdir=$ac_optarg ;; -target | --target | --targe | --targ | --tar | --ta | --t) ac_prev=target_alias ;; -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) target_alias=$ac_optarg ;; -v | -verbose | --verbose | --verbos | --verbo | --verb) verbose=yes ;; -version | --version | --versio | --versi | --vers | -V) ac_init_version=: ;; -with-* | --with-*) ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--with-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=\$ac_optarg ;; -without-* | --without-*) ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && as_fn_error $? "invalid package name: '$ac_useropt'" ac_useropt_orig=$ac_useropt ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" "*) ;; *) ac_unrecognized_opts="$ac_unrecognized_opts$ac_unrecognized_sep--without-$ac_useropt_orig" ac_unrecognized_sep=', ';; esac eval with_$ac_useropt=no ;; --x) # Obsolete; use --with-x. with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ | --x-incl | --x-inc | --x-in | --x-i) ac_prev=x_includes ;; -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) x_includes=$ac_optarg ;; -x-libraries | --x-libraries | --x-librarie | --x-librari \ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) ac_prev=x_libraries ;; -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; -*) as_fn_error $? "unrecognized option: '$ac_option' Try '$0 --help' for more information" ;; *=*) ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) as_fn_error $? "invalid variable name: '$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; *) # FIXME: should be removed in autoconf 3.0. printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac done if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi # Check all directory arguments for consistency. for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ datadir sysconfdir sharedstatedir localstatedir includedir \ oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ libdir localedir mandir runstatedir do eval ac_val=\$$ac_var # Remove trailing slashes. case $ac_val in */ ) ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'` eval $ac_var=\$ac_val;; esac # Be sure to have absolute directory names. case $ac_val in [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: '$host' # used to hold the argument of --host etc. # FIXME: To remove some day. build=$build_alias host=$host_alias target=$target_alias # FIXME: To remove some day. if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi fi ac_tool_prefix= test -n "$host_alias" && ac_tool_prefix=$host_alias- test "$silent" = yes && exec 6>/dev/null ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. if test -z "$srcdir"; then ac_srcdir_defaulted=yes # Try the directory containing this script, then the parent directory. ac_confdir=`$as_dirname -- "$as_myself" || $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` srcdir=$ac_confdir if test ! -r "$srcdir/$ac_unique_file"; then srcdir=.. fi else ac_srcdir_defaulted=no fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but 'cd $srcdir' does not work" ac_abs_confdir=`( cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then srcdir=. fi # Remove unnecessary trailing slashes from srcdir. # Double slashes in file names in object file debugging info # mess up M-x gdb in Emacs. case $srcdir in */) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; esac for ac_var in $ac_precious_vars; do eval ac_env_${ac_var}_set=\${${ac_var}+set} eval ac_env_${ac_var}_value=\$${ac_var} eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} eval ac_cv_env_${ac_var}_value=\$${ac_var} done # # Report the --help message. # if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF 'configure' configures OpenBGPD 8.8 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration: -h, --help display this help and exit --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit -q, --quiet, --silent do not print 'checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for '--cache-file=config.cache' -n, --no-create do not create output files --srcdir=DIR find the sources in DIR [configure dir or '..'] Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [$ac_default_prefix] --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX [PREFIX] By default, 'make install' will install all the files in '$ac_default_prefix/bin', '$ac_default_prefix/lib' etc. You can specify an installation prefix other than '$ac_default_prefix' using '--prefix', for instance '--prefix=\$HOME'. For better control, use the options below. Fine tuning of the installation directories: --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --libexecdir=DIR program executables [EPREFIX/libexec] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] --localstatedir=DIR modifiable single-machine data [PREFIX/var] --runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run] --libdir=DIR object code libraries [EPREFIX/lib] --includedir=DIR C header files [PREFIX/include] --oldincludedir=DIR C header files for non-gcc [/usr/include] --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] --datadir=DIR read-only architecture-independent data [DATAROOTDIR] --infodir=DIR info documentation [DATAROOTDIR/info] --localedir=DIR locale-dependent data [DATAROOTDIR/locale] --mandir=DIR man documentation [DATAROOTDIR/man] --docdir=DIR documentation root [DATAROOTDIR/doc/openbgpd] --htmldir=DIR html documentation [DOCDIR] --dvidir=DIR dvi documentation [DOCDIR] --pdfdir=DIR pdf documentation [DOCDIR] --psdir=DIR ps documentation [DOCDIR] _ACEOF cat <<\_ACEOF Program names: --program-prefix=PREFIX prepend PREFIX to installed program names --program-suffix=SUFFIX append SUFFIX to installed program names --program-transform-name=PROGRAM run sed PROGRAM on installed program names System types: --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] _ACEOF fi if test -n "$ac_init_help"; then case $ac_init_help in short | recursive ) echo "Configuration of OpenBGPD 8.8:";; esac cat <<\_ACEOF Optional Features: --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking speeds up one-time build --enable-shared[=PKGS] build shared libraries [default=yes] --enable-static[=PKGS] build static libraries [default=yes] --enable-fast-install[=PKGS] optimize for fast installation [default=yes] --disable-libtool-lock avoid locking (might break parallel builds) --disable-bgplgd build bgplgd [default=enabled] --disable-fib-support build without fib support [default=enabled] --disable-warnings enable compiler warnings [default=enabled] Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use both] --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-sysroot=DIR Search for dependent libraries within DIR (or the compiler's sysroot if not specified). --with-event=pkg-name Use pkg-config(1) pkg-name to find libevent --with-event-cflags=STRING Extra compiler flags to build with libevent --with-event-ldflags=STRING Extra flags for linker to link with libevent --with-privsep-user=user Privilege separation user for bgpd --with-bgplgd-user=user Privilege drop user for bgplgd --with-www-user=user Owner of the FastCGI socket used by bgplgd --with-wwwrunstatedir=DIR Location for bgplgd FastCGI socket [LOCALSTATEDIR/www/run] --with-runstatedir=DIR Location for bgpd control socket [LOCALSTATEDIR/run] Some influential environment variables: CC C compiler command CFLAGS C compiler flags LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory YACC The 'Yet Another Compiler Compiler' implementation to use. Defaults to the first program found out of: 'bison -y', 'byacc', 'yacc'. YFLAGS The list of arguments that will be passed by default to $YACC. This script will default YFLAGS to the empty string to avoid a default value of '-d' given by some make applications. Use these variables to override the choices made by 'configure' or to help it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider. _ACEOF ac_status=$? fi if test "$ac_init_help" = "recursive"; then # If there are subdirs, report their specific --help. for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue test -d "$ac_dir" || { cd "$srcdir" && ac_pwd=`pwd` && srcdir=. && test -d "$ac_dir"; } || continue ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } # Check for configure.gnu first; this name is used for a wrapper for # Metaconfig's "Configure" on case-insensitive file systems. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive elif test -f "$ac_srcdir/configure"; then echo && $SHELL "$ac_srcdir/configure" --help=recursive else printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF OpenBGPD configure 8.8 generated by GNU Autoconf 2.72 Copyright (C) 2023 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF exit fi ## ------------------------ ## ## Autoconf initialization. ## ## ------------------------ ## # ac_fn_c_try_compile LINENO # -------------------------- # Try to compile conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest.beam if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest.$ac_objext then : ac_retval=0 else case e in #( e) printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 ;; esac fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_compile # ac_fn_c_check_header_compile LINENO HEADER VAR INCLUDES # ------------------------------------------------------- # Tests whether HEADER exists and can be compiled using the include files in # INCLUDES, setting the cache variable VAR accordingly. ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 printf %s "checking for $2... " >&6; } if eval test \${$3+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF if ac_fn_c_try_compile "$LINENO" then : eval "$3=yes" else case e in #( e) eval "$3=no" ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi eval ac_res=\$$3 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile # ac_fn_c_try_link LINENO # ----------------------- # Try to link conftest.$ac_ext, and return whether this succeeded. ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then grep -v '^ *+' conftest.err >conftest.er1 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext } then : ac_retval=0 else case e in #( e) printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 ;; esac fi # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would # interfere with the next link command; also delete a directory that is # left behind by Apple's compiler. We do this before executing the actions. rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_link # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 printf %s "checking for $2... " >&6; } if eval test \${$3+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case declares $2. For example, HP-UX 11i declares gettimeofday. */ #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $2 (void); below. */ #include #undef $2 /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ #ifdef __cplusplus extern "C" #endif char $2 (void); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$2 || defined __stub___$2 choke me #endif int main (void) { return $2 (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : eval "$3=yes" else case e in #( e) eval "$3=no" ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ;; esac fi eval ac_res=\$$3 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func # ac_fn_c_try_run LINENO # ---------------------- # Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that # executables *can* be run. ac_fn_c_try_run () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; } then : ac_retval=0 else case e in #( e) printf "%s\n" "$as_me: program exited with status $ac_status" >&5 printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=$ac_status ;; esac fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno as_fn_set_status $ac_retval } # ac_fn_c_try_run # ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES # ---------------------------------------------------- # Tries to find if the field MEMBER exists in type AGGR, after including # INCLUDES, setting cache variable VAR accordingly. ac_fn_c_check_member () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5 printf %s "checking for $2.$3... " >&6; } if eval test \${$4+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main (void) { static $2 ac_aggr; if (ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : eval "$4=yes" else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $5 int main (void) { static $2 ac_aggr; if (sizeof ac_aggr.$3) return 0; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : eval "$4=yes" else case e in #( e) eval "$4=no" ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi eval ac_res=\$$4 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_member ac_configure_args_raw= for ac_arg do case $ac_arg in *\'*) ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append ac_configure_args_raw " '$ac_arg'" done case $ac_configure_args_raw in *$as_nl*) ac_safe_unquote= ;; *) ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. ac_unsafe_a="$ac_unsafe_z#~" ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; esac cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by OpenBGPD $as_me 8.8, which was generated by GNU Autoconf 2.72. Invocation command line was $ $0$ac_configure_args_raw _ACEOF exec 5>>config.log { cat <<_ASUNAME ## --------- ## ## Platform. ## ## --------- ## hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` uname -m = `(uname -m) 2>/dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` /bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` /bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` /usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` /bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` /bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` _ASUNAME as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac printf "%s\n" "PATH: $as_dir" done IFS=$as_save_IFS } >&5 cat >&5 <<_ACEOF ## ----------- ## ## Core tests. ## ## ----------- ## _ACEOF # Keep a trace of the command line. # Strip out --no-create and --no-recursion so they do not pile up. # Strip out --silent because we don't want to record it for future runs. # Also quote any args containing shell meta-characters. # Make two passes to allow for proper duplicate-argument suppression. ac_configure_args= ac_configure_args0= ac_configure_args1= ac_must_keep_next=false for ac_pass in 1 2 do for ac_arg do case $ac_arg in -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; 2) as_fn_append ac_configure_args1 " '$ac_arg'" if test $ac_must_keep_next = true; then ac_must_keep_next=false # Got value, back to normal. else case $ac_arg in *=* | --config-cache | -C | -disable-* | --disable-* \ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ | -with-* | --with-* | -without-* | --without-* | --x) case "$ac_configure_args0 " in "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; esac ;; -* ) ac_must_keep_next=true ;; esac fi as_fn_append ac_configure_args " '$ac_arg'" ;; esac done done { ac_configure_args0=; unset ac_configure_args0;} { ac_configure_args1=; unset ac_configure_args1;} # When interrupted or exit'd, cleanup temporary files, and complete # config.log. We remove comments because anyway the quotes in there # would cause problems or look ugly. # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? # Sanitize IFS. IFS=" "" $as_nl" # Save into config.log some information that might help in debugging. { echo printf "%s\n" "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( *${as_nl}ac_space=\ *) sed -n \ "s/'\''/'\''\\\\'\'''\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" ;; #( *) sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) echo printf "%s\n" "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo for ac_var in $ac_subst_vars do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then printf "%s\n" "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo for ac_var in $ac_subst_files do eval ac_val=\$$ac_var case $ac_val in *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then printf "%s\n" "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo cat confdefs.h echo fi test "$ac_signal" != 0 && printf "%s\n" "$as_me: caught signal $ac_signal" printf "%s\n" "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && exit $exit_status ' 0 for ac_signal in 1 2 13 15; do trap 'ac_signal='$ac_signal'; as_fn_exit 1' $ac_signal done ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h printf "%s\n" "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. if test -n "$CONFIG_SITE"; then ac_site_files="$CONFIG_SITE" elif test "x$prefix" != xNONE; then ac_site_files="$prefix/share/config.site $prefix/etc/config.site" else ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi for ac_site_file in $ac_site_files do case $ac_site_file in #( */*) : ;; #( *) : ac_site_file=./$ac_site_file ;; esac if test -f "$ac_site_file" && test -r "$ac_site_file"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See 'config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 printf "%s\n" "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 printf "%s\n" "$as_me: creating cache $cache_file" >&6;} >$cache_file fi # Test code for whether the C compiler supports C89 (global declarations) ac_c_conftest_c89_globals=' /* Does the compiler advertise C89 conformance? Do not test the value of __STDC__, because some compilers set it to 0 while being otherwise adequately conformant. */ #if !defined __STDC__ # error "Compiler does not advertise C89 conformance" #endif #include #include struct stat; /* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ struct buf { int x; }; struct buf * (*rcsopen) (struct buf *, struct stat *, int); static char *e (char **p, int i) { return p[i]; } static char *f (char * (*g) (char **, int), char **p, ...) { char *s; va_list v; va_start (v,p); s = g (p, va_arg (v,int)); va_end (v); return s; } /* C89 style stringification. */ #define noexpand_stringify(a) #a const char *stringified = noexpand_stringify(arbitrary+token=sequence); /* C89 style token pasting. Exercises some of the corner cases that e.g. old MSVC gets wrong, but not very hard. */ #define noexpand_concat(a,b) a##b #define expand_concat(a,b) noexpand_concat(a,b) extern int vA; extern int vbee; #define aye A #define bee B int *pvA = &expand_concat(v,aye); int *pvbee = &noexpand_concat(v,bee); /* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has function prototypes and stuff, but not \xHH hex character constants. These do not provoke an error unfortunately, instead are silently treated as an "x". The following induces an error, until -std is added to get proper ANSI mode. Curiously \x00 != x always comes out true, for an array size at least. It is necessary to write \x00 == 0 to get something that is true only with -std. */ int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1]; /* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters inside strings and character constants. */ #define FOO(x) '\''x'\'' int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1]; int test (int i, double x); struct s1 {int (*f) (int a);}; struct s2 {int (*f) (double a);}; int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int), int, int);' # Test code for whether the C compiler supports C89 (body of main). ac_c_conftest_c89_main=' ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); ' # Test code for whether the C compiler supports C99 (global declarations) ac_c_conftest_c99_globals=' /* Does the compiler advertise C99 conformance? */ #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L # error "Compiler does not advertise C99 conformance" #endif // See if C++-style comments work. #include extern int puts (const char *); extern int printf (const char *, ...); extern int dprintf (int, const char *, ...); extern void *malloc (size_t); extern void free (void *); // Check varargs macros. These examples are taken from C99 6.10.3.5. // dprintf is used instead of fprintf to avoid needing to declare // FILE and stderr. #define debug(...) dprintf (2, __VA_ARGS__) #define showlist(...) puts (#__VA_ARGS__) #define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) static void test_varargs_macros (void) { int x = 1234; int y = 5678; debug ("Flag"); debug ("X = %d\n", x); showlist (The first, second, and third items.); report (x>y, "x is %d but y is %d", x, y); } // Check long long types. #define BIG64 18446744073709551615ull #define BIG32 4294967295ul #define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) #if !BIG_OK #error "your preprocessor is broken" #endif #if BIG_OK #else #error "your preprocessor is broken" #endif static long long int bignum = -9223372036854775807LL; static unsigned long long int ubignum = BIG64; struct incomplete_array { int datasize; double data[]; }; struct named_init { int number; const wchar_t *name; double average; }; typedef const char *ccp; static inline int test_restrict (ccp restrict text) { // Iterate through items via the restricted pointer. // Also check for declarations in for loops. for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) continue; return 0; } // Check varargs and va_copy. static bool test_varargs (const char *format, ...) { va_list args; va_start (args, format); va_list args_copy; va_copy (args_copy, args); const char *str = ""; int number = 0; float fnumber = 0; while (*format) { switch (*format++) { case '\''s'\'': // string str = va_arg (args_copy, const char *); break; case '\''d'\'': // int number = va_arg (args_copy, int); break; case '\''f'\'': // float fnumber = va_arg (args_copy, double); break; default: break; } } va_end (args_copy); va_end (args); return *str && number && fnumber; } ' # Test code for whether the C compiler supports C99 (body of main). ac_c_conftest_c99_main=' // Check bool. _Bool success = false; success |= (argc != 0); // Check restrict. if (test_restrict ("String literal") == 0) success = true; char *restrict newvar = "Another string"; // Check varargs. success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234); test_varargs_macros (); // Check flexible array members. struct incomplete_array *ia = malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); ia->datasize = 10; for (int i = 0; i < ia->datasize; ++i) ia->data[i] = i * 1.234; // Work around memory leak warnings. free (ia); // Check named initializers. struct named_init ni = { .number = 34, .name = L"Test wide string", .average = 543.34343, }; ni.number = 58; int dynamic_array[ni.number]; dynamic_array[0] = argv[0][0]; dynamic_array[ni.number - 1] = 543; // work around unused variable warnings ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' || dynamic_array[ni.number - 1] != 543); ' # Test code for whether the C compiler supports C11 (global declarations) ac_c_conftest_c11_globals=' /* Does the compiler advertise C11 conformance? */ #if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L # error "Compiler does not advertise C11 conformance" #endif // Check _Alignas. char _Alignas (double) aligned_as_double; char _Alignas (0) no_special_alignment; extern char aligned_as_int; char _Alignas (0) _Alignas (int) aligned_as_int; // Check _Alignof. enum { int_alignment = _Alignof (int), int_array_alignment = _Alignof (int[100]), char_alignment = _Alignof (char) }; _Static_assert (0 < -_Alignof (int), "_Alignof is signed"); // Check _Noreturn. int _Noreturn does_not_return (void) { for (;;) continue; } // Check _Static_assert. struct test_static_assert { int x; _Static_assert (sizeof (int) <= sizeof (long int), "_Static_assert does not work in struct"); long int y; }; // Check UTF-8 literals. #define u8 syntax error! char const utf8_literal[] = u8"happens to be ASCII" "another string"; // Check duplicate typedefs. typedef long *long_ptr; typedef long int *long_ptr; typedef long_ptr long_ptr; // Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1. struct anonymous { union { struct { int i; int j; }; struct { int k; long int l; } w; }; int m; } v1; ' # Test code for whether the C compiler supports C11 (body of main). ac_c_conftest_c11_main=' _Static_assert ((offsetof (struct anonymous, i) == offsetof (struct anonymous, w.k)), "Anonymous union alignment botch"); v1.i = 2; v1.w.k = 5; ok |= v1.i != 5; ' # Test code for whether the C compiler supports C11 (complete). ac_c_conftest_c11_program="${ac_c_conftest_c89_globals} ${ac_c_conftest_c99_globals} ${ac_c_conftest_c11_globals} int main (int argc, char **argv) { int ok = 0; ${ac_c_conftest_c89_main} ${ac_c_conftest_c99_main} ${ac_c_conftest_c11_main} return ok; } " # Test code for whether the C compiler supports C99 (complete). ac_c_conftest_c99_program="${ac_c_conftest_c89_globals} ${ac_c_conftest_c99_globals} int main (int argc, char **argv) { int ok = 0; ${ac_c_conftest_c89_main} ${ac_c_conftest_c99_main} return ok; } " # Test code for whether the C compiler supports C89 (complete). ac_c_conftest_c89_program="${ac_c_conftest_c89_globals} int main (int argc, char **argv) { int ok = 0; ${ac_c_conftest_c89_main} return ok; } " as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H" as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H" as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H" as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H" as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H" as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H" as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H" as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H" as_fn_append ac_header_c_list " wchar.h wchar_h HAVE_WCHAR_H" as_fn_append ac_header_c_list " minix/config.h minix_config_h HAVE_MINIX_CONFIG_H" # Auxiliary files required by this configure script. ac_aux_files="ltmain.sh compile missing install-sh config.guess config.sub" # Locations in which to look for auxiliary files. ac_aux_dir_candidates="${srcdir}${PATH_SEPARATOR}${srcdir}/..${PATH_SEPARATOR}${srcdir}/../.." # Search for a directory containing all of the required auxiliary files, # $ac_aux_files, from the $PATH-style list $ac_aux_dir_candidates. # If we don't find one directory that contains all the files we need, # we report the set of missing files from the *first* directory in # $ac_aux_dir_candidates and give up. ac_missing_aux_files="" ac_first_candidate=: printf "%s\n" "$as_me:${as_lineno-$LINENO}: looking for aux files: $ac_aux_files" >&5 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in $ac_aux_dir_candidates do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac as_found=: printf "%s\n" "$as_me:${as_lineno-$LINENO}: trying $as_dir" >&5 ac_aux_dir_found=yes ac_install_sh= for ac_aux in $ac_aux_files do # As a special case, if "install-sh" is required, that requirement # can be satisfied by any of "install-sh", "install.sh", or "shtool", # and $ac_install_sh is set appropriately for whichever one is found. if test x"$ac_aux" = x"install-sh" then if test -f "${as_dir}install-sh"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install-sh found" >&5 ac_install_sh="${as_dir}install-sh -c" elif test -f "${as_dir}install.sh"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install.sh found" >&5 ac_install_sh="${as_dir}install.sh -c" elif test -f "${as_dir}shtool"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}shtool found" >&5 ac_install_sh="${as_dir}shtool install -c" else ac_aux_dir_found=no if $ac_first_candidate; then ac_missing_aux_files="${ac_missing_aux_files} install-sh" else break fi fi else if test -f "${as_dir}${ac_aux}"; then printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}${ac_aux} found" >&5 else ac_aux_dir_found=no if $ac_first_candidate; then ac_missing_aux_files="${ac_missing_aux_files} ${ac_aux}" else break fi fi fi done if test "$ac_aux_dir_found" = yes; then ac_aux_dir="$as_dir" break fi ac_first_candidate=false as_found=false done IFS=$as_save_IFS if $as_found then : else case e in #( e) as_fn_error $? "cannot find required auxiliary files:$ac_missing_aux_files" "$LINENO" 5 ;; esac fi # These three variables are undocumented and unsupported, # and are intended to be withdrawn in a future Autoconf release. # They can cause serious problems if a builder's source tree is in a directory # whose full name contains unusual characters. if test -f "${ac_aux_dir}config.guess"; then ac_config_guess="$SHELL ${ac_aux_dir}config.guess" fi if test -f "${ac_aux_dir}config.sub"; then ac_config_sub="$SHELL ${ac_aux_dir}config.sub" fi if test -f "$ac_aux_dir/configure"; then ac_configure="$SHELL ${ac_aux_dir}configure" fi # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false for ac_var in $ac_precious_vars; do eval ac_old_set=\$ac_cv_env_${ac_var}_set eval ac_new_set=\$ac_env_${ac_var}_set eval ac_old_val=\$ac_cv_env_${ac_var}_value eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&5 printf "%s\n" "$as_me: error: '$ac_var' was set to '$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' was not set in the previous run" >&5 printf "%s\n" "$as_me: error: '$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) if test "x$ac_old_val" != "x$ac_new_val"; then # differences in whitespace do not lead to failure. ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: '$ac_var' has changed since the previous run:" >&5 printf "%s\n" "$as_me: error: '$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&5 printf "%s\n" "$as_me: warning: ignoring whitespace changes in '$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: '$ac_old_val'" >&5 printf "%s\n" "$as_me: former value: '$ac_old_val'" >&2;} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: '$ac_new_val'" >&5 printf "%s\n" "$as_me: current value: '$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. *) as_fn_append ac_configure_args " '$ac_arg'" ;; esac fi done if $ac_cache_corrupted; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} as_fn_error $? "run '${MAKE-make} distclean' and/or 'rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## ## -------------------- ## ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu # Make sure we can run config.sub. $SHELL "${ac_aux_dir}config.sub" sun4 >/dev/null 2>&1 || as_fn_error $? "cannot run $SHELL ${ac_aux_dir}config.sub" "$LINENO" 5 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 printf %s "checking build system type... " >&6; } if test ${ac_cv_build+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_build_alias=$build_alias test "x$ac_build_alias" = x && ac_build_alias=`$SHELL "${ac_aux_dir}config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 ac_cv_build=`$SHELL "${ac_aux_dir}config.sub" $ac_build_alias` || as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $ac_build_alias failed" "$LINENO" 5 ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 printf "%s\n" "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; esac build=$ac_cv_build ac_save_IFS=$IFS; IFS='-' set x $ac_cv_build shift build_cpu=$1 build_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: build_os=$* IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 printf %s "checking host system type... " >&6; } if test ${ac_cv_host+y} then : printf %s "(cached) " >&6 else case e in #( e) if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else ac_cv_host=`$SHELL "${ac_aux_dir}config.sub" $host_alias` || as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $host_alias failed" "$LINENO" 5 fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 printf "%s\n" "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; esac host=$ac_cv_host ac_save_IFS=$IFS; IFS='-' set x $ac_cv_host shift host_cpu=$1 host_vendor=$2 shift; shift # Remember, the first character of IFS is used to create $*, # except with old shells: host_os=$* IFS=$ac_save_IFS case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac am__api_version='1.16' # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install # AmigaOS /C/install, which installs bootblocks on floppy discs # AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 printf %s "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then if test ${ac_cv_path_install+y} then : printf %s "(cached) " >&6 else case e in #( e) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac # Account for fact that we put trailing slashes in our PATH walk. case $as_dir in #(( ./ | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. # Don't use installbsd from OSF since it installs stuff as root # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_prog$ac_exec_ext"; then if test $ac_prog = install && grep dspmsg "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && grep pwplus "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else rm -rf conftest.one conftest.two conftest.dir echo one > conftest.one echo two > conftest.two mkdir conftest.dir if "$as_dir$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir/" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then ac_cv_path_install="$as_dir$ac_prog$ac_exec_ext -c" break 3 fi fi fi done done ;; esac done IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir ;; esac fi if test ${ac_cv_path_install+y}; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a # value for INSTALL within a source directory, because that will # break other packages using the cache if that directory is # removed, or if the value is a relative name. INSTALL=$ac_install_sh fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 printf "%s\n" "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 printf %s "checking whether build environment is sane... " >&6; } # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[\\\"\#\$\&\'\`$am_lf]*) as_fn_error $? "unsafe absolute working directory name" "$LINENO" 5;; esac case $srcdir in *[\\\"\#\$\&\'\`$am_lf\ \ ]*) as_fn_error $? "unsafe srcdir value: '$srcdir'" "$LINENO" 5;; esac # Do 'set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( am_has_slept=no for am_try in 1 2; do echo "timestamp, slept: $am_has_slept" > conftest.file set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$*" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi if test "$*" != "X $srcdir/configure conftest.file" \ && test "$*" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". as_fn_error $? "ls -t appears to fail. Make sure there is not a broken alias in your environment" "$LINENO" 5 fi if test "$2" = conftest.file || test $am_try -eq 2; then break fi # Just in case. sleep 1 am_has_slept=yes done test "$2" = conftest.file ) then # Ok. : else as_fn_error $? "newly created file is older than distributed files! Check your system clock" "$LINENO" 5 fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } # If we didn't sleep, we still need to ensure time stamps of config.status and # generated files are strictly newer. am_sleep_pid= if grep 'slept: no' conftest.file >/dev/null 2>&1; then ( sleep 1 ) & am_sleep_pid=$! fi rm -f conftest.file test "$program_prefix" != NONE && program_transform_name="s&^&$program_prefix&;$program_transform_name" # Use a double $ so make ignores it. test "$program_suffix" != NONE && program_transform_name="s&\$&$program_suffix&;$program_transform_name" # Double any \ or $. # By default was 's,x,x', remove it if useless. ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' program_transform_name=`printf "%s\n" "$program_transform_name" | sed "$ac_script"` # Expand $ac_aux_dir to an absolute path. am_aux_dir=`cd "$ac_aux_dir" && pwd` if test x"${MISSING+set}" != xset; then MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then am_missing_run="$MISSING " else am_missing_run= { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 printf "%s\n" "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi # Installed binaries are usually stripped using 'strip' when the user # run "make install-strip". However 'strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the 'STRIP' environment variable to overrule this program. if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_STRIP+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 printf "%s\n" "$STRIP" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_STRIP+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 printf "%s\n" "$ac_ct_STRIP" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then STRIP=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP fi else STRIP="$ac_cv_prog_STRIP" fi fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a race-free mkdir -p" >&5 printf %s "checking for a race-free mkdir -p... " >&6; } if test -z "$MKDIR_P"; then if test ${ac_cv_path_mkdir+y} then : printf %s "(cached) " >&6 else case e in #( e) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do as_fn_executable_p "$as_dir$ac_prog$ac_exec_ext" || continue case `"$as_dir$ac_prog$ac_exec_ext" --version 2>&1` in #( 'mkdir ('*'coreutils) '* | \ *'BusyBox '* | \ 'mkdir (fileutils) '4.1*) ac_cv_path_mkdir=$as_dir$ac_prog$ac_exec_ext break 3;; esac done done done IFS=$as_save_IFS ;; esac fi test -d ./--version && rmdir ./--version if test ${ac_cv_path_mkdir+y}; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use plain mkdir -p, # in the hope it doesn't have the bugs of ancient mkdir. MKDIR_P='mkdir -p' fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 printf "%s\n" "$MKDIR_P" >&6; } for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_AWK+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 printf "%s\n" "$AWK" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$AWK" && break done { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 printf %s "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` if eval test \${ac_cv_prog_make_${ac_make}_set+y} then : printf %s "(cached) " >&6 else case e in #( e) cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @echo '@@@%%%=$(MAKE)=@@@%%%' _ACEOF # GNU make sometimes prints "make[1]: Entering ...", which would confuse us. case `${MAKE-make} -f conftest.make 2>/dev/null` in *@@@%%%=?*=@@@%%%*) eval ac_cv_prog_make_${ac_make}_set=yes;; *) eval ac_cv_prog_make_${ac_make}_set=no;; esac rm -f conftest.make ;; esac fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } SET_MAKE= else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null # Check whether --enable-silent-rules was given. if test ${enable_silent_rules+y} then : enableval=$enable_silent_rules; fi case $enable_silent_rules in # ((( yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=1;; esac am_make=${MAKE-make} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 printf %s "checking whether $am_make supports nested variables... " >&6; } if test ${am_cv_make_support_nested_variables+y} then : printf %s "(cached) " >&6 else case e in #( e) if printf "%s\n" 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 am__doit: @$(TRUE) .PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then am_cv_make_support_nested_variables=yes else am_cv_make_support_nested_variables=no fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 printf "%s\n" "$am_cv_make_support_nested_variables" >&6; } if test $am_cv_make_support_nested_variables = yes; then AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' else AM_V=$AM_DEFAULT_VERBOSITY AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY fi AM_BACKSLASH='\' if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." am__isrc=' -I$(srcdir)' # test to see if srcdir already configured if test -f $srcdir/config.status; then as_fn_error $? "source directory already configured; run \"make distclean\" there first" "$LINENO" 5 fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi # Define the identity of the package. PACKAGE='openbgpd' VERSION='8.8' printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h printf "%s\n" "#define VERSION \"$VERSION\"" >>confdefs.h # Some tools Automake needs. ACLOCAL=${ACLOCAL-"${am_missing_run}aclocal-${am__api_version}"} AUTOCONF=${AUTOCONF-"${am_missing_run}autoconf"} AUTOMAKE=${AUTOMAKE-"${am_missing_run}automake-${am__api_version}"} AUTOHEADER=${AUTOHEADER-"${am_missing_run}autoheader"} MAKEINFO=${MAKEINFO-"${am_missing_run}makeinfo"} # For better backward compatibility. To be removed once Automake 1.9.x # dies out for good. For more background, see: # # mkdir_p='$(MKDIR_P)' # We need awk for the "check" target (and possibly the TAP driver). The # system "awk" is bad on some platforms. # Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AMTAR='$${TAR-tar}' # We'll loop over all known methods to create a tar archive until one works. _am_tools='gnutar pax cpio none' am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' # Variables for tags utilities; see am/tags.am if test -z "$CTAGS"; then CTAGS=ctags fi if test -z "$ETAGS"; then ETAGS=etags fi if test -z "$CSCOPE"; then CSCOPE=cscope fi # POSIX will say in a future version that running "rm -f" with no argument # is OK; and we want to be able to make that assumption in our Makefile # recipes. So use an aggressive probe to check that the usage we want is # actually supported "in the wild" to an acceptable degree. # See automake bug#10828. # To make any issue more visible, cause the running configure to be aborted # by default if the 'rm' program in use doesn't match our expectations; the # user can still override this though. if rm -f && rm -fr && rm -rf; then : OK; else cat >&2 <<'END' Oops! Your 'rm' program seems unable to run without file operands specified on the command line, even when the '-f' option is present. This is contrary to the behaviour of most rm programs out there, and not conforming with the upcoming POSIX standard: Please tell bug-automake@gnu.org about your system, including the value of your $PATH and any error possibly output before this message. This can help us improve future automake versions. END if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then echo 'Configuration will proceed anyway, since you have set the' >&2 echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 echo >&2 else cat >&2 <<'END' Aborting the configuration process, to ensure you take notice of the issue. You can download and install GNU coreutils to get an 'rm' implementation that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM to "yes", and re-run configure. END as_fn_error $? "Your 'rm' program is bad, sorry." "$LINENO" 5 fi fi # Check whether --enable-silent-rules was given. if test ${enable_silent_rules+y} then : enableval=$enable_silent_rules; fi case $enable_silent_rules in # ((( yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=0;; esac am_make=${MAKE-make} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 printf %s "checking whether $am_make supports nested variables... " >&6; } if test ${am_cv_make_support_nested_variables+y} then : printf %s "(cached) " >&6 else case e in #( e) if printf "%s\n" 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 am__doit: @$(TRUE) .PHONY: am__doit' | $am_make -f - >/dev/null 2>&1; then am_cv_make_support_nested_variables=yes else am_cv_make_support_nested_variables=no fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 printf "%s\n" "$am_cv_make_support_nested_variables" >&6; } if test $am_cv_make_support_nested_variables = yes; then AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' else AM_V=$AM_DEFAULT_VERBOSITY AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY fi AM_BACKSLASH='\' ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then for ac_prog in cc gcc do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cc gcc do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 printf "%s\n" "$ac_ct_CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See 'config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion -version; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 printf %s "checking whether the C compiler works... " >&6; } ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" ac_rmfiles= for ac_file in $ac_files do case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; * ) ac_rmfiles="$ac_rmfiles $ac_file";; esac done rm -f $ac_rmfiles if { { ac_try="$ac_link_default" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : # Autoconf-2.13 could set the ac_cv_exeext variable to 'no'. # So ignore a value of 'no', otherwise this would lead to 'EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, # so that the user can short-circuit this test for compilers unknown to # Autoconf. for ac_file in $ac_files '' do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; [ab].out ) # We found the default executable, but exeext='' is most # certainly right. break;; *.* ) if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi # We set ac_cv_exeext here because the later test for it is not # safe: cross compilers may not add the suffix if given an '-o' # argument, so we may need to know it at that point already. # Even if this section looks crufty: it has the advantage of # actually working. break;; * ) break;; esac done test "$ac_cv_exeext" = no && ac_cv_exeext= else case e in #( e) ac_file='' ;; esac fi if test -z "$ac_file" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See 'config.log' for more details" "$LINENO" 5; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 printf %s "checking for C compiler default output file name... " >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 printf "%s\n" "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 printf %s "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : # If both 'conftest.exe' and 'conftest' are 'present' (well, observable) # catch 'conftest.exe'. For instance with Cygwin, 'ls conftest' will # work properly (i.e., refer to 'conftest.exe'), while it won't with # 'rm'. for ac_file in conftest.exe conftest conftest.*; do test -f "$ac_file" || continue case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM | *.o | *.obj ) ;; *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` break;; * ) break;; esac done else case e in #( e) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See 'config.log' for more details" "$LINENO" 5; } ;; esac fi rm -f conftest conftest$ac_cv_exeext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 printf "%s\n" "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include int main (void) { FILE *f = fopen ("conftest.out", "w"); if (!f) return 1; return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 printf %s "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error 77 "cannot run C compiled programs. If you meant to cross compile, use '--host'. See 'config.log' for more details" "$LINENO" 5; } fi fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 printf "%s\n" "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext \ conftest.o conftest.obj conftest.out ac_clean_files=$ac_clean_files_save { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 printf %s "checking for suffix of object files... " >&6; } if test ${ac_cv_objext+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF rm -f conftest.o conftest.obj if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.dSYM ) ;; *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` break;; esac done else case e in #( e) printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See 'config.log' for more details" "$LINENO" 5; } ;; esac fi rm -f conftest.$ac_cv_objext conftest.$ac_ext ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 printf "%s\n" "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 printf %s "checking whether the compiler supports GNU C... " >&6; } if test ${ac_cv_c_compiler_gnu+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_compiler_gnu=yes else case e in #( e) ac_compiler_gnu=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } ac_compiler_gnu=$ac_cv_c_compiler_gnu if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+y} ac_save_CFLAGS=$CFLAGS { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 printf %s "checking whether $CC accepts -g... " >&6; } if test ${ac_cv_prog_cc_g+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_g=yes else case e in #( e) CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : else case e in #( e) ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 printf "%s\n" "$ac_cv_prog_cc_g" >&6; } if test $ac_test_CFLAGS; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi ac_prog_cc_stdc=no if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 printf %s "checking for $CC option to enable C11 features... " >&6; } if test ${ac_cv_prog_cc_c11+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_cv_prog_cc_c11=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c11_program _ACEOF for ac_arg in '' -std=gnu11 do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c11=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c11" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC ;; esac fi if test "x$ac_cv_prog_cc_c11" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else case e in #( e) if test "x$ac_cv_prog_cc_c11" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } CC="$CC $ac_cv_prog_cc_c11" ;; esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 ac_prog_cc_stdc=c11 ;; esac fi fi if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 printf %s "checking for $CC option to enable C99 features... " >&6; } if test ${ac_cv_prog_cc_c99+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_cv_prog_cc_c99=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c99_program _ACEOF for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c99=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c99" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC ;; esac fi if test "x$ac_cv_prog_cc_c99" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else case e in #( e) if test "x$ac_cv_prog_cc_c99" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } CC="$CC $ac_cv_prog_cc_c99" ;; esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 ac_prog_cc_stdc=c99 ;; esac fi fi if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 printf %s "checking for $CC option to enable C89 features... " >&6; } if test ${ac_cv_prog_cc_c89+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c89_program _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC ;; esac fi if test "x$ac_cv_prog_cc_c89" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else case e in #( e) if test "x$ac_cv_prog_cc_c89" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } CC="$CC $ac_cv_prog_cc_c89" ;; esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 ac_prog_cc_stdc=c89 ;; esac fi fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 printf %s "checking whether $CC understands -c and -o together... " >&6; } if test ${am_cv_prog_cc_c_o+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF # Make sure it works both with $CC and with simple cc. # Following AC_PROG_CC_C_O, we do the test twice because some # compilers refuse to overwrite an existing .o file with -o, # though they will create one. am_cv_prog_cc_c_o=yes for am_i in 1 2; do if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } \ && test -f conftest2.$ac_objext; then : OK else am_cv_prog_cc_c_o=no break fi done rm -f core conftest* unset am_i ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 printf "%s\n" "$am_cv_prog_cc_c_o" >&6; } if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 printf %s "checking whether ${MAKE-make} supports the include directive... " >&6; } cat > confinc.mk << 'END' am__doit: @echo this is the am__doit target >confinc.out .PHONY: am__doit END am__include="#" am__quote= # BSD make does it like this. echo '.include "confinc.mk" # ignored' > confmf.BSD # Other make implementations (GNU, Solaris 10, AIX) do it like this. echo 'include confinc.mk # ignored' > confmf.GNU _am_result=no for s in GNU BSD; do { echo "$as_me:$LINENO: ${MAKE-make} -f confmf.$s && cat confinc.out" >&5 (${MAKE-make} -f confmf.$s && cat confinc.out) >&5 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } case $?:`cat confinc.out 2>/dev/null` in #( '0:this is the am__doit target') : case $s in #( BSD) : am__include='.include' am__quote='"' ;; #( *) : am__include='include' am__quote='' ;; esac ;; #( *) : ;; esac if test "$am__include" != "#"; then _am_result="yes ($s style)" break fi done rm -f confinc.* confmf.* { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 printf "%s\n" "${_am_result}" >&6; } # Check whether --enable-dependency-tracking was given. if test ${enable_dependency_tracking+y} then : enableval=$enable_dependency_tracking; fi if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' am__nodep='_no' fi if test "x$enable_dependency_tracking" != xno; then AMDEP_TRUE= AMDEP_FALSE='#' else AMDEP_TRUE='#' AMDEP_FALSE= fi depcc="$CC" am_compiler_list= { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 printf %s "checking dependency style of $depcc... " >&6; } if test ${am_cv_CC_dependencies_compiler_type+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named 'D' -- because '-MD' means "put the output # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_CC_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` fi am__universal=false case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with # Solaris 10 /bin/sh. echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle '-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # After this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_CC_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_CC_dependencies_compiler_type=none fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 printf "%s\n" "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if test "x$enable_dependency_tracking" != xno \ && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then am__fastdepCC_TRUE= am__fastdepCC_FALSE='#' else am__fastdepCC_TRUE='#' am__fastdepCC_FALSE= fi case $host_os in *linux*) ac_header= ac_cache= for ac_item in $ac_header_c_list do if test $ac_cache; then ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default" if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then printf "%s\n" "#define $ac_item 1" >> confdefs.h fi ac_header= ac_cache= elif test $ac_header; then ac_cache=$ac_item else ac_header=$ac_item fi done if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes then : printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether it is safe to define __EXTENSIONS__" >&5 printf %s "checking whether it is safe to define __EXTENSIONS__... " >&6; } if test ${ac_cv_safe_to_define___extensions__+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ # define __EXTENSIONS__ 1 $ac_includes_default int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_safe_to_define___extensions__=yes else case e in #( e) ac_cv_safe_to_define___extensions__=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_safe_to_define___extensions__" >&5 printf "%s\n" "$ac_cv_safe_to_define___extensions__" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether _XOPEN_SOURCE should be defined" >&5 printf %s "checking whether _XOPEN_SOURCE should be defined... " >&6; } if test ${ac_cv_should_define__xopen_source+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_cv_should_define__xopen_source=no if test $ac_cv_header_wchar_h = yes then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include mbstate_t x; int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #define _XOPEN_SOURCE 500 #include mbstate_t x; int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_should_define__xopen_source=yes fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_should_define__xopen_source" >&5 printf "%s\n" "$ac_cv_should_define__xopen_source" >&6; } printf "%s\n" "#define _ALL_SOURCE 1" >>confdefs.h printf "%s\n" "#define _DARWIN_C_SOURCE 1" >>confdefs.h printf "%s\n" "#define _GNU_SOURCE 1" >>confdefs.h printf "%s\n" "#define _HPUX_ALT_XOPEN_SOCKET_API 1" >>confdefs.h printf "%s\n" "#define _NETBSD_SOURCE 1" >>confdefs.h printf "%s\n" "#define _OPENBSD_SOURCE 1" >>confdefs.h printf "%s\n" "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_IEC_60559_ATTRIBS_EXT__ 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_IEC_60559_BFP_EXT__ 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_IEC_60559_DFP_EXT__ 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_IEC_60559_EXT__ 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_IEC_60559_FUNCS_EXT__ 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_IEC_60559_TYPES_EXT__ 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_LIB_EXT2__ 1" >>confdefs.h printf "%s\n" "#define __STDC_WANT_MATH_SPEC_FUNCS__ 1" >>confdefs.h printf "%s\n" "#define _TANDEM_SOURCE 1" >>confdefs.h if test $ac_cv_header_minix_config_h = yes then : MINIX=yes printf "%s\n" "#define _MINIX 1" >>confdefs.h printf "%s\n" "#define _POSIX_SOURCE 1" >>confdefs.h printf "%s\n" "#define _POSIX_1_SOURCE 2" >>confdefs.h else case e in #( e) MINIX= ;; esac fi if test $ac_cv_safe_to_define___extensions__ = yes then : printf "%s\n" "#define __EXTENSIONS__ 1" >>confdefs.h fi if test $ac_cv_should_define__xopen_source = yes then : printf "%s\n" "#define _XOPEN_SOURCE 500" >>confdefs.h fi ;; *) ;; esac case $host_os in *darwin*) HOST_OS=darwin printf "%s\n" "#define SPT_TYPE SPT_REUSEARGV" >>confdefs.h # # Don't use arc4random on systems before 10.12 because of # weak seed on failure to open /dev/random, based on latest # public source: # http://www.opensource.apple.com/source/Libc/Libc-997.90.3/gen/FreeBSD/arc4random.c # # We use the presence of getentropy() to detect 10.12. The # following check take into account that: # # - iOS <= 10.1 fails because of missing getentropy and # hence they miss sys/random.h # # - in macOS 10.12 getentropy is not tagged as introduced in # 10.12 so we cannot use it for target < 10.12 # cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include /* Systems without getentropy() should die here */ /* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */ #ifndef MAC_OS_X_VERSION_10_12 # define MAC_OS_X_VERSION_10_12 101200 #endif #if defined(MAC_OS_X_VERSION_MIN_REQUIRED) # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 # error "Running on Mac OSX 10.11 or earlier" # endif #endif int main (void) { char buf[1]; getentropy(buf, 1); ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : USE_BUILTIN_ARC4RANDOM=no else case e in #( e) USE_BUILTIN_ARC4RANDOM=yes ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to use builtin arc4random" >&5 printf %s "checking whether to use builtin arc4random... " >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $USE_BUILTIN_ARC4RANDOM" >&5 printf "%s\n" "$USE_BUILTIN_ARC4RANDOM" >&6; } ;; *freebsd*) HOST_OS=freebsd cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #if __FreeBSD_version < 1200000 undefined #endif int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : USE_BUILTIN_ARC4RANDOM=no else case e in #( e) USE_BUILTIN_ARC4RANDOM=yes ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; *linux*) HOST_OS=linux AM_CFLAGS="-D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE" printf "%s\n" "#define SPT_TYPE SPT_REUSEARGV" >>confdefs.h ;; *netbsd*) HOST_OS=netbsd AM_CFLAGS="-D_OPENBSD_SOURCE" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #if __NetBSD_Version__ < 700000001 undefined #endif int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : USE_BUILTIN_ARC4RANDOM=no else case e in #( e) USE_BUILTIN_ARC4RANDOM=yes ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; *openbsd*) HOST_OS=openbsd printf "%s\n" "#define HAVE_ATTRIBUTE__BOUNDED__ 1" >>confdefs.h printf "%s\n" "#define HAVE_ATTRIBUTE__DEAD 1" >>confdefs.h printf "%s\n" "#define HAVE_ATTRIBUTE__PACKED 1" >>confdefs.h ;; *solaris*) HOST_OS=solaris AM_CFLAGS="-D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP" ;; *) ;; esac if test x$HOST_OS = xdarwin; then HOST_DARWIN_TRUE= HOST_DARWIN_FALSE='#' else HOST_DARWIN_TRUE='#' HOST_DARWIN_FALSE= fi if test x$HOST_OS = xfreebsd; then HOST_FREEBSD_TRUE= HOST_FREEBSD_FALSE='#' else HOST_FREEBSD_TRUE='#' HOST_FREEBSD_FALSE= fi if test x$HOST_OS = xlinux; then HOST_LINUX_TRUE= HOST_LINUX_FALSE='#' else HOST_LINUX_TRUE='#' HOST_LINUX_FALSE= fi if test x$HOST_OS = xnetbsd; then HOST_NETBSD_TRUE= HOST_NETBSD_FALSE='#' else HOST_NETBSD_TRUE='#' HOST_NETBSD_FALSE= fi if test x$HOST_OS = xopenbsd; then HOST_OPENBSD_TRUE= HOST_OPENBSD_FALSE='#' else HOST_OPENBSD_TRUE='#' HOST_OPENBSD_FALSE= fi if test x$HOST_OS = xsolaris; then HOST_SOLARIS_TRUE= HOST_SOLARIS_FALSE='#' else HOST_SOLARIS_TRUE='#' HOST_SOLARIS_FALSE= fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 printf %s "checking for a sed that does not truncate output... " >&6; } if test ${ac_cv_path_SED+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for ac_i in 1 2 3 4 5 6 7; do ac_script="$ac_script$as_nl$ac_script" done echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed { ac_script=; unset ac_script;} if test -z "$SED"; then ac_path_SED_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in sed gsed do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_SED="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_SED" || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED case `"$ac_path_SED" --version 2>&1` in #( *GNU*) ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; #( *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" '' >> "conftest.nl" "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_SED_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_SED="$ac_path_SED" ac_path_SED_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_SED_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_SED"; then as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 fi else ac_cv_path_SED=$SED fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 printf "%s\n" "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 printf "%s\n" "$ac_ct_CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else ac_prog_rejected=no as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS if test $ac_prog_rejected = yes; then # We found a bogon in the path, so make sure we never use it. set dummy $ac_cv_prog_CC shift if test $# != 0; then # We chose a different compiler from the bogus one. # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@" fi fi fi ;; esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then for ac_prog in cl.exe do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$CC" && break done fi if test -z "$CC"; then ac_ct_CC=$CC for ac_prog in cl.exe do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 printf "%s\n" "$ac_ct_CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$ac_ct_CC" && break done if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi fi fi if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. set dummy ${ac_tool_prefix}clang; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}clang" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi CC=$ac_cv_prog_CC if test -n "$CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 printf "%s\n" "$CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "clang", so it can be a program name with args. set dummy clang; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_CC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="clang" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 printf "%s\n" "$ac_ct_CC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then CC="" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC fi else CC="$ac_cv_prog_CC" fi fi test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See 'config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion -version; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then sed '10a\ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 printf %s "checking whether the compiler supports GNU C... " >&6; } if test ${ac_cv_c_compiler_gnu+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #ifndef __GNUC__ choke me #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_compiler_gnu=yes else case e in #( e) ac_compiler_gnu=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } ac_compiler_gnu=$ac_cv_c_compiler_gnu if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi ac_test_CFLAGS=${CFLAGS+y} ac_save_CFLAGS=$CFLAGS { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 printf %s "checking whether $CC accepts -g... " >&6; } if test ${ac_cv_prog_cc_g+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_g=yes else case e in #( e) CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : else case e in #( e) ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_g=yes fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 printf "%s\n" "$ac_cv_prog_cc_g" >&6; } if test $ac_test_CFLAGS; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then CFLAGS="-g -O2" else CFLAGS="-g" fi else if test "$GCC" = yes; then CFLAGS="-O2" else CFLAGS= fi fi ac_prog_cc_stdc=no if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 printf %s "checking for $CC option to enable C11 features... " >&6; } if test ${ac_cv_prog_cc_c11+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_cv_prog_cc_c11=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c11_program _ACEOF for ac_arg in '' -std=gnu11 do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c11=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c11" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC ;; esac fi if test "x$ac_cv_prog_cc_c11" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else case e in #( e) if test "x$ac_cv_prog_cc_c11" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } CC="$CC $ac_cv_prog_cc_c11" ;; esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 ac_prog_cc_stdc=c11 ;; esac fi fi if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 printf %s "checking for $CC option to enable C99 features... " >&6; } if test ${ac_cv_prog_cc_c99+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_cv_prog_cc_c99=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c99_program _ACEOF for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c99=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c99" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC ;; esac fi if test "x$ac_cv_prog_cc_c99" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else case e in #( e) if test "x$ac_cv_prog_cc_c99" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } CC="$CC $ac_cv_prog_cc_c99" ;; esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 ac_prog_cc_stdc=c99 ;; esac fi fi if test x$ac_prog_cc_stdc = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 printf %s "checking for $CC option to enable C89 features... " >&6; } if test ${ac_cv_prog_cc_c89+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_cv_prog_cc_c89=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_c_conftest_c89_program _ACEOF for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" if ac_fn_c_try_compile "$LINENO" then : ac_cv_prog_cc_c89=$ac_arg fi rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC ;; esac fi if test "x$ac_cv_prog_cc_c89" = xno then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 printf "%s\n" "unsupported" >&6; } else case e in #( e) if test "x$ac_cv_prog_cc_c89" = x then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 printf "%s\n" "none needed" >&6; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } CC="$CC $ac_cv_prog_cc_c89" ;; esac fi ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 ac_prog_cc_stdc=c89 ;; esac fi fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 printf %s "checking whether $CC understands -c and -o together... " >&6; } if test ${am_cv_prog_cc_c_o+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF # Make sure it works both with $CC and with simple cc. # Following AC_PROG_CC_C_O, we do the test twice because some # compilers refuse to overwrite an existing .o file with -o, # though they will create one. am_cv_prog_cc_c_o=yes for am_i in 1 2; do if { echo "$as_me:$LINENO: $CC -c conftest.$ac_ext -o conftest2.$ac_objext" >&5 ($CC -c conftest.$ac_ext -o conftest2.$ac_objext) >&5 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } \ && test -f conftest2.$ac_objext; then : OK else am_cv_prog_cc_c_o=no break fi done rm -f core conftest* unset am_i ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 printf "%s\n" "$am_cv_prog_cc_c_o" >&6; } if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu depcc="$CC" am_compiler_list= { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 printf %s "checking dependency style of $depcc... " >&6; } if test ${am_cv_CC_dependencies_compiler_type+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named 'D' -- because '-MD' means "put the output # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_CC_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n 's/^#*\([a-zA-Z0-9]*\))$/\1/p' < ./depcomp` fi am__universal=false case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with # Solaris 10 /bin/sh. echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle '-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # After this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_CC_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_CC_dependencies_compiler_type=none fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 printf "%s\n" "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if test "x$enable_dependency_tracking" != xno \ && test "$am_cv_CC_dependencies_compiler_type" = gcc3; then am__fastdepCC_TRUE= am__fastdepCC_FALSE='#' else am__fastdepCC_TRUE='#' am__fastdepCC_FALSE= fi case `pwd` in *\ * | *\ *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 printf "%s\n" "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; esac macro_version='2.4.2' macro_revision='1.3337' ltmain="$ac_aux_dir/ltmain.sh" # Backslashify metacharacters that are still active within # double-quoted strings. sed_quote_subst='s/\(["`$\\]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\(["`\\]\)/\\\1/g' # Sed substitution to delay expansion of an escaped shell variable in a # double_quote_subst'ed string. delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g' # Sed substitution to delay expansion of an escaped single quote. delay_single_quote_subst='s/'\''/'\'\\\\\\\'\''/g' # Sed substitution to avoid accidental globbing in evaled expressions no_glob_subst='s/\*/\\\*/g' ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 printf %s "checking how to print strings... " >&6; } # Test print first, because it will be a builtin if present. if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then ECHO='print -r --' elif test "X`printf %s $ECHO 2>/dev/null`" = "X$ECHO"; then ECHO='printf %s\n' else # Use this function as a fallback that always works. func_fallback_echo () { eval 'cat <<_LTECHO_EOF $1 _LTECHO_EOF' } ECHO='func_fallback_echo' fi # func_echo_all arg... # Invoke $ECHO with all args, space-separated. func_echo_all () { $ECHO "" } case "$ECHO" in printf*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: printf" >&5 printf "%s\n" "printf" >&6; } ;; print*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 printf "%s\n" "print -r" >&6; } ;; *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cat" >&5 printf "%s\n" "cat" >&6; } ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 printf %s "checking for a sed that does not truncate output... " >&6; } if test ${ac_cv_path_SED+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for ac_i in 1 2 3 4 5 6 7; do ac_script="$ac_script$as_nl$ac_script" done echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed { ac_script=; unset ac_script;} if test -z "$SED"; then ac_path_SED_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in sed gsed do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_SED="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_SED" || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED case `"$ac_path_SED" --version 2>&1` in #( *GNU*) ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; #( *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" '' >> "conftest.nl" "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_SED_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_SED="$ac_path_SED" ac_path_SED_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_SED_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_SED"; then as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5 fi else ac_cv_path_SED=$SED fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 printf "%s\n" "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed test -z "$SED" && SED=sed Xsed="$SED -e 1s/^X//" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 printf %s "checking for grep that handles long lines and -e... " >&6; } if test ${ac_cv_path_GREP+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in grep ggrep do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_GREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP case `"$ac_path_GREP" --version 2>&1` in #( *GNU*) ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; #( *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_GREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_GREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_GREP"; then as_fn_error $? "no acceptable grep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_GREP=$GREP fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 printf "%s\n" "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 printf %s "checking for egrep... " >&6; } if test ${ac_cv_path_EGREP+y} then : printf %s "(cached) " >&6 else case e in #( e) if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else if test -z "$EGREP"; then ac_path_EGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in egrep do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_EGREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP case `"$ac_path_EGREP" --version 2>&1` in #( *GNU*) ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; #( *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_EGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_EGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_EGREP"; then as_fn_error $? "no acceptable egrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_EGREP=$EGREP fi fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 printf "%s\n" "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" EGREP_TRADITIONAL=$EGREP ac_cv_path_EGREP_TRADITIONAL=$EGREP { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 printf %s "checking for fgrep... " >&6; } if test ${ac_cv_path_FGREP+y} then : printf %s "(cached) " >&6 else case e in #( e) if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 then ac_cv_path_FGREP="$GREP -F" else if test -z "$FGREP"; then ac_path_FGREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_prog in fgrep do for ac_exec_ext in '' $ac_executable_extensions; do ac_path_FGREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_FGREP" || continue # Check for GNU ac_path_FGREP and select it if it is found. # Check for GNU $ac_path_FGREP case `"$ac_path_FGREP" --version 2>&1` in #( *GNU*) ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; #( *) ac_count=0 printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" printf "%s\n" 'FGREP' >> "conftest.nl" "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val if test $ac_count -gt ${ac_path_FGREP_max-0}; then # Best one so far, save it but keep looking for a better one ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_max=$ac_count fi # 10*(2^10) chars as input seems more than enough test $ac_count -gt 10 && break done rm -f conftest.in conftest.tmp conftest.nl conftest.out;; esac $ac_path_FGREP_found && break 3 done done done IFS=$as_save_IFS if test -z "$ac_cv_path_FGREP"; then as_fn_error $? "no acceptable fgrep could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" "$LINENO" 5 fi else ac_cv_path_FGREP=$FGREP fi fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 printf "%s\n" "$ac_cv_path_FGREP" >&6; } FGREP="$ac_cv_path_FGREP" test -z "$GREP" && GREP=grep # Check whether --with-gnu-ld was given. if test ${with_gnu_ld+y} then : withval=$with_gnu_ld; test "$withval" = no || with_gnu_ld=yes else case e in #( e) with_gnu_ld=no ;; esac fi ac_prog=ld if test "$GCC" = yes; then # Check if gcc -print-prog-name=ld gives a path. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 printf %s "checking for ld used by $CC... " >&6; } case $host in *-*-mingw*) # gcc leaves a trailing carriage return which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) ac_prog=`($CC -print-prog-name=ld) 2>&5` ;; esac case $ac_prog in # Accept absolute paths. [\\/]* | ?:[\\/]*) re_direlt='/[^/][^/]*/\.\./' # Canonicalize the pathname of ld ac_prog=`$ECHO "$ac_prog"| $SED 's%\\\\%/%g'` while $ECHO "$ac_prog" | $GREP "$re_direlt" > /dev/null 2>&1; do ac_prog=`$ECHO $ac_prog| $SED "s%$re_direlt%/%"` done test -z "$LD" && LD="$ac_prog" ;; "") # If it fails, then pretend we aren't using GCC. ac_prog=ld ;; *) # If it is relative, then search for the first ld in PATH. with_gnu_ld=unknown ;; esac elif test "$with_gnu_ld" = yes; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 printf %s "checking for GNU ld... " >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 printf %s "checking for non-GNU ld... " >&6; } fi if test ${lt_cv_path_LD+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -z "$LD"; then lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then lt_cv_path_LD="$ac_dir/$ac_prog" # Check to see if the program is GNU ld. I'd rather use --version, # but apparently some variants of GNU ld only accept -v. # Break only if it was the GNU/non-GNU ld that we prefer. case `"$lt_cv_path_LD" -v 2>&1 &5 printf "%s\n" "$LD" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 printf %s "checking if the linker ($LD) is GNU ld... " >&6; } if test ${lt_cv_prog_gnu_ld+y} then : printf %s "(cached) " >&6 else case e in #( e) # I'd rather use --version here, but apparently some GNU lds only accept -v. case `$LD -v 2>&1 &5 printf "%s\n" "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 printf %s "checking for BSD- or MS-compatible name lister (nm)... " >&6; } if test ${lt_cv_path_NM+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM="$NM" else lt_nm_to_check="${ac_tool_prefix}nm" if test -n "$ac_tool_prefix" && test "$build" = "$host"; then lt_nm_to_check="$lt_nm_to_check nm" fi for lt_tmp_nm in $lt_nm_to_check; do lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. tmp_nm="$ac_dir/$lt_tmp_nm" if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then # Check to see if the nm accepts a BSD-compat flag. # Adding the `sed 1q' prevents false positives on HP-UX, which says: # nm: unknown option "B" ignored # Tru64's nm complains that /dev/null is an invalid object file case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in */dev/null* | *'Invalid file or object type'*) lt_cv_path_NM="$tmp_nm -B" break ;; *) case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in */dev/null*) lt_cv_path_NM="$tmp_nm -p" break ;; *) lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but continue # so that we can try to find one that supports BSD flags ;; esac ;; esac fi done IFS="$lt_save_ifs" done : ${lt_cv_path_NM=no} fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 printf "%s\n" "$lt_cv_path_NM" >&6; } if test "$lt_cv_path_NM" != "no"; then NM="$lt_cv_path_NM" else # Didn't find any BSD compatible name lister, look for dumpbin. if test -n "$DUMPBIN"; then : # Let the user override the test. else if test -n "$ac_tool_prefix"; then for ac_prog in dumpbin "link -dump" do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_DUMPBIN+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$DUMPBIN"; then ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi DUMPBIN=$ac_cv_prog_DUMPBIN if test -n "$DUMPBIN"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 printf "%s\n" "$DUMPBIN" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$DUMPBIN" && break done fi if test -z "$DUMPBIN"; then ac_ct_DUMPBIN=$DUMPBIN for ac_prog in dumpbin "link -dump" do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_DUMPBIN+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_DUMPBIN"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN if test -n "$ac_ct_DUMPBIN"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 printf "%s\n" "$ac_ct_DUMPBIN" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$ac_ct_DUMPBIN" && break done if test "x$ac_ct_DUMPBIN" = x; then DUMPBIN=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DUMPBIN=$ac_ct_DUMPBIN fi fi case `$DUMPBIN -symbols /dev/null 2>&1 | sed '1q'` in *COFF*) DUMPBIN="$DUMPBIN -symbols" ;; *) DUMPBIN=: ;; esac fi if test "$DUMPBIN" != ":"; then NM="$DUMPBIN" fi fi test -z "$NM" && NM=nm { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 printf %s "checking the name lister ($NM) interface... " >&6; } if test ${lt_cv_nm_interface+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) (eval "$ac_compile" 2>conftest.err) cat conftest.err >&5 (eval echo "\"\$as_me:$LINENO: $NM \\\"conftest.$ac_objext\\\"\"" >&5) (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out) cat conftest.err >&5 (eval echo "\"\$as_me:$LINENO: output\"" >&5) cat conftest.out >&5 if $GREP 'External.*some_variable' conftest.out > /dev/null; then lt_cv_nm_interface="MS dumpbin" fi rm -f conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 printf "%s\n" "$lt_cv_nm_interface" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 printf %s "checking whether ln -s works... " >&6; } LN_S=$as_ln_s if test "$LN_S" = "ln -s"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 printf "%s\n" "no, using $LN_S" >&6; } fi # find the maximum length of command line arguments { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 printf %s "checking the maximum length of command line arguments... " >&6; } if test ${lt_cv_sys_max_cmd_len+y} then : printf %s "(cached) " >&6 else case e in #( e) i=0 teststring="ABCD" case $build_os in msdosdjgpp*) # On DJGPP, this test can blow up pretty badly due to problems in libc # (any single argument exceeding 2000 bytes causes a buffer overrun # during glob expansion). Even if it were fixed, the result of this # check would be larger than it should be. lt_cv_sys_max_cmd_len=12288; # 12K is about right ;; gnu*) # Under GNU Hurd, this test is not required because there is # no limit to the length of command line arguments. # Libtool will interpret -1 as no limit whatsoever lt_cv_sys_max_cmd_len=-1; ;; cygwin* | mingw* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, # you end up with a "frozen" computer, even though with patience # the test eventually succeeds (with a max line length of 256k). # Instead, let's just punt: use the minimum linelength reported by # all of the supported platforms: 8192 (on NT/2K/XP). lt_cv_sys_max_cmd_len=8192; ;; mint*) # On MiNT this can take a long time and run out of memory. lt_cv_sys_max_cmd_len=8192; ;; amigaos*) # On AmigaOS with pdksh, this test takes hours, literally. # So we just punt and use a minimum line length of 8192. lt_cv_sys_max_cmd_len=8192; ;; netbsd* | freebsd* | openbsd* | darwin* | dragonfly*) # This has been around since 386BSD, at least. Likely further. if test -x /sbin/sysctl; then lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` elif test -x /usr/sbin/sysctl; then lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax` else lt_cv_sys_max_cmd_len=65536 # usable default for all BSDs fi # And add a safety zone lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` ;; interix*) # We know the value 262144 and hardcode it with a safety zone (like BSD) lt_cv_sys_max_cmd_len=196608 ;; os2*) # The test takes a long time on OS/2. lt_cv_sys_max_cmd_len=8192 ;; osf*) # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not # nice to cause kernel panics so lets avoid the loop below. # First set a reasonable default. lt_cv_sys_max_cmd_len=16384 # if test -x /sbin/sysconfig; then case `/sbin/sysconfig -q proc exec_disable_arg_limit` in *1*) lt_cv_sys_max_cmd_len=-1 ;; esac fi ;; sco3.2v5*) lt_cv_sys_max_cmd_len=102400 ;; sysv5* | sco5v6* | sysv4.2uw2*) kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` if test -n "$kargmax"; then lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` else lt_cv_sys_max_cmd_len=32768 fi ;; *) lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null` if test -n "$lt_cv_sys_max_cmd_len"; then lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4` lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3` else # Make teststring a little bigger before we do anything with it. # a 1K string should be a reasonable start. for i in 1 2 3 4 5 6 7 8 ; do teststring=$teststring$teststring done SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}} # If test is not a shell built-in, we'll probably end up computing a # maximum length that is only half of the actual maximum length, but # we can't tell. while { test "X"`env echo "$teststring$teststring" 2>/dev/null` \ = "X$teststring$teststring"; } >/dev/null 2>&1 && test $i != 17 # 1/2 MB should be enough do i=`expr $i + 1` teststring=$teststring$teststring done # Only check the string length outside the loop. lt_cv_sys_max_cmd_len=`expr "X$teststring" : ".*" 2>&1` teststring= # Add a significant safety factor because C++ compilers can tack on # massive amounts of additional arguments before passing them to the # linker. It appears as though 1/2 is a usable value. lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2` fi ;; esac ;; esac fi if test -n $lt_cv_sys_max_cmd_len ; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 printf "%s\n" "$lt_cv_sys_max_cmd_len" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none" >&5 printf "%s\n" "none" >&6; } fi max_cmd_len=$lt_cv_sys_max_cmd_len : ${CP="cp -f"} : ${MV="mv -f"} : ${RM="rm -f"} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the shell understands some XSI constructs" >&5 printf %s "checking whether the shell understands some XSI constructs... " >&6; } # Try some XSI features xsi_shell=no ( _lt_dummy="a/b/c" test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \ = c,a/b,b/c, \ && eval 'test $(( 1 + 1 )) -eq 2 \ && test "${#_lt_dummy}" -eq 5' ) >/dev/null 2>&1 \ && xsi_shell=yes { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $xsi_shell" >&5 printf "%s\n" "$xsi_shell" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the shell understands \"+=\"" >&5 printf %s "checking whether the shell understands \"+=\"... " >&6; } lt_shell_append=no ( foo=bar; set foo baz; eval "$1+=\$2" && test "$foo" = barbaz ) \ >/dev/null 2>&1 \ && lt_shell_append=yes { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_shell_append" >&5 printf "%s\n" "$lt_shell_append" >&6; } if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then lt_unset=unset else lt_unset=false fi # test EBCDIC or ASCII case `echo X|tr X '\101'` in A) # ASCII based system # \n is not interpreted correctly by Solaris 8 /usr/ucb/tr lt_SP2NL='tr \040 \012' lt_NL2SP='tr \015\012 \040\040' ;; *) # EBCDIC based system lt_SP2NL='tr \100 \n' lt_NL2SP='tr \r\n \100\100' ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 printf %s "checking how to convert $build file names to $host format... " >&6; } if test ${lt_cv_to_host_file_cmd+y} then : printf %s "(cached) " >&6 else case e in #( e) case $host in *-*-mingw* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 ;; *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_cygwin_to_w32 ;; * ) # otherwise, assume *nix lt_cv_to_host_file_cmd=func_convert_file_nix_to_w32 ;; esac ;; *-*-cygwin* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin ;; *-*-cygwin* ) lt_cv_to_host_file_cmd=func_convert_file_noop ;; * ) # otherwise, assume *nix lt_cv_to_host_file_cmd=func_convert_file_nix_to_cygwin ;; esac ;; * ) # unhandled hosts (and "normal" native builds) lt_cv_to_host_file_cmd=func_convert_file_noop ;; esac ;; esac fi to_host_file_cmd=$lt_cv_to_host_file_cmd { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 printf "%s\n" "$lt_cv_to_host_file_cmd" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 printf %s "checking how to convert $build file names to toolchain format... " >&6; } if test ${lt_cv_to_tool_file_cmd+y} then : printf %s "(cached) " >&6 else case e in #( e) #assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in *-*-mingw* ) case $build in *-*-mingw* ) # actually msys lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 ;; esac ;; esac ;; esac fi to_tool_file_cmd=$lt_cv_to_tool_file_cmd { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 printf "%s\n" "$lt_cv_to_tool_file_cmd" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 printf %s "checking for $LD option to reload object files... " >&6; } if test ${lt_cv_ld_reload_flag+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_ld_reload_flag='-r' ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 printf "%s\n" "$lt_cv_ld_reload_flag" >&6; } reload_flag=$lt_cv_ld_reload_flag case $reload_flag in "" | " "*) ;; *) reload_flag=" $reload_flag" ;; esac reload_cmds='$LD$reload_flag -o $output$reload_objs' case $host_os in cygwin* | mingw* | pw32* | cegcc*) if test "$GCC" != yes; then reload_cmds=false fi ;; darwin*) if test "$GCC" = yes; then reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs' else reload_cmds='$LD$reload_flag -o $output$reload_objs' fi ;; esac if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. set dummy ${ac_tool_prefix}objdump; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_OBJDUMP+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi OBJDUMP=$ac_cv_prog_OBJDUMP if test -n "$OBJDUMP"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 printf "%s\n" "$OBJDUMP" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_OBJDUMP"; then ac_ct_OBJDUMP=$OBJDUMP # Extract the first word of "objdump", so it can be a program name with args. set dummy objdump; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_OBJDUMP+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OBJDUMP="objdump" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP if test -n "$ac_ct_OBJDUMP"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 printf "%s\n" "$ac_ct_OBJDUMP" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then OBJDUMP="false" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP fi else OBJDUMP="$ac_cv_prog_OBJDUMP" fi test -z "$OBJDUMP" && OBJDUMP=objdump { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 printf %s "checking how to recognize dependent libraries... " >&6; } if test ${lt_cv_deplibs_check_method+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_file_magic_cmd='$MAGIC_CMD' lt_cv_file_magic_test_file= lt_cv_deplibs_check_method='unknown' # Need to set the preceding variable on all platforms that support # interlibrary dependencies. # 'none' -- dependencies not supported. # `unknown' -- same as none, but documents that we really don't know. # 'pass_all' -- all dependencies passed with no checks. # 'test_compile' -- check by making test program. # 'file_magic [[regex]]' -- check by looking for files in library path # which responds to the $file_magic_cmd with a given extended regex. # If you have `file' or equivalent on your system and you're not sure # whether `pass_all' will *always* work, you probably want this one. case $host_os in aix[4-9]*) lt_cv_deplibs_check_method=pass_all ;; beos*) lt_cv_deplibs_check_method=pass_all ;; bsdi[45]*) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' lt_cv_file_magic_cmd='/usr/bin/file -L' lt_cv_file_magic_test_file=/shlib/libc.so ;; cygwin*) # func_win32_libid is a shell function defined in ltmain.sh lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' ;; mingw* | pw32*) # Base MSYS/MinGW do not provide the 'file' command needed by # func_win32_libid shell function, so use a weaker test based on 'objdump', # unless we find 'file', for example because we are cross-compiling. # func_win32_libid assumes BSD nm, so disallow it if using MS dumpbin. if ( test "$lt_cv_nm_interface" = "BSD nm" && file / ) >/dev/null 2>&1; then lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL' lt_cv_file_magic_cmd='func_win32_libid' else # Keep this pattern in sync with the one in func_win32_libid. lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' lt_cv_file_magic_cmd='$OBJDUMP -f' fi ;; cegcc*) # use the weaker test based on 'objdump'. See mingw*. lt_cv_deplibs_check_method='file_magic file format pe-arm-.*little(.*architecture: arm)?' lt_cv_file_magic_cmd='$OBJDUMP -f' ;; darwin* | rhapsody*) lt_cv_deplibs_check_method=pass_all ;; freebsd* | dragonfly*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then case $host_cpu in i*86 ) # Not sure whether the presence of OpenBSD here was a mistake. # Let's accept both of them until this is cleared up. lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` ;; esac else lt_cv_deplibs_check_method=pass_all fi ;; gnu*) lt_cv_deplibs_check_method=pass_all ;; haiku*) lt_cv_deplibs_check_method=pass_all ;; hpux10.20* | hpux11*) lt_cv_file_magic_cmd=/usr/bin/file case $host_cpu in ia64*) lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so ;; hppa*64*) lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF[ -][0-9][0-9])(-bit)?( [LM]SB)? shared object( file)?[, -]* PA-RISC [0-9]\.[0-9]' lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl ;; *) lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|PA-RISC[0-9]\.[0-9]) shared library' lt_cv_file_magic_test_file=/usr/lib/libc.sl ;; esac ;; interix[3-9]*) # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|\.a)$' ;; irix5* | irix6* | nonstopux*) case $LD in *-32|*"-32 ") libmagic=32-bit;; *-n32|*"-n32 ") libmagic=N32;; *-64|*"-64 ") libmagic=64-bit;; *) libmagic=never-match;; esac lt_cv_deplibs_check_method=pass_all ;; # This must be glibc/ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) lt_cv_deplibs_check_method=pass_all ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so|_pic\.a)$' fi ;; newos6*) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' lt_cv_file_magic_cmd=/usr/bin/file lt_cv_file_magic_test_file=/usr/lib/libnls.so ;; *nto* | *qnx*) lt_cv_deplibs_check_method=pass_all ;; openbsd*) if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' else lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|_pic\.a)$' fi ;; osf3* | osf4* | osf5*) lt_cv_deplibs_check_method=pass_all ;; rdos*) lt_cv_deplibs_check_method=pass_all ;; solaris*) lt_cv_deplibs_check_method=pass_all ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) lt_cv_deplibs_check_method=pass_all ;; sysv4 | sysv4.3*) case $host_vendor in motorola) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib) M[0-9][0-9]* Version [0-9]' lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*` ;; ncr) lt_cv_deplibs_check_method=pass_all ;; sequent) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [LM]SB (shared object|dynamic lib )' ;; sni) lt_cv_file_magic_cmd='/bin/file' lt_cv_deplibs_check_method="file_magic ELF [0-9][0-9]*-bit [LM]SB dynamic lib" lt_cv_file_magic_test_file=/lib/libc.so ;; siemens) lt_cv_deplibs_check_method=pass_all ;; pc) lt_cv_deplibs_check_method=pass_all ;; esac ;; tpf*) lt_cv_deplibs_check_method=pass_all ;; esac ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 printf "%s\n" "$lt_cv_deplibs_check_method" >&6; } file_magic_glob= want_nocaseglob=no if test "$build" = "$host"; then case $host_os in mingw* | pw32*) if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then want_nocaseglob=yes else file_magic_glob=`echo aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ | $SED -e "s/\(..\)/s\/[\1]\/[\1]\/g;/g"` fi ;; esac fi file_magic_cmd=$lt_cv_file_magic_cmd deplibs_check_method=$lt_cv_deplibs_check_method test -z "$deplibs_check_method" && deplibs_check_method=unknown if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. set dummy ${ac_tool_prefix}dlltool; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_DLLTOOL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$DLLTOOL"; then ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi DLLTOOL=$ac_cv_prog_DLLTOOL if test -n "$DLLTOOL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 printf "%s\n" "$DLLTOOL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_DLLTOOL"; then ac_ct_DLLTOOL=$DLLTOOL # Extract the first word of "dlltool", so it can be a program name with args. set dummy dlltool; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_DLLTOOL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_DLLTOOL"; then ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL if test -n "$ac_ct_DLLTOOL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 printf "%s\n" "$ac_ct_DLLTOOL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DLLTOOL" = x; then DLLTOOL="false" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DLLTOOL=$ac_ct_DLLTOOL fi else DLLTOOL="$ac_cv_prog_DLLTOOL" fi test -z "$DLLTOOL" && DLLTOOL=dlltool { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 printf %s "checking how to associate runtime and link libraries... " >&6; } if test ${lt_cv_sharedlib_from_linklib_cmd+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in cygwin* | mingw* | pw32* | cegcc*) # two different shell functions defined in ltmain.sh # decide which to use based on capabilities of $DLLTOOL case `$DLLTOOL --help 2>&1` in *--identify-strict*) lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib ;; *) lt_cv_sharedlib_from_linklib_cmd=func_cygming_dll_for_implib_fallback ;; esac ;; *) # fallback: assume linklib IS sharedlib lt_cv_sharedlib_from_linklib_cmd="$ECHO" ;; esac ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 printf "%s\n" "$lt_cv_sharedlib_from_linklib_cmd" >&6; } sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO if test -n "$ac_tool_prefix"; then for ac_prog in ar do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_AR+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_AR="$ac_tool_prefix$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi AR=$ac_cv_prog_AR if test -n "$AR"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 printf "%s\n" "$AR" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$AR" && break done fi if test -z "$AR"; then ac_ct_AR=$AR for ac_prog in ar do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_AR+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_AR="$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_AR=$ac_cv_prog_ac_ct_AR if test -n "$ac_ct_AR"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 printf "%s\n" "$ac_ct_AR" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$ac_ct_AR" && break done if test "x$ac_ct_AR" = x; then AR="false" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR fi fi : ${AR=ar} : ${AR_FLAGS=cru} { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 printf %s "checking for archiver @FILE support... " >&6; } if test ${lt_cv_ar_at_file+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_ar_at_file=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : echo conftest.$ac_objext > conftest.lst lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 (eval $lt_ar_try) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test "$ac_status" -eq 0; then # Ensure the archiver fails upon bogus file names. rm -f conftest.$ac_objext libconftest.a { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 (eval $lt_ar_try) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test "$ac_status" -ne 0; then lt_cv_ar_at_file=@ fi fi rm -f conftest.* libconftest.a fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 printf "%s\n" "$lt_cv_ar_at_file" >&6; } if test "x$lt_cv_ar_at_file" = xno; then archiver_list_spec= else archiver_list_spec=$lt_cv_ar_at_file fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_STRIP+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 printf "%s\n" "$STRIP" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_STRIP+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 printf "%s\n" "$ac_ct_STRIP" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then STRIP=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP fi else STRIP="$ac_cv_prog_STRIP" fi test -z "$STRIP" && STRIP=: if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. set dummy ${ac_tool_prefix}ranlib; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_RANLIB+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi RANLIB=$ac_cv_prog_RANLIB if test -n "$RANLIB"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 printf "%s\n" "$RANLIB" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_RANLIB"; then ac_ct_RANLIB=$RANLIB # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_RANLIB+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_RANLIB"; then ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_RANLIB="ranlib" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB if test -n "$ac_ct_RANLIB"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 printf "%s\n" "$ac_ct_RANLIB" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_RANLIB" = x; then RANLIB=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac RANLIB=$ac_ct_RANLIB fi else RANLIB="$ac_cv_prog_RANLIB" fi test -z "$RANLIB" && RANLIB=: # Determine commands to create old-style static archives. old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs' old_postinstall_cmds='chmod 644 $oldlib' old_postuninstall_cmds= if test -n "$RANLIB"; then case $host_os in openbsd*) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" ;; *) old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" ;; esac old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" fi case $host_os in darwin*) lock_old_archive_extraction=yes ;; *) lock_old_archive_extraction=no ;; esac # If no C compiler was specified, use CC. LTCC=${LTCC-"$CC"} # If no C compiler flags were specified, use CFLAGS. LTCFLAGS=${LTCFLAGS-"$CFLAGS"} # Allow CC to be a program name with arguments. compiler=$CC # Check for command to grab the raw symbol name followed by C symbol from nm. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 printf %s "checking command to parse $NM output from $compiler object... " >&6; } if test ${lt_cv_sys_global_symbol_pipe+y} then : printf %s "(cached) " >&6 else case e in #( e) # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] # Character class describing NM global symbol codes. symcode='[BCDEGRST]' # Regexp to match symbols that can be accessed directly from C. sympat='\([_A-Za-z][_A-Za-z0-9]*\)' # Define system-specific variables. case $host_os in aix*) symcode='[BCDT]' ;; cygwin* | mingw* | pw32* | cegcc*) symcode='[ABCDGISTW]' ;; hpux*) if test "$host_cpu" = ia64; then symcode='[ABCDEGRST]' fi ;; irix* | nonstopux*) symcode='[BCDEGRST]' ;; osf*) symcode='[BCDEGQRST]' ;; solaris*) symcode='[BDRT]' ;; sco3.2v5*) symcode='[DT]' ;; sysv4.2uw2*) symcode='[DT]' ;; sysv5* | sco5v6* | unixware* | OpenUNIX*) symcode='[ABDT]' ;; sysv4) symcode='[DFNSTU]' ;; esac # If we're using GNU nm, then use its standard symbol codes. case `$NM -V 2>&1` in *GNU* | *'with BFD'*) symcode='[ABCDGIRSTW]' ;; esac # Transform an extracted symbol line into a proper C declaration. # Some systems (esp. on ia64) link data and code symbols differently, # so use this general approach. lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'" # Transform an extracted symbol line into symbol name and symbol address lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([^ ]*\)[ ]*$/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"\2\", (void *) \&\2},/p'" lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n -e 's/^: \([^ ]*\)[ ]*$/ {\\\"\1\\\", (void *) 0},/p' -e 's/^$symcode* \([^ ]*\) \(lib[^ ]*\)$/ {\"\2\", (void *) \&\2},/p' -e 's/^$symcode* \([^ ]*\) \([^ ]*\)$/ {\"lib\2\", (void *) \&\2},/p'" # Handle CRLF in mingw tool chain opt_cr= case $build_os in mingw*) opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp ;; esac # Try without a prefix underscore, then with it. for ac_symprfx in "" "_"; do # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol. symxfrm="\\1 $ac_symprfx\\2 \\2" # Write the raw and C identifiers. if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Fake it for dumpbin and say T for any non-static function # and D for any global variable. # Also find C++ and __fastcall symbols from MSVC++, # which start with @ or ?. lt_cv_sys_global_symbol_pipe="$AWK '"\ " {last_section=section; section=\$ 3};"\ " /^COFF SYMBOL TABLE/{for(i in hide) delete hide[i]};"\ " /Section length .*#relocs.*(pick any)/{hide[last_section]=1};"\ " \$ 0!~/External *\|/{next};"\ " / 0+ UNDEF /{next}; / UNDEF \([^|]\)*()/{next};"\ " {if(hide[section]) next};"\ " {f=0}; \$ 0~/\(\).*\|/{f=1}; {printf f ? \"T \" : \"D \"};"\ " {split(\$ 0, a, /\||\r/); split(a[2], s)};"\ " s[1]~/^[@?]/{print s[1], s[1]; next};"\ " s[1]~prfx {split(s[1],t,\"@\"); print t[1], substr(t[1],length(prfx))}"\ " ' prfx=^$ac_symprfx" else lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" fi lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" # Check to see that the pipe works correctly. pipe_works=no rm -f conftest* cat > conftest.$ac_ext <<_LT_EOF #ifdef __cplusplus extern "C" { #endif char nm_test_var; void nm_test_func(void); void nm_test_func(void){} #ifdef __cplusplus } #endif int main(){nm_test_var='a';nm_test_func();return(0);} _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # Now try to grab the symbols. nlist=conftest.nm if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then mv -f "$nlist"T "$nlist" else rm -f "$nlist"T fi # Make sure that we snagged all the symbols we need. if $GREP ' nm_test_var$' "$nlist" >/dev/null; then if $GREP ' nm_test_func$' "$nlist" >/dev/null; then cat <<_LT_EOF > conftest.$ac_ext /* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) /* DATA imports from DLLs on WIN32 con't be const, because runtime relocations are performed -- see ld's documentation on pseudo-relocs. */ # define LT_DLSYM_CONST #elif defined(__osf__) /* This system does not cope well with relocations in const data. */ # define LT_DLSYM_CONST #else # define LT_DLSYM_CONST const #endif #ifdef __cplusplus extern "C" { #endif _LT_EOF # Now generate the symbol file. eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | $GREP -v main >> conftest.$ac_ext' cat <<_LT_EOF >> conftest.$ac_ext /* The mapping between symbol names and symbols. */ LT_DLSYM_CONST struct { const char *name; void *address; } lt__PROGRAM__LTX_preloaded_symbols[] = { { "@PROGRAM@", (void *) 0 }, _LT_EOF $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/ {\"\2\", (void *) \&\2},/" < "$nlist" | $GREP -v main >> conftest.$ac_ext cat <<\_LT_EOF >> conftest.$ac_ext {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt__PROGRAM__LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif _LT_EOF # Now try linking the two files. mv conftest.$ac_objext conftstm.$ac_objext lt_globsym_save_LIBS=$LIBS lt_globsym_save_CFLAGS=$CFLAGS LIBS="conftstm.$ac_objext" CFLAGS="$CFLAGS$lt_prog_compiler_no_builtin_flag" if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest${ac_exeext}; then pipe_works=yes fi LIBS=$lt_globsym_save_LIBS CFLAGS=$lt_globsym_save_CFLAGS else echo "cannot find nm_test_func in $nlist" >&5 fi else echo "cannot find nm_test_var in $nlist" >&5 fi else echo "cannot run $lt_cv_sys_global_symbol_pipe" >&5 fi else echo "$progname: failed program was:" >&5 cat conftest.$ac_ext >&5 fi rm -rf conftest* conftst* # Do not use the global_symbol_pipe unless it works. if test "$pipe_works" = yes; then break else lt_cv_sys_global_symbol_pipe= fi done ;; esac fi if test -z "$lt_cv_sys_global_symbol_pipe"; then lt_cv_sys_global_symbol_to_cdecl= fi if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 printf "%s\n" "failed" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ok" >&5 printf "%s\n" "ok" >&6; } fi # Response file support. if test "$lt_cv_nm_interface" = "MS dumpbin"; then nm_file_list_spec='@' elif $NM --help 2>/dev/null | grep '[@]FILE' >/dev/null; then nm_file_list_spec='@' fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 printf %s "checking for sysroot... " >&6; } # Check whether --with-sysroot was given. if test ${with_sysroot+y} then : withval=$with_sysroot; else case e in #( e) with_sysroot=no ;; esac fi lt_sysroot= case ${with_sysroot} in #( yes) if test "$GCC" = yes; then lt_sysroot=`$CC --print-sysroot 2>/dev/null` fi ;; #( /*) lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` ;; #( no|'') ;; #( *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${with_sysroot}" >&5 printf "%s\n" "${with_sysroot}" >&6; } as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5 ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 printf "%s\n" "${lt_sysroot:-no}" >&6; } # Check whether --enable-libtool-lock was given. if test ${enable_libtool_lock+y} then : enableval=$enable_libtool_lock; fi test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes # Some flags need to be propagated to the compiler or linker for good # libtool support. case $host in ia64-*-hpux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.$ac_objext` in *ELF-32*) HPUX_IA64_MODE="32" ;; *ELF-64*) HPUX_IA64_MODE="64" ;; esac fi rm -rf conftest* ;; *-*-irix6*) # Find out which ABI we are using. echo '#line '$LINENO' "configure"' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then if test "$lt_cv_prog_gnu_ld" = yes; then case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -melf32bsmip" ;; *N32*) LD="${LD-ld} -melf32bmipn32" ;; *64-bit*) LD="${LD-ld} -melf64bmip" ;; esac else case `/usr/bin/file conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; *N32*) LD="${LD-ld} -n32" ;; *64-bit*) LD="${LD-ld} -64" ;; esac fi fi rm -rf conftest* ;; x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *32-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_i386_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_i386" ;; ppc64-*linux*|powerpc64-*linux*) LD="${LD-ld} -m elf32ppclinux" ;; s390x-*linux*) LD="${LD-ld} -m elf_s390" ;; sparc64-*linux*) LD="${LD-ld} -m elf32_sparc" ;; esac ;; *64-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_x86_64_fbsd" ;; x86_64-*linux*) LD="${LD-ld} -m elf_x86_64" ;; ppc*-*linux*|powerpc*-*linux*) LD="${LD-ld} -m elf64ppc" ;; s390*-*linux*|s390*-*tpf*) LD="${LD-ld} -m elf64_s390" ;; sparc*-*linux*) LD="${LD-ld} -m elf64_sparc" ;; esac ;; esac fi rm -rf conftest* ;; *-*-sco3.2v5*) # On SCO OpenServer 5, we need -belf to get full-featured binaries. SAVE_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS -belf" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 printf %s "checking whether the C compiler needs -belf... " >&6; } if test ${lt_cv_cc_needs_belf+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : lt_cv_cc_needs_belf=yes else case e in #( e) lt_cv_cc_needs_belf=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 printf "%s\n" "$lt_cv_cc_needs_belf" >&6; } if test x"$lt_cv_cc_needs_belf" != x"yes"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS="$SAVE_CFLAGS" fi ;; *-*solaris*) # Find out which ABI we are using. echo 'int i;' > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then case `/usr/bin/file conftest.o` in *64-bit*) case $lt_cv_prog_gnu_ld in yes*) case $host in i?86-*-solaris*) LD="${LD-ld} -m elf_x86_64" ;; sparc*-*-solaris*) LD="${LD-ld} -m elf64_sparc" ;; esac # GNU ld 2.21 introduced _sol2 emulations. Use them if available. if ${LD-ld} -V | grep _sol2 >/dev/null 2>&1; then LD="${LD-ld}_sol2" fi ;; *) if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then LD="${LD-ld} -64" fi ;; esac ;; esac fi rm -rf conftest* ;; esac need_locks="$enable_libtool_lock" if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args. set dummy ${ac_tool_prefix}mt; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_MANIFEST_TOOL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$MANIFEST_TOOL"; then ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL if test -n "$MANIFEST_TOOL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 printf "%s\n" "$MANIFEST_TOOL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_MANIFEST_TOOL"; then ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL # Extract the first word of "mt", so it can be a program name with args. set dummy mt; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_MANIFEST_TOOL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_MANIFEST_TOOL"; then ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL if test -n "$ac_ct_MANIFEST_TOOL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 printf "%s\n" "$ac_ct_MANIFEST_TOOL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_MANIFEST_TOOL" = x; then MANIFEST_TOOL=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL fi else MANIFEST_TOOL="$ac_cv_prog_MANIFEST_TOOL" fi test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 printf %s "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } if test ${lt_cv_path_mainfest_tool+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_path_mainfest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out cat conftest.err >&5 if $GREP 'Manifest Tool' conftest.out > /dev/null; then lt_cv_path_mainfest_tool=yes fi rm -f conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 printf "%s\n" "$lt_cv_path_mainfest_tool" >&6; } if test "x$lt_cv_path_mainfest_tool" != xyes; then MANIFEST_TOOL=: fi case $host_os in rhapsody* | darwin*) if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_DSYMUTIL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$DSYMUTIL"; then ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi DSYMUTIL=$ac_cv_prog_DSYMUTIL if test -n "$DSYMUTIL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 printf "%s\n" "$DSYMUTIL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_DSYMUTIL"; then ac_ct_DSYMUTIL=$DSYMUTIL # Extract the first word of "dsymutil", so it can be a program name with args. set dummy dsymutil; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_DSYMUTIL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_DSYMUTIL"; then ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL if test -n "$ac_ct_DSYMUTIL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 printf "%s\n" "$ac_ct_DSYMUTIL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DSYMUTIL" = x; then DSYMUTIL=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DSYMUTIL=$ac_ct_DSYMUTIL fi else DSYMUTIL="$ac_cv_prog_DSYMUTIL" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. set dummy ${ac_tool_prefix}nmedit; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_NMEDIT+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$NMEDIT"; then ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi NMEDIT=$ac_cv_prog_NMEDIT if test -n "$NMEDIT"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 printf "%s\n" "$NMEDIT" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_NMEDIT"; then ac_ct_NMEDIT=$NMEDIT # Extract the first word of "nmedit", so it can be a program name with args. set dummy nmedit; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_NMEDIT+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_NMEDIT"; then ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_NMEDIT="nmedit" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT if test -n "$ac_ct_NMEDIT"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 printf "%s\n" "$ac_ct_NMEDIT" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_NMEDIT" = x; then NMEDIT=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac NMEDIT=$ac_ct_NMEDIT fi else NMEDIT="$ac_cv_prog_NMEDIT" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. set dummy ${ac_tool_prefix}lipo; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_LIPO+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$LIPO"; then ac_cv_prog_LIPO="$LIPO" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_LIPO="${ac_tool_prefix}lipo" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi LIPO=$ac_cv_prog_LIPO if test -n "$LIPO"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 printf "%s\n" "$LIPO" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_LIPO"; then ac_ct_LIPO=$LIPO # Extract the first word of "lipo", so it can be a program name with args. set dummy lipo; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_LIPO+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_LIPO"; then ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_LIPO="lipo" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO if test -n "$ac_ct_LIPO"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 printf "%s\n" "$ac_ct_LIPO" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_LIPO" = x; then LIPO=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac LIPO=$ac_ct_LIPO fi else LIPO="$ac_cv_prog_LIPO" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. set dummy ${ac_tool_prefix}otool; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_OTOOL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$OTOOL"; then ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OTOOL="${ac_tool_prefix}otool" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi OTOOL=$ac_cv_prog_OTOOL if test -n "$OTOOL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 printf "%s\n" "$OTOOL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_OTOOL"; then ac_ct_OTOOL=$OTOOL # Extract the first word of "otool", so it can be a program name with args. set dummy otool; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_OTOOL+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_OTOOL"; then ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OTOOL="otool" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL if test -n "$ac_ct_OTOOL"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 printf "%s\n" "$ac_ct_OTOOL" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL" = x; then OTOOL=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL=$ac_ct_OTOOL fi else OTOOL="$ac_cv_prog_OTOOL" fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. set dummy ${ac_tool_prefix}otool64; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_OTOOL64+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$OTOOL64"; then ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi OTOOL64=$ac_cv_prog_OTOOL64 if test -n "$OTOOL64"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 printf "%s\n" "$OTOOL64" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi fi if test -z "$ac_cv_prog_OTOOL64"; then ac_ct_OTOOL64=$OTOOL64 # Extract the first word of "otool64", so it can be a program name with args. set dummy otool64; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_ac_ct_OTOOL64+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$ac_ct_OTOOL64"; then ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OTOOL64="otool64" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 if test -n "$ac_ct_OTOOL64"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 printf "%s\n" "$ac_ct_OTOOL64" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL64" = x; then OTOOL64=":" else case $cross_compiling:$ac_tool_warned in yes:) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL64=$ac_ct_OTOOL64 fi else OTOOL64="$ac_cv_prog_OTOOL64" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 printf %s "checking for -single_module linker flag... " >&6; } if test ${lt_cv_apple_cc_single_mod+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_apple_cc_single_mod=no if test -z "${LT_MULTI_MODULE}"; then # By default we will add the -single_module flag. You can override # by either setting the environment variable LT_MULTI_MODULE # non-empty at configure time, or by adding -multi_module to the # link flags. rm -rf libconftest.dylib* echo "int foo(void){return 1;}" > conftest.c echo "$LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c" >&5 $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \ -dynamiclib -Wl,-single_module conftest.c 2>conftest.err _lt_result=$? # If there is a non-empty error log, and "single_module" # appears in it, assume the flag caused a linker warning if test -s conftest.err && $GREP single_module conftest.err; then cat conftest.err >&5 # Otherwise, if the output was created with a 0 exit code from # the compiler, it worked. elif test -f libconftest.dylib && test $_lt_result -eq 0; then lt_cv_apple_cc_single_mod=yes else cat conftest.err >&5 fi rm -rf libconftest.dylib* rm -f conftest.* fi ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 printf "%s\n" "$lt_cv_apple_cc_single_mod" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 printf %s "checking for -exported_symbols_list linker flag... " >&6; } if test ${lt_cv_ld_exported_symbols_list+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : lt_cv_ld_exported_symbols_list=yes else case e in #( e) lt_cv_ld_exported_symbols_list=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS="$save_LDFLAGS" ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 printf "%s\n" "$lt_cv_ld_exported_symbols_list" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 printf %s "checking for -force_load linker flag... " >&6; } if test ${lt_cv_ld_force_load+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_ld_force_load=no cat > conftest.c << _LT_EOF int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 echo "$AR cru libconftest.a conftest.o" >&5 $AR cru libconftest.a conftest.o 2>&5 echo "$RANLIB libconftest.a" >&5 $RANLIB libconftest.a 2>&5 cat > conftest.c << _LT_EOF int main() { return 0;} _LT_EOF echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5 $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err _lt_result=$? if test -s conftest.err && $GREP force_load conftest.err; then cat conftest.err >&5 elif test -f conftest && test $_lt_result -eq 0 && $GREP forced_load conftest >/dev/null 2>&1 ; then lt_cv_ld_force_load=yes else cat conftest.err >&5 fi rm -f conftest.err libconftest.a conftest conftest.c rm -rf conftest.dSYM ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 printf "%s\n" "$lt_cv_ld_force_load" >&6; } case $host_os in rhapsody* | darwin1.[012]) _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; darwin1.*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; darwin*) # darwin 5.x on # if running on 10.5 or later, the deployment target defaults # to the OS version, if on x86, and 10.4, the deployment # target defaults to 10.4. Don't you love it? case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in 10.0,*86*-darwin8*|10.0,*-darwin[91]*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; 10.[012]*) _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;; 10.*) _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;; esac ;; esac if test "$lt_cv_apple_cc_single_mod" = "yes"; then _lt_dar_single_mod='$single_module' fi if test "$lt_cv_ld_exported_symbols_list" = "yes"; then _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym' else _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' fi if test "$DSYMUTIL" != ":" && test "$lt_cv_ld_force_load" = "no"; then _lt_dsymutil='~$DSYMUTIL $lib || :' else _lt_dsymutil= fi ;; esac ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default " if test "x$ac_cv_header_dlfcn_h" = xyes then : printf "%s\n" "#define HAVE_DLFCN_H 1" >>confdefs.h fi # Set options enable_dlopen=no enable_win32_dll=no # Check whether --enable-shared was given. if test ${enable_shared+y} then : enableval=$enable_shared; p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; no) enable_shared=no ;; *) enable_shared=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_shared=yes fi done IFS="$lt_save_ifs" ;; esac else case e in #( e) enable_shared=yes ;; esac fi # Check whether --enable-static was given. if test ${enable_static+y} then : enableval=$enable_static; p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; no) enable_static=no ;; *) enable_static=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_static=yes fi done IFS="$lt_save_ifs" ;; esac else case e in #( e) enable_static=yes ;; esac fi # Check whether --with-pic was given. if test ${with_pic+y} then : withval=$with_pic; lt_p=${PACKAGE-default} case $withval in yes|no) pic_mode=$withval ;; *) pic_mode=default # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for lt_pkg in $withval; do IFS="$lt_save_ifs" if test "X$lt_pkg" = "X$lt_p"; then pic_mode=yes fi done IFS="$lt_save_ifs" ;; esac else case e in #( e) pic_mode=default ;; esac fi test -z "$pic_mode" && pic_mode=default # Check whether --enable-fast-install was given. if test ${enable_fast_install+y} then : enableval=$enable_fast_install; p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; no) enable_fast_install=no ;; *) enable_fast_install=no # Look at the argument we got. We use all the common list separators. lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR," for pkg in $enableval; do IFS="$lt_save_ifs" if test "X$pkg" = "X$p"; then enable_fast_install=yes fi done IFS="$lt_save_ifs" ;; esac else case e in #( e) enable_fast_install=yes ;; esac fi # This can be used to rebuild libtool when needed LIBTOOL_DEPS="$ltmain" # Always use our own libtool. LIBTOOL='$(SHELL) $(top_builddir)/libtool' test -z "$LN_S" && LN_S="ln -s" if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 printf %s "checking for objdir... " >&6; } if test ${lt_cv_objdir+y} then : printf %s "(cached) " >&6 else case e in #( e) rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then lt_cv_objdir=.libs else # MS-DOS does not allow filenames that begin with a dot. lt_cv_objdir=_libs fi rmdir .libs 2>/dev/null ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 printf "%s\n" "$lt_cv_objdir" >&6; } objdir=$lt_cv_objdir printf "%s\n" "#define LT_OBJDIR \"$lt_cv_objdir/\"" >>confdefs.h case $host_os in aix3*) # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi ;; esac # Global variables: ofile=libtool can_build_shared=yes # All known linkers require a `.a' archive for static linking (except MSVC, # which needs '.lib'). libext=a with_gnu_ld="$lt_cv_prog_gnu_ld" old_CC="$CC" old_CFLAGS="$CFLAGS" # Set sane defaults for various variables test -z "$CC" && CC=cc test -z "$LTCC" && LTCC=$CC test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS test -z "$LD" && LD=ld test -z "$ac_objext" && ac_objext=o for cc_temp in $compiler""; do case $cc_temp in compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; \-*) ;; *) break;; esac done cc_basename=`$ECHO "$cc_temp" | $SED "s%.*/%%; s%^$host_alias-%%"` # Only perform the check for file, if the check method requires it test -z "$MAGIC_CMD" && MAGIC_CMD=file case $deplibs_check_method in file_magic*) if test "$file_magic_cmd" = '$MAGIC_CMD'; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 printf %s "checking for ${ac_tool_prefix}file... " >&6; } if test ${lt_cv_path_MAGIC_CMD+y} then : printf %s "(cached) " >&6 else case e in #( e) case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. ;; *) lt_save_MAGIC_CMD="$MAGIC_CMD" lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" for ac_dir in $ac_dummy; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/${ac_tool_prefix}file; then lt_cv_path_MAGIC_CMD="$ac_dir/${ac_tool_prefix}file" if test -n "$file_magic_test_file"; then case $deplibs_check_method in "file_magic "*) file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | $EGREP "$file_magic_regex" > /dev/null; then : else cat <<_LT_EOF 1>&2 *** Warning: the command libtool uses to detect shared libraries, *** $file_magic_cmd, produces output that libtool cannot recognize. *** The result is that libtool may fail to recognize shared libraries *** as such. This will affect the creation of libtool libraries that *** depend on shared libraries, but programs linked with such libtool *** libraries will work regardless of this problem. Nevertheless, you *** may want to report the problem to your system manager and/or to *** bug-libtool@gnu.org _LT_EOF fi ;; esac fi break fi done IFS="$lt_save_ifs" MAGIC_CMD="$lt_save_MAGIC_CMD" ;; esac ;; esac fi MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if test -n "$MAGIC_CMD"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 printf "%s\n" "$MAGIC_CMD" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi if test -z "$lt_cv_path_MAGIC_CMD"; then if test -n "$ac_tool_prefix"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for file" >&5 printf %s "checking for file... " >&6; } if test ${lt_cv_path_MAGIC_CMD+y} then : printf %s "(cached) " >&6 else case e in #( e) case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path. ;; *) lt_save_MAGIC_CMD="$MAGIC_CMD" lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR ac_dummy="/usr/bin$PATH_SEPARATOR$PATH" for ac_dir in $ac_dummy; do IFS="$lt_save_ifs" test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/file; then lt_cv_path_MAGIC_CMD="$ac_dir/file" if test -n "$file_magic_test_file"; then case $deplibs_check_method in "file_magic "*) file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"` MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null | $EGREP "$file_magic_regex" > /dev/null; then : else cat <<_LT_EOF 1>&2 *** Warning: the command libtool uses to detect shared libraries, *** $file_magic_cmd, produces output that libtool cannot recognize. *** The result is that libtool may fail to recognize shared libraries *** as such. This will affect the creation of libtool libraries that *** depend on shared libraries, but programs linked with such libtool *** libraries will work regardless of this problem. Nevertheless, you *** may want to report the problem to your system manager and/or to *** bug-libtool@gnu.org _LT_EOF fi ;; esac fi break fi done IFS="$lt_save_ifs" MAGIC_CMD="$lt_save_MAGIC_CMD" ;; esac ;; esac fi MAGIC_CMD="$lt_cv_path_MAGIC_CMD" if test -n "$MAGIC_CMD"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 printf "%s\n" "$MAGIC_CMD" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi else MAGIC_CMD=: fi fi fi ;; esac # Use C for the default configuration in the libtool script lt_save_CC="$CC" ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu # Source file extension for C test sources. ac_ext=c # Object file extension for compiled C test sources. objext=o objext=$objext # Code to be used in simple compile tests lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests lt_simple_link_test_code='int main(){return(0);}' # If no C compiler was specified, use CC. LTCC=${LTCC-"$CC"} # If no C compiler flags were specified, use CFLAGS. LTCFLAGS=${LTCFLAGS-"$CFLAGS"} # Allow CC to be a program name with arguments. compiler=$CC # Save the default compiler, since it gets overwritten when the other # tags are being tested, and _LT_TAGVAR(compiler, []) is a NOP. compiler_DEFAULT=$CC # save warnings/boilerplate of simple test code ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" >conftest.$ac_ext eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_compiler_boilerplate=`cat conftest.err` $RM conftest* ac_outfile=conftest.$ac_objext echo "$lt_simple_link_test_code" >conftest.$ac_ext eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err _lt_linker_boilerplate=`cat conftest.err` $RM -r conftest* ## CAVEAT EMPTOR: ## There is no encapsulation within the following macros, do not change ## the running order or otherwise move them around unless you know exactly ## what you are doing... if test -n "$compiler"; then lt_prog_compiler_no_builtin_flag= if test "$GCC" = yes; then case $cc_basename in nvcc*) lt_prog_compiler_no_builtin_flag=' -Xcompiler -fno-builtin' ;; *) lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 printf %s "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } if test ${lt_cv_prog_compiler_rtti_exceptions+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_prog_compiler_rtti_exceptions=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-fno-rtti -fno-exceptions" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. # The option is referenced via a variable to avoid confusing sed. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then lt_cv_prog_compiler_rtti_exceptions=yes fi fi $RM conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 printf "%s\n" "$lt_cv_prog_compiler_rtti_exceptions" >&6; } if test x"$lt_cv_prog_compiler_rtti_exceptions" = xyes; then lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" else : fi fi lt_prog_compiler_wl= lt_prog_compiler_pic= lt_prog_compiler_static= if test "$GCC" = yes; then lt_prog_compiler_wl='-Wl,' lt_prog_compiler_static='-static' case $host_os in aix*) # All AIX code is PIC. if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor lt_prog_compiler_static='-Bstatic' fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support lt_prog_compiler_pic='-fPIC' ;; m68k) # FIXME: we need at least 68020 code to build shared libraries, but # adding the `-m68020' flag to GCC prevents building anything better, # like `-m68040'. lt_prog_compiler_pic='-m68020 -resident32 -malways-restore-a4' ;; esac ;; beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style # (--disable-auto-import) libraries lt_prog_compiler_pic='-DDLL_EXPORT' ;; darwin* | rhapsody*) # PIC is the default on this platform # Common symbols not allowed in MH_DYLIB files lt_prog_compiler_pic='-fno-common' ;; haiku*) # PIC is the default for Haiku. # The "-static" flag exists, but is broken. lt_prog_compiler_static= ;; hpux*) # PIC is the default for 64-bit PA HP-UX, but not for 32-bit # PA HP-UX. On IA64 HP-UX, PIC is the default but the pic flag # sets the default TLS model and affects inlining. case $host_cpu in hppa*64*) # +Z the default ;; *) lt_prog_compiler_pic='-fPIC' ;; esac ;; interix[3-9]*) # Interix 3.x gcc -fpic/-fPIC options generate broken code. # Instead, we relocate shared libraries at runtime. ;; msdosdjgpp*) # Just because we use GCC doesn't mean we suddenly get shared libraries # on systems that don't support them. lt_prog_compiler_can_build_shared=no enable_shared=no ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. lt_prog_compiler_pic='-fPIC -shared' ;; sysv4*MP*) if test -d /usr/nec; then lt_prog_compiler_pic=-Kconform_pic fi ;; *) lt_prog_compiler_pic='-fPIC' ;; esac case $cc_basename in nvcc*) # Cuda Compiler Driver 2.2 lt_prog_compiler_wl='-Xlinker ' if test -n "$lt_prog_compiler_pic"; then lt_prog_compiler_pic="-Xcompiler $lt_prog_compiler_pic" fi ;; esac else # PORTME Check for flag to pass linker flags through the system compiler. case $host_os in aix*) lt_prog_compiler_wl='-Wl,' if test "$host_cpu" = ia64; then # AIX 5 now supports IA64 processor lt_prog_compiler_static='-Bstatic' else lt_prog_compiler_static='-bnso -bI:/lib/syscalls.exp' fi ;; mingw* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). lt_prog_compiler_pic='-DDLL_EXPORT' ;; hpux9* | hpux10* | hpux11*) lt_prog_compiler_wl='-Wl,' # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but # not for PA HP-UX. case $host_cpu in hppa*64*|ia64*) # +Z the default ;; *) lt_prog_compiler_pic='+Z' ;; esac # Is there a better lt_prog_compiler_static that works with the bundled CC? lt_prog_compiler_static='${wl}-a ${wl}archive' ;; irix5* | irix6* | nonstopux*) lt_prog_compiler_wl='-Wl,' # PIC (with -KPIC) is the default. lt_prog_compiler_static='-non_shared' ;; linux* | k*bsd*-gnu | kopensolaris*-gnu) case $cc_basename in # old Intel for x86_64 which still supported -KPIC. ecc*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-static' ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-fPIC' lt_prog_compiler_static='-static' ;; # Lahey Fortran 8.1. lf95*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='--shared' lt_prog_compiler_static='--static' ;; nagfor*) # NAG Fortran compiler lt_prog_compiler_wl='-Wl,-Wl,,' lt_prog_compiler_pic='-PIC' lt_prog_compiler_static='-Bstatic' ;; pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) # Portland Group compilers (*not* the Pentium gcc compiler, # which looks to be a dead project) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-fpic' lt_prog_compiler_static='-Bstatic' ;; ccc*) lt_prog_compiler_wl='-Wl,' # All Alpha code is PIC. lt_prog_compiler_static='-non_shared' ;; xl* | bgxl* | bgf* | mpixl*) # IBM XL C 8.0/Fortran 10.1, 11.1 on PPC and BlueGene lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-qpic' lt_prog_compiler_static='-qstaticlink' ;; *) case `$CC -V 2>&1 | sed 5q` in *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*) # Sun Fortran 8.3 passes all unrecognized flags to the linker lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' lt_prog_compiler_wl='' ;; *Sun\ F* | *Sun*Fortran*) lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' lt_prog_compiler_wl='-Qoption ld ' ;; *Sun\ C*) # Sun C 5.9 lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' lt_prog_compiler_wl='-Wl,' ;; *Intel*\ [CF]*Compiler*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-fPIC' lt_prog_compiler_static='-static' ;; *Portland\ Group*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-fpic' lt_prog_compiler_static='-Bstatic' ;; esac ;; esac ;; newsos6) lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' ;; *nto* | *qnx*) # QNX uses GNU C++, but need to define -shared option too, otherwise # it will coredump. lt_prog_compiler_pic='-fPIC -shared' ;; osf3* | osf4* | osf5*) lt_prog_compiler_wl='-Wl,' # All OSF/1 code is PIC. lt_prog_compiler_static='-non_shared' ;; rdos*) lt_prog_compiler_static='-non_shared' ;; solaris*) lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' case $cc_basename in f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) lt_prog_compiler_wl='-Qoption ld ';; *) lt_prog_compiler_wl='-Wl,';; esac ;; sunos4*) lt_prog_compiler_wl='-Qoption ld ' lt_prog_compiler_pic='-PIC' lt_prog_compiler_static='-Bstatic' ;; sysv4 | sysv4.2uw2* | sysv4.3*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' ;; sysv4*MP*) if test -d /usr/nec ;then lt_prog_compiler_pic='-Kconform_pic' lt_prog_compiler_static='-Bstatic' fi ;; sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-Bstatic' ;; unicos*) lt_prog_compiler_wl='-Wl,' lt_prog_compiler_can_build_shared=no ;; uts4*) lt_prog_compiler_pic='-pic' lt_prog_compiler_static='-Bstatic' ;; *) lt_prog_compiler_can_build_shared=no ;; esac fi case $host_os in # For platforms which do not support PIC, -DPIC is meaningless: *djgpp*) lt_prog_compiler_pic= ;; *) lt_prog_compiler_pic="$lt_prog_compiler_pic -DPIC" ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 printf %s "checking for $compiler option to produce PIC... " >&6; } if test ${lt_cv_prog_compiler_pic+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_prog_compiler_pic=$lt_prog_compiler_pic ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 printf "%s\n" "$lt_cv_prog_compiler_pic" >&6; } lt_prog_compiler_pic=$lt_cv_prog_compiler_pic # # Check to make sure the PIC flag actually works. # if test -n "$lt_prog_compiler_pic"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } if test ${lt_cv_prog_compiler_pic_works+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_prog_compiler_pic_works=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="$lt_prog_compiler_pic -DPIC" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. # The option is referenced via a variable to avoid confusing sed. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' >conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then lt_cv_prog_compiler_pic_works=yes fi fi $RM conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 printf "%s\n" "$lt_cv_prog_compiler_pic_works" >&6; } if test x"$lt_cv_prog_compiler_pic_works" = xyes; then case $lt_prog_compiler_pic in "" | " "*) ;; *) lt_prog_compiler_pic=" $lt_prog_compiler_pic" ;; esac else lt_prog_compiler_pic= lt_prog_compiler_can_build_shared=no fi fi # # Check to make sure the static flag actually works. # wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } if test ${lt_cv_prog_compiler_static_works+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_prog_compiler_static_works=no save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS $lt_tmp_static_flag" echo "$lt_simple_link_test_code" > conftest.$ac_ext if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then # The linker can only warn and ignore the option if not recognized # So say no if there are warnings if test -s conftest.err; then # Append any errors to the config.log. cat conftest.err 1>&5 $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if diff conftest.exp conftest.er2 >/dev/null; then lt_cv_prog_compiler_static_works=yes fi else lt_cv_prog_compiler_static_works=yes fi fi $RM -r conftest* LDFLAGS="$save_LDFLAGS" ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 printf "%s\n" "$lt_cv_prog_compiler_static_works" >&6; } if test x"$lt_cv_prog_compiler_static_works" = xyes; then : else lt_prog_compiler_static= fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } if test ${lt_cv_prog_compiler_c_o+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest cd conftest mkdir out echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-o out/conftest2.$ac_objext" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then lt_cv_prog_compiler_c_o=yes fi fi chmod u+w . 2>&5 $RM conftest* # SGI C++ compiler will create directory out/ii_files/ for # template instantiation test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files $RM out/* && rmdir out cd .. $RM -r conftest $RM conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } if test ${lt_cv_prog_compiler_c_o+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest cd conftest mkdir out echo "$lt_simple_compile_test_code" > conftest.$ac_ext lt_compiler_flag="-o out/conftest2.$ac_objext" # Insert the option either (1) after the last *FLAGS variable, or # (2) before a word containing "conftest.", or (3) at the end. # Note that $ac_compile itself does not contain backslashes and begins # with a dollar sign (not a hyphen), so the echo should work correctly. lt_compile=`echo "$ac_compile" | $SED \ -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` (eval echo "\"\$as_me:$LINENO: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings $ECHO "$_lt_compiler_boilerplate" | $SED '/^$/d' > out/conftest.exp $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2 if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then lt_cv_prog_compiler_c_o=yes fi fi chmod u+w . 2>&5 $RM conftest* # SGI C++ compiler will create directory out/ii_files/ for # template instantiation test -d out/ii_files && $RM out/ii_files/* && rmdir out/ii_files $RM out/* && rmdir out cd .. $RM -r conftest $RM conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } hard_links="nottested" if test "$lt_cv_prog_compiler_c_o" = no && test "$need_locks" != no; then # do not overwrite the value of need_locks provided by the user { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 printf %s "checking if we can lock with hard links... " >&6; } hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 printf "%s\n" "$hard_links" >&6; } if test "$hard_links" = no; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&5 printf "%s\n" "$as_me: WARNING: \`$CC' does not support \`-c -o', so \`make -j' may be unsafe" >&2;} need_locks=warn fi else need_locks=no fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } runpath_var= allow_undefined_flag= always_export_symbols=no archive_cmds= archive_expsym_cmds= compiler_needs_object=no enable_shared_with_static_runtimes=no export_dynamic_flag_spec= export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' hardcode_automatic=no hardcode_direct=no hardcode_direct_absolute=no hardcode_libdir_flag_spec= hardcode_libdir_separator= hardcode_minus_L=no hardcode_shlibpath_var=unsupported inherit_rpath=no link_all_deplibs=unknown module_cmds= module_expsym_cmds= old_archive_from_new_cmds= old_archive_from_expsyms_cmds= thread_safe_flag_spec= whole_archive_flag_spec= # include_expsyms should be a list of space-separated symbols to be *always* # included in the symbol list include_expsyms= # exclude_expsyms can be an extended regexp of symbols to exclude # it will be wrapped by ` (' and `)$', so one must not match beginning or # end of line. Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc', # as well as any symbol that contains `d'. exclude_expsyms='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out # platforms (ab)use it in PIC code, but their linkers get confused if # the symbol is explicitly referenced. Since portable code cannot # rely on this symbol name, it's probably fine to never include it in # preloaded symbol tables. # Exclude shared library initialization/finalization symbols. extract_expsyms_cmds= case $host_os in cygwin* | mingw* | pw32* | cegcc*) # FIXME: the MSVC++ port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using # Microsoft Visual C++. if test "$GCC" != yes; then with_gnu_ld=no fi ;; interix*) # we just hope/assume this is gcc and not c89 (= MSVC++) with_gnu_ld=yes ;; openbsd*) with_gnu_ld=no ;; esac ld_shlibs=yes # On some targets, GNU ld is compatible enough with the native linker # that we're better off using the native interface for both. lt_use_gnu_ld_interface=no if test "$with_gnu_ld" = yes; then case $host_os in aix*) # The AIX port of GNU ld has always aspired to compatibility # with the native linker. However, as the warning in the GNU ld # block says, versions before 2.19.5* couldn't really create working # shared libraries, regardless of the interface used. case `$LD -v 2>&1` in *\ \(GNU\ Binutils\)\ 2.19.5*) ;; *\ \(GNU\ Binutils\)\ 2.[2-9]*) ;; *\ \(GNU\ Binutils\)\ [3-9]*) ;; *) lt_use_gnu_ld_interface=yes ;; esac ;; *) lt_use_gnu_ld_interface=yes ;; esac fi if test "$lt_use_gnu_ld_interface" = yes; then # If archive_cmds runs LD, not CC, wlarc should be empty wlarc='${wl}' # Set some defaults for GNU ld with shared library support. These # are reset later if shared libraries are not supported. Putting them # here allows them to be overridden if necessary. runpath_var=LD_RUN_PATH hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' export_dynamic_flag_spec='${wl}--export-dynamic' # ancient GNU ld didn't support --whole-archive et. al. if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then whole_archive_flag_spec="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive' else whole_archive_flag_spec= fi supports_anon_versioning=no case `$LD -v 2>&1` in *GNU\ gold*) supports_anon_versioning=yes ;; *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ... *\ 2.11.*) ;; # other 2.11 versions *) supports_anon_versioning=yes ;; esac # See if GNU ld supports shared libraries. case $host_os in aix[3-9]*) # On AIX/PPC, the GNU linker is very broken if test "$host_cpu" != ia64; then ld_shlibs=no cat <<_LT_EOF 1>&2 *** Warning: the GNU linker, at least up to release 2.19, is reported *** to be unable to reliably create shared libraries on AIX. *** Therefore, libtool is disabling shared libraries support. If you *** really care for shared libraries, you may want to install binutils *** 2.20 or above, or modify your PATH so that a non-GNU linker is found. *** You will then need to restart the configuration process. _LT_EOF fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='' ;; m68k) archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes ;; esac ;; beos*) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then allow_undefined_flag=unsupported # Joseph Beckenbach says some releases of gcc # support --undefined. This deserves some investigation. FIXME archive_cmds='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' else ld_shlibs=no fi ;; cygwin* | mingw* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, # as there is no search path for DLLs. hardcode_libdir_flag_spec='-L$libdir' export_dynamic_flag_spec='${wl}--export-all-symbols' allow_undefined_flag=unsupported always_export_symbols=no enable_shared_with_static_runtimes=yes export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1 DATA/;s/^.*[ ]__nm__\([^ ]*\)[ ][^ ]*/\1 DATA/;/^I[ ]/d;/^[AITW][ ]/s/.* //'\'' | sort | uniq > $export_symbols' exclude_expsyms='[_]+GLOBAL_OFFSET_TABLE_|[_]+GLOBAL__[FID]_.*|[_]+head_[A-Za-z0-9_]+_dll|[A-Za-z0-9_]+_dll_iname' if $LD --help 2>&1 | $GREP 'auto-import' > /dev/null; then archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' # If the export-symbols file already is a .def file (1st line # is EXPORTS), use it as is; otherwise, prepend... archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then cp $export_symbols $output_objdir/$soname.def; else echo EXPORTS > $output_objdir/$soname.def; cat $export_symbols >> $output_objdir/$soname.def; fi~ $CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib' else ld_shlibs=no fi ;; haiku*) archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' link_all_deplibs=yes ;; interix[3-9]*) hardcode_direct=no hardcode_shlibpath_var=no hardcode_libdir_flag_spec='${wl}-rpath,$libdir' export_dynamic_flag_spec='${wl}-E' # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc. # Instead, shared libraries are loaded at an image base (0x10000000 by # default) and relocated if they conflict, which is a slow very memory # consuming and fragmenting process. To avoid this, we pick a random, # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' archive_expsym_cmds='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) tmp_diet=no if test "$host_os" = linux-dietlibc; then case $cc_basename in diet\ *) tmp_diet=yes;; # linux-dietlibc with static linking (!diet-dyn) esac fi if $LD --help 2>&1 | $EGREP ': supported targets:.* elf' > /dev/null \ && test "$tmp_diet" = no then tmp_addflag=' $pic_flag' tmp_sharedflag='-shared' case $cc_basename,$host_cpu in pgcc*) # Portland Group C compiler whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag' ;; pgf77* | pgf90* | pgf95* | pgfortran*) # Portland Group f77 and f90 compilers whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' tmp_addflag=' $pic_flag -Mnomain' ;; ecc*,ia64* | icc*,ia64*) # Intel C compiler on ia64 tmp_addflag=' -i_dynamic' ;; efc*,ia64* | ifort*,ia64*) # Intel Fortran compiler on ia64 tmp_addflag=' -i_dynamic -nofor_main' ;; ifc* | ifort*) # Intel Fortran compiler tmp_addflag=' -nofor_main' ;; lf95*) # Lahey Fortran 8.1 whole_archive_flag_spec= tmp_sharedflag='--shared' ;; xl[cC]* | bgxl[cC]* | mpixl[cC]*) # IBM XL C 8.0 on PPC (deal with xlf below) tmp_sharedflag='-qmkshrobj' tmp_addflag= ;; nvcc*) # Cuda Compiler Driver 2.2 whole_archive_flag_spec='${wl}--whole-archive`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' compiler_needs_object=yes ;; esac case `$CC -V 2>&1 | sed 5q` in *Sun\ C*) # Sun C 5.9 whole_archive_flag_spec='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` ${wl}--no-whole-archive' compiler_needs_object=yes tmp_sharedflag='-G' ;; *Sun\ F*) # Sun Fortran 8.3 tmp_sharedflag='-G' ;; esac archive_cmds='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' if test "x$supports_anon_versioning" = xyes; then archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib' fi case $cc_basename in xlf* | bgf* | bgxlf* | mpixlf*) # IBM XL Fortran 10.1 on PPC cannot create shared libs itself whole_archive_flag_spec='--whole-archive$convenience --no-whole-archive' hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' if test "x$supports_anon_versioning" = xyes; then archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' fi ;; esac else ld_shlibs=no fi ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib' wlarc= else archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' fi ;; solaris*) if $LD -v 2>&1 | $GREP 'BFD 2\.8' > /dev/null; then ld_shlibs=no cat <<_LT_EOF 1>&2 *** Warning: The releases 2.8.* of the GNU linker cannot reliably *** create shared libraries on Solaris systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.9.1 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF elif $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else ld_shlibs=no fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) case `$LD -v 2>&1` in *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) ld_shlibs=no cat <<_LT_EOF 1>&2 *** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not *** reliably create shared libraries on SCO systems. Therefore, libtool *** is disabling shared libraries support. We urge you to upgrade GNU *** binutils to release 2.16.91.0.3 or newer. Another option is to modify *** your PATH or compiler configuration so that the native linker is *** used, and then restart. _LT_EOF ;; *) # For security reasons, it is highly recommended that you always # use absolute paths for naming shared libraries, and exclude the # DT_RUNPATH tag from executables and libraries. But doing so # requires that you compile everything twice, which is a pain. if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else ld_shlibs=no fi ;; esac ;; sunos4*) archive_cmds='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags' wlarc= hardcode_direct=yes hardcode_shlibpath_var=no ;; *) if $LD --help 2>&1 | $GREP ': supported targets:.* elf' > /dev/null; then archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib' else ld_shlibs=no fi ;; esac if test "$ld_shlibs" = no; then runpath_var= hardcode_libdir_flag_spec= export_dynamic_flag_spec= whole_archive_flag_spec= fi else # PORTME fill in a description of your system's linker (not GNU ld) case $host_os in aix3*) allow_undefined_flag=unsupported always_export_symbols=yes archive_expsym_cmds='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname' # Note: this linker hardcodes the directories in LIBPATH if there # are no directories specified by -L. hardcode_minus_L=yes if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then # Neither direct hardcoding nor static linking is supported with a # broken collect2. hardcode_direct=unsupported fi ;; aix[4-9]*) if test "$host_cpu" = ia64; then # On IA64, the linker does run time linking by default, so we don't # have to do anything special. aix_use_runtimelinking=no exp_sym_flag='-Bexport' no_entry_flag="" else # If we're using GNU nm, then we don't want the "-C" option. # -C means demangle to AIX nm, but means don't demangle with GNU nm # Also, AIX nm treats weak defined symbols like other global # defined symbols, whereas GNU nm marks them as "W". if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' else export_symbols_cmds='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B")) && (substr(\$ 3,1,1) != ".")) { print \$ 3 } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no # Test if we are trying to use run time linking or normal # AIX style linking. If -brtl is somewhere in LDFLAGS, we # need to do runtime linking. case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) for ld_flag in $LDFLAGS; do if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then aix_use_runtimelinking=yes break fi done ;; esac exp_sym_flag='-bexport' no_entry_flag='-bnoentry' fi # When large executables or shared objects are built, AIX ld can # have problems creating the table of contents. If linking a library # or program results in "error TOC overflow" add -mminimal-toc to # CXXFLAGS/CFLAGS for g++/gcc. In the cases where that is not # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS. archive_cmds='' hardcode_direct=yes hardcode_direct_absolute=yes hardcode_libdir_separator=':' link_all_deplibs=yes file_list_spec='${wl}-f,' if test "$GCC" = yes; then case $host_os in aix4.[012]|aix4.[012].*) # We only want to do this on AIX 4.2 and lower, the check # below for broken collect2 doesn't work under 4.3+ collect2name=`${CC} -print-prog-name=collect2` if test -f "$collect2name" && strings "$collect2name" | $GREP resolve_lib_name >/dev/null then # We have reworked collect2 : else # We have old collect2 hardcode_direct=unsupported # It fails to find uninstalled libraries when the uninstalled # path is not listed in the libpath. Setting hardcode_minus_L # to unsupported forces relinking hardcode_minus_L=yes hardcode_libdir_flag_spec='-L$libdir' hardcode_libdir_separator= fi ;; esac shared_flag='-shared' if test "$aix_use_runtimelinking" = yes; then shared_flag="$shared_flag "'${wl}-G' fi else # not using gcc if test "$host_cpu" = ia64; then # VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release # chokes on -Wl,-G. The following line is correct: shared_flag='-G' else if test "$aix_use_runtimelinking" = yes; then shared_flag='${wl}-G' else shared_flag='${wl}-bM:SRE' fi fi fi export_dynamic_flag_spec='${wl}-bexpall' # It seems that -bexpall does not export symbols beginning with # underscore (_), so it is better to generate a list of symbols to export. always_export_symbols=yes if test "$aix_use_runtimelinking" = yes; then # Warning - without using the other runtime loading flags (-brtl), # -berok will link without error, but may produce a broken library. allow_undefined_flag='-berok' # Determine the default libpath from the value encoded in an # empty executable. if test "${lt_cv_aix_libpath+set}" = set; then aix_libpath=$lt_cv_aix_libpath else if test ${lt_cv_aix_libpath_+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { /^0/ { s/^0 *\([^ ]*\) *$/\1/ p } }' lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` # Check for a 64-bit object if we didn't find anything. if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_="/usr/lib:/lib" fi ;; esac fi aix_libpath=$lt_cv_aix_libpath_ fi hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" archive_expsym_cmds='$CC -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then func_echo_all "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag" else if test "$host_cpu" = ia64; then hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' allow_undefined_flag="-z nodefs" archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols" else # Determine the default libpath from the value encoded in an # empty executable. if test "${lt_cv_aix_libpath+set}" = set; then aix_libpath=$lt_cv_aix_libpath else if test ${lt_cv_aix_libpath_+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { /^0/ { s/^0 *\([^ ]*\) *$/\1/ p } }' lt_cv_aix_libpath_=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` # Check for a 64-bit object if we didn't find anything. if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_="/usr/lib:/lib" fi ;; esac fi aix_libpath=$lt_cv_aix_libpath_ fi hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" # Warning - without using the other run time loading flags, # -berok will link without error, but may produce a broken library. no_undefined_flag=' ${wl}-bernotok' allow_undefined_flag=' ${wl}-berok' if test "$with_gnu_ld" = yes; then # We only use this code for GNU lds that support --whole-archive. whole_archive_flag_spec='${wl}--whole-archive$convenience ${wl}--no-whole-archive' else # Exported symbols can be pulled into shared objects from archives whole_archive_flag_spec='$convenience' fi archive_cmds_need_lc=yes # This is similar to how AIX traditionally builds its shared libraries. archive_expsym_cmds="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname' fi fi ;; amigaos*) case $host_cpu in powerpc) # see comment about AmigaOS4 .so support archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib' archive_expsym_cmds='' ;; m68k) archive_cmds='$RM $output_objdir/a2ixlibrary.data~$ECHO "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$ECHO "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$ECHO "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$ECHO "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)' hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes ;; esac ;; bsdi[45]*) export_dynamic_flag_spec=-rdynamic ;; cygwin* | mingw* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using # Microsoft Visual C++. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. case $cc_basename in cl*) # Native MSVC hardcode_libdir_flag_spec=' ' allow_undefined_flag=unsupported always_export_symbols=yes file_list_spec='@' # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=".dll" # FIXME: Setting linknames here is a bad hack. archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-dll~linknames=' archive_expsym_cmds='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then sed -n -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' -e '1\\\!p' < $export_symbols > $output_objdir/$soname.exp; else sed -e 's/\\\\\\\(.*\\\\\\\)/-link\\\ -EXPORT:\\\\\\\1/' < $export_symbols > $output_objdir/$soname.exp; fi~ $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ linknames=' # The linker will not automatically build a static lib if we build a DLL. # _LT_TAGVAR(old_archive_from_new_cmds, )='true' enable_shared_with_static_runtimes=yes exclude_expsyms='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' export_symbols_cmds='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[BCDGRS][ ]/s/.*[ ]\([^ ]*\)/\1,DATA/'\'' | $SED -e '\''/^[AITW][ ]/s/.*[ ]//'\'' | sort | uniq > $export_symbols' # Don't use ranlib old_postinstall_cmds='chmod 644 $oldlib' postlink_cmds='lt_outputfile="@OUTPUT@"~ lt_tool_outputfile="@TOOL_OUTPUT@"~ case $lt_outputfile in *.exe|*.EXE) ;; *) lt_outputfile="$lt_outputfile.exe" lt_tool_outputfile="$lt_tool_outputfile.exe" ;; esac~ if test "$MANIFEST_TOOL" != ":" && test -f "$lt_outputfile.manifest"; then $MANIFEST_TOOL -manifest "$lt_tool_outputfile.manifest" -outputresource:"$lt_tool_outputfile" || exit 1; $RM "$lt_outputfile.manifest"; fi' ;; *) # Assume MSVC wrapper hardcode_libdir_flag_spec=' ' allow_undefined_flag=unsupported # Tell ltmain to make .lib files, not .a files. libext=lib # Tell ltmain to make .dll files, not .so files. shrext_cmds=".dll" # FIXME: Setting linknames here is a bad hack. archive_cmds='$CC -o $lib $libobjs $compiler_flags `func_echo_all "$deplibs" | $SED '\''s/ -lc$//'\''` -link -dll~linknames=' # The linker will automatically build a .lib file if we build a DLL. old_archive_from_new_cmds='true' # FIXME: Should let the user specify the lib program. old_archive_cmds='lib -OUT:$oldlib$oldobjs$old_deplibs' enable_shared_with_static_runtimes=yes ;; esac ;; darwin* | rhapsody*) archive_cmds_need_lc=no hardcode_direct=no hardcode_automatic=yes hardcode_shlibpath_var=unsupported if test "$lt_cv_ld_force_load" = "yes"; then whole_archive_flag_spec='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience ${wl}-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' else whole_archive_flag_spec='' fi link_all_deplibs=yes allow_undefined_flag="$_lt_dar_allow_undefined" case $cc_basename in ifort*) _lt_dar_can_shared=yes ;; *) _lt_dar_can_shared=$GCC ;; esac if test "$_lt_dar_can_shared" = "yes"; then output_verbose_link_cmd=func_echo_all archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}" module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}" archive_expsym_cmds="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}" module_expsym_cmds="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}" else ld_shlibs=no fi ;; dgux*) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_libdir_flag_spec='-L$libdir' hardcode_shlibpath_var=no ;; # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor # support. Future versions do this automatically, but an explicit c++rt0.o # does not break anything, and helps significantly (at the cost of a little # extra space). freebsd2.2*) archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o' hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes hardcode_shlibpath_var=no ;; # Unfortunately, older versions of FreeBSD 2 do not have this feature. freebsd2.*) archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=yes hardcode_minus_L=yes hardcode_shlibpath_var=no ;; # FreeBSD 3 and greater uses gcc -shared to do shared libraries. freebsd* | dragonfly*) archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes hardcode_shlibpath_var=no ;; hpux9*) if test "$GCC" = yes; then archive_cmds='$RM $output_objdir/$soname~$CC -shared $pic_flag ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' else archive_cmds='$RM $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib' fi hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: hardcode_direct=yes # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes export_dynamic_flag_spec='${wl}-E' ;; hpux10*) if test "$GCC" = yes && test "$with_gnu_ld" = no; then archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' fi if test "$with_gnu_ld" = no; then hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: hardcode_direct=yes hardcode_direct_absolute=yes export_dynamic_flag_spec='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes fi ;; hpux11*) if test "$GCC" = yes && test "$with_gnu_ld" = no; then case $host_cpu in hppa*64*) archive_cmds='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) archive_cmds='$CC -shared $pic_flag ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' ;; esac else case $host_cpu in hppa*64*) archive_cmds='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' ;; ia64*) archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags' ;; *) # Older versions of the 11.00 compiler do not understand -b yet # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 printf %s "checking if $CC understands -b... " >&6; } if test ${lt_cv_prog_compiler__b+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_prog_compiler__b=no save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -b" echo "$lt_simple_link_test_code" > conftest.$ac_ext if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then # The linker can only warn and ignore the option if not recognized # So say no if there are warnings if test -s conftest.err; then # Append any errors to the config.log. cat conftest.err 1>&5 $ECHO "$_lt_linker_boilerplate" | $SED '/^$/d' > conftest.exp $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2 if diff conftest.exp conftest.er2 >/dev/null; then lt_cv_prog_compiler__b=yes fi else lt_cv_prog_compiler__b=yes fi fi $RM -r conftest* LDFLAGS="$save_LDFLAGS" ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 printf "%s\n" "$lt_cv_prog_compiler__b" >&6; } if test x"$lt_cv_prog_compiler__b" = xyes; then archive_cmds='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags' fi ;; esac fi if test "$with_gnu_ld" = no; then hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' hardcode_libdir_separator=: case $host_cpu in hppa*64*|ia64*) hardcode_direct=no hardcode_shlibpath_var=no ;; *) hardcode_direct=yes hardcode_direct_absolute=yes export_dynamic_flag_spec='${wl}-E' # hardcode_minus_L: Not really in the search PATH, # but as the default location of the library. hardcode_minus_L=yes ;; esac fi ;; irix5* | irix6* | nonstopux*) if test "$GCC" = yes; then archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' # Try to use the -exported_symbol ld option, if it does not # work, assume that -exports_file does not work either and # implicitly export all symbols. # This should be the same for all languages, so no per-tag cache variable. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 printf %s "checking whether the $host_os linker accepts -exported_symbol... " >&6; } if test ${lt_cv_irix_exported_symbol+y} then : printf %s "(cached) " >&6 else case e in #( e) save_LDFLAGS="$LDFLAGS" LDFLAGS="$LDFLAGS -shared ${wl}-exported_symbol ${wl}foo ${wl}-update_registry ${wl}/dev/null" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int foo (void) { return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : lt_cv_irix_exported_symbol=yes else case e in #( e) lt_cv_irix_exported_symbol=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS="$save_LDFLAGS" ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } if test "$lt_cv_irix_exported_symbol" = yes; then archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations ${wl}-exports_file ${wl}$export_symbols -o $lib' fi else archive_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' archive_expsym_cmds='$CC -shared $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -exports_file $export_symbols -o $lib' fi archive_cmds_need_lc='no' hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: inherit_rpath=yes link_all_deplibs=yes ;; netbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' # a.out else archive_cmds='$LD -shared -o $lib $libobjs $deplibs $linker_flags' # ELF fi hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes hardcode_shlibpath_var=no ;; newsos6) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=yes hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: hardcode_shlibpath_var=no ;; *nto* | *qnx*) ;; openbsd*) if test -f /usr/libexec/ld.so; then hardcode_direct=yes hardcode_shlibpath_var=no hardcode_direct_absolute=yes if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols' hardcode_libdir_flag_spec='${wl}-rpath,$libdir' export_dynamic_flag_spec='${wl}-E' else case $host_os in openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) archive_cmds='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags' hardcode_libdir_flag_spec='-R$libdir' ;; *) archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' hardcode_libdir_flag_spec='${wl}-rpath,$libdir' ;; esac fi else ld_shlibs=no fi ;; os2*) hardcode_libdir_flag_spec='-L$libdir' hardcode_minus_L=yes allow_undefined_flag=unsupported archive_cmds='$ECHO "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$ECHO "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~echo DATA >> $output_objdir/$libname.def~echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def' old_archive_from_new_cmds='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def' ;; osf3*) if test "$GCC" = yes; then allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' else allow_undefined_flag=' -expect_unresolved \*' archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' fi archive_cmds_need_lc='no' hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' hardcode_libdir_separator=: ;; osf4* | osf5*) # as osf3* with the addition of -msym flag if test "$GCC" = yes; then allow_undefined_flag=' ${wl}-expect_unresolved ${wl}\*' archive_cmds='$CC -shared${allow_undefined_flag} $pic_flag $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && func_echo_all "${wl}-set_version ${wl}$verstring"` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib' hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' else allow_undefined_flag=' -expect_unresolved \*' archive_cmds='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags -msym -soname $soname `test -n "$verstring" && func_echo_all "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib' archive_expsym_cmds='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; printf "%s\\n" "-hidden">> $lib.exp~ $CC -shared${allow_undefined_flag} ${wl}-input ${wl}$lib.exp $compiler_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && $ECHO "-set_version $verstring"` -update_registry ${output_objdir}/so_locations -o $lib~$RM $lib.exp' # Both c and cxx compiler support -rpath directly hardcode_libdir_flag_spec='-rpath $libdir' fi archive_cmds_need_lc='no' hardcode_libdir_separator=: ;; solaris*) no_undefined_flag=' -z defs' if test "$GCC" = yes; then wlarc='${wl}' archive_cmds='$CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -shared $pic_flag ${wl}-z ${wl}text ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' else case `$CC -V 2>&1` in *"Compilers 5.0"*) wlarc='' archive_cmds='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags' archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$RM $lib.exp' ;; *) wlarc='${wl}' archive_cmds='$CC -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~echo "local: *; };" >> $lib.exp~ $CC -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $compiler_flags~$RM $lib.exp' ;; esac fi hardcode_libdir_flag_spec='-R$libdir' hardcode_shlibpath_var=no case $host_os in solaris2.[0-5] | solaris2.[0-5].*) ;; *) # The compiler driver will combine and reorder linker options, # but understands `-z linker_flag'. GCC discards it without `$wl', # but is careful enough not to reorder. # Supported since Solaris 2.6 (maybe 2.5.1?) if test "$GCC" = yes; then whole_archive_flag_spec='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract' else whole_archive_flag_spec='-z allextract$convenience -z defaultextract' fi ;; esac link_all_deplibs=yes ;; sunos4*) if test "x$host_vendor" = xsequent; then # Use $CC to link under sequent, because it throws in some extra .o # files that make .init and .fini sections work. archive_cmds='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags' fi hardcode_libdir_flag_spec='-L$libdir' hardcode_direct=yes hardcode_minus_L=yes hardcode_shlibpath_var=no ;; sysv4) case $host_vendor in sni) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=yes # is this really true??? ;; siemens) ## LD is ld it makes a PLAMLIB ## CC just makes a GrossModule. archive_cmds='$LD -G -o $lib $libobjs $deplibs $linker_flags' reload_cmds='$CC -r -o $output$reload_objs' hardcode_direct=no ;; motorola) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_direct=no #Motorola manual says yes, but my tests say they lie ;; esac runpath_var='LD_RUN_PATH' hardcode_shlibpath_var=no ;; sysv4.3*) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_shlibpath_var=no export_dynamic_flag_spec='-Bexport' ;; sysv4*MP*) if test -d /usr/nec; then archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_shlibpath_var=no runpath_var=LD_RUN_PATH hardcode_runpath_var=yes ld_shlibs=yes fi ;; sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) no_undefined_flag='${wl}-z,text' archive_cmds_need_lc=no hardcode_shlibpath_var=no runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; sysv5* | sco3.2v5* | sco5v6*) # Note: We can NOT use -z defs as we might desire, because we do not # link with -lc, and that would cause any symbols used from libc to # always be unresolved, which means just about no library would # ever link correctly. If we're not using GNU ld we use -z text # though, which does catch some bad symbols but isn't as heavy-handed # as -z defs. no_undefined_flag='${wl}-z,text' allow_undefined_flag='${wl}-z,nodefs' archive_cmds_need_lc=no hardcode_shlibpath_var=no hardcode_libdir_flag_spec='${wl}-R,$libdir' hardcode_libdir_separator=':' link_all_deplibs=yes export_dynamic_flag_spec='${wl}-Bexport' runpath_var='LD_RUN_PATH' if test "$GCC" = yes; then archive_cmds='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' else archive_cmds='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' archive_expsym_cmds='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags' fi ;; uts4*) archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags' hardcode_libdir_flag_spec='-L$libdir' hardcode_shlibpath_var=no ;; *) ld_shlibs=no ;; esac if test x$host_vendor = xsni; then case $host in sysv4 | sysv4.2uw2* | sysv4.3* | sysv5*) export_dynamic_flag_spec='${wl}-Blargedynsym' ;; esac fi fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 printf "%s\n" "$ld_shlibs" >&6; } test "$ld_shlibs" = no && can_build_shared=no with_gnu_ld=$with_gnu_ld # # Do we need to explicitly link libc? # case "x$archive_cmds_need_lc" in x|xyes) # Assume -lc should be added archive_cmds_need_lc=yes if test "$enable_shared" = yes && test "$GCC" = yes; then case $archive_cmds in *'~'*) # FIXME: we may have to deal with multi-command sequences. ;; '$CC '*) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 printf %s "checking whether -lc should be explicitly linked in... " >&6; } if test ${lt_cv_archive_cmds_need_lc+y} then : printf %s "(cached) " >&6 else case e in #( e) $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest libobjs=conftest.$ac_objext deplibs= wl=$lt_prog_compiler_wl pic_flag=$lt_prog_compiler_pic compiler_flags=-v linker_flags=-v verstring= output_objdir=. libname=conftest lt_save_allow_undefined_flag=$allow_undefined_flag allow_undefined_flag= if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc=no else lt_cv_archive_cmds_need_lc=yes fi allow_undefined_flag=$lt_save_allow_undefined_flag else cat conftest.err 1>&5 fi $RM conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 printf "%s\n" "$lt_cv_archive_cmds_need_lc" >&6; } archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc ;; esac fi ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 printf %s "checking dynamic linker characteristics... " >&6; } if test "$GCC" = yes; then case $host_os in darwin*) lt_awk_arg="/^libraries:/,/LR/" ;; *) lt_awk_arg="/^libraries:/" ;; esac case $host_os in mingw* | cegcc*) lt_sed_strip_eq="s,=\([A-Za-z]:\),\1,g" ;; *) lt_sed_strip_eq="s,=/,/,g" ;; esac lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` case $lt_search_path_spec in *\;*) # if the path contains ";" then we assume it to be the separator # otherwise default to the standard path separator (i.e. ":") - it is # assumed that no part of a normal pathname contains ";" but that should # okay in the real world where ";" in dirpaths is itself problematic. lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED 's/;/ /g'` ;; *) lt_search_path_spec=`$ECHO "$lt_search_path_spec" | $SED "s/$PATH_SEPARATOR/ /g"` ;; esac # Ok, now we have the path, separated by spaces, we can step through it # and add multilib dir if necessary. lt_tmp_lt_search_path_spec= lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null` for lt_sys_path in $lt_search_path_spec; do if test -d "$lt_sys_path/$lt_multi_os_dir"; then lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir" else test -d "$lt_sys_path" && \ lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path" fi done lt_search_path_spec=`$ECHO "$lt_tmp_lt_search_path_spec" | awk ' BEGIN {RS=" "; FS="/|\n";} { lt_foo=""; lt_count=0; for (lt_i = NF; lt_i > 0; lt_i--) { if ($lt_i != "" && $lt_i != ".") { if ($lt_i == "..") { lt_count++; } else { if (lt_count == 0) { lt_foo="/" $lt_i lt_foo; } else { lt_count--; } } } } if (lt_foo != "") { lt_freq[lt_foo]++; } if (lt_freq[lt_foo] == 1) { print lt_foo; } }'` # AWK program above erroneously prepends '/' to C:/dos/paths # for these hosts. case $host_os in mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ $SED 's,/\([A-Za-z]:\),\1,g'` ;; esac sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` else sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib" fi library_names_spec= libname_spec='lib$name' soname_spec= shrext_cmds=".so" postinstall_cmds= postuninstall_cmds= finish_cmds= finish_eval= shlibpath_var= shlibpath_overrides_runpath=unknown version_type=none dynamic_linker="$host_os ld.so" sys_lib_dlsearch_path_spec="/lib /usr/lib" need_lib_prefix=unknown hardcode_into_libs=no # when you set need_version to no, make sure it does not cause -set_version # flags to be left without arguments need_version=unknown case $host_os in aix3*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a' shlibpath_var=LIBPATH # AIX 3 has no versioning support, so we append a major version to the name. soname_spec='${libname}${release}${shared_ext}$major' ;; aix[4-9]*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no hardcode_into_libs=yes if test "$host_cpu" = ia64; then # AIX 5 supports IA64 library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH else # With GCC up to 2.95.x, collect2 would create an import file # for dependence libraries. The import file would start with # the line `#! .'. This would cause the generated library to # depend on `.', always an invalid library. This was fixed in # development snapshots of GCC prior to 3.0. case $host_os in aix4 | aix4.[01] | aix4.[01].*) if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)' echo ' yes ' echo '#endif'; } | ${CC} -E - | $GREP yes > /dev/null; then : else can_build_shared=no fi ;; esac # AIX (on Power*) has no versioning support, so currently we can not hardcode correct # soname into executable. Probably we can add versioning support to # collect2, so additional links can be useful in future. if test "$aix_use_runtimelinking" = yes; then # If using run time linking (on AIX 4.2 or later) use lib.so # instead of lib.a to let people know that these are not # typical AIX shared libraries. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' else # We preserve .a as extension for shared libraries through AIX4.2 # and later when we are not doing run time linking. library_names_spec='${libname}${release}.a $libname.a' soname_spec='${libname}${release}${shared_ext}$major' fi shlibpath_var=LIBPATH fi ;; amigaos*) case $host_cpu in powerpc) # Since July 2007 AmigaOS4 officially supports .so libraries. # When compiling the executable, add -use-dynld -Lsobjs: to the compileline. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' ;; m68k) library_names_spec='$libname.ixlibrary $libname.a' # Create ${libname}_ixlibrary.a entries in /sys/libs. finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`func_echo_all "$lib" | $SED '\''s%^.*/\([^/]*\)\.ixlibrary$%\1%'\''`; test $RM /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done' ;; esac ;; beos*) library_names_spec='${libname}${shared_ext}' dynamic_linker="$host_os ld.so" shlibpath_var=LIBRARY_PATH ;; bsdi[45]*) version_type=linux # correct to gnu/linux during the next big refactor need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib" sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib" # the default ld.so.conf also contains /usr/contrib/lib and # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow # libtool to hard-code these into programs ;; cygwin* | mingw* | pw32* | cegcc*) version_type=windows shrext_cmds=".dll" need_version=no need_lib_prefix=no case $GCC,$cc_basename in yes,*) # gcc library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds postinstall_cmds='base_file=`basename \${file}`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname~ chmod a+x \$dldir/$dlname~ if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" ;; mingw* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' ;; esac dynamic_linker='Win32 ld.exe' ;; *,cl*) # Native MSVC libname_spec='$name' soname_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext}' library_names_spec='${libname}.dll.lib' case $build_os in mingw*) sys_lib_search_path_spec= lt_save_ifs=$IFS IFS=';' for lt_path in $LIB do IFS=$lt_save_ifs # Let DOS variable expansion print the short 8.3 style file name. lt_path=`cd "$lt_path" 2>/dev/null && cmd //C "for %i in (".") do @echo %~si"` sys_lib_search_path_spec="$sys_lib_search_path_spec $lt_path" done IFS=$lt_save_ifs # Convert to MSYS style. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` ;; cygwin*) # Convert to unix form, then to dos form, then back to unix form # but this time dos style (no spaces!) so that the unix form looks # like /cygdrive/c/PROGRA~1:/cygdr... sys_lib_search_path_spec=`cygpath --path --unix "$LIB"` sys_lib_search_path_spec=`cygpath --path --dos "$sys_lib_search_path_spec" 2>/dev/null` sys_lib_search_path_spec=`cygpath --path --unix "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` ;; *) sys_lib_search_path_spec="$LIB" if $ECHO "$sys_lib_search_path_spec" | $GREP ';[c-zC-Z]:/' >/dev/null; then # It is most probably a Windows format PATH. sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'` else sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e "s/$PATH_SEPARATOR/ /g"` fi # FIXME: find the short name or the path components, as spaces are # common. (e.g. "Program Files" -> "PROGRA~1") ;; esac # DLL is installed to $(libdir)/../bin by postinstall_cmds postinstall_cmds='base_file=`basename \${file}`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ test -d \$dldir || mkdir -p \$dldir~ $install_prog $dir/$dlname \$dldir/$dlname' postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' shlibpath_overrides_runpath=yes dynamic_linker='Win32 link.exe' ;; *) # Assume MSVC wrapper library_names_spec='${libname}`echo ${release} | $SED -e 's/[.]/-/g'`${versuffix}${shared_ext} $libname.lib' dynamic_linker='Win32 ld.exe' ;; esac # FIXME: first we should search . and the directory the executable is in shlibpath_var=PATH ;; darwin* | rhapsody*) dynamic_linker="$host_os dyld" version_type=darwin need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${major}$shared_ext ${libname}$shared_ext' soname_spec='${libname}${release}${major}$shared_ext' shlibpath_overrides_runpath=yes shlibpath_var=DYLD_LIBRARY_PATH shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`' sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib" sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib' ;; dgux*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; freebsd* | dragonfly*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then objformat=`/usr/bin/objformat` else case $host_os in freebsd[23].*) objformat=aout ;; *) objformat=elf ;; esac fi version_type=freebsd-$objformat case $version_type in freebsd-elf*) library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' need_version=no need_lib_prefix=no ;; freebsd-*) library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix' need_version=yes ;; esac shlibpath_var=LD_LIBRARY_PATH case $host_os in freebsd2.*) shlibpath_overrides_runpath=yes ;; freebsd3.[01]* | freebsdelf3.[01]*) shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; freebsd3.[2-9]* | freebsdelf3.[2-9]* | \ freebsd4.[0-5] | freebsdelf4.[0-5] | freebsd4.1.1 | freebsdelf4.1.1) shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; *) # from 4.6 on, and DragonFly shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; esac ;; gnu*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; haiku*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no dynamic_linker="$host_os runtime_loader" library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LIBRARY_PATH shlibpath_overrides_runpath=yes sys_lib_dlsearch_path_spec='/boot/home/config/lib /boot/common/lib /boot/system/lib' hardcode_into_libs=yes ;; hpux9* | hpux10* | hpux11*) # Give a soname corresponding to the major version so that dld.sl refuses to # link against other versions. version_type=sunos need_lib_prefix=no need_version=no case $host_cpu in ia64*) shrext_cmds='.so' hardcode_into_libs=yes dynamic_linker="$host_os dld.so" shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' if test "X$HPUX_IA64_MODE" = X32; then sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib" else sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64" fi sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; hppa*64*) shrext_cmds='.sl' hardcode_into_libs=yes dynamic_linker="$host_os dld.sl" shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH shlibpath_overrides_runpath=yes # Unless +noenvvar is specified. library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64" sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec ;; *) shrext_cmds='.sl' dynamic_linker="$host_os dld.sl" shlibpath_var=SHLIB_PATH shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' ;; esac # HP-UX runs *really* slowly unless shared libraries are mode 555, ... postinstall_cmds='chmod 555 $lib' # or fails outright, so override atomically: install_override_mode=555 ;; interix[3-9]*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; irix5* | irix6* | nonstopux*) case $host_os in nonstopux*) version_type=nonstopux ;; *) if test "$lt_cv_prog_gnu_ld" = yes; then version_type=linux # correct to gnu/linux during the next big refactor else version_type=irix fi ;; esac need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}' case $host_os in irix5* | nonstopux*) libsuff= shlibsuff= ;; *) case $LD in # libtool.m4 will add one of these switches to LD *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= libmagic=32-bit;; *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 libmagic=N32;; *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 libmagic=64-bit;; *) libsuff= shlibsuff= libmagic=never-match;; esac ;; esac shlibpath_var=LD_LIBRARY${shlibsuff}_PATH shlibpath_overrides_runpath=no sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}" sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}" hardcode_into_libs=yes ;; # No shared lib support for Linux oldld, aout, or coff. linux*oldld* | linux*aout* | linux*coff*) dynamic_linker=no ;; # This must be glibc/ELF. linux* | k*bsd*-gnu | kopensolaris*-gnu) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH if test ${lt_cv_shlibpath_overrides_runpath+y} then : printf %s "(cached) " >&6 else case e in #( e) lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir eval "libdir=/foo; wl=\"$lt_prog_compiler_wl\"; \ LDFLAGS=\"\$LDFLAGS $hardcode_libdir_flag_spec\"" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null then : lt_cv_shlibpath_overrides_runpath=yes fi fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir ;; esac fi shlibpath_overrides_runpath=$lt_cv_shlibpath_overrides_runpath # This implies no fast_install, which is unacceptable. # Some rework will be needed to allow for fast_install # before this can be enabled. hardcode_into_libs=yes # Append ld.so.conf contents to the search path if test -f /etc/ld.so.conf; then lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \$2)); skip = 1; } { if (!skip) print \$0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ ]*hwcap[ ]/d;s/[:, ]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;s/"//g;/^$/d' | tr '\n' ' '` sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra" fi # We used to test for /lib/ld.so.1 and disable shared libraries on # powerpc, because MkLinux only supported shared libraries with the # GNU dynamic linker. Since this was broken with cross compilers, # most powerpc-linux boxes support dynamic linking these days and # people can always --disable-shared, the test was removed, and we # assume the GNU/Linux dynamic linker is in use. dynamic_linker='GNU/Linux ld.so' ;; netbsd*) version_type=sunos need_lib_prefix=no need_version=no if echo __ELF__ | $CC -E - | $GREP __ELF__ >/dev/null; then library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' dynamic_linker='NetBSD (a.out) ld.so' else library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' dynamic_linker='NetBSD ld.elf_so' fi shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes ;; newsos6) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes ;; *nto* | *qnx*) version_type=qnx need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes dynamic_linker='ldqnx.so' ;; openbsd*) version_type=sunos sys_lib_dlsearch_path_spec="/usr/lib" need_lib_prefix=no # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs. case $host_os in openbsd3.3 | openbsd3.3.*) need_version=yes ;; *) need_version=no ;; esac library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir' shlibpath_var=LD_LIBRARY_PATH if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then case $host_os in openbsd2.[89] | openbsd2.[89].*) shlibpath_overrides_runpath=no ;; *) shlibpath_overrides_runpath=yes ;; esac else shlibpath_overrides_runpath=yes fi ;; os2*) libname_spec='$name' shrext_cmds=".dll" need_lib_prefix=no library_names_spec='$libname${shared_ext} $libname.a' dynamic_linker='OS/2 ld.exe' shlibpath_var=LIBPATH ;; osf3* | osf4* | osf5*) version_type=osf need_lib_prefix=no need_version=no soname_spec='${libname}${release}${shared_ext}$major' library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib" sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec" ;; rdos*) dynamic_linker=no ;; solaris*) version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes # ldd complains unless libraries are executable postinstall_cmds='chmod +x $lib' ;; sunos4*) version_type=sunos library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix' finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes if test "$with_gnu_ld" = yes; then need_lib_prefix=no fi need_version=yes ;; sysv4 | sysv4.3*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH case $host_vendor in sni) shlibpath_overrides_runpath=no need_lib_prefix=no runpath_var=LD_RUN_PATH ;; siemens) need_lib_prefix=no ;; motorola) need_lib_prefix=no need_version=no shlibpath_overrides_runpath=no sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib' ;; esac ;; sysv4*MP*) if test -d /usr/nec ;then version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}' soname_spec='$libname${shared_ext}.$major' shlibpath_var=LD_LIBRARY_PATH fi ;; sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) version_type=freebsd-elf need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=yes hardcode_into_libs=yes if test "$with_gnu_ld" = yes; then sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib' else sys_lib_search_path_spec='/usr/ccs/lib /usr/lib' case $host_os in sco3.2v5*) sys_lib_search_path_spec="$sys_lib_search_path_spec /lib" ;; esac fi sys_lib_dlsearch_path_spec='/usr/lib' ;; tpf*) # TPF is a cross-target only. Preferred cross-host = GNU/Linux. version_type=linux # correct to gnu/linux during the next big refactor need_lib_prefix=no need_version=no library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' shlibpath_var=LD_LIBRARY_PATH shlibpath_overrides_runpath=no hardcode_into_libs=yes ;; uts4*) version_type=linux # correct to gnu/linux during the next big refactor library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}' soname_spec='${libname}${release}${shared_ext}$major' shlibpath_var=LD_LIBRARY_PATH ;; *) dynamic_linker=no ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 printf "%s\n" "$dynamic_linker" >&6; } test "$dynamic_linker" = no && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" if test "$GCC" = yes; then variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH" fi if test "${lt_cv_sys_lib_search_path_spec+set}" = set; then sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec" fi if test "${lt_cv_sys_lib_dlsearch_path_spec+set}" = set; then sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 printf %s "checking how to hardcode library paths into programs... " >&6; } hardcode_action= if test -n "$hardcode_libdir_flag_spec" || test -n "$runpath_var" || test "X$hardcode_automatic" = "Xyes" ; then # We can hardcode non-existent directories. if test "$hardcode_direct" != no && # If the only mechanism to avoid hardcoding is shlibpath_var, we # have to relink, otherwise we might link with an installed library # when we should be linking with a yet-to-be-installed one ## test "$_LT_TAGVAR(hardcode_shlibpath_var, )" != no && test "$hardcode_minus_L" != no; then # Linking always hardcodes the temporary library directory. hardcode_action=relink else # We can link without hardcoding, and we can hardcode nonexisting dirs. hardcode_action=immediate fi else # We cannot hardcode anything, or else we can only hardcode existing # directories. hardcode_action=unsupported fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 printf "%s\n" "$hardcode_action" >&6; } if test "$hardcode_action" = relink || test "$inherit_rpath" = yes; then # Fast installation is not supported enable_fast_install=no elif test "$shlibpath_overrides_runpath" = yes || test "$enable_shared" = no; then # Fast installation is not necessary enable_fast_install=needless fi if test "x$enable_dlopen" != xyes; then enable_dlopen=unknown enable_dlopen_self=unknown enable_dlopen_self_static=unknown else lt_cv_dlopen=no lt_cv_dlopen_libs= case $host_os in beos*) lt_cv_dlopen="load_add_on" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ;; mingw* | pw32* | cegcc*) lt_cv_dlopen="LoadLibrary" lt_cv_dlopen_libs= ;; cygwin*) lt_cv_dlopen="dlopen" lt_cv_dlopen_libs= ;; darwin*) # if libdl is installed we need to link against it { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 printf %s "checking for dlopen in -ldl... " >&6; } if test ${ac_cv_lib_dl_dlopen+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char dlopen (void); int main (void) { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_dl_dlopen=yes else case e in #( e) ac_cv_lib_dl_dlopen=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; } if test "x$ac_cv_lib_dl_dlopen" = xyes then : lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" else case e in #( e) lt_cv_dlopen="dyld" lt_cv_dlopen_libs= lt_cv_dlopen_self=yes ;; esac fi ;; *) ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" if test "x$ac_cv_func_shl_load" = xyes then : lt_cv_dlopen="shl_load" else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 printf %s "checking for shl_load in -ldld... " >&6; } if test ${ac_cv_lib_dld_shl_load+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char shl_load (void); int main (void) { return shl_load (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_dld_shl_load=yes else case e in #( e) ac_cv_lib_dld_shl_load=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; } if test "x$ac_cv_lib_dld_shl_load" = xyes then : lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld" else case e in #( e) ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" if test "x$ac_cv_func_dlopen" = xyes then : lt_cv_dlopen="dlopen" else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 printf %s "checking for dlopen in -ldl... " >&6; } if test ${ac_cv_lib_dl_dlopen+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char dlopen (void); int main (void) { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_dl_dlopen=yes else case e in #( e) ac_cv_lib_dl_dlopen=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; } if test "x$ac_cv_lib_dl_dlopen" = xyes then : lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl" else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 printf %s "checking for dlopen in -lsvld... " >&6; } if test ${ac_cv_lib_svld_dlopen+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS LIBS="-lsvld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char dlopen (void); int main (void) { return dlopen (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_svld_dlopen=yes else case e in #( e) ac_cv_lib_svld_dlopen=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 printf "%s\n" "$ac_cv_lib_svld_dlopen" >&6; } if test "x$ac_cv_lib_svld_dlopen" = xyes then : lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld" else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 printf %s "checking for dld_link in -ldld... " >&6; } if test ${ac_cv_lib_dld_dld_link+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char dld_link (void); int main (void) { return dld_link (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_dld_dld_link=yes else case e in #( e) ac_cv_lib_dld_dld_link=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 printf "%s\n" "$ac_cv_lib_dld_dld_link" >&6; } if test "x$ac_cv_lib_dld_dld_link" = xyes then : lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld" fi ;; esac fi ;; esac fi ;; esac fi ;; esac fi ;; esac fi ;; esac if test "x$lt_cv_dlopen" != xno; then enable_dlopen=yes else enable_dlopen=no fi case $lt_cv_dlopen in dlopen) save_CPPFLAGS="$CPPFLAGS" test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H" save_LDFLAGS="$LDFLAGS" wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\" save_LIBS="$LIBS" LIBS="$lt_cv_dlopen_libs $LIBS" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 printf %s "checking whether a program can dlopen itself... " >&6; } if test ${lt_cv_dlopen_self+y} then : printf %s "(cached) " >&6 else case e in #( e) if test "$cross_compiling" = yes; then : lt_cv_dlopen_self=cross else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF #line $LINENO "configure" #include "confdefs.h" #if HAVE_DLFCN_H #include #endif #include #ifdef RTLD_GLOBAL # define LT_DLGLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL # define LT_DLGLOBAL DL_GLOBAL # else # define LT_DLGLOBAL 0 # endif #endif /* We may have to define LT_DLLAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_DLLAZY_OR_NOW # ifdef RTLD_LAZY # define LT_DLLAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY # define LT_DLLAZY_OR_NOW DL_LAZY # else # ifdef RTLD_NOW # define LT_DLLAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW # define LT_DLLAZY_OR_NOW DL_NOW # else # define LT_DLLAZY_OR_NOW 0 # endif # endif # endif # endif #endif /* When -fvisbility=hidden is used, assume the code has been annotated correspondingly for the symbols needed. */ #if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) int fnord () __attribute__((visibility("default"))); #endif int fnord () { return 42; } int main () { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; if (self) { if (dlsym (self,"fnord")) status = $lt_dlno_uscore; else { if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; else puts (dlerror ()); } /* dlclose (self); */ } else puts (dlerror ()); return status; } _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? case x$lt_status in x$lt_dlno_uscore) lt_cv_dlopen_self=yes ;; x$lt_dlneed_uscore) lt_cv_dlopen_self=yes ;; x$lt_dlunknown|x*) lt_cv_dlopen_self=no ;; esac else : # compilation failed lt_cv_dlopen_self=no fi fi rm -fr conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 printf "%s\n" "$lt_cv_dlopen_self" >&6; } if test "x$lt_cv_dlopen_self" = xyes; then wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 printf %s "checking whether a statically linked program can dlopen itself... " >&6; } if test ${lt_cv_dlopen_self_static+y} then : printf %s "(cached) " >&6 else case e in #( e) if test "$cross_compiling" = yes; then : lt_cv_dlopen_self_static=cross else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF #line $LINENO "configure" #include "confdefs.h" #if HAVE_DLFCN_H #include #endif #include #ifdef RTLD_GLOBAL # define LT_DLGLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL # define LT_DLGLOBAL DL_GLOBAL # else # define LT_DLGLOBAL 0 # endif #endif /* We may have to define LT_DLLAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_DLLAZY_OR_NOW # ifdef RTLD_LAZY # define LT_DLLAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY # define LT_DLLAZY_OR_NOW DL_LAZY # else # ifdef RTLD_NOW # define LT_DLLAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW # define LT_DLLAZY_OR_NOW DL_NOW # else # define LT_DLLAZY_OR_NOW 0 # endif # endif # endif # endif #endif /* When -fvisbility=hidden is used, assume the code has been annotated correspondingly for the symbols needed. */ #if defined(__GNUC__) && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) int fnord () __attribute__((visibility("default"))); #endif int fnord () { return 42; } int main () { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; if (self) { if (dlsym (self,"fnord")) status = $lt_dlno_uscore; else { if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore; else puts (dlerror ()); } /* dlclose (self); */ } else puts (dlerror ()); return status; } _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest${ac_exeext} 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? case x$lt_status in x$lt_dlno_uscore) lt_cv_dlopen_self_static=yes ;; x$lt_dlneed_uscore) lt_cv_dlopen_self_static=yes ;; x$lt_dlunknown|x*) lt_cv_dlopen_self_static=no ;; esac else : # compilation failed lt_cv_dlopen_self_static=no fi fi rm -fr conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 printf "%s\n" "$lt_cv_dlopen_self_static" >&6; } fi CPPFLAGS="$save_CPPFLAGS" LDFLAGS="$save_LDFLAGS" LIBS="$save_LIBS" ;; esac case $lt_cv_dlopen_self in yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;; *) enable_dlopen_self=unknown ;; esac case $lt_cv_dlopen_self_static in yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;; *) enable_dlopen_self_static=unknown ;; esac fi striplib= old_striplib= { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 printf %s "checking whether stripping libraries is possible... " >&6; } if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" test -z "$striplib" && striplib="$STRIP --strip-unneeded" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else # FIXME - insert some real tests, host_os isn't really good enough case $host_os in darwin*) if test -n "$STRIP" ; then striplib="$STRIP -x" old_striplib="$STRIP -S" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi ;; *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } ;; esac fi # Report which library types will actually be built { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 printf %s "checking if libtool supports shared libraries... " >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 printf "%s\n" "$can_build_shared" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 printf %s "checking whether to build shared libraries... " >&6; } test "$can_build_shared" = "no" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and # are all built from PIC. case $host_os in aix3*) test "$enable_shared" = yes && enable_static=no if test -n "$RANLIB"; then archive_cmds="$archive_cmds~\$RANLIB \$lib" postinstall_cmds='$RANLIB $lib' fi ;; aix[4-9]*) if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then test "$enable_shared" = yes && enable_static=no fi ;; esac { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 printf "%s\n" "$enable_shared" >&6; } { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 printf %s "checking whether to build static libraries... " >&6; } # Make sure either enable_shared or enable_static is yes. test "$enable_shared" = yes || enable_static=yes { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 printf "%s\n" "$enable_static" >&6; } fi ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu CC="$lt_save_CC" ac_config_commands="$ac_config_commands libtool" # Only expand once: for ac_prog in 'bison -y' byacc do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 printf %s "checking for $ac_word... " >&6; } if test ${ac_cv_prog_YACC+y} then : printf %s "(cached) " >&6 else case e in #( e) if test -n "$YACC"; then ac_cv_prog_YACC="$YACC" # Let the user override the test. else as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac for ac_exec_ext in '' $ac_executable_extensions; do if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_YACC="$ac_prog" printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done done IFS=$as_save_IFS fi ;; esac fi YACC=$ac_cv_prog_YACC if test -n "$YACC"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $YACC" >&5 printf "%s\n" "$YACC" >&6; } else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } fi test -n "$YACC" && break done test -n "$YACC" || YACC="yacc" # Check whether --enable-bgplgd was given. if test ${enable_bgplgd+y} then : enableval=$enable_bgplgd; case $enableval in yes) enable_bgplgd=yes;; no) enable_bgplgd=no;; *) enable_bgplgd=yes;; esac else case e in #( e) enable_bgplgd=yes ;; esac fi # Check whether --enable-fib-support was given. if test ${enable_fib_support+y} then : enableval=$enable_fib_support; case $enableval in yes) disable_fib=no;; no) disable_fib=yes;; *) disable_fib=no;; esac else case e in #( e) disable_fib=no ;; esac fi # Check whether --enable-warnings was given. if test ${enable_warnings+y} then : enableval=$enable_warnings; case $enableval in yes) enable_warnings=yes;; no) enable_warnings=no;; *) enable_warnings=yes;; esac else case e in #( e) enable_warnings=yes ;; esac fi if test "$enable_warnings" = yes; then AM_CFLAGS="$AM_CFLAGS -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare" save_cflags="$CFLAGS" CFLAGS=-Wno-pointer-sign { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether CC supports -Wno-pointer-sign" >&5 printf %s "checking whether CC supports -Wno-pointer-sign... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } WARN_CFLAGS=-Wno-pointer-sign else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext AM_CFLAGS="$AM_CFLAGS $WARN_CFLAGS" CFLAGS="$save_cflags" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if compiling with clang" >&5 printf %s "checking if compiling with clang... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int main (void) { #ifndef __clang__ not clang #endif ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } CLANG_FLAGS=-Qunused-arguments else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext AM_CFLAGS="$AM_CFLAGS $CLANG_FLAGS" AM_LDFLAGS="$AM_LDFLAGS $CLANG_FLAGS" # check for headers ac_fn_c_check_header_compile "$LINENO" "endian.h" "ac_cv_header_endian_h" "$ac_includes_default" if test "x$ac_cv_header_endian_h" = xyes then : printf "%s\n" "#define HAVE_ENDIAN_H 1" >>confdefs.h fi ac_fn_c_check_header_compile "$LINENO" "netinet/ip_ipsp.h" "ac_cv_header_netinet_ip_ipsp_h" "#include " if test "x$ac_cv_header_netinet_ip_ipsp_h" = xyes then : printf "%s\n" "#define HAVE_NETINET_IP_IPSP_H 1" >>confdefs.h fi ac_fn_c_check_header_compile "$LINENO" "linux/in6.h" "ac_cv_header_linux_in6_h" "$ac_includes_default" if test "x$ac_cv_header_linux_in6_h" = xyes then : printf "%s\n" "#define HAVE_LINUX_IN6_H 1" >>confdefs.h fi ac_fn_c_check_header_compile "$LINENO" "linux/if.h" "ac_cv_header_linux_if_h" "$ac_includes_default" if test "x$ac_cv_header_linux_if_h" = xyes then : printf "%s\n" "#define HAVE_LINUX_IF_H 1" >>confdefs.h fi # check functions that are expected to be in libc ac_fn_c_check_func "$LINENO" "asprintf" "ac_cv_func_asprintf" if test "x$ac_cv_func_asprintf" = xyes then : printf "%s\n" "#define HAVE_ASPRINTF 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "explicit_bzero" "ac_cv_func_explicit_bzero" if test "x$ac_cv_func_explicit_bzero" = xyes then : printf "%s\n" "#define HAVE_EXPLICIT_BZERO 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "reallocarray" "ac_cv_func_reallocarray" if test "x$ac_cv_func_reallocarray" = xyes then : printf "%s\n" "#define HAVE_REALLOCARRAY 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "recallocarray" "ac_cv_func_recallocarray" if test "x$ac_cv_func_recallocarray" = xyes then : printf "%s\n" "#define HAVE_RECALLOCARRAY 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "freezero" "ac_cv_func_freezero" if test "x$ac_cv_func_freezero" = xyes then : printf "%s\n" "#define HAVE_FREEZERO 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "setproctitle" "ac_cv_func_setproctitle" if test "x$ac_cv_func_setproctitle" = xyes then : printf "%s\n" "#define HAVE_SETPROCTITLE 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "setgroups" "ac_cv_func_setgroups" if test "x$ac_cv_func_setgroups" = xyes then : printf "%s\n" "#define HAVE_SETGROUPS 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "setregid" "ac_cv_func_setregid" if test "x$ac_cv_func_setregid" = xyes then : printf "%s\n" "#define HAVE_SETREGID 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "setresgid" "ac_cv_func_setresgid" if test "x$ac_cv_func_setresgid" = xyes then : printf "%s\n" "#define HAVE_SETRESGID 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "setreuid" "ac_cv_func_setreuid" if test "x$ac_cv_func_setreuid" = xyes then : printf "%s\n" "#define HAVE_SETREUID 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "setresuid" "ac_cv_func_setresuid" if test "x$ac_cv_func_setresuid" = xyes then : printf "%s\n" "#define HAVE_SETRESUID 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat" if test "x$ac_cv_func_strlcat" = xyes then : printf "%s\n" "#define HAVE_STRLCAT 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy" if test "x$ac_cv_func_strlcpy" = xyes then : printf "%s\n" "#define HAVE_STRLCPY 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "strtonum" "ac_cv_func_strtonum" if test "x$ac_cv_func_strtonum" = xyes then : printf "%s\n" "#define HAVE_STRTONUM 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "sysconf" "ac_cv_func_sysconf" if test "x$ac_cv_func_sysconf" = xyes then : printf "%s\n" "#define HAVE_SYSCONF 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "pledge" "ac_cv_func_pledge" if test "x$ac_cv_func_pledge" = xyes then : printf "%s\n" "#define HAVE_PLEDGE 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "unveil" "ac_cv_func_unveil" if test "x$ac_cv_func_unveil" = xyes then : printf "%s\n" "#define HAVE_UNVEIL 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "getdtablecount" "ac_cv_func_getdtablecount" if test "x$ac_cv_func_getdtablecount" = xyes then : printf "%s\n" "#define HAVE_GETDTABLECOUNT 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "getrtable" "ac_cv_func_getrtable" if test "x$ac_cv_func_getrtable" = xyes then : printf "%s\n" "#define HAVE_GETRTABLE 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "strnvis" "ac_cv_func_strnvis" if test "x$ac_cv_func_strnvis" = xyes then : printf "%s\n" "#define HAVE_STRNVIS 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "arc4random" "ac_cv_func_arc4random" if test "x$ac_cv_func_arc4random" = xyes then : printf "%s\n" "#define HAVE_ARC4RANDOM 1" >>confdefs.h fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for getentropy" >&5 printf %s "checking for getentropy... " >&6; } if test ${ac_cv_func_getentropy+y} then : printf %s "(cached) " >&6 else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include /* * Explanation: * * - iOS <= 10.1 fails because of missing sys/random.h * * - in macOS 10.12 getentropy is not tagged as introduced in * 10.12 so we cannot use it for target < 10.12 */ #ifdef __APPLE__ # include # include # if (TARGET_OS_IPHONE || TARGET_OS_SIMULATOR) # include /* Not available as of iOS <= 10.1 */ # else # include /* Pre 10.12 systems should die here */ /* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */ # ifndef MAC_OS_X_VERSION_10_12 # define MAC_OS_X_VERSION_10_12 101200 /* Robustness */ # endif # if defined(MAC_OS_X_VERSION_MIN_REQUIRED) # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 # error "Targeting on Mac OSX 10.11 or earlier" # endif # endif # endif #endif /* __APPLE__ */ int main (void) { char buffer; (void)getentropy(&buffer, sizeof (buffer)); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_func_getentropy="yes" else case e in #( e) ac_cv_func_getentropy="no" ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getentropy" >&5 printf "%s\n" "$ac_cv_func_getentropy" >&6; } # check auxiliary libraries that might contain other functions { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing clock_gettime" >&5 printf %s "checking for library containing clock_gettime... " >&6; } if test ${ac_cv_search_clock_gettime+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char clock_gettime (void); int main (void) { return clock_gettime (); ; return 0; } _ACEOF for ac_lib in '' rt posix4 do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi if ac_fn_c_try_link "$LINENO" then : ac_cv_search_clock_gettime=$ac_res fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext if test ${ac_cv_search_clock_gettime+y} then : break fi done if test ${ac_cv_search_clock_gettime+y} then : else case e in #( e) ac_cv_search_clock_gettime=no ;; esac fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_clock_gettime" >&5 printf "%s\n" "$ac_cv_search_clock_gettime" >&6; } ac_res=$ac_cv_search_clock_gettime if test "$ac_res" != no then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing inet_net_pton" >&5 printf %s "checking for library containing inet_net_pton... " >&6; } if test ${ac_cv_search_inet_net_pton+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char inet_net_pton (void); int main (void) { return inet_net_pton (); ; return 0; } _ACEOF for ac_lib in '' resolv do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi if ac_fn_c_try_link "$LINENO" then : ac_cv_search_inet_net_pton=$ac_res fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext if test ${ac_cv_search_inet_net_pton+y} then : break fi done if test ${ac_cv_search_inet_net_pton+y} then : else case e in #( e) ac_cv_search_inet_net_pton=no ;; esac fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_inet_net_pton" >&5 printf "%s\n" "$ac_cv_search_inet_net_pton" >&6; } ac_res=$ac_cv_search_inet_net_pton if test "$ac_res" != no then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi ac_fn_c_check_func "$LINENO" "clock_gettime" "ac_cv_func_clock_gettime" if test "x$ac_cv_func_clock_gettime" = xyes then : printf "%s\n" "#define HAVE_CLOCK_GETTIME 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "inet_net_pton" "ac_cv_func_inet_net_pton" if test "x$ac_cv_func_inet_net_pton" = xyes then : printf "%s\n" "#define HAVE_INET_NET_PTON 1" >>confdefs.h fi # check needed libutil functions { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing ibuf_open" >&5 printf %s "checking for library containing ibuf_open... " >&6; } if test ${ac_cv_search_ibuf_open+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char ibuf_open (void); int main (void) { return ibuf_open (); ; return 0; } _ACEOF for ac_lib in '' util do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi if ac_fn_c_try_link "$LINENO" then : ac_cv_search_ibuf_open=$ac_res fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext if test ${ac_cv_search_ibuf_open+y} then : break fi done if test ${ac_cv_search_ibuf_open+y} then : else case e in #( e) ac_cv_search_ibuf_open=no ;; esac fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ibuf_open" >&5 printf "%s\n" "$ac_cv_search_ibuf_open" >&6; } ac_res=$ac_cv_search_ibuf_open if test "$ac_res" != no then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for library containing fmt_scaled" >&5 printf %s "checking for library containing fmt_scaled... " >&6; } if test ${ac_cv_search_fmt_scaled+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_func_search_save_LIBS=$LIBS cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char fmt_scaled (void); int main (void) { return fmt_scaled (); ; return 0; } _ACEOF for ac_lib in '' util do if test -z "$ac_lib"; then ac_res="none required" else ac_res=-l$ac_lib LIBS="-l$ac_lib $ac_func_search_save_LIBS" fi if ac_fn_c_try_link "$LINENO" then : ac_cv_search_fmt_scaled=$ac_res fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext if test ${ac_cv_search_fmt_scaled+y} then : break fi done if test ${ac_cv_search_fmt_scaled+y} then : else case e in #( e) ac_cv_search_fmt_scaled=no ;; esac fi rm conftest.$ac_ext LIBS=$ac_func_search_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_fmt_scaled" >&5 printf "%s\n" "$ac_cv_search_fmt_scaled" >&6; } ac_res=$ac_cv_search_fmt_scaled if test "$ac_res" != no then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" fi ac_fn_c_check_func "$LINENO" "ibuf_open" "ac_cv_func_ibuf_open" if test "x$ac_cv_func_ibuf_open" = xyes then : printf "%s\n" "#define HAVE_IBUF_OPEN 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "imsgbuf_init" "ac_cv_func_imsgbuf_init" if test "x$ac_cv_func_imsgbuf_init" = xyes then : printf "%s\n" "#define HAVE_IMSGBUF_INIT 1" >>confdefs.h fi ac_fn_c_check_func "$LINENO" "fmt_scaled" "ac_cv_func_fmt_scaled" if test "x$ac_cv_func_fmt_scaled" = xyes then : printf "%s\n" "#define HAVE_FMT_SCALED 1" >>confdefs.h fi # check if HOST_NAME_MAX is available { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for HOST_NAME_MAX" >&5 printf %s "checking for HOST_NAME_MAX... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include int main (void) { char buf[HOST_NAME_MAX + 1]; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } printf "%s\n" "#define HAVE_HOST_NAME_MAX 1" >>confdefs.h else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext # check if pftable code can be used for ac_header in net/pfvar.h do : ac_fn_c_check_header_compile "$LINENO" "net/pfvar.h" "ac_cv_header_net_pfvar_h" " #include #include " if test "x$ac_cv_header_net_pfvar_h" = xyes then : printf "%s\n" "#define HAVE_NET_PFVAR_H 1" >>confdefs.h { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working pftable" >&5 printf %s "checking for working pftable... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include int main (void) { struct pfioc_table tio; struct pfr_astats dummy; struct pfr_addr pfa; int a = DIOCRCLRADDRS, b = DIOCRGETASTATS, c = DIOCRDELADDRS, d = DIOCRADDADDRS; ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } ac_cv_have_pftable="yes" else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi done if test "x$ac_cv_func_strnvis" = "xyes"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working strnvis" >&5 printf %s "checking for working strnvis... " >&6; } if test "$cross_compiling" = yes then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cross compiling: assuming broken" >&5 printf "%s\n" "$as_me: WARNING: cross compiling: assuming broken" >&2;} ac_cv_broken_strnvis="yes" else case e in #( e) cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include #include #include #include static void sighandler(int sig) { _exit(1); } int main (void) { char dst[16]; signal(SIGSEGV, sighandler); if (strnvis(dst, "src", 4, 0) && strcmp(dst, "src") == 0) exit(0); exit(1) ; return 0; } _ACEOF if ac_fn_c_try_run "$LINENO" then : { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 printf "%s\n" "yes" >&6; } else case e in #( e) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 printf "%s\n" "no" >&6; } ac_cv_broken_strnvis="yes" ;; esac fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ conftest.$ac_objext conftest.beam conftest.$ac_ext ;; esac fi fi if test "$disable_fib" = no; then # check for libmnl { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for mnl_socket_recvfrom in -lmnl" >&5 printf %s "checking for mnl_socket_recvfrom in -lmnl... " >&6; } if test ${ac_cv_lib_mnl_mnl_socket_recvfrom+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS LIBS="-lmnl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char mnl_socket_recvfrom (void); int main (void) { return mnl_socket_recvfrom (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_mnl_mnl_socket_recvfrom=yes else case e in #( e) ac_cv_lib_mnl_mnl_socket_recvfrom=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mnl_mnl_socket_recvfrom" >&5 printf "%s\n" "$ac_cv_lib_mnl_mnl_socket_recvfrom" >&6; } if test "x$ac_cv_lib_mnl_mnl_socket_recvfrom" = xyes then : printf "%s\n" "#define HAVE_LIBMNL 1" >>confdefs.h LIBS="-lmnl $LIBS" fi if test "x$ac_cv_lib_mnl_mnl_socket_recvfrom" = "xyes"; then for ac_func in mnl_socket_open2 do : ac_fn_c_check_func "$LINENO" "mnl_socket_open2" "ac_cv_func_mnl_socket_open2" if test "x$ac_cv_func_mnl_socket_open2" = xyes then : printf "%s\n" "#define HAVE_MNL_SOCKET_OPEN2 1" >>confdefs.h else case e in #( e) as_fn_error $? "libmnl >= 1.0.4 required" "$LINENO" 5 ;; esac fi done fi fi # Share test results with automake if test "x$ac_cv_func_asprintf" = xyes; then HAVE_ASPRINTF_TRUE= HAVE_ASPRINTF_FALSE='#' else HAVE_ASPRINTF_TRUE='#' HAVE_ASPRINTF_FALSE= fi if test "x$ac_cv_func_closefrom" = xyes; then HAVE_CLOSEFROM_TRUE= HAVE_CLOSEFROM_FALSE='#' else HAVE_CLOSEFROM_TRUE='#' HAVE_CLOSEFROM_FALSE= fi if test "x$ac_cv_func_clock_getres" = xyes; then HAVE_CLOCK_GETRES_TRUE= HAVE_CLOCK_GETRES_FALSE='#' else HAVE_CLOCK_GETRES_TRUE='#' HAVE_CLOCK_GETRES_FALSE= fi if test "x$ac_cv_func_clock_gettime" = xyes; then HAVE_CLOCK_GETTIME_TRUE= HAVE_CLOCK_GETTIME_FALSE='#' else HAVE_CLOCK_GETTIME_TRUE='#' HAVE_CLOCK_GETTIME_FALSE= fi if test "x$ac_cv_func_explicit_bzero" = xyes; then HAVE_EXPLICIT_BZERO_TRUE= HAVE_EXPLICIT_BZERO_FALSE='#' else HAVE_EXPLICIT_BZERO_TRUE='#' HAVE_EXPLICIT_BZERO_FALSE= fi if test "x$ac_cv_func_freezero" = xyes; then HAVE_FREEZERO_TRUE= HAVE_FREEZERO_FALSE='#' else HAVE_FREEZERO_TRUE='#' HAVE_FREEZERO_FALSE= fi if test "x$ac_cv_func_getentropy" = xyes; then HAVE_GETENTROPY_TRUE= HAVE_GETENTROPY_FALSE='#' else HAVE_GETENTROPY_TRUE='#' HAVE_GETENTROPY_FALSE= fi if test "x$ac_cv_func_ibuf_open" = xyes -a "x$ac_cv_func_imsgbuf_init" = xyes; then HAVE_IMSG_TRUE= HAVE_IMSG_FALSE='#' else HAVE_IMSG_TRUE='#' HAVE_IMSG_FALSE= fi if test "x$ac_cv_func_MD5Init" = xyes; then HAVE_MD5_TRUE= HAVE_MD5_FALSE='#' else HAVE_MD5_TRUE='#' HAVE_MD5_FALSE= fi if test "x$ac_cv_func_memmem" = xyes; then HAVE_MEMMEM_TRUE= HAVE_MEMMEM_FALSE='#' else HAVE_MEMMEM_TRUE='#' HAVE_MEMMEM_FALSE= fi if test "x$ac_cv_func_poll" = xyes; then HAVE_POLL_TRUE= HAVE_POLL_FALSE='#' else HAVE_POLL_TRUE='#' HAVE_POLL_FALSE= fi if test "x$ac_cv_func_reallocarray" = xyes; then HAVE_REALLOCARRAY_TRUE= HAVE_REALLOCARRAY_FALSE='#' else HAVE_REALLOCARRAY_TRUE='#' HAVE_REALLOCARRAY_FALSE= fi if test "x$ac_cv_func_recallocarray" = xyes; then HAVE_RECALLOCARRAY_TRUE= HAVE_RECALLOCARRAY_FALSE='#' else HAVE_RECALLOCARRAY_TRUE='#' HAVE_RECALLOCARRAY_FALSE= fi if test "x$ac_cv_func_setgroups" = xyes; then HAVE_SETGROUPS_TRUE= HAVE_SETGROUPS_FALSE='#' else HAVE_SETGROUPS_TRUE='#' HAVE_SETGROUPS_FALSE= fi if test "x$ac_cv_func_setresgid" = xyes; then HAVE_SETRESGID_TRUE= HAVE_SETRESGID_FALSE='#' else HAVE_SETRESGID_TRUE='#' HAVE_SETRESGID_FALSE= fi if test "x$ac_cv_func_setresuid" = xyes; then HAVE_SETRESUID_TRUE= HAVE_SETRESUID_FALSE='#' else HAVE_SETRESUID_TRUE='#' HAVE_SETRESUID_FALSE= fi if test "x$ac_cv_func_setproctitle" = xyes; then HAVE_SETPROCTITLE_TRUE= HAVE_SETPROCTITLE_FALSE='#' else HAVE_SETPROCTITLE_TRUE='#' HAVE_SETPROCTITLE_FALSE= fi if test "x$ac_cv_func_strlcat" = xyes; then HAVE_STRLCAT_TRUE= HAVE_STRLCAT_FALSE='#' else HAVE_STRLCAT_TRUE='#' HAVE_STRLCAT_FALSE= fi if test "x$ac_cv_func_strlcpy" = xyes; then HAVE_STRLCPY_TRUE= HAVE_STRLCPY_FALSE='#' else HAVE_STRLCPY_TRUE='#' HAVE_STRLCPY_FALSE= fi if test "x$ac_cv_func_strtonum" = xyes; then HAVE_STRTONUM_TRUE= HAVE_STRTONUM_FALSE='#' else HAVE_STRTONUM_TRUE='#' HAVE_STRTONUM_FALSE= fi if test "x$ac_cv_func_sysconf" = xyes; then HAVE_SYSCONF_TRUE= HAVE_SYSCONF_FALSE='#' else HAVE_SYSCONF_TRUE='#' HAVE_SYSCONF_FALSE= fi if test "x$ac_cv_func_pledge" = xyes; then HAVE_PLEDGE_TRUE= HAVE_PLEDGE_FALSE='#' else HAVE_PLEDGE_TRUE='#' HAVE_PLEDGE_FALSE= fi if test "x$ac_cv_func_unveil" = xyes; then HAVE_UNVEIL_TRUE= HAVE_UNVEIL_FALSE='#' else HAVE_UNVEIL_TRUE='#' HAVE_UNVEIL_FALSE= fi if test "x$ac_cv_func_getdtablecount" = xyes; then HAVE_GETDTABLECOUNT_TRUE= HAVE_GETDTABLECOUNT_FALSE='#' else HAVE_GETDTABLECOUNT_TRUE='#' HAVE_GETDTABLECOUNT_FALSE= fi if test "x$ac_cv_func_getrtable" = xyes; then HAVE_GETRTABLE_TRUE= HAVE_GETRTABLE_FALSE='#' else HAVE_GETRTABLE_TRUE='#' HAVE_GETRTABLE_FALSE= fi if test "x$ac_cv_func_strnvis" = xyes; then HAVE_STRNVIS_TRUE= HAVE_STRNVIS_FALSE='#' else HAVE_STRNVIS_TRUE='#' HAVE_STRNVIS_FALSE= fi if test "x$ac_cv_broken_strnvis" = xyes; then BROKEN_STRNVIS_TRUE= BROKEN_STRNVIS_FALSE='#' else BROKEN_STRNVIS_TRUE='#' BROKEN_STRNVIS_FALSE= fi if test "x$ac_cv_func_inet_net_pton" = xyes; then HAVE_INET_NET_PTON_TRUE= HAVE_INET_NET_PTON_FALSE='#' else HAVE_INET_NET_PTON_TRUE='#' HAVE_INET_NET_PTON_FALSE= fi if test "x$ac_cv_func_fmt_scaled" = xyes; then HAVE_FMT_SCALED_TRUE= HAVE_FMT_SCALED_FALSE='#' else HAVE_FMT_SCALED_TRUE='#' HAVE_FMT_SCALED_FALSE= fi if test "x$ac_cv_func_mnl_socket_open2" = "xyes"; then HAVE_MNL_TRUE= HAVE_MNL_FALSE='#' else HAVE_MNL_TRUE='#' HAVE_MNL_FALSE= fi if test "x$ac_cv_have_pftable" = "xyes"; then HAVE_PFTABLE_TRUE= HAVE_PFTABLE_FALSE='#' else HAVE_PFTABLE_TRUE='#' HAVE_PFTABLE_FALSE= fi # overrides for arc4random implementations with known issues if test "x$USE_BUILTIN_ARC4RANDOM" != xyes \ -a "x$ac_cv_func_arc4random" = xyes; then HAVE_ARC4RANDOM_TRUE= HAVE_ARC4RANDOM_FALSE='#' else HAVE_ARC4RANDOM_TRUE='#' HAVE_ARC4RANDOM_FALSE= fi ac_fn_c_check_member "$LINENO" "struct tcp_md5sig" "tcpm_key" "ac_cv_member_struct_tcp_md5sig_tcpm_key" " #include #include #include " if test "x$ac_cv_member_struct_tcp_md5sig_tcpm_key" = xyes then : printf "%s\n" "#define HAVE_STRUCT_TCP_MD5SIG_TCPM_KEY 1" >>confdefs.h fi if test "x$ac_cv_member_struct_tcp_md5sig_tcpm_key" = xyes; then HAVE_LINUX_TCPMD5_TRUE= HAVE_LINUX_TCPMD5_FALSE='#' else HAVE_LINUX_TCPMD5_TRUE='#' HAVE_LINUX_TCPMD5_FALSE= fi ac_fn_c_check_func "$LINENO" "setfib" "ac_cv_func_setfib" if test "x$ac_cv_func_setfib" = xyes then : printf "%s\n" "#define HAVE_SETFIB 1" >>confdefs.h fi if test "x$HOST_OS" = xfreebsd \ -a "x$ac_cv_func_setfib" = "xyes"; then HAVE_SETFIB_TRUE= HAVE_SETFIB_FALSE='#' else HAVE_SETFIB_TRUE='#' HAVE_SETFIB_FALSE= fi if test "$enable_bgplgd" = yes; then # Check whether --with-event was given. if test ${with_event+y} then : withval=$with_event; PKG_NAME="$withval" fi if test X"$PKG_NAME" != X; then LIBEVENT_CFLAGS=`pkg-config --cflags-only-I $PKG_NAME 2>/dev/null` LIBEVENT_LDFLAGS=`pkg-config --libs-only-L $PKG_NAME 2>/dev/null` fi # Check whether --with-event-cflags was given. if test ${with_event_cflags+y} then : withval=$with_event_cflags; LIBEVENT_CFLAGS="$withval" fi # Check whether --with-event-ldflags was given. if test ${with_event_ldflags+y} then : withval=$with_event_ldflags; LIBEVENT_LDFLAGS="$withval" fi AM_CFLAGS="$AM_CFLAGS $LIBEVENT_CFLAGS" AM_LDFLAGS="$AM_LDFLAGS $LIBEVENT_LDFLAGS" save_cflags="$CFLAGS" save_ldflags="$LDFLAGS" CFLAGS="$AM_CFLAGS $CFLAGS" LDFLAGS="$AM_LDFLAGS $LDFLAGS" for ac_header in event.h do : ac_fn_c_check_header_compile "$LINENO" "event.h" "ac_cv_header_event_h" "$ac_includes_default" if test "x$ac_cv_header_event_h" = xyes then : printf "%s\n" "#define HAVE_EVENT_H 1" >>confdefs.h else case e in #( e) as_fn_error $? "libevent headers required" "$LINENO" 5 ;; esac fi done { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for event_init in -levent" >&5 printf %s "checking for event_init in -levent... " >&6; } if test ${ac_cv_lib_event_event_init+y} then : printf %s "(cached) " >&6 else case e in #( e) ac_check_lib_save_LIBS=$LIBS LIBS="-levent $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. The 'extern "C"' is for builds by C++ compilers; although this is not generally supported in C code supporting it here has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif char event_init (void); int main (void) { return event_init (); ; return 0; } _ACEOF if ac_fn_c_try_link "$LINENO" then : ac_cv_lib_event_event_init=yes else case e in #( e) ac_cv_lib_event_event_init=no ;; esac fi rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_event_event_init" >&5 printf "%s\n" "$ac_cv_lib_event_event_init" >&6; } if test "x$ac_cv_lib_event_event_init" = xyes then : printf "%s\n" "#define HAVE_LIBEVENT 1" >>confdefs.h LIBS="-levent $LIBS" else case e in #( e) as_fn_error $? "libevent required" "$LINENO" 5 ;; esac fi for ac_func in event_init event_dispatch do : as_ac_var=`printf "%s\n" "ac_cv_func_$ac_func" | sed "$as_sed_sh"` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" if eval test \"x\$"$as_ac_var"\" = x"yes" then : cat >>confdefs.h <<_ACEOF #define `printf "%s\n" "HAVE_$ac_func" | sed "$as_sed_cpp"` 1 _ACEOF else case e in #( e) as_fn_error $? "libevent required" "$LINENO" 5 ;; esac fi done CFLAGS="$save_cflags" LDFLAGS="$save_ldflags" fi # Check whether --with-privsep-user was given. if test ${with_privsep_user+y} then : withval=$with_privsep_user; BGPD_USER="$withval" else case e in #( e) BGPD_USER="_bgpd" ;; esac fi printf "%s\n" "#define BGPD_USER \"$BGPD_USER\"" >>confdefs.h if test "$enable_bgplgd" = yes; then # Check whether --with-bgplgd-user was given. if test ${with_bgplgd_user+y} then : withval=$with_bgplgd_user; BGPLGD_USER="$withval" else case e in #( e) BGPLGD_USER="_bgplgd" ;; esac fi printf "%s\n" "#define BGPLGD_USER \"$BGPLGD_USER\"" >>confdefs.h # Check whether --with-www-user was given. if test ${with_www_user+y} then : withval=$with_www_user; WWW_USER="$withval" else case e in #( e) WWW_USER="www" ;; esac fi printf "%s\n" "#define WWW_USER \"$WWW_USER\"" >>confdefs.h # Check whether --with-wwwrunstatedir was given. if test ${with_wwwrunstatedir+y} then : withval=$with_wwwrunstatedir; wwwrunstatedir="$withval" fi if test "x$runstatedir" = x; then wwwrunstatedir='${localstatedir}/www/run' fi fi if test "$enable_bgplgd" = yes; then BUILD_BGPLGD_TRUE= BUILD_BGPLGD_FALSE='#' else BUILD_BGPLGD_TRUE='#' BUILD_BGPLGD_FALSE= fi if test "$disable_fib" = yes; then DISABLE_FIB_TRUE= DISABLE_FIB_FALSE='#' else DISABLE_FIB_TRUE='#' DISABLE_FIB_FALSE= fi # workaround the issue that there is no autoconf release supporting # runstatedir but many linux distros patched their versions instead # Check if the variable is set, if not use a basic default. # Check whether --with-runstatedir was given. if test ${with_runstatedir+y} then : withval=$with_runstatedir; runstatedir="$withval" fi if test "x$runstatedir" = x; then runstatedir='${localstatedir}/run' fi ac_config_files="$ac_config_files Makefile include/Makefile compat/Makefile src/bgpctl/Makefile src/bgpd/Makefile src/bgplgd/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure # scripts and configure runs, see configure's option --config-cache. # It is not useful on other systems. If it contains results you don't # want to keep, you may remove or edit it. # # config.status only pays attention to the cache file if you give it # the --recheck option to rerun configure. # # 'ac_cv_env_foo' variables (set or unset) will be overridden when # loading this file, other *unset* 'ac_cv_foo' will be assigned the # following values. _ACEOF # The following way of writing the cache mishandles newlines in values, # but we know of no workaround that is simple, portable, and efficient. # So, we kill variables containing newlines. # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. ( for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do eval ac_val=\$$ac_var case $ac_val in #( *${as_nl}*) case $ac_var in #( *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( BASH_ARGV | BASH_SOURCE) eval $ac_var= ;; #( *) { eval $ac_var=; unset $ac_var;} ;; esac ;; esac done (set) 2>&1 | case $as_nl`(ac_space=' '; set) 2>&1` in #( *${as_nl}ac_space=\ *) # 'set' does not quote correctly, so add quotes: double-quote # substitution turns \\\\ into \\, and sed turns \\ into \. sed -n \ "s/'/'\\\\''/g; s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" ;; #( *) # 'set' quotes correctly as required by POSIX, so do not add quotes. sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" ;; esac | sort ) | sed ' /^ac_cv_env_/b end t clear :clear s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 printf "%s\n" "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else case $cache_file in #( */* | ?:*) mv -f confcache "$cache_file"$$ && mv -f "$cache_file"$$ "$cache_file" ;; #( *) mv -f confcache "$cache_file" ;; esac fi fi else { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. # # If the first sed substitution is executed (which looks for macros that # take arguments), then branch to the quote section. Otherwise, # look for a macro that doesn't take arguments. ac_script=' :mline /\\$/{ N s,\\\n,, b mline } t clear :clear s/^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\)/-D\1=\2/g t quote s/^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\)/-D\1=\2/g t quote b any :quote s/[][ `~#$^&*(){}\\|;'\''"<>?]/\\&/g s/\$/$$/g H :any ${ g s/^\n// s/\n/ /g p } ' DEFS=`sed -n "$ac_script" confdefs.h` ac_libobjs= ac_ltlibobjs= U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" as_fn_append ac_ltlibobjs " \${LIBOBJDIR}$ac_i"'$U.lo' done LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 printf %s "checking that generated files are newer than configure... " >&6; } if test -n "$am_sleep_pid"; then # Hide warnings about reused PIDs. wait $am_sleep_pid 2>/dev/null fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: done" >&5 printf "%s\n" "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' else am__EXEEXT_TRUE='#' am__EXEEXT_FALSE= fi if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then as_fn_error $? "conditional \"AMDEP\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then as_fn_error $? "conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HOST_DARWIN_TRUE}" && test -z "${HOST_DARWIN_FALSE}"; then as_fn_error $? "conditional \"HOST_DARWIN\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HOST_FREEBSD_TRUE}" && test -z "${HOST_FREEBSD_FALSE}"; then as_fn_error $? "conditional \"HOST_FREEBSD\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HOST_LINUX_TRUE}" && test -z "${HOST_LINUX_FALSE}"; then as_fn_error $? "conditional \"HOST_LINUX\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HOST_NETBSD_TRUE}" && test -z "${HOST_NETBSD_FALSE}"; then as_fn_error $? "conditional \"HOST_NETBSD\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HOST_OPENBSD_TRUE}" && test -z "${HOST_OPENBSD_FALSE}"; then as_fn_error $? "conditional \"HOST_OPENBSD\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HOST_SOLARIS_TRUE}" && test -z "${HOST_SOLARIS_FALSE}"; then as_fn_error $? "conditional \"HOST_SOLARIS\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${am__fastdepCC_TRUE}" && test -z "${am__fastdepCC_FALSE}"; then as_fn_error $? "conditional \"am__fastdepCC\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_ASPRINTF_TRUE}" && test -z "${HAVE_ASPRINTF_FALSE}"; then as_fn_error $? "conditional \"HAVE_ASPRINTF\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_CLOSEFROM_TRUE}" && test -z "${HAVE_CLOSEFROM_FALSE}"; then as_fn_error $? "conditional \"HAVE_CLOSEFROM\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_CLOCK_GETRES_TRUE}" && test -z "${HAVE_CLOCK_GETRES_FALSE}"; then as_fn_error $? "conditional \"HAVE_CLOCK_GETRES\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_CLOCK_GETTIME_TRUE}" && test -z "${HAVE_CLOCK_GETTIME_FALSE}"; then as_fn_error $? "conditional \"HAVE_CLOCK_GETTIME\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_EXPLICIT_BZERO_TRUE}" && test -z "${HAVE_EXPLICIT_BZERO_FALSE}"; then as_fn_error $? "conditional \"HAVE_EXPLICIT_BZERO\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_FREEZERO_TRUE}" && test -z "${HAVE_FREEZERO_FALSE}"; then as_fn_error $? "conditional \"HAVE_FREEZERO\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_GETENTROPY_TRUE}" && test -z "${HAVE_GETENTROPY_FALSE}"; then as_fn_error $? "conditional \"HAVE_GETENTROPY\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_IMSG_TRUE}" && test -z "${HAVE_IMSG_FALSE}"; then as_fn_error $? "conditional \"HAVE_IMSG\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_MD5_TRUE}" && test -z "${HAVE_MD5_FALSE}"; then as_fn_error $? "conditional \"HAVE_MD5\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_MEMMEM_TRUE}" && test -z "${HAVE_MEMMEM_FALSE}"; then as_fn_error $? "conditional \"HAVE_MEMMEM\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_POLL_TRUE}" && test -z "${HAVE_POLL_FALSE}"; then as_fn_error $? "conditional \"HAVE_POLL\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_REALLOCARRAY_TRUE}" && test -z "${HAVE_REALLOCARRAY_FALSE}"; then as_fn_error $? "conditional \"HAVE_REALLOCARRAY\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_RECALLOCARRAY_TRUE}" && test -z "${HAVE_RECALLOCARRAY_FALSE}"; then as_fn_error $? "conditional \"HAVE_RECALLOCARRAY\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_SETGROUPS_TRUE}" && test -z "${HAVE_SETGROUPS_FALSE}"; then as_fn_error $? "conditional \"HAVE_SETGROUPS\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_SETRESGID_TRUE}" && test -z "${HAVE_SETRESGID_FALSE}"; then as_fn_error $? "conditional \"HAVE_SETRESGID\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_SETRESUID_TRUE}" && test -z "${HAVE_SETRESUID_FALSE}"; then as_fn_error $? "conditional \"HAVE_SETRESUID\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_SETPROCTITLE_TRUE}" && test -z "${HAVE_SETPROCTITLE_FALSE}"; then as_fn_error $? "conditional \"HAVE_SETPROCTITLE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_STRLCAT_TRUE}" && test -z "${HAVE_STRLCAT_FALSE}"; then as_fn_error $? "conditional \"HAVE_STRLCAT\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_STRLCPY_TRUE}" && test -z "${HAVE_STRLCPY_FALSE}"; then as_fn_error $? "conditional \"HAVE_STRLCPY\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_STRTONUM_TRUE}" && test -z "${HAVE_STRTONUM_FALSE}"; then as_fn_error $? "conditional \"HAVE_STRTONUM\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_SYSCONF_TRUE}" && test -z "${HAVE_SYSCONF_FALSE}"; then as_fn_error $? "conditional \"HAVE_SYSCONF\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_PLEDGE_TRUE}" && test -z "${HAVE_PLEDGE_FALSE}"; then as_fn_error $? "conditional \"HAVE_PLEDGE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_UNVEIL_TRUE}" && test -z "${HAVE_UNVEIL_FALSE}"; then as_fn_error $? "conditional \"HAVE_UNVEIL\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_GETDTABLECOUNT_TRUE}" && test -z "${HAVE_GETDTABLECOUNT_FALSE}"; then as_fn_error $? "conditional \"HAVE_GETDTABLECOUNT\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_GETRTABLE_TRUE}" && test -z "${HAVE_GETRTABLE_FALSE}"; then as_fn_error $? "conditional \"HAVE_GETRTABLE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_STRNVIS_TRUE}" && test -z "${HAVE_STRNVIS_FALSE}"; then as_fn_error $? "conditional \"HAVE_STRNVIS\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${BROKEN_STRNVIS_TRUE}" && test -z "${BROKEN_STRNVIS_FALSE}"; then as_fn_error $? "conditional \"BROKEN_STRNVIS\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_INET_NET_PTON_TRUE}" && test -z "${HAVE_INET_NET_PTON_FALSE}"; then as_fn_error $? "conditional \"HAVE_INET_NET_PTON\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_FMT_SCALED_TRUE}" && test -z "${HAVE_FMT_SCALED_FALSE}"; then as_fn_error $? "conditional \"HAVE_FMT_SCALED\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_MNL_TRUE}" && test -z "${HAVE_MNL_FALSE}"; then as_fn_error $? "conditional \"HAVE_MNL\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_PFTABLE_TRUE}" && test -z "${HAVE_PFTABLE_FALSE}"; then as_fn_error $? "conditional \"HAVE_PFTABLE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_ARC4RANDOM_TRUE}" && test -z "${HAVE_ARC4RANDOM_FALSE}"; then as_fn_error $? "conditional \"HAVE_ARC4RANDOM\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_LINUX_TCPMD5_TRUE}" && test -z "${HAVE_LINUX_TCPMD5_FALSE}"; then as_fn_error $? "conditional \"HAVE_LINUX_TCPMD5\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${HAVE_SETFIB_TRUE}" && test -z "${HAVE_SETFIB_FALSE}"; then as_fn_error $? "conditional \"HAVE_SETFIB\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${BUILD_BGPLGD_TRUE}" && test -z "${BUILD_BGPLGD_FALSE}"; then as_fn_error $? "conditional \"BUILD_BGPLGD\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${DISABLE_FIB_TRUE}" && test -z "${DISABLE_FIB_FALSE}"; then as_fn_error $? "conditional \"DISABLE_FIB\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi : "${CONFIG_STATUS=./config.status}" ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL # Generated by $as_me. # Run this file to recreate the current configuration. # Compiler output produced by configure, useful for debugging # configure, is in config.log if it exists. debug=false ac_cs_recheck=false ac_cs_silent=false SHELL=\${CONFIG_SHELL-$SHELL} export SHELL _ASEOF cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 ## -------------------- ## ## M4sh Initialization. ## ## -------------------- ## # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case e in #( e) case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( *) : ;; esac ;; esac fi # Reset variables that may have inherited troublesome values from # the environment. # IFS needs to be set, to space, tab, and newline, in precisely that order. # (If _AS_PATH_WALK were called with IFS unset, it would have the # side effect of setting IFS to empty, thus disabling word splitting.) # Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl IFS=" "" $as_nl" PS1='$ ' PS2='> ' PS4='+ ' # Ensure predictable behavior from utilities with locale-dependent output. LC_ALL=C export LC_ALL LANGUAGE=C export LANGUAGE # We cannot yet rely on "unset" to work, but we need these variables # to be unset--not just set to an empty or harmless value--now, to # avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct # also avoids known problems related to "unset" and subshell syntax # in other old shells (e.g. bash 2.01 and pdksh 5.2.14). for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH do eval test \${$as_var+y} \ && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : done # Ensure that fds 0, 1, and 2 are open. if (exec 3>&0) 2>/dev/null; then :; else exec 0&1) 2>/dev/null; then :; else exec 1>/dev/null; fi if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. if ${PATH_SEPARATOR+false} :; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || PATH_SEPARATOR=';' } fi # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS case $as_dir in #((( '') as_dir=./ ;; */) ;; *) as_dir=$as_dir/ ;; esac test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS ;; esac # We did not find ourselves, most probably we were run as 'sh COMMAND' # in which case we are not to be found in the path. if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the # script with STATUS, using 1 if that was 0. as_fn_error () { as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. as_fn_set_status () { return $1 } # as_fn_set_status # as_fn_exit STATUS # ----------------- # Exit the shell with STATUS, even in a "trap 0" or "set -e" context. as_fn_exit () { set +e as_fn_set_status $1 exit $1 } # as_fn_exit # as_fn_unset VAR # --------------- # Portably unset VAR. as_fn_unset () { { eval $1=; unset $1;} } as_unset=as_fn_unset # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null then : eval 'as_fn_append () { eval $1+=\$2 }' else case e in #( e) as_fn_append () { eval $1=\$$1\$2 } ;; esac fi # as_fn_append # as_fn_arith ARG... # ------------------ # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null then : eval 'as_fn_arith () { as_val=$(( $* )) }' else case e in #( e) as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } ;; esac fi # as_fn_arith if expr a : '\(a\)' >/dev/null 2>&1 && test "X`expr 00001 : '.*\(...\)'`" = X001; then as_expr=expr else as_expr=false fi if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then as_basename=basename else as_basename=false fi if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then as_dirname=dirname else as_dirname=false fi as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` # Avoid depending upon Character Ranges. as_cr_letters='abcdefghijklmnopqrstuvwxyz' as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits # Determine whether it's possible to make 'echo' print without a newline. # These variables are no longer used directly by Autoconf, but are AC_SUBSTed # for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) case `echo 'xy\c'` in *c*) ECHO_T=' ';; # ECHO_T is single tab character. xy) ECHO_C='\c';; *) echo `echo ksh88 bug on AIX 6.1` > /dev/null ECHO_T=' ';; esac;; *) ECHO_N='-n';; esac # For backward compatibility with old third-party macros, we provide # the shell variables $as_echo and $as_echo_n. New code should use # AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. as_echo='printf %s\n' as_echo_n='printf %s' rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file else rm -f conf$$.dir mkdir conf$$.dir 2>/dev/null fi if (echo >conf$$.file) 2>/dev/null; then if ln -s conf$$.file conf$$ 2>/dev/null; then as_ln_s='ln -s' # ... but there are two gotchas: # 1) On MSYS, both 'ln -s file dir' and 'ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; 'ln -s' creates a wrapper executable. # In both cases, we have to default to 'cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else as_ln_s='cp -pR' fi else as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null # as_fn_mkdir_p # ------------- # Create "$as_dir" as a directory, including parents if necessary. as_fn_mkdir_p () { case $as_dir in #( -*) as_dir=./$as_dir;; esac test -d "$as_dir" || eval $as_mkdir_p || { as_dirs= while :; do case $as_dir in #( *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" as_dir=`$as_dirname -- "$as_dir" || $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p if mkdir -p . 2>/dev/null; then as_mkdir_p='mkdir -p "$as_dir"' else test -d ./-p && rmdir ./-p as_mkdir_p=false fi # as_fn_executable_p FILE # ----------------------- # Test if FILE is an executable regular file. as_fn_executable_p () { test -f "$1" && test -x "$1" } # as_fn_executable_p as_test_x='test -x' as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_sed_cpp="y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g" as_tr_cpp="eval sed '$as_sed_cpp'" # deprecated # Sed expression to map a string onto a valid variable name. as_sed_sh="y%*+%pp%;s%[^_$as_cr_alnum]%_%g" as_tr_sh="eval sed '$as_sed_sh'" # deprecated exec 6>&1 ## ----------------------------------- ## ## Main body of $CONFIG_STATUS script. ## ## ----------------------------------- ## _ASEOF test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1 cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Save the log message, to keep $0 and so on meaningful, and to # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" This file was extended by OpenBGPD $as_me 8.8, which was generated by GNU Autoconf 2.72. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS CONFIG_LINKS = $CONFIG_LINKS CONFIG_COMMANDS = $CONFIG_COMMANDS $ $0 $@ on `(hostname || uname -n) 2>/dev/null | sed 1q` " _ACEOF case $ac_config_files in *" "*) set x $ac_config_files; shift; ac_config_files=$*;; esac cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # Files that config.status was made for. config_files="$ac_config_files" config_commands="$ac_config_commands" _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 ac_cs_usage="\ '$as_me' instantiates files and other configuration actions from templates according to the current configuration. Unless the files and actions are specified as TAGs, all are instantiated by default. Usage: $0 [OPTION]... [TAG]... -h, --help print this help, then exit -V, --version print version number and configuration settings, then exit --config print configuration, then exit -q, --quiet, --silent do not print progress messages -d, --debug don't remove temporary files --recheck update $as_me by reconfiguring in the same conditions --file=FILE[:TEMPLATE] instantiate the configuration file FILE Configuration files: $config_files Configuration commands: $config_commands Report bugs to the package provider." _ACEOF ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ OpenBGPD config.status 8.8 configured by $0, generated by GNU Autoconf 2.72, with options \\"\$ac_cs_config\\" Copyright (C) 2023 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." ac_pwd='$ac_pwd' srcdir='$srcdir' INSTALL='$INSTALL' MKDIR_P='$MKDIR_P' AWK='$AWK' test -n "\$AWK" || AWK=awk _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # The default lists apply if the user does not specify any file. ac_need_defaults=: while test $# != 0 do case $1 in --*=?*) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` ac_shift=: ;; --*=) ac_option=`expr "X$1" : 'X\([^=]*\)='` ac_optarg= ac_shift=: ;; *) ac_option=$1 ac_optarg=$2 ac_shift=shift ;; esac case $ac_option in # Handling of the options. -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) printf "%s\n" "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) printf "%s\n" "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" ac_need_defaults=false;; --he | --h | --help | --hel | -h ) printf "%s\n" "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; # This is an error. -*) as_fn_error $? "unrecognized option: '$1' Try '$0 --help' for more information." ;; *) as_fn_append ac_config_targets " $1" ac_need_defaults=false ;; esac shift done ac_configure_extra_args= if $ac_cs_silent; then exec 6>/dev/null ac_configure_extra_args="$ac_configure_extra_args --silent" fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" fi _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 exec 5>>config.log { echo sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX printf "%s\n" "$ac_log" } >&5 _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 # # INIT-COMMANDS # AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}" # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH sed_quote_subst='$sed_quote_subst' double_quote_subst='$double_quote_subst' delay_variable_subst='$delay_variable_subst' macro_version='`$ECHO "$macro_version" | $SED "$delay_single_quote_subst"`' macro_revision='`$ECHO "$macro_revision" | $SED "$delay_single_quote_subst"`' enable_shared='`$ECHO "$enable_shared" | $SED "$delay_single_quote_subst"`' enable_static='`$ECHO "$enable_static" | $SED "$delay_single_quote_subst"`' pic_mode='`$ECHO "$pic_mode" | $SED "$delay_single_quote_subst"`' enable_fast_install='`$ECHO "$enable_fast_install" | $SED "$delay_single_quote_subst"`' SHELL='`$ECHO "$SHELL" | $SED "$delay_single_quote_subst"`' ECHO='`$ECHO "$ECHO" | $SED "$delay_single_quote_subst"`' PATH_SEPARATOR='`$ECHO "$PATH_SEPARATOR" | $SED "$delay_single_quote_subst"`' host_alias='`$ECHO "$host_alias" | $SED "$delay_single_quote_subst"`' host='`$ECHO "$host" | $SED "$delay_single_quote_subst"`' host_os='`$ECHO "$host_os" | $SED "$delay_single_quote_subst"`' build_alias='`$ECHO "$build_alias" | $SED "$delay_single_quote_subst"`' build='`$ECHO "$build" | $SED "$delay_single_quote_subst"`' build_os='`$ECHO "$build_os" | $SED "$delay_single_quote_subst"`' SED='`$ECHO "$SED" | $SED "$delay_single_quote_subst"`' Xsed='`$ECHO "$Xsed" | $SED "$delay_single_quote_subst"`' GREP='`$ECHO "$GREP" | $SED "$delay_single_quote_subst"`' EGREP='`$ECHO "$EGREP" | $SED "$delay_single_quote_subst"`' FGREP='`$ECHO "$FGREP" | $SED "$delay_single_quote_subst"`' LD='`$ECHO "$LD" | $SED "$delay_single_quote_subst"`' NM='`$ECHO "$NM" | $SED "$delay_single_quote_subst"`' LN_S='`$ECHO "$LN_S" | $SED "$delay_single_quote_subst"`' max_cmd_len='`$ECHO "$max_cmd_len" | $SED "$delay_single_quote_subst"`' ac_objext='`$ECHO "$ac_objext" | $SED "$delay_single_quote_subst"`' exeext='`$ECHO "$exeext" | $SED "$delay_single_quote_subst"`' lt_unset='`$ECHO "$lt_unset" | $SED "$delay_single_quote_subst"`' lt_SP2NL='`$ECHO "$lt_SP2NL" | $SED "$delay_single_quote_subst"`' lt_NL2SP='`$ECHO "$lt_NL2SP" | $SED "$delay_single_quote_subst"`' lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_quote_subst"`' lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`' reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`' reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`' OBJDUMP='`$ECHO "$OBJDUMP" | $SED "$delay_single_quote_subst"`' deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`' file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`' file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`' want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`' DLLTOOL='`$ECHO "$DLLTOOL" | $SED "$delay_single_quote_subst"`' sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`' AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`' AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`' archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`' STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`' RANLIB='`$ECHO "$RANLIB" | $SED "$delay_single_quote_subst"`' old_postinstall_cmds='`$ECHO "$old_postinstall_cmds" | $SED "$delay_single_quote_subst"`' old_postuninstall_cmds='`$ECHO "$old_postuninstall_cmds" | $SED "$delay_single_quote_subst"`' old_archive_cmds='`$ECHO "$old_archive_cmds" | $SED "$delay_single_quote_subst"`' lock_old_archive_extraction='`$ECHO "$lock_old_archive_extraction" | $SED "$delay_single_quote_subst"`' CC='`$ECHO "$CC" | $SED "$delay_single_quote_subst"`' CFLAGS='`$ECHO "$CFLAGS" | $SED "$delay_single_quote_subst"`' compiler='`$ECHO "$compiler" | $SED "$delay_single_quote_subst"`' GCC='`$ECHO "$GCC" | $SED "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_pipe='`$ECHO "$lt_cv_sys_global_symbol_pipe" | $SED "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_to_cdecl='`$ECHO "$lt_cv_sys_global_symbol_to_cdecl" | $SED "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_to_c_name_address='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address" | $SED "$delay_single_quote_subst"`' lt_cv_sys_global_symbol_to_c_name_address_lib_prefix='`$ECHO "$lt_cv_sys_global_symbol_to_c_name_address_lib_prefix" | $SED "$delay_single_quote_subst"`' nm_file_list_spec='`$ECHO "$nm_file_list_spec" | $SED "$delay_single_quote_subst"`' lt_sysroot='`$ECHO "$lt_sysroot" | $SED "$delay_single_quote_subst"`' objdir='`$ECHO "$objdir" | $SED "$delay_single_quote_subst"`' MAGIC_CMD='`$ECHO "$MAGIC_CMD" | $SED "$delay_single_quote_subst"`' lt_prog_compiler_no_builtin_flag='`$ECHO "$lt_prog_compiler_no_builtin_flag" | $SED "$delay_single_quote_subst"`' lt_prog_compiler_pic='`$ECHO "$lt_prog_compiler_pic" | $SED "$delay_single_quote_subst"`' lt_prog_compiler_wl='`$ECHO "$lt_prog_compiler_wl" | $SED "$delay_single_quote_subst"`' lt_prog_compiler_static='`$ECHO "$lt_prog_compiler_static" | $SED "$delay_single_quote_subst"`' lt_cv_prog_compiler_c_o='`$ECHO "$lt_cv_prog_compiler_c_o" | $SED "$delay_single_quote_subst"`' need_locks='`$ECHO "$need_locks" | $SED "$delay_single_quote_subst"`' MANIFEST_TOOL='`$ECHO "$MANIFEST_TOOL" | $SED "$delay_single_quote_subst"`' DSYMUTIL='`$ECHO "$DSYMUTIL" | $SED "$delay_single_quote_subst"`' NMEDIT='`$ECHO "$NMEDIT" | $SED "$delay_single_quote_subst"`' LIPO='`$ECHO "$LIPO" | $SED "$delay_single_quote_subst"`' OTOOL='`$ECHO "$OTOOL" | $SED "$delay_single_quote_subst"`' OTOOL64='`$ECHO "$OTOOL64" | $SED "$delay_single_quote_subst"`' libext='`$ECHO "$libext" | $SED "$delay_single_quote_subst"`' shrext_cmds='`$ECHO "$shrext_cmds" | $SED "$delay_single_quote_subst"`' extract_expsyms_cmds='`$ECHO "$extract_expsyms_cmds" | $SED "$delay_single_quote_subst"`' archive_cmds_need_lc='`$ECHO "$archive_cmds_need_lc" | $SED "$delay_single_quote_subst"`' enable_shared_with_static_runtimes='`$ECHO "$enable_shared_with_static_runtimes" | $SED "$delay_single_quote_subst"`' export_dynamic_flag_spec='`$ECHO "$export_dynamic_flag_spec" | $SED "$delay_single_quote_subst"`' whole_archive_flag_spec='`$ECHO "$whole_archive_flag_spec" | $SED "$delay_single_quote_subst"`' compiler_needs_object='`$ECHO "$compiler_needs_object" | $SED "$delay_single_quote_subst"`' old_archive_from_new_cmds='`$ECHO "$old_archive_from_new_cmds" | $SED "$delay_single_quote_subst"`' old_archive_from_expsyms_cmds='`$ECHO "$old_archive_from_expsyms_cmds" | $SED "$delay_single_quote_subst"`' archive_cmds='`$ECHO "$archive_cmds" | $SED "$delay_single_quote_subst"`' archive_expsym_cmds='`$ECHO "$archive_expsym_cmds" | $SED "$delay_single_quote_subst"`' module_cmds='`$ECHO "$module_cmds" | $SED "$delay_single_quote_subst"`' module_expsym_cmds='`$ECHO "$module_expsym_cmds" | $SED "$delay_single_quote_subst"`' with_gnu_ld='`$ECHO "$with_gnu_ld" | $SED "$delay_single_quote_subst"`' allow_undefined_flag='`$ECHO "$allow_undefined_flag" | $SED "$delay_single_quote_subst"`' no_undefined_flag='`$ECHO "$no_undefined_flag" | $SED "$delay_single_quote_subst"`' hardcode_libdir_flag_spec='`$ECHO "$hardcode_libdir_flag_spec" | $SED "$delay_single_quote_subst"`' hardcode_libdir_separator='`$ECHO "$hardcode_libdir_separator" | $SED "$delay_single_quote_subst"`' hardcode_direct='`$ECHO "$hardcode_direct" | $SED "$delay_single_quote_subst"`' hardcode_direct_absolute='`$ECHO "$hardcode_direct_absolute" | $SED "$delay_single_quote_subst"`' hardcode_minus_L='`$ECHO "$hardcode_minus_L" | $SED "$delay_single_quote_subst"`' hardcode_shlibpath_var='`$ECHO "$hardcode_shlibpath_var" | $SED "$delay_single_quote_subst"`' hardcode_automatic='`$ECHO "$hardcode_automatic" | $SED "$delay_single_quote_subst"`' inherit_rpath='`$ECHO "$inherit_rpath" | $SED "$delay_single_quote_subst"`' link_all_deplibs='`$ECHO "$link_all_deplibs" | $SED "$delay_single_quote_subst"`' always_export_symbols='`$ECHO "$always_export_symbols" | $SED "$delay_single_quote_subst"`' export_symbols_cmds='`$ECHO "$export_symbols_cmds" | $SED "$delay_single_quote_subst"`' exclude_expsyms='`$ECHO "$exclude_expsyms" | $SED "$delay_single_quote_subst"`' include_expsyms='`$ECHO "$include_expsyms" | $SED "$delay_single_quote_subst"`' prelink_cmds='`$ECHO "$prelink_cmds" | $SED "$delay_single_quote_subst"`' postlink_cmds='`$ECHO "$postlink_cmds" | $SED "$delay_single_quote_subst"`' file_list_spec='`$ECHO "$file_list_spec" | $SED "$delay_single_quote_subst"`' variables_saved_for_relink='`$ECHO "$variables_saved_for_relink" | $SED "$delay_single_quote_subst"`' need_lib_prefix='`$ECHO "$need_lib_prefix" | $SED "$delay_single_quote_subst"`' need_version='`$ECHO "$need_version" | $SED "$delay_single_quote_subst"`' version_type='`$ECHO "$version_type" | $SED "$delay_single_quote_subst"`' runpath_var='`$ECHO "$runpath_var" | $SED "$delay_single_quote_subst"`' shlibpath_var='`$ECHO "$shlibpath_var" | $SED "$delay_single_quote_subst"`' shlibpath_overrides_runpath='`$ECHO "$shlibpath_overrides_runpath" | $SED "$delay_single_quote_subst"`' libname_spec='`$ECHO "$libname_spec" | $SED "$delay_single_quote_subst"`' library_names_spec='`$ECHO "$library_names_spec" | $SED "$delay_single_quote_subst"`' soname_spec='`$ECHO "$soname_spec" | $SED "$delay_single_quote_subst"`' install_override_mode='`$ECHO "$install_override_mode" | $SED "$delay_single_quote_subst"`' postinstall_cmds='`$ECHO "$postinstall_cmds" | $SED "$delay_single_quote_subst"`' postuninstall_cmds='`$ECHO "$postuninstall_cmds" | $SED "$delay_single_quote_subst"`' finish_cmds='`$ECHO "$finish_cmds" | $SED "$delay_single_quote_subst"`' finish_eval='`$ECHO "$finish_eval" | $SED "$delay_single_quote_subst"`' hardcode_into_libs='`$ECHO "$hardcode_into_libs" | $SED "$delay_single_quote_subst"`' sys_lib_search_path_spec='`$ECHO "$sys_lib_search_path_spec" | $SED "$delay_single_quote_subst"`' sys_lib_dlsearch_path_spec='`$ECHO "$sys_lib_dlsearch_path_spec" | $SED "$delay_single_quote_subst"`' hardcode_action='`$ECHO "$hardcode_action" | $SED "$delay_single_quote_subst"`' enable_dlopen='`$ECHO "$enable_dlopen" | $SED "$delay_single_quote_subst"`' enable_dlopen_self='`$ECHO "$enable_dlopen_self" | $SED "$delay_single_quote_subst"`' enable_dlopen_self_static='`$ECHO "$enable_dlopen_self_static" | $SED "$delay_single_quote_subst"`' old_striplib='`$ECHO "$old_striplib" | $SED "$delay_single_quote_subst"`' striplib='`$ECHO "$striplib" | $SED "$delay_single_quote_subst"`' LTCC='$LTCC' LTCFLAGS='$LTCFLAGS' compiler='$compiler_DEFAULT' # A function that is used when there is no print builtin or printf. func_fallback_echo () { eval 'cat <<_LTECHO_EOF \$1 _LTECHO_EOF' } # Quote evaled strings. for var in SHELL \ ECHO \ PATH_SEPARATOR \ SED \ GREP \ EGREP \ FGREP \ LD \ NM \ LN_S \ lt_SP2NL \ lt_NL2SP \ reload_flag \ OBJDUMP \ deplibs_check_method \ file_magic_cmd \ file_magic_glob \ want_nocaseglob \ DLLTOOL \ sharedlib_from_linklib_cmd \ AR \ AR_FLAGS \ archiver_list_spec \ STRIP \ RANLIB \ CC \ CFLAGS \ compiler \ lt_cv_sys_global_symbol_pipe \ lt_cv_sys_global_symbol_to_cdecl \ lt_cv_sys_global_symbol_to_c_name_address \ lt_cv_sys_global_symbol_to_c_name_address_lib_prefix \ nm_file_list_spec \ lt_prog_compiler_no_builtin_flag \ lt_prog_compiler_pic \ lt_prog_compiler_wl \ lt_prog_compiler_static \ lt_cv_prog_compiler_c_o \ need_locks \ MANIFEST_TOOL \ DSYMUTIL \ NMEDIT \ LIPO \ OTOOL \ OTOOL64 \ shrext_cmds \ export_dynamic_flag_spec \ whole_archive_flag_spec \ compiler_needs_object \ with_gnu_ld \ allow_undefined_flag \ no_undefined_flag \ hardcode_libdir_flag_spec \ hardcode_libdir_separator \ exclude_expsyms \ include_expsyms \ file_list_spec \ variables_saved_for_relink \ libname_spec \ library_names_spec \ soname_spec \ install_override_mode \ finish_eval \ old_striplib \ striplib; do case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in *[\\\\\\\`\\"\\\$]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED \\"\\\$sed_quote_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done # Double-quote double-evaled strings. for var in reload_cmds \ old_postinstall_cmds \ old_postuninstall_cmds \ old_archive_cmds \ extract_expsyms_cmds \ old_archive_from_new_cmds \ old_archive_from_expsyms_cmds \ archive_cmds \ archive_expsym_cmds \ module_cmds \ module_expsym_cmds \ export_symbols_cmds \ prelink_cmds \ postlink_cmds \ postinstall_cmds \ postuninstall_cmds \ finish_cmds \ sys_lib_search_path_spec \ sys_lib_dlsearch_path_spec; do case \`eval \\\\\$ECHO \\\\""\\\\\$\$var"\\\\"\` in *[\\\\\\\`\\"\\\$]*) eval "lt_\$var=\\\\\\"\\\`\\\$ECHO \\"\\\$\$var\\" | \\\$SED -e \\"\\\$double_quote_subst\\" -e \\"\\\$sed_quote_subst\\" -e \\"\\\$delay_variable_subst\\"\\\`\\\\\\"" ;; *) eval "lt_\$var=\\\\\\"\\\$\$var\\\\\\"" ;; esac done ac_aux_dir='$ac_aux_dir' xsi_shell='$xsi_shell' lt_shell_append='$lt_shell_append' # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes INIT. if test -n "\${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi PACKAGE='$PACKAGE' VERSION='$VERSION' TIMESTAMP='$TIMESTAMP' RM='$RM' ofile='$ofile' _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # Handling of arguments. for ac_config_target in $ac_config_targets do case $ac_config_target in "depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;; "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "include/Makefile") CONFIG_FILES="$CONFIG_FILES include/Makefile" ;; "compat/Makefile") CONFIG_FILES="$CONFIG_FILES compat/Makefile" ;; "src/bgpctl/Makefile") CONFIG_FILES="$CONFIG_FILES src/bgpctl/Makefile" ;; "src/bgpd/Makefile") CONFIG_FILES="$CONFIG_FILES src/bgpd/Makefile" ;; "src/bgplgd/Makefile") CONFIG_FILES="$CONFIG_FILES src/bgplgd/Makefile" ;; *) as_fn_error $? "invalid argument: '$ac_config_target'" "$LINENO" 5;; esac done # If the user did not use the arguments to specify the items to instantiate, # then the envvar interface is used. Set only those that are not. # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files test ${CONFIG_COMMANDS+y} || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree # simply because there is no reason against having it here, and in addition, # creating and moving files from /tmp can sometimes cause problems. # Hook for its removal unless debugging. # Note that there is a small window in which the directory will not be cleaned: # after its creation but before its name has been assigned to '$tmp'. $debug || { tmp= ac_tmp= trap 'exit_status=$? : "${ac_tmp:=$tmp}" { test ! -d "$ac_tmp" || rm -fr "$ac_tmp"; } && exit $exit_status ' 0 trap 'as_fn_exit 1' 1 2 13 15 } # Create a (secure) tmp directory for tmp files. { tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && test -d "$tmp" } || { tmp=./conf$$-$RANDOM (umask 077 && mkdir "$tmp") } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5 ac_tmp=$tmp # Set up the scripts for CONFIG_FILES section. # No need to generate them if there are no CONFIG_FILES. # This happens for instance with './config.status config.h'. if test -n "$CONFIG_FILES"; then ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this # point, so we can use a bashism as a fallback. if test "x$ac_cr" = x; then eval ac_cr=\$\'\\r\' fi ac_cs_awk_cr=`$AWK 'BEGIN { print "a\rb" }' /dev/null` if test "$ac_cs_awk_cr" = "a${ac_cr}b"; then ac_cs_awk_cr='\\r' else ac_cs_awk_cr=$ac_cr fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF { echo "cat >conf$$subs.awk <<_ACEOF" && echo "$ac_subst_vars" | sed 's/.*/&!$&$ac_delim/' && echo "_ACEOF" } >conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_num=`echo "$ac_subst_vars" | grep -c '^'` ac_delim='%!_!# ' for ac_last_try in false false false false false :; do . ./conf$$subs.sh || as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 ac_delim_n=`sed -n "s/.*$ac_delim\$/X/p" conf$$subs.awk | grep -c X` if test $ac_delim_n = $ac_delim_num; then break elif $ac_last_try; then as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 else ac_delim="$ac_delim!$ac_delim _$ac_delim!! " fi done rm -f conf$$subs.sh cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK && _ACEOF sed -n ' h s/^/S["/; s/!.*/"]=/ p g s/^[^!]*!// :repl t repl s/'"$ac_delim"'$// t delim :nl h s/\(.\{148\}\)..*/\1/ t more1 s/["\\]/\\&/g; s/^/"/; s/$/\\n"\\/ p n b repl :more1 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t nl :delim h s/\(.\{148\}\)..*/\1/ t more2 s/["\\]/\\&/g; s/^/"/; s/$/"/ p b :more2 s/["\\]/\\&/g; s/^/"/; s/$/"\\/ p g s/.\{148\}// t delim ' >$CONFIG_STATUS || ac_write_fail=1 rm -f conf$$subs.awk cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" } { line = $ 0 nfields = split(line, field, "@") substed = 0 len = length(field[1]) for (i = 2; i < nfields; i++) { key = field[i] keylen = length(key) if (S_is_set[key]) { value = S[key] line = substr(line, 1, len) "" value "" substr(line, len + keylen + 3) len += length(value) + length(field[++i]) substed = 1 } else len += 1 + keylen } print line } _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 if sed "s/$ac_cr//" < /dev/null > /dev/null 2>&1; then sed "s/$ac_cr\$//; s/$ac_cr/$ac_cs_awk_cr/g" else cat fi < "$ac_tmp/subs1.awk" > "$ac_tmp/subs.awk" \ || as_fn_error $? "could not setup config files machinery" "$LINENO" 5 _ACEOF # VPATH may cause trouble with some makes, so we remove sole $(srcdir), # ${srcdir} and @srcdir@ entries from VPATH if srcdir is ".", strip leading and # trailing colons and then remove the whole line if VPATH becomes empty # (actually we leave an empty line to preserve line numbers). if test "x$srcdir" = x.; then ac_vpsub='/^[ ]*VPATH[ ]*=[ ]*/{ h s/// s/^/:/ s/[ ]*$/:/ s/:\$(srcdir):/:/g s/:\${srcdir}:/:/g s/:@srcdir@:/:/g s/^:*// s/:*$// x s/\(=[ ]*\).*/\1/ G s/\n// s/^[^=]*=[ ]*$// }' fi cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 fi # test -n "$CONFIG_FILES" eval set X " :F $CONFIG_FILES :C $CONFIG_COMMANDS" shift for ac_tag do case $ac_tag in :[FHLC]) ac_mode=$ac_tag; continue;; esac case $ac_mode$ac_tag in :[FHL]*:*);; :L* | :C*:*) as_fn_error $? "invalid tag '$ac_tag'" "$LINENO" 5;; :[FH]-) ac_tag=-:-;; :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; esac ac_save_IFS=$IFS IFS=: set x $ac_tag IFS=$ac_save_IFS shift ac_file=$1 shift case $ac_mode in :L) ac_source=$1;; :[FH]) ac_file_inputs= for ac_f do case $ac_f in -) ac_f="$ac_tmp/stdin";; *) # Look for the file first in the build tree, then in the source tree # (if the path is not absolute). The absolute path cannot be DOS-style, # because $ac_f cannot contain ':'. test -f "$ac_f" || case $ac_f in [\\/$]*) false;; *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; esac || as_fn_error 1 "cannot find input file: '$ac_f'" "$LINENO" 5;; esac case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done # Let's still pretend it is 'configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 printf "%s\n" "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) ac_sed_conf_input=`printf "%s\n" "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac case $ac_tag in *:-:* | *:-) cat >"$ac_tmp/stdin" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; esac ;; esac ac_dir=`$as_dirname -- "$ac_file" || $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` as_dir="$ac_dir"; as_fn_mkdir_p ac_builddir=. case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; esac ;; esac ac_abs_top_builddir=$ac_pwd ac_abs_builddir=$ac_pwd$ac_dir_suffix # for backward compatibility: ac_top_builddir=$ac_top_build_prefix case $srcdir in .) # We are building in place. ac_srcdir=. ac_top_srcdir=$ac_top_builddir_sub ac_abs_top_srcdir=$ac_pwd ;; [\\/]* | ?:[\\/]* ) # Absolute name. ac_srcdir=$srcdir$ac_dir_suffix; ac_top_srcdir=$srcdir ac_abs_top_srcdir=$srcdir ;; *) # Relative name. ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix ac_top_srcdir=$ac_top_build_prefix$srcdir ac_abs_top_srcdir=$ac_pwd/$srcdir ;; esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix case $ac_mode in :F) # # CONFIG_FILE # case $INSTALL in [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; esac ac_MKDIR_P=$MKDIR_P case $MKDIR_P in [\\/$]* | ?:[\\/]* ) ;; */*) ac_MKDIR_P=$ac_top_build_prefix$MKDIR_P ;; esac _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # If the template does not know about datarootdir, expand it. # FIXME: This hack should be removed a few years after 2.60. ac_datarootdir_hack=; ac_datarootdir_seen= ac_sed_dataroot=' /datarootdir/ { p q } /@datadir@/p /@docdir@/p /@infodir@/p /@localedir@/p /@mandir@/p' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' s&@datadir@&$datadir&g s&@docdir@&$docdir&g s&@infodir@&$infodir&g s&@localedir@&$localedir&g s&@mandir@&$mandir&g s&\\\${datarootdir}&$datarootdir&g' ;; esac _ACEOF # Neutralize VPATH when '$srcdir' = '.'. # Shell code in configure.ac might set extrasub. # FIXME: do we really want to maintain this feature? cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_sed_extra="$ac_vpsub $extrasub _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 :t /@[a-zA-Z_][a-zA-Z_0-9]*@/!b s|@configure_input@|$ac_sed_conf_input|;t t s&@top_builddir@&$ac_top_builddir_sub&;t t s&@top_build_prefix@&$ac_top_build_prefix&;t t s&@srcdir@&$ac_srcdir&;t t s&@abs_srcdir@&$ac_abs_srcdir&;t t s&@top_srcdir@&$ac_top_srcdir&;t t s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t s&@builddir@&$ac_builddir&;t t s&@abs_builddir@&$ac_abs_builddir&;t t s&@abs_top_builddir@&$ac_abs_top_builddir&;t t s&@INSTALL@&$ac_INSTALL&;t t s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable 'datarootdir' which seems to be undefined. Please make sure it is defined" >&5 printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable 'datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" case $ac_file in -) cat "$ac_tmp/out" && rm -f "$ac_tmp/out";; *) rm -f "$ac_file" && mv "$ac_tmp/out" "$ac_file";; esac \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 ;; :C) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 printf "%s\n" "$as_me: executing $ac_file commands" >&6;} ;; esac case $ac_file$ac_mode in "depfiles":C) test x"$AMDEP_TRUE" != x"" || { # Older Autoconf quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. # TODO: see whether this extra hack can be removed once we start # requiring Autoconf 2.70 or later. case $CONFIG_FILES in #( *\'*) : eval set x "$CONFIG_FILES" ;; #( *) : set x $CONFIG_FILES ;; #( *) : ;; esac shift # Used to flag and report bootstrapping failures. am_rc=0 for am_mf do # Strip MF so we end up with the name of the file. am_mf=`printf "%s\n" "$am_mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile which includes # dependency-tracking related rules and includes. # Grep'ing the whole file directly is not great: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ || continue am_dirpart=`$as_dirname -- "$am_mf" || $as_expr X"$am_mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$am_mf" : 'X\(//\)[^/]' \| \ X"$am_mf" : 'X\(//\)$' \| \ X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X"$am_mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q } /^X\(\/\/\)[^/].*/{ s//\1/ q } /^X\(\/\/\)$/{ s//\1/ q } /^X\(\/\).*/{ s//\1/ q } s/.*/./; q'` am_filepart=`$as_basename -- "$am_mf" || $as_expr X/"$am_mf" : '.*/\([^/][^/]*\)/*$' \| \ X"$am_mf" : 'X\(//\)$' \| \ X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || printf "%s\n" X/"$am_mf" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q } /^X\/\(\/\/\)$/{ s//\1/ q } /^X\/\(\/\).*/{ s//\1/ q } s/.*/./; q'` { echo "$as_me:$LINENO: cd "$am_dirpart" \ && sed -e '/# am--include-marker/d' "$am_filepart" \ | $MAKE -f - am--depfiles" >&5 (cd "$am_dirpart" \ && sed -e '/# am--include-marker/d' "$am_filepart" \ | $MAKE -f - am--depfiles) >&5 2>&5 ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } || am_rc=$? done if test $am_rc -ne 0; then { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} as_fn_error $? "Something went wrong bootstrapping makefile fragments for automatic dependency tracking. If GNU make was not used, consider re-running the configure script with MAKE=\"gmake\" (or whatever is necessary). You can also try re-running configure with the '--disable-dependency-tracking' option to at least be able to build the package (albeit without support for automatic dependency tracking). See 'config.log' for more details" "$LINENO" 5; } fi { am_dirpart=; unset am_dirpart;} { am_filepart=; unset am_filepart;} { am_mf=; unset am_mf;} { am_rc=; unset am_rc;} rm -f conftest-deps.mk } ;; "libtool":C) # See if we are running on zsh, and set the options which allow our # commands through without removal of \ escapes. if test -n "${ZSH_VERSION+set}" ; then setopt NO_GLOB_SUBST fi cfgfile="${ofile}T" trap "$RM \"$cfgfile\"; exit 1" 1 2 15 $RM "$cfgfile" cat <<_LT_EOF >> "$cfgfile" #! $SHELL # `$ECHO "$ofile" | sed 's%^.*/%%'` - Provide generalized library-building support services. # Generated automatically by $as_me ($PACKAGE$TIMESTAMP) $VERSION # Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, # 2006, 2007, 2008, 2009, 2010, 2011 Free Software # Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is part of GNU Libtool. # # GNU Libtool 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 of # the License, or (at your option) any later version. # # As a special exception to the GNU General Public License, # if you distribute this file as part of a program or library that # is built using GNU Libtool, you may include this file under the # same distribution terms that you use for the rest of that program. # # GNU Libtool 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. # # You should have received a copy of the GNU General Public License # along with GNU Libtool; see the file COPYING. If not, a copy # can be downloaded from http://www.gnu.org/licenses/gpl.html, or # obtained by writing to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # The names of the tagged configurations supported by this script. available_tags="" # ### BEGIN LIBTOOL CONFIG # Which release of libtool.m4 was used? macro_version=$macro_version macro_revision=$macro_revision # Whether or not to build shared libraries. build_libtool_libs=$enable_shared # Whether or not to build static libraries. build_old_libs=$enable_static # What type of objects to build. pic_mode=$pic_mode # Whether or not to optimize for fast installation. fast_install=$enable_fast_install # Shell to use when invoking shell scripts. SHELL=$lt_SHELL # An echo program that protects backslashes. ECHO=$lt_ECHO # The PATH separator for the build system. PATH_SEPARATOR=$lt_PATH_SEPARATOR # The host system. host_alias=$host_alias host=$host host_os=$host_os # The build system. build_alias=$build_alias build=$build build_os=$build_os # A sed program that does not truncate output. SED=$lt_SED # Sed that helps us avoid accidentally triggering echo(1) options like -n. Xsed="\$SED -e 1s/^X//" # A grep program that handles long lines. GREP=$lt_GREP # An ERE matcher. EGREP=$lt_EGREP # A literal string matcher. FGREP=$lt_FGREP # A BSD- or MS-compatible name lister. NM=$lt_NM # Whether we need soft or hard links. LN_S=$lt_LN_S # What is the maximum length of a command? max_cmd_len=$max_cmd_len # Object file suffix (normally "o"). objext=$ac_objext # Executable file suffix (normally ""). exeext=$exeext # whether the shell understands "unset". lt_unset=$lt_unset # turn spaces into newlines. SP2NL=$lt_lt_SP2NL # turn newlines into spaces. NL2SP=$lt_lt_NL2SP # convert \$build file names to \$host format. to_host_file_cmd=$lt_cv_to_host_file_cmd # convert \$build files to toolchain format. to_tool_file_cmd=$lt_cv_to_tool_file_cmd # An object symbol dumper. OBJDUMP=$lt_OBJDUMP # Method to check whether dependent libraries are shared objects. deplibs_check_method=$lt_deplibs_check_method # Command to use when deplibs_check_method = "file_magic". file_magic_cmd=$lt_file_magic_cmd # How to find potential files when deplibs_check_method = "file_magic". file_magic_glob=$lt_file_magic_glob # Find potential files using nocaseglob when deplibs_check_method = "file_magic". want_nocaseglob=$lt_want_nocaseglob # DLL creation program. DLLTOOL=$lt_DLLTOOL # Command to associate shared and link libraries. sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd # The archiver. AR=$lt_AR # Flags to create an archive. AR_FLAGS=$lt_AR_FLAGS # How to feed a file listing to the archiver. archiver_list_spec=$lt_archiver_list_spec # A symbol stripping program. STRIP=$lt_STRIP # Commands used to install an old-style archive. RANLIB=$lt_RANLIB old_postinstall_cmds=$lt_old_postinstall_cmds old_postuninstall_cmds=$lt_old_postuninstall_cmds # Whether to use a lock for old archive extraction. lock_old_archive_extraction=$lock_old_archive_extraction # A C compiler. LTCC=$lt_CC # LTCC compiler flags. LTCFLAGS=$lt_CFLAGS # Take the output of nm and produce a listing of raw symbols and C names. global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe # Transform the output of nm in a proper C declaration. global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl # Transform the output of nm in a C name address pair. global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address # Transform the output of nm in a C name address pair when lib prefix is needed. global_symbol_to_c_name_address_lib_prefix=$lt_lt_cv_sys_global_symbol_to_c_name_address_lib_prefix # Specify filename containing input files for \$NM. nm_file_list_spec=$lt_nm_file_list_spec # The root where to search for dependent libraries,and in which our libraries should be installed. lt_sysroot=$lt_sysroot # The name of the directory that contains temporary libtool files. objdir=$objdir # Used to examine libraries when file_magic_cmd begins with "file". MAGIC_CMD=$MAGIC_CMD # Must we lock files when doing compilation? need_locks=$lt_need_locks # Manifest tool. MANIFEST_TOOL=$lt_MANIFEST_TOOL # Tool to manipulate archived DWARF debug symbol files on Mac OS X. DSYMUTIL=$lt_DSYMUTIL # Tool to change global to local symbols on Mac OS X. NMEDIT=$lt_NMEDIT # Tool to manipulate fat objects and archives on Mac OS X. LIPO=$lt_LIPO # ldd/readelf like tool for Mach-O binaries on Mac OS X. OTOOL=$lt_OTOOL # ldd/readelf like tool for 64 bit Mach-O binaries on Mac OS X 10.4. OTOOL64=$lt_OTOOL64 # Old archive suffix (normally "a"). libext=$libext # Shared library suffix (normally ".so"). shrext_cmds=$lt_shrext_cmds # The commands to extract the exported symbol list from a shared archive. extract_expsyms_cmds=$lt_extract_expsyms_cmds # Variables whose values should be saved in libtool wrapper scripts and # restored at link time. variables_saved_for_relink=$lt_variables_saved_for_relink # Do we need the "lib" prefix for modules? need_lib_prefix=$need_lib_prefix # Do we need a version for libraries? need_version=$need_version # Library versioning type. version_type=$version_type # Shared library runtime path variable. runpath_var=$runpath_var # Shared library path variable. shlibpath_var=$shlibpath_var # Is shlibpath searched before the hard-coded library search path? shlibpath_overrides_runpath=$shlibpath_overrides_runpath # Format of library name prefix. libname_spec=$lt_libname_spec # List of archive names. First name is the real one, the rest are links. # The last name is the one that the linker finds with -lNAME library_names_spec=$lt_library_names_spec # The coded name of the library, if different from the real name. soname_spec=$lt_soname_spec # Permission mode override for installation of shared libraries. install_override_mode=$lt_install_override_mode # Command to use after installation of a shared archive. postinstall_cmds=$lt_postinstall_cmds # Command to use after uninstallation of a shared archive. postuninstall_cmds=$lt_postuninstall_cmds # Commands used to finish a libtool library installation in a directory. finish_cmds=$lt_finish_cmds # As "finish_cmds", except a single script fragment to be evaled but # not shown. finish_eval=$lt_finish_eval # Whether we should hardcode library paths into libraries. hardcode_into_libs=$hardcode_into_libs # Compile-time system search path for libraries. sys_lib_search_path_spec=$lt_sys_lib_search_path_spec # Run-time system search path for libraries. sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec # Whether dlopen is supported. dlopen_support=$enable_dlopen # Whether dlopen of programs is supported. dlopen_self=$enable_dlopen_self # Whether dlopen of statically linked programs is supported. dlopen_self_static=$enable_dlopen_self_static # Commands to strip libraries. old_striplib=$lt_old_striplib striplib=$lt_striplib # The linker used to build libraries. LD=$lt_LD # How to create reloadable object files. reload_flag=$lt_reload_flag reload_cmds=$lt_reload_cmds # Commands used to build an old-style archive. old_archive_cmds=$lt_old_archive_cmds # A language specific compiler. CC=$lt_compiler # Is the compiler the GNU compiler? with_gcc=$GCC # Compiler flag to turn off builtin functions. no_builtin_flag=$lt_lt_prog_compiler_no_builtin_flag # Additional compiler flags for building library objects. pic_flag=$lt_lt_prog_compiler_pic # How to pass a linker flag through the compiler. wl=$lt_lt_prog_compiler_wl # Compiler flag to prevent dynamic linking. link_static_flag=$lt_lt_prog_compiler_static # Does compiler simultaneously support -c and -o options? compiler_c_o=$lt_lt_cv_prog_compiler_c_o # Whether or not to add -lc for building shared libraries. build_libtool_need_lc=$archive_cmds_need_lc # Whether or not to disallow shared libs when runtime libs are static. allow_libtool_libs_with_static_runtimes=$enable_shared_with_static_runtimes # Compiler flag to allow reflexive dlopens. export_dynamic_flag_spec=$lt_export_dynamic_flag_spec # Compiler flag to generate shared objects directly from archives. whole_archive_flag_spec=$lt_whole_archive_flag_spec # Whether the compiler copes with passing no objects directly. compiler_needs_object=$lt_compiler_needs_object # Create an old-style archive from a shared archive. old_archive_from_new_cmds=$lt_old_archive_from_new_cmds # Create a temporary old-style archive to link instead of a shared archive. old_archive_from_expsyms_cmds=$lt_old_archive_from_expsyms_cmds # Commands used to build a shared archive. archive_cmds=$lt_archive_cmds archive_expsym_cmds=$lt_archive_expsym_cmds # Commands used to build a loadable module if different from building # a shared archive. module_cmds=$lt_module_cmds module_expsym_cmds=$lt_module_expsym_cmds # Whether we are building with GNU ld or not. with_gnu_ld=$lt_with_gnu_ld # Flag that allows shared libraries with undefined symbols to be built. allow_undefined_flag=$lt_allow_undefined_flag # Flag that enforces no undefined symbols. no_undefined_flag=$lt_no_undefined_flag # Flag to hardcode \$libdir into a binary during linking. # This must work even if \$libdir does not exist hardcode_libdir_flag_spec=$lt_hardcode_libdir_flag_spec # Whether we need a single "-rpath" flag with a separated argument. hardcode_libdir_separator=$lt_hardcode_libdir_separator # Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes # DIR into the resulting binary. hardcode_direct=$hardcode_direct # Set to "yes" if using DIR/libNAME\${shared_ext} during linking hardcodes # DIR into the resulting binary and the resulting library dependency is # "absolute",i.e impossible to change by setting \${shlibpath_var} if the # library is relocated. hardcode_direct_absolute=$hardcode_direct_absolute # Set to "yes" if using the -LDIR flag during linking hardcodes DIR # into the resulting binary. hardcode_minus_L=$hardcode_minus_L # Set to "yes" if using SHLIBPATH_VAR=DIR during linking hardcodes DIR # into the resulting binary. hardcode_shlibpath_var=$hardcode_shlibpath_var # Set to "yes" if building a shared library automatically hardcodes DIR # into the library and all subsequent libraries and executables linked # against it. hardcode_automatic=$hardcode_automatic # Set to yes if linker adds runtime paths of dependent libraries # to runtime path list. inherit_rpath=$inherit_rpath # Whether libtool must link a program against all its dependency libraries. link_all_deplibs=$link_all_deplibs # Set to "yes" if exported symbols are required. always_export_symbols=$always_export_symbols # The commands to list exported symbols. export_symbols_cmds=$lt_export_symbols_cmds # Symbols that should not be listed in the preloaded symbols. exclude_expsyms=$lt_exclude_expsyms # Symbols that must always be exported. include_expsyms=$lt_include_expsyms # Commands necessary for linking programs (against libraries) with templates. prelink_cmds=$lt_prelink_cmds # Commands necessary for finishing linking programs. postlink_cmds=$lt_postlink_cmds # Specify filename containing input files. file_list_spec=$lt_file_list_spec # How to hardcode a shared library path into an executable. hardcode_action=$hardcode_action # ### END LIBTOOL CONFIG _LT_EOF case $host_os in aix3*) cat <<\_LT_EOF >> "$cfgfile" # AIX sometimes has problems with the GCC collect2 program. For some # reason, if we set the COLLECT_NAMES environment variable, the problems # vanish in a puff of smoke. if test "X${COLLECT_NAMES+set}" != Xset; then COLLECT_NAMES= export COLLECT_NAMES fi _LT_EOF ;; esac ltmain="$ac_aux_dir/ltmain.sh" # We use sed instead of cat because bash on DJGPP gets confused if # if finds mixed CR/LF and LF-only lines. Since sed operates in # text mode, it properly converts lines to CR/LF. This bash problem # is reportedly fixed, but why not run on old versions too? sed '$q' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) if test x"$xsi_shell" = xyes; then sed -e '/^func_dirname ()$/,/^} # func_dirname /c\ func_dirname ()\ {\ \ case ${1} in\ \ */*) func_dirname_result="${1%/*}${2}" ;;\ \ * ) func_dirname_result="${3}" ;;\ \ esac\ } # Extended-shell func_dirname implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_basename ()$/,/^} # func_basename /c\ func_basename ()\ {\ \ func_basename_result="${1##*/}"\ } # Extended-shell func_basename implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_dirname_and_basename ()$/,/^} # func_dirname_and_basename /c\ func_dirname_and_basename ()\ {\ \ case ${1} in\ \ */*) func_dirname_result="${1%/*}${2}" ;;\ \ * ) func_dirname_result="${3}" ;;\ \ esac\ \ func_basename_result="${1##*/}"\ } # Extended-shell func_dirname_and_basename implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_stripname ()$/,/^} # func_stripname /c\ func_stripname ()\ {\ \ # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are\ \ # positional parameters, so assign one to ordinary parameter first.\ \ func_stripname_result=${3}\ \ func_stripname_result=${func_stripname_result#"${1}"}\ \ func_stripname_result=${func_stripname_result%"${2}"}\ } # Extended-shell func_stripname implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_split_long_opt ()$/,/^} # func_split_long_opt /c\ func_split_long_opt ()\ {\ \ func_split_long_opt_name=${1%%=*}\ \ func_split_long_opt_arg=${1#*=}\ } # Extended-shell func_split_long_opt implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_split_short_opt ()$/,/^} # func_split_short_opt /c\ func_split_short_opt ()\ {\ \ func_split_short_opt_arg=${1#??}\ \ func_split_short_opt_name=${1%"$func_split_short_opt_arg"}\ } # Extended-shell func_split_short_opt implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_lo2o ()$/,/^} # func_lo2o /c\ func_lo2o ()\ {\ \ case ${1} in\ \ *.lo) func_lo2o_result=${1%.lo}.${objext} ;;\ \ *) func_lo2o_result=${1} ;;\ \ esac\ } # Extended-shell func_lo2o implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_xform ()$/,/^} # func_xform /c\ func_xform ()\ {\ func_xform_result=${1%.*}.lo\ } # Extended-shell func_xform implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_arith ()$/,/^} # func_arith /c\ func_arith ()\ {\ func_arith_result=$(( $* ))\ } # Extended-shell func_arith implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_len ()$/,/^} # func_len /c\ func_len ()\ {\ func_len_result=${#1}\ } # Extended-shell func_len implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: fi if test x"$lt_shell_append" = xyes; then sed -e '/^func_append ()$/,/^} # func_append /c\ func_append ()\ {\ eval "${1}+=\\${2}"\ } # Extended-shell func_append implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: sed -e '/^func_append_quoted ()$/,/^} # func_append_quoted /c\ func_append_quoted ()\ {\ \ func_quote_for_eval "${2}"\ \ eval "${1}+=\\\\ \\$func_quote_for_eval_result"\ } # Extended-shell func_append_quoted implementation' "$cfgfile" > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: # Save a `func_append' function call where possible by direct use of '+=' sed -e 's%func_append \([a-zA-Z_]\{1,\}\) "%\1+="%g' $cfgfile > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: else # Save a `func_append' function call even when '+=' is not available sed -e 's%func_append \([a-zA-Z_]\{1,\}\) "%\1="$\1%g' $cfgfile > $cfgfile.tmp \ && mv -f "$cfgfile.tmp" "$cfgfile" \ || (rm -f "$cfgfile" && cp "$cfgfile.tmp" "$cfgfile" && rm -f "$cfgfile.tmp") test 0 -eq $? || _lt_function_replace_fail=: fi if test x"$_lt_function_replace_fail" = x":"; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Unable to substitute extended shell functions in $ofile" >&5 printf "%s\n" "$as_me: WARNING: Unable to substitute extended shell functions in $ofile" >&2;} fi mv -f "$cfgfile" "$ofile" || (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile") chmod +x "$ofile" ;; esac done # for ac_tag as_fn_exit 0 _ACEOF ac_clean_files=$ac_clean_files_save test $ac_write_fail = 0 || as_fn_error $? "write failure creating $CONFIG_STATUS" "$LINENO" 5 # configure is writing to config.log, and then calls config.status. # config.status does its own redirection, appending to config.log. # Unfortunately, on DOS this fails, as config.log is still kept open # by configure, so config.status won't be able to write to it; its # output is simply discarded. So we exec the FD to /dev/null, # effectively closing config.log, so it can be properly (re)opened and # appended to by config.status. When coming back to configure, we # need to make the FD available again. if test "$no_create" != yes; then ac_cs_success=: ac_config_status_args= test "$silent" = yes && ac_config_status_args="$ac_config_status_args --quiet" exec 5>/dev/null $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false exec 5>>config.log # Use ||, not &&, to avoid exiting from the if with $? = 1, which # would make configure fail if this is the last instruction. $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi openbgpd-8.8/configure.ac100644 001750 001750 00000036744 14730104726 0011201# # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. AC_INIT([OpenBGPD], m4_esyscmd([tr -d '\n' < VERSION])) AC_CANONICAL_HOST AM_INIT_AUTOMAKE([subdir-objects foreign]) AC_CONFIG_MACRO_DIR([m4]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AC_PROG_CC([cc gcc]) case $host_os in *linux*) AC_USE_SYSTEM_EXTENSIONS ;; *) ;; esac case $host_os in *darwin*) HOST_OS=darwin AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV]) # # Don't use arc4random on systems before 10.12 because of # weak seed on failure to open /dev/random, based on latest # public source: # http://www.opensource.apple.com/source/Libc/Libc-997.90.3/gen/FreeBSD/arc4random.c # # We use the presence of getentropy() to detect 10.12. The # following check take into account that: # # - iOS <= 10.1 fails because of missing getentropy and # hence they miss sys/random.h # # - in macOS 10.12 getentropy is not tagged as introduced in # 10.12 so we cannot use it for target < 10.12 # AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include #include #include /* Systems without getentropy() should die here */ /* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */ #ifndef MAC_OS_X_VERSION_10_12 # define MAC_OS_X_VERSION_10_12 101200 #endif #if defined(MAC_OS_X_VERSION_MIN_REQUIRED) # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 # error "Running on Mac OSX 10.11 or earlier" # endif #endif ]], [[ char buf[1]; getentropy(buf, 1); ]])], [ USE_BUILTIN_ARC4RANDOM=no ], [ USE_BUILTIN_ARC4RANDOM=yes ] ) AC_MSG_CHECKING([whether to use builtin arc4random]) AC_MSG_RESULT([$USE_BUILTIN_ARC4RANDOM]) ;; *freebsd*) HOST_OS=freebsd AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include #if __FreeBSD_version < 1200000 undefined #endif ]], [[]])], [ USE_BUILTIN_ARC4RANDOM=no ], [ USE_BUILTIN_ARC4RANDOM=yes ] ) ;; *linux*) HOST_OS=linux AM_CFLAGS="-D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE" AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV]) ;; *netbsd*) HOST_OS=netbsd AM_CFLAGS="-D_OPENBSD_SOURCE" AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include #if __NetBSD_Version__ < 700000001 undefined #endif ]], [[]])], [ USE_BUILTIN_ARC4RANDOM=no ], [ USE_BUILTIN_ARC4RANDOM=yes ] ) ;; *openbsd*) HOST_OS=openbsd AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__]) AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead]) AC_DEFINE([HAVE_ATTRIBUTE__PACKED], [1], [OpenBSD has __packed]) ;; *solaris*) HOST_OS=solaris AM_CFLAGS="-D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP" ;; *) ;; esac AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin]) AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd]) AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux]) AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd]) AM_CONDITIONAL([HOST_OPENBSD], [test x$HOST_OS = xopenbsd]) AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris]) AC_PROG_SED AC_PROG_CC AM_PROG_CC_C_O LT_INIT AC_PROG_YACC AC_ARG_ENABLE(bgplgd, AS_HELP_STRING([--disable-bgplgd], [ build bgplgd [default=enabled]]), [case $enableval in yes) enable_bgplgd=yes;; no) enable_bgplgd=no;; *) enable_bgplgd=yes;; esac], enable_bgplgd=yes) AC_ARG_ENABLE(fib-support, AS_HELP_STRING([--disable-fib-support], [ build without fib support [default=enabled]]), [case $enableval in yes) disable_fib=no;; no) disable_fib=yes;; *) disable_fib=no;; esac], disable_fib=no) AC_ARG_ENABLE(warnings, AS_HELP_STRING([--disable-warnings], [ enable compiler warnings [default=enabled]]), [case $enableval in yes) enable_warnings=yes;; no) enable_warnings=no;; *) enable_warnings=yes;; esac], enable_warnings=yes) if test "$enable_warnings" = yes; then AM_CFLAGS="$AM_CFLAGS -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare" save_cflags="$CFLAGS" CFLAGS=-Wno-pointer-sign AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], [AC_MSG_RESULT([yes])] [WARN_CFLAGS=-Wno-pointer-sign], [AC_MSG_RESULT([no])] ) AM_CFLAGS="$AM_CFLAGS $WARN_CFLAGS" CFLAGS="$save_cflags" fi AC_MSG_CHECKING([if compiling with clang]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ #ifndef __clang__ not clang #endif ]])], [AC_MSG_RESULT([yes])] [CLANG_FLAGS=-Qunused-arguments], [AC_MSG_RESULT([no])] ) AM_CFLAGS="$AM_CFLAGS $CLANG_FLAGS" AM_LDFLAGS="$AM_LDFLAGS $CLANG_FLAGS" # check for headers AC_CHECK_HEADERS([endian.h]) AC_CHECK_HEADERS([netinet/ip_ipsp.h], [], [], [[#include ]]) AC_CHECK_HEADERS([linux/in6.h]) AC_CHECK_HEADERS([linux/if.h]) # check functions that are expected to be in libc AC_CHECK_FUNCS([asprintf explicit_bzero]) AC_CHECK_FUNCS([reallocarray recallocarray freezero]) AC_CHECK_FUNCS([setproctitle setgroups]) AC_CHECK_FUNCS([setregid setresgid setreuid setresuid]) AC_CHECK_FUNCS([strlcat strlcpy strtonum sysconf]) AC_CHECK_FUNCS([pledge unveil]) AC_CHECK_FUNCS([getdtablecount getrtable]) AC_CHECK_FUNCS([strnvis]) AC_CHECK_FUNCS([arc4random]) AC_CACHE_CHECK([for getentropy], ac_cv_func_getentropy, [ AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include #include /* * Explanation: * * - iOS <= 10.1 fails because of missing sys/random.h * * - in macOS 10.12 getentropy is not tagged as introduced in * 10.12 so we cannot use it for target < 10.12 */ #ifdef __APPLE__ # include # include # if (TARGET_OS_IPHONE || TARGET_OS_SIMULATOR) # include /* Not available as of iOS <= 10.1 */ # else # include /* Pre 10.12 systems should die here */ /* Based on: https://gitweb.torproject.org/tor.git/commit/?id=16fcbd21 */ # ifndef MAC_OS_X_VERSION_10_12 # define MAC_OS_X_VERSION_10_12 101200 /* Robustness */ # endif # if defined(MAC_OS_X_VERSION_MIN_REQUIRED) # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12 # error "Targeting on Mac OSX 10.11 or earlier" # endif # endif # endif #endif /* __APPLE__ */ ]], [[ char buffer; (void)getentropy(&buffer, sizeof (buffer)); ]])], [ ac_cv_func_getentropy="yes" ], [ ac_cv_func_getentropy="no" ]) ]) # check auxiliary libraries that might contain other functions AC_SEARCH_LIBS([clock_gettime],[rt posix4]) AC_SEARCH_LIBS([inet_net_pton],[resolv]) AC_CHECK_FUNCS([clock_gettime inet_net_pton]) # check needed libutil functions AC_SEARCH_LIBS([ibuf_open], [util]) AC_SEARCH_LIBS([fmt_scaled], [util]) AC_CHECK_FUNCS([ibuf_open imsgbuf_init fmt_scaled]) # check if HOST_NAME_MAX is available AC_MSG_CHECKING([for HOST_NAME_MAX]) AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[ #include #include ]], [[ char buf[HOST_NAME_MAX + 1]; ]])], [AC_MSG_RESULT([yes]) AC_DEFINE(HAVE_HOST_NAME_MAX) ], [AC_MSG_RESULT([no])] ) # check if pftable code can be used AC_CHECK_HEADERS([net/pfvar.h], [ AC_MSG_CHECKING([for working pftable]) AC_COMPILE_IFELSE( [AC_LANG_PROGRAM([[ #include #include #include #include ]], [[ struct pfioc_table tio; struct pfr_astats dummy; struct pfr_addr pfa; int a = DIOCRCLRADDRS, b = DIOCRGETASTATS, c = DIOCRDELADDRS, d = DIOCRADDADDRS; ]])], [AC_MSG_RESULT([yes]) ac_cv_have_pftable="yes" ], [AC_MSG_RESULT([no])] )], [], [[ #include #include ]]) dnl NetBSD added an strnvis and unfortunately made it incompatible with the dnl existing one in OpenBSD and Linux's libbsd (the former having existed dnl for over ten years). Despite this incompatibility being reported during dnl development (see http://gnats.netbsd.org/44977) they still shipped it. dnl Even more unfortunately FreeBSD and later MacOS picked up this incompatible dnl implementation. Try to detect this mess, and assume the only safe option dnl if we're cross compiling. dnl dnl OpenBSD, 2001: strnvis(char *dst, const char *src, size_t dlen, int flag); dnl NetBSD: 2012, strnvis(char *dst, size_t dlen, const char *src, int flag); if test "x$ac_cv_func_strnvis" = "xyes"; then AC_MSG_CHECKING([for working strnvis]) AC_RUN_IFELSE( [AC_LANG_PROGRAM([[ #include #include #include #include #include static void sighandler(int sig) { _exit(1); } ]], [[ char dst[16]; signal(SIGSEGV, sighandler); if (strnvis(dst, "src", 4, 0) && strcmp(dst, "src") == 0) exit(0); exit(1) ]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no]) ac_cv_broken_strnvis="yes" ], [AC_MSG_WARN([cross compiling: assuming broken]) ac_cv_broken_strnvis="yes" ] ) fi if test "$disable_fib" = no; then # check for libmnl AC_CHECK_LIB([mnl], [mnl_socket_recvfrom], [], []) if test "x$ac_cv_lib_mnl_mnl_socket_recvfrom" = "xyes"; then AC_CHECK_FUNCS([mnl_socket_open2], [], [AC_MSG_ERROR([libmnl >= 1.0.4 required])]) fi fi # Share test results with automake AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes]) AM_CONDITIONAL([HAVE_CLOCK_GETRES], [test "x$ac_cv_func_clock_getres" = xyes]) AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes]) AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes]) AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes]) AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes -a "x$ac_cv_func_imsgbuf_init" = xyes]) AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes]) AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes]) AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) AM_CONDITIONAL([HAVE_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" = xyes]) AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes]) AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes]) AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes]) AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes]) AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes]) AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes]) AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes]) AM_CONDITIONAL([HAVE_SYSCONF], [test "x$ac_cv_func_sysconf" = xyes]) AM_CONDITIONAL([HAVE_PLEDGE], [test "x$ac_cv_func_pledge" = xyes]) AM_CONDITIONAL([HAVE_UNVEIL], [test "x$ac_cv_func_unveil" = xyes]) AM_CONDITIONAL([HAVE_GETDTABLECOUNT], [test "x$ac_cv_func_getdtablecount" = xyes]) AM_CONDITIONAL([HAVE_GETRTABLE], [test "x$ac_cv_func_getrtable" = xyes]) AM_CONDITIONAL([HAVE_STRNVIS], [test "x$ac_cv_func_strnvis" = xyes]) AM_CONDITIONAL([BROKEN_STRNVIS], [test "x$ac_cv_broken_strnvis" = xyes]) AM_CONDITIONAL([HAVE_INET_NET_PTON], [test "x$ac_cv_func_inet_net_pton" = xyes]) AM_CONDITIONAL([HAVE_FMT_SCALED], [test "x$ac_cv_func_fmt_scaled" = xyes]) AM_CONDITIONAL([HAVE_MNL], [test "x$ac_cv_func_mnl_socket_open2" = "xyes"]) AM_CONDITIONAL([HAVE_PFTABLE], [test "x$ac_cv_have_pftable" = "xyes"]) # overrides for arc4random implementations with known issues AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$USE_BUILTIN_ARC4RANDOM" != xyes \ -a "x$ac_cv_func_arc4random" = xyes]) AC_CHECK_MEMBERS([struct tcp_md5sig.tcpm_key], , , [ #include #include #include ] ) AM_CONDITIONAL([HAVE_LINUX_TCPMD5], [test "x$ac_cv_member_struct_tcp_md5sig_tcpm_key" = xyes]) AC_CHECK_FUNCS([setfib]) AM_CONDITIONAL([HAVE_SETFIB], [test "x$HOST_OS" = xfreebsd \ -a "x$ac_cv_func_setfib" = "xyes"]) if test "$enable_bgplgd" = yes; then AC_ARG_WITH([event], AS_HELP_STRING([--with-event=pkg-name], [Use pkg-config(1) pkg-name to find libevent]), PKG_NAME="$withval" ) if test X"$PKG_NAME" != X; then LIBEVENT_CFLAGS=`pkg-config --cflags-only-I $PKG_NAME 2>/dev/null` LIBEVENT_LDFLAGS=`pkg-config --libs-only-L $PKG_NAME 2>/dev/null` fi AC_ARG_WITH([event-cflags], AS_HELP_STRING([--with-event-cflags=STRING], [Extra compiler flags to build with libevent]), LIBEVENT_CFLAGS="$withval" ) AC_ARG_WITH([event-ldflags], AS_HELP_STRING([--with-event-ldflags=STRING], [Extra flags for linker to link with libevent]), LIBEVENT_LDFLAGS="$withval" ) AM_CFLAGS="$AM_CFLAGS $LIBEVENT_CFLAGS" AM_LDFLAGS="$AM_LDFLAGS $LIBEVENT_LDFLAGS" save_cflags="$CFLAGS" save_ldflags="$LDFLAGS" CFLAGS="$AM_CFLAGS $CFLAGS" LDFLAGS="$AM_LDFLAGS $LDFLAGS" AC_CHECK_HEADERS([event.h], [], [AC_MSG_ERROR([libevent headers required])]) AC_CHECK_LIB([event], [event_init], [], [AC_MSG_ERROR([libevent required])]) AC_CHECK_FUNCS([event_init event_dispatch], [], [AC_MSG_ERROR([libevent required])]) CFLAGS="$save_cflags" LDFLAGS="$save_ldflags" fi AC_ARG_WITH([privsep-user], AS_HELP_STRING([--with-privsep-user=user], [Privilege separation user for bgpd]), BGPD_USER="$withval", BGPD_USER="_bgpd" ) AC_DEFINE_UNQUOTED(BGPD_USER, "$BGPD_USER", [Unprivileged user]) AC_SUBST(BGPD_USER) if test "$enable_bgplgd" = yes; then AC_ARG_WITH([bgplgd-user], AS_HELP_STRING([--with-bgplgd-user=user], [Privilege drop user for bgplgd]), BGPLGD_USER="$withval", BGPLGD_USER="_bgplgd" ) AC_DEFINE_UNQUOTED(BGPLGD_USER, "$BGPLGD_USER", [bgplgd unprivileged user]) AC_SUBST(BGPLGD_USER) AC_ARG_WITH([www-user], AS_HELP_STRING([--with-www-user=user], [Owner of the FastCGI socket used by bgplgd]), WWW_USER="$withval", WWW_USER="www" ) AC_DEFINE_UNQUOTED(WWW_USER, "$WWW_USER", [www unprivileged user]) AC_SUBST(WWW_USER) AC_ARG_WITH([wwwrunstatedir], AS_HELP_STRING([--with-wwwrunstatedir=DIR], [Location for bgplgd FastCGI socket [LOCALSTATEDIR/www/run]]), wwwrunstatedir="$withval" ) if test "x$runstatedir" = x; then wwwrunstatedir='${localstatedir}/www/run' AC_SUBST(wwwrunstatedir) fi fi AM_CONDITIONAL([BUILD_BGPLGD], [test "$enable_bgplgd" = yes]) AM_CONDITIONAL([DISABLE_FIB], [test "$disable_fib" = yes]) # workaround the issue that there is no autoconf release supporting # runstatedir but many linux distros patched their versions instead # Check if the variable is set, if not use a basic default. AC_ARG_WITH([runstatedir], AS_HELP_STRING([--with-runstatedir=DIR], [Location for bgpd control socket [LOCALSTATEDIR/run]]), runstatedir="$withval" ) if test "x$runstatedir" = x; then runstatedir='${localstatedir}/run' AC_SUBST(runstatedir) fi AC_SUBST(AM_CFLAGS) AC_SUBST(AM_LDFLAGS) AC_CONFIG_FILES([ Makefile include/Makefile compat/Makefile src/bgpctl/Makefile src/bgpd/Makefile src/bgplgd/Makefile ]) AC_OUTPUT openbgpd-8.8/aclocal.m4100644 001750 001750 00000122736 14751151137 0010551# generated automatically by aclocal 1.16.5 -*- Autoconf -*- # Copyright (C) 1996-2021 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.72],, [m4_warning([this file was generated for autoconf 2.72. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) # Copyright (C) 2002-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_AUTOMAKE_VERSION(VERSION) # ---------------------------- # Automake X.Y traces this macro to ensure aclocal.m4 has been # generated from the m4 files accompanying Automake X.Y. # (This private macro should not be called outside this file.) AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.16' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. m4_if([$1], [1.16.5], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) # _AM_AUTOCONF_VERSION(VERSION) # ----------------------------- # aclocal traces this macro to find the Autoconf version. # This is a private macro too. Using m4_define simplifies # the logic in aclocal, which can simply ignore this definition. m4_define([_AM_AUTOCONF_VERSION], []) # AM_SET_CURRENT_AUTOMAKE_VERSION # ------------------------------- # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], [AM_AUTOMAKE_VERSION([1.16.5])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- # Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets # $ac_aux_dir to '$srcdir/foo'. In other projects, it is set to # '$srcdir', '$srcdir/..', or '$srcdir/../..'. # # Of course, Automake must honor this variable whenever it calls a # tool from the auxiliary directory. The problem is that $srcdir (and # therefore $ac_aux_dir as well) can be either absolute or relative, # depending on how configure is run. This is pretty annoying, since # it makes $ac_aux_dir quite unusable in subdirectories: in the top # source directory, any form will work fine, but in subdirectories a # relative path needs to be adjusted first. # # $ac_aux_dir/missing # fails when called from a subdirectory if $ac_aux_dir is relative # $top_srcdir/$ac_aux_dir/missing # fails if $ac_aux_dir is absolute, # fails when called from a subdirectory in a VPATH build with # a relative $ac_aux_dir # # The reason of the latter failure is that $top_srcdir and $ac_aux_dir # are both prefixed by $srcdir. In an in-source build this is usually # harmless because $srcdir is '.', but things will broke when you # start a VPATH build or use an absolute $srcdir. # # So we could use something similar to $top_srcdir/$ac_aux_dir/missing, # iff we strip the leading $srcdir from $ac_aux_dir. That would be: # am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"` # and then we would define $MISSING as # MISSING="\${SHELL} $am_aux_dir/missing" # This will work as long as MISSING is not called from configure, because # unfortunately $(top_srcdir) has no meaning in configure. # However there are other variables, like CC, which are often used in # configure, and could therefore not use this "fixed" $ac_aux_dir. # # Another solution, used here, is to always expand $ac_aux_dir to an # absolute PATH. The drawback is that using absolute paths prevent a # configured tree to be moved without reconfiguration. AC_DEFUN([AM_AUX_DIR_EXPAND], [AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl # Expand $ac_aux_dir to an absolute path. am_aux_dir=`cd "$ac_aux_dir" && pwd` ]) # AM_CONDITIONAL -*- Autoconf -*- # Copyright (C) 1997-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_CONDITIONAL(NAME, SHELL-CONDITION) # ------------------------------------- # Define a conditional. AC_DEFUN([AM_CONDITIONAL], [AC_PREREQ([2.52])dnl m4_if([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])], [$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl AC_SUBST([$1_TRUE])dnl AC_SUBST([$1_FALSE])dnl _AM_SUBST_NOTMAKE([$1_TRUE])dnl _AM_SUBST_NOTMAKE([$1_FALSE])dnl m4_define([_AM_COND_VALUE_$1], [$2])dnl if $2; then $1_TRUE= $1_FALSE='#' else $1_TRUE='#' $1_FALSE= fi AC_CONFIG_COMMANDS_PRE( [if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then AC_MSG_ERROR([[conditional "$1" was never defined. Usually this means the macro was only invoked conditionally.]]) fi])]) # Copyright (C) 1999-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # There are a few dirty hacks below to avoid letting 'AC_PROG_CC' be # written in clear, in which case automake, when reading aclocal.m4, # will think it sees a *use*, and therefore will trigger all it's # C support machinery. Also note that it means that autoscan, seeing # CC etc. in the Makefile, will ask for an AC_PROG_CC use... # _AM_DEPENDENCIES(NAME) # ---------------------- # See how the compiler implements dependency checking. # NAME is "CC", "CXX", "OBJC", "OBJCXX", "UPC", or "GJC". # We try a few techniques and use that to set a single cache variable. # # We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was # modified to invoke _AM_DEPENDENCIES(CC); we would have a circular # dependency, and given that the user is not expected to run this macro, # just rely on AC_PROG_CC. AC_DEFUN([_AM_DEPENDENCIES], [AC_REQUIRE([AM_SET_DEPDIR])dnl AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl AC_REQUIRE([AM_MAKE_INCLUDE])dnl AC_REQUIRE([AM_DEP_TRACK])dnl m4_if([$1], [CC], [depcc="$CC" am_compiler_list=], [$1], [CXX], [depcc="$CXX" am_compiler_list=], [$1], [OBJC], [depcc="$OBJC" am_compiler_list='gcc3 gcc'], [$1], [OBJCXX], [depcc="$OBJCXX" am_compiler_list='gcc3 gcc'], [$1], [UPC], [depcc="$UPC" am_compiler_list=], [$1], [GCJ], [depcc="$GCJ" am_compiler_list='gcc3 gcc'], [depcc="$$1" am_compiler_list=]) AC_CACHE_CHECK([dependency style of $depcc], [am_cv_$1_dependencies_compiler_type], [if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For # instance it was reported that on HP-UX the gcc test will end up # making a dummy file named 'D' -- because '-MD' means "put the output # in D". rm -rf conftest.dir mkdir conftest.dir # Copy depcomp to subdir because otherwise we won't find it if we're # using a relative directory. cp "$am_depcomp" conftest.dir cd conftest.dir # We will build objects and dependencies in a subdirectory because # it helps to detect inapplicable dependency modes. For instance # both Tru64's cc and ICC support -MD to output dependencies as a # side effect of compilation, but ICC will put the dependencies in # the current directory while Tru64 will put them in the object # directory. mkdir sub am_cv_$1_dependencies_compiler_type=none if test "$am_compiler_list" = ""; then am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp` fi am__universal=false m4_case([$1], [CC], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac], [CXX], [case " $depcc " in #( *\ -arch\ *\ -arch\ *) am__universal=true ;; esac]) for depmode in $am_compiler_list; do # Setup a source with many dependencies, because some compilers # like to wrap large dependency lists on column 80 (with \), and # we should not choose a depcomp mode which is confused by this. # # We need to recreate these files for each test, as the compiler may # overwrite some of them when testing with obscure command lines. # This happens at least with the AIX C compiler. : > sub/conftest.c for i in 1 2 3 4 5 6; do echo '#include "conftst'$i'.h"' >> sub/conftest.c # Using ": > sub/conftst$i.h" creates only sub/conftst1.h with # Solaris 10 /bin/sh. echo '/* dummy */' > sub/conftst$i.h done echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf # We check with '-c' and '-o' for the sake of the "dashmstdout" # mode. It turns out that the SunPro C++ compiler does not properly # handle '-M -o', and we need to detect this. Also, some Intel # versions had trouble with output in subdirs. am__obj=sub/conftest.${OBJEXT-o} am__minus_obj="-o $am__obj" case $depmode in gcc) # This depmode causes a compiler race in universal mode. test "$am__universal" = false || continue ;; nosideeffect) # After this tag, mechanisms are not by side-effect, so they'll # only be used when explicitly requested. if test "x$enable_dependency_tracking" = xyes; then continue else break fi ;; msvc7 | msvc7msys | msvisualcpp | msvcmsys) # This compiler won't grok '-c -o', but also, the minuso test has # not run yet. These depmodes are late enough in the game, and # so weak that their functioning should not be impacted. am__obj=conftest.${OBJEXT-o} am__minus_obj= ;; none) break ;; esac if depmode=$depmode \ source=sub/conftest.c object=$am__obj \ depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \ $SHELL ./depcomp $depcc -c $am__minus_obj sub/conftest.c \ >/dev/null 2>conftest.err && grep sub/conftst1.h sub/conftest.Po > /dev/null 2>&1 && grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 && grep $am__obj sub/conftest.Po > /dev/null 2>&1 && ${MAKE-make} -s -f confmf > /dev/null 2>&1; then # icc doesn't choke on unknown options, it will just issue warnings # or remarks (even with -Werror). So we grep stderr for any message # that says an option was ignored or not supported. # When given -MP, icc 7.0 and 7.1 complain thusly: # icc: Command line warning: ignoring option '-M'; no argument required # The diagnosis changed in icc 8.0: # icc: Command line remark: option '-MP' not supported if (grep 'ignoring option' conftest.err || grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else am_cv_$1_dependencies_compiler_type=$depmode break fi fi done cd .. rm -rf conftest.dir else am_cv_$1_dependencies_compiler_type=none fi ]) AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type]) AM_CONDITIONAL([am__fastdep$1], [ test "x$enable_dependency_tracking" != xno \ && test "$am_cv_$1_dependencies_compiler_type" = gcc3]) ]) # AM_SET_DEPDIR # ------------- # Choose a directory name for dependency files. # This macro is AC_REQUIREd in _AM_DEPENDENCIES. AC_DEFUN([AM_SET_DEPDIR], [AC_REQUIRE([AM_SET_LEADING_DOT])dnl AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl ]) # AM_DEP_TRACK # ------------ AC_DEFUN([AM_DEP_TRACK], [AC_ARG_ENABLE([dependency-tracking], [dnl AS_HELP_STRING( [--enable-dependency-tracking], [do not reject slow dependency extractors]) AS_HELP_STRING( [--disable-dependency-tracking], [speeds up one-time build])]) if test "x$enable_dependency_tracking" != xno; then am_depcomp="$ac_aux_dir/depcomp" AMDEPBACKSLASH='\' am__nodep='_no' fi AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno]) AC_SUBST([AMDEPBACKSLASH])dnl _AM_SUBST_NOTMAKE([AMDEPBACKSLASH])dnl AC_SUBST([am__nodep])dnl _AM_SUBST_NOTMAKE([am__nodep])dnl ]) # Generate code to set up dependency tracking. -*- Autoconf -*- # Copyright (C) 1999-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_OUTPUT_DEPENDENCY_COMMANDS # ------------------------------ AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS], [{ # Older Autoconf quotes --file arguments for eval, but not when files # are listed without --file. Let's play safe and only enable the eval # if we detect the quoting. # TODO: see whether this extra hack can be removed once we start # requiring Autoconf 2.70 or later. AS_CASE([$CONFIG_FILES], [*\'*], [eval set x "$CONFIG_FILES"], [*], [set x $CONFIG_FILES]) shift # Used to flag and report bootstrapping failures. am_rc=0 for am_mf do # Strip MF so we end up with the name of the file. am_mf=`AS_ECHO(["$am_mf"]) | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile which includes # dependency-tracking related rules and includes. # Grep'ing the whole file directly is not great: AIX grep has a line # limit of 2048, but all sed's we know have understand at least 4000. sed -n 's,^am--depfiles:.*,X,p' "$am_mf" | grep X >/dev/null 2>&1 \ || continue am_dirpart=`AS_DIRNAME(["$am_mf"])` am_filepart=`AS_BASENAME(["$am_mf"])` AM_RUN_LOG([cd "$am_dirpart" \ && sed -e '/# am--include-marker/d' "$am_filepart" \ | $MAKE -f - am--depfiles]) || am_rc=$? done if test $am_rc -ne 0; then AC_MSG_FAILURE([Something went wrong bootstrapping makefile fragments for automatic dependency tracking. If GNU make was not used, consider re-running the configure script with MAKE="gmake" (or whatever is necessary). You can also try re-running configure with the '--disable-dependency-tracking' option to at least be able to build the package (albeit without support for automatic dependency tracking).]) fi AS_UNSET([am_dirpart]) AS_UNSET([am_filepart]) AS_UNSET([am_mf]) AS_UNSET([am_rc]) rm -f conftest-deps.mk } ])# _AM_OUTPUT_DEPENDENCY_COMMANDS # AM_OUTPUT_DEPENDENCY_COMMANDS # ----------------------------- # This macro should only be invoked once -- use via AC_REQUIRE. # # This code is only required when automatic dependency tracking is enabled. # This creates each '.Po' and '.Plo' makefile fragment that we'll need in # order to bootstrap the dependency handling code. AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], [AC_CONFIG_COMMANDS([depfiles], [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS], [AMDEP_TRUE="$AMDEP_TRUE" MAKE="${MAKE-make}"])]) # Do all the work for Automake. -*- Autoconf -*- # Copyright (C) 1996-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This macro actually does too much. Some checks are only needed if # your package does certain things. But this isn't really a big deal. dnl Redefine AC_PROG_CC to automatically invoke _AM_PROG_CC_C_O. m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC]) [_AM_PROG_CC_C_O ]) # AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE]) # AM_INIT_AUTOMAKE([OPTIONS]) # ----------------------------------------------- # The call with PACKAGE and VERSION arguments is the old style # call (pre autoconf-2.50), which is being phased out. PACKAGE # and VERSION should now be passed to AC_INIT and removed from # the call to AM_INIT_AUTOMAKE. # We support both call styles for the transition. After # the next Automake release, Autoconf can make the AC_INIT # arguments mandatory, and then we can depend on a new Autoconf # release and drop the old call support. AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.65])dnl m4_ifdef([_$0_ALREADY_INIT], [m4_fatal([$0 expanded multiple times ]m4_defn([_$0_ALREADY_INIT]))], [m4_define([_$0_ALREADY_INIT], m4_expansion_stack)])dnl dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl the ones we care about. m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl AC_REQUIRE([AC_PROG_INSTALL])dnl if test "`cd $srcdir && pwd`" != "`pwd`"; then # Use -I$(srcdir) only when $(srcdir) != ., so that make's output # is not polluted with repeated "-I." AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl # test to see if srcdir already configured if test -f $srcdir/config.status; then AC_MSG_ERROR([source directory already configured; run "make distclean" there first]) fi fi # test whether we have cygpath if test -z "$CYGPATH_W"; then if (cygpath --version) >/dev/null 2>/dev/null; then CYGPATH_W='cygpath -w' else CYGPATH_W=echo fi fi AC_SUBST([CYGPATH_W]) # Define the identity of the package. dnl Distinguish between old-style and new-style calls. m4_ifval([$2], [AC_DIAGNOSE([obsolete], [$0: two- and three-arguments forms are deprecated.]) m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl AC_SUBST([PACKAGE], [$1])dnl AC_SUBST([VERSION], [$2])], [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. m4_if( m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([AC_PACKAGE_VERSION], [ok]), [ok:ok],, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl _AM_IF_OPTION([no-define],, [AC_DEFINE_UNQUOTED([PACKAGE], ["$PACKAGE"], [Name of package]) AC_DEFINE_UNQUOTED([VERSION], ["$VERSION"], [Version number of package])])dnl # Some tools Automake needs. AC_REQUIRE([AM_SANITY_CHECK])dnl AC_REQUIRE([AC_ARG_PROGRAM])dnl AM_MISSING_PROG([ACLOCAL], [aclocal-${am__api_version}]) AM_MISSING_PROG([AUTOCONF], [autoconf]) AM_MISSING_PROG([AUTOMAKE], [automake-${am__api_version}]) AM_MISSING_PROG([AUTOHEADER], [autoheader]) AM_MISSING_PROG([MAKEINFO], [makeinfo]) AC_REQUIRE([AM_PROG_INSTALL_SH])dnl AC_REQUIRE([AM_PROG_INSTALL_STRIP])dnl AC_REQUIRE([AC_PROG_MKDIR_P])dnl # For better backward compatibility. To be removed once Automake 1.9.x # dies out for good. For more background, see: # # AC_SUBST([mkdir_p], ['$(MKDIR_P)']) # We need awk for the "check" target (and possibly the TAP driver). The # system "awk" is bad on some platforms. AC_REQUIRE([AC_PROG_AWK])dnl AC_REQUIRE([AC_PROG_MAKE_SET])dnl AC_REQUIRE([AM_SET_LEADING_DOT])dnl _AM_IF_OPTION([tar-ustar], [_AM_PROG_TAR([ustar])], [_AM_IF_OPTION([tar-pax], [_AM_PROG_TAR([pax])], [_AM_PROG_TAR([v7])])]) _AM_IF_OPTION([no-dependencies],, [AC_PROVIDE_IFELSE([AC_PROG_CC], [_AM_DEPENDENCIES([CC])], [m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC])[_AM_DEPENDENCIES([CC])])])dnl AC_PROVIDE_IFELSE([AC_PROG_CXX], [_AM_DEPENDENCIES([CXX])], [m4_define([AC_PROG_CXX], m4_defn([AC_PROG_CXX])[_AM_DEPENDENCIES([CXX])])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJC], [_AM_DEPENDENCIES([OBJC])], [m4_define([AC_PROG_OBJC], m4_defn([AC_PROG_OBJC])[_AM_DEPENDENCIES([OBJC])])])dnl AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], [_AM_DEPENDENCIES([OBJCXX])], [m4_define([AC_PROG_OBJCXX], m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl ]) # Variables for tags utilities; see am/tags.am if test -z "$CTAGS"; then CTAGS=ctags fi AC_SUBST([CTAGS]) if test -z "$ETAGS"; then ETAGS=etags fi AC_SUBST([ETAGS]) if test -z "$CSCOPE"; then CSCOPE=cscope fi AC_SUBST([CSCOPE]) AC_REQUIRE([AM_SILENT_RULES])dnl dnl The testsuite driver may need to know about EXEEXT, so add the dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This dnl macro is hooked onto _AC_COMPILER_EXEEXT early, see below. AC_CONFIG_COMMANDS_PRE(dnl [m4_provide_if([_AM_COMPILER_EXEEXT], [AM_CONDITIONAL([am__EXEEXT], [test -n "$EXEEXT"])])])dnl # POSIX will say in a future version that running "rm -f" with no argument # is OK; and we want to be able to make that assumption in our Makefile # recipes. So use an aggressive probe to check that the usage we want is # actually supported "in the wild" to an acceptable degree. # See automake bug#10828. # To make any issue more visible, cause the running configure to be aborted # by default if the 'rm' program in use doesn't match our expectations; the # user can still override this though. if rm -f && rm -fr && rm -rf; then : OK; else cat >&2 <<'END' Oops! Your 'rm' program seems unable to run without file operands specified on the command line, even when the '-f' option is present. This is contrary to the behaviour of most rm programs out there, and not conforming with the upcoming POSIX standard: Please tell bug-automake@gnu.org about your system, including the value of your $PATH and any error possibly output before this message. This can help us improve future automake versions. END if test x"$ACCEPT_INFERIOR_RM_PROGRAM" = x"yes"; then echo 'Configuration will proceed anyway, since you have set the' >&2 echo 'ACCEPT_INFERIOR_RM_PROGRAM variable to "yes"' >&2 echo >&2 else cat >&2 <<'END' Aborting the configuration process, to ensure you take notice of the issue. You can download and install GNU coreutils to get an 'rm' implementation that behaves properly: . If you want to complete the configuration process using your problematic 'rm' anyway, export the environment variable ACCEPT_INFERIOR_RM_PROGRAM to "yes", and re-run configure. END AC_MSG_ERROR([Your 'rm' program is bad, sorry.]) fi fi dnl The trailing newline in this macro's definition is deliberate, for dnl backward compatibility and to allow trailing 'dnl'-style comments dnl after the AM_INIT_AUTOMAKE invocation. See automake bug#16841. ]) dnl Hook into '_AC_COMPILER_EXEEXT' early to learn its expansion. Do not dnl add the conditional right here, as _AC_COMPILER_EXEEXT may be further dnl mangled by Autoconf and run in a shell conditional statement. m4_define([_AC_COMPILER_EXEEXT], m4_defn([_AC_COMPILER_EXEEXT])[m4_provide([_AM_COMPILER_EXEEXT])]) # When config.status generates a header, we must update the stamp-h file. # This file resides in the same directory as the config header # that is generated. The stamp files are numbered to have different names. # Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the # loop where config.status creates the headers, so we can generate # our stamp files there. AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK], [# Compute $1's index in $config_headers. _am_arg=$1 _am_stamp_count=1 for _am_header in $config_headers :; do case $_am_header in $_am_arg | $_am_arg:* ) break ;; * ) _am_stamp_count=`expr $_am_stamp_count + 1` ;; esac done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) # Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_SH # ------------------ # Define $install_sh. AC_DEFUN([AM_PROG_INSTALL_SH], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl if test x"${install_sh+set}" != xset; then case $am_aux_dir in *\ * | *\ *) install_sh="\${SHELL} '$am_aux_dir/install-sh'" ;; *) install_sh="\${SHELL} $am_aux_dir/install-sh" esac fi AC_SUBST([install_sh])]) # Copyright (C) 2003-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # Check whether the underlying file-system supports filenames # with a leading dot. For instance MS-DOS doesn't. AC_DEFUN([AM_SET_LEADING_DOT], [rm -rf .tst 2>/dev/null mkdir .tst 2>/dev/null if test -d .tst; then am__leading_dot=. else am__leading_dot=_ fi rmdir .tst 2>/dev/null AC_SUBST([am__leading_dot])]) # Check to see how 'make' treats includes. -*- Autoconf -*- # Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MAKE_INCLUDE() # ----------------- # Check whether make has an 'include' directive that can support all # the idioms we need for our automatic dependency tracking code. AC_DEFUN([AM_MAKE_INCLUDE], [AC_MSG_CHECKING([whether ${MAKE-make} supports the include directive]) cat > confinc.mk << 'END' am__doit: @echo this is the am__doit target >confinc.out .PHONY: am__doit END am__include="#" am__quote= # BSD make does it like this. echo '.include "confinc.mk" # ignored' > confmf.BSD # Other make implementations (GNU, Solaris 10, AIX) do it like this. echo 'include confinc.mk # ignored' > confmf.GNU _am_result=no for s in GNU BSD; do AM_RUN_LOG([${MAKE-make} -f confmf.$s && cat confinc.out]) AS_CASE([$?:`cat confinc.out 2>/dev/null`], ['0:this is the am__doit target'], [AS_CASE([$s], [BSD], [am__include='.include' am__quote='"'], [am__include='include' am__quote=''])]) if test "$am__include" != "#"; then _am_result="yes ($s style)" break fi done rm -f confinc.* confmf.* AC_MSG_RESULT([${_am_result}]) AC_SUBST([am__include])]) AC_SUBST([am__quote])]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- # Copyright (C) 1997-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_MISSING_PROG(NAME, PROGRAM) # ------------------------------ AC_DEFUN([AM_MISSING_PROG], [AC_REQUIRE([AM_MISSING_HAS_RUN]) $1=${$1-"${am_missing_run}$2"} AC_SUBST($1)]) # AM_MISSING_HAS_RUN # ------------------ # Define MISSING if not defined so far and test if it is modern enough. # If it is, set am_missing_run to use it, otherwise, to nothing. AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then am_missing_run="$MISSING " else am_missing_run= AC_MSG_WARN(['missing' script is too old or missing]) fi ]) # Helper functions for option handling. -*- Autoconf -*- # Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_MANGLE_OPTION(NAME) # ----------------------- AC_DEFUN([_AM_MANGLE_OPTION], [[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])]) # _AM_SET_OPTION(NAME) # -------------------- # Set option NAME. Presently that only means defining a flag for this option. AC_DEFUN([_AM_SET_OPTION], [m4_define(_AM_MANGLE_OPTION([$1]), [1])]) # _AM_SET_OPTIONS(OPTIONS) # ------------------------ # OPTIONS is a space-separated list of Automake options. AC_DEFUN([_AM_SET_OPTIONS], [m4_foreach_w([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])]) # _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET]) # ------------------------------------------- # Execute IF-SET if OPTION is set, IF-NOT-SET otherwise. AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) # Copyright (C) 1999-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_CC_C_O # --------------- # Like AC_PROG_CC_C_O, but changed for automake. We rewrite AC_PROG_CC # to automatically call this. AC_DEFUN([_AM_PROG_CC_C_O], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([compile])dnl AC_LANG_PUSH([C])dnl AC_CACHE_CHECK( [whether $CC understands -c and -o together], [am_cv_prog_cc_c_o], [AC_LANG_CONFTEST([AC_LANG_PROGRAM([])]) # Make sure it works both with $CC and with simple cc. # Following AC_PROG_CC_C_O, we do the test twice because some # compilers refuse to overwrite an existing .o file with -o, # though they will create one. am_cv_prog_cc_c_o=yes for am_i in 1 2; do if AM_RUN_LOG([$CC -c conftest.$ac_ext -o conftest2.$ac_objext]) \ && test -f conftest2.$ac_objext; then : OK else am_cv_prog_cc_c_o=no break fi done rm -f core conftest* unset am_i]) if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. # But if we don't then we get into trouble of one sort or another. # A longer-term fix would be to have automake use am__CC in this case, # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)" CC="$am_aux_dir/compile $CC" fi AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) # Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_RUN_LOG(COMMAND) # ------------------- # Run COMMAND, save the exit status in ac_status, and log it. # (This has been adapted from Autoconf's _AC_RUN_LOG macro.) AC_DEFUN([AM_RUN_LOG], [{ echo "$as_me:$LINENO: $1" >&AS_MESSAGE_LOG_FD ($1) >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD ac_status=$? echo "$as_me:$LINENO: \$? = $ac_status" >&AS_MESSAGE_LOG_FD (exit $ac_status); }]) # Check to make sure that the build environment is sane. -*- Autoconf -*- # Copyright (C) 1996-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_SANITY_CHECK # --------------- AC_DEFUN([AM_SANITY_CHECK], [AC_MSG_CHECKING([whether build environment is sane]) # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' ' case `pwd` in *[[\\\"\#\$\&\'\`$am_lf]]*) AC_MSG_ERROR([unsafe absolute working directory name]);; esac case $srcdir in *[[\\\"\#\$\&\'\`$am_lf\ \ ]]*) AC_MSG_ERROR([unsafe srcdir value: '$srcdir']);; esac # Do 'set' in a subshell so we don't clobber the current shell's # arguments. Must try -L first in case configure is actually a # symlink; some systems play weird games with the mod time of symlinks # (eg FreeBSD returns the mod time of the symlink's containing # directory). if ( am_has_slept=no for am_try in 1 2; do echo "timestamp, slept: $am_has_slept" > conftest.file set X `ls -Lt "$srcdir/configure" conftest.file 2> /dev/null` if test "$[*]" = "X"; then # -L didn't work. set X `ls -t "$srcdir/configure" conftest.file` fi if test "$[*]" != "X $srcdir/configure conftest.file" \ && test "$[*]" != "X conftest.file $srcdir/configure"; then # If neither matched, then we have a broken ls. This can happen # if, for instance, CONFIG_SHELL is bash and it inherits a # broken ls alias from the environment. This has actually # happened. Such a system could not be considered "sane". AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken alias in your environment]) fi if test "$[2]" = conftest.file || test $am_try -eq 2; then break fi # Just in case. sleep 1 am_has_slept=yes done test "$[2]" = conftest.file ) then # Ok. : else AC_MSG_ERROR([newly created file is older than distributed files! Check your system clock]) fi AC_MSG_RESULT([yes]) # If we didn't sleep, we still need to ensure time stamps of config.status and # generated files are strictly newer. am_sleep_pid= if grep 'slept: no' conftest.file >/dev/null 2>&1; then ( sleep 1 ) & am_sleep_pid=$! fi AC_CONFIG_COMMANDS_PRE( [AC_MSG_CHECKING([that generated files are newer than configure]) if test -n "$am_sleep_pid"; then # Hide warnings about reused PIDs. wait $am_sleep_pid 2>/dev/null fi AC_MSG_RESULT([done])]) rm -f conftest.file ]) # Copyright (C) 2009-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_SILENT_RULES([DEFAULT]) # -------------------------- # Enable less verbose build rules; with the default set to DEFAULT # ("yes" being less verbose, "no" or empty being verbose). AC_DEFUN([AM_SILENT_RULES], [AC_ARG_ENABLE([silent-rules], [dnl AS_HELP_STRING( [--enable-silent-rules], [less verbose build output (undo: "make V=1")]) AS_HELP_STRING( [--disable-silent-rules], [verbose build output (undo: "make V=0")])dnl ]) case $enable_silent_rules in @%:@ ((( yes) AM_DEFAULT_VERBOSITY=0;; no) AM_DEFAULT_VERBOSITY=1;; *) AM_DEFAULT_VERBOSITY=m4_if([$1], [yes], [0], [1]);; esac dnl dnl A few 'make' implementations (e.g., NonStop OS and NextStep) dnl do not support nested variable expansions. dnl See automake bug#9928 and bug#10237. am_make=${MAKE-make} AC_CACHE_CHECK([whether $am_make supports nested variables], [am_cv_make_support_nested_variables], [if AS_ECHO([['TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 am__doit: @$(TRUE) .PHONY: am__doit']]) | $am_make -f - >/dev/null 2>&1; then am_cv_make_support_nested_variables=yes else am_cv_make_support_nested_variables=no fi]) if test $am_cv_make_support_nested_variables = yes; then dnl Using '$V' instead of '$(V)' breaks IRIX make. AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' else AM_V=$AM_DEFAULT_VERBOSITY AM_DEFAULT_V=$AM_DEFAULT_VERBOSITY fi AC_SUBST([AM_V])dnl AM_SUBST_NOTMAKE([AM_V])dnl AC_SUBST([AM_DEFAULT_V])dnl AM_SUBST_NOTMAKE([AM_DEFAULT_V])dnl AC_SUBST([AM_DEFAULT_VERBOSITY])dnl AM_BACKSLASH='\' AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) # Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # AM_PROG_INSTALL_STRIP # --------------------- # One issue with vendor 'install' (even GNU) is that you can't # specify the program used to strip binaries. This is especially # annoying in cross-compiling environments, where the build's strip # is unlikely to handle the host's binaries. # Fortunately install-sh will honor a STRIPPROG variable, so we # always use install-sh in "make install-strip", and initialize # STRIPPROG with the value of the STRIP variable (set by the user). AC_DEFUN([AM_PROG_INSTALL_STRIP], [AC_REQUIRE([AM_PROG_INSTALL_SH])dnl # Installed binaries are usually stripped using 'strip' when the user # run "make install-strip". However 'strip' might not be the right # tool to use in cross-compilation environments, therefore Automake # will honor the 'STRIP' environment variable to overrule this program. dnl Don't test for $cross_compiling = yes, because it might be 'maybe'. if test "$cross_compiling" != no; then AC_CHECK_TOOL([STRIP], [strip], :) fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) # Copyright (C) 2006-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_SUBST_NOTMAKE(VARIABLE) # --------------------------- # Prevent Automake from outputting VARIABLE = @VARIABLE@ in Makefile.in. # This macro is traced by Automake. AC_DEFUN([_AM_SUBST_NOTMAKE]) # AM_SUBST_NOTMAKE(VARIABLE) # -------------------------- # Public sister of _AM_SUBST_NOTMAKE. AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- # Copyright (C) 2004-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # _AM_PROG_TAR(FORMAT) # -------------------- # Check how to create a tarball in format FORMAT. # FORMAT should be one of 'v7', 'ustar', or 'pax'. # # Substitute a variable $(am__tar) that is a command # writing to stdout a FORMAT-tarball containing the directory # $tardir. # tardir=directory && $(am__tar) > result.tar # # Substitute a variable $(am__untar) that extract such # a tarball read from stdin. # $(am__untar) < result.tar # AC_DEFUN([_AM_PROG_TAR], [# Always define AMTAR for backward compatibility. Yes, it's still used # in the wild :-( We should find a proper way to deprecate it ... AC_SUBST([AMTAR], ['$${TAR-tar}']) # We'll loop over all known methods to create a tar archive until one works. _am_tools='gnutar m4_if([$1], [ustar], [plaintar]) pax cpio none' m4_if([$1], [v7], [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'], [m4_case([$1], [ustar], [# The POSIX 1988 'ustar' format is defined with fixed-size fields. # There is notably a 21 bits limit for the UID and the GID. In fact, # the 'pax' utility can hang on bigger UID/GID (see automake bug#8343 # and bug#13588). am_max_uid=2097151 # 2^21 - 1 am_max_gid=$am_max_uid # The $UID and $GID variables are not portable, so we need to resort # to the POSIX-mandated id(1) utility. Errors in the 'id' calls # below are definitely unexpected, so allow the users to see them # (that is, avoid stderr redirection). am_uid=`id -u || echo unknown` am_gid=`id -g || echo unknown` AC_MSG_CHECKING([whether UID '$am_uid' is supported by ustar format]) if test $am_uid -le $am_max_uid; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) _am_tools=none fi AC_MSG_CHECKING([whether GID '$am_gid' is supported by ustar format]) if test $am_gid -le $am_max_gid; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) _am_tools=none fi], [pax], [], [m4_fatal([Unknown tar format])]) AC_MSG_CHECKING([how to create a $1 tar archive]) # Go ahead even if we have the value already cached. We do so because we # need to set the values for the 'am__tar' and 'am__untar' variables. _am_tools=${am_cv_prog_tar_$1-$_am_tools} for _am_tool in $_am_tools; do case $_am_tool in gnutar) for _am_tar in tar gnutar gtar; do AM_RUN_LOG([$_am_tar --version]) && break done am__tar="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$$tardir"' am__tar_="$_am_tar --format=m4_if([$1], [pax], [posix], [$1]) -chf - "'"$tardir"' am__untar="$_am_tar -xf -" ;; plaintar) # Must skip GNU tar: if it does not support --format= it doesn't create # ustar tarball either. (tar --version) >/dev/null 2>&1 && continue am__tar='tar chf - "$$tardir"' am__tar_='tar chf - "$tardir"' am__untar='tar xf -' ;; pax) am__tar='pax -L -x $1 -w "$$tardir"' am__tar_='pax -L -x $1 -w "$tardir"' am__untar='pax -r' ;; cpio) am__tar='find "$$tardir" -print | cpio -o -H $1 -L' am__tar_='find "$tardir" -print | cpio -o -H $1 -L' am__untar='cpio -i -H $1 -d' ;; none) am__tar=false am__tar_=false am__untar=false ;; esac # If the value was cached, stop now. We just wanted to have am__tar # and am__untar set. test -n "${am_cv_prog_tar_$1}" && break # tar/untar a dummy directory, and stop if the command works. rm -rf conftest.dir mkdir conftest.dir echo GrepMe > conftest.dir/file AM_RUN_LOG([tardir=conftest.dir && eval $am__tar_ >conftest.tar]) rm -rf conftest.dir if test -s conftest.tar; then AM_RUN_LOG([$am__untar /dev/null 2>&1 && break fi done rm -rf conftest.dir AC_CACHE_VAL([am_cv_prog_tar_$1], [am_cv_prog_tar_$1=$_am_tool]) AC_MSG_RESULT([$am_cv_prog_tar_$1])]) AC_SUBST([am__tar]) AC_SUBST([am__untar]) ]) # _AM_PROG_TAR m4_include([m4/libtool.m4]) m4_include([m4/ltoptions.m4]) m4_include([m4/ltsugar.m4]) m4_include([m4/ltversion.m4]) m4_include([m4/lt~obsolete.m4]) openbgpd-8.8/Makefile.in100644 001750 001750 00000065061 14751151140 0010745# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @BUILD_BGPLGD_TRUE@am__append_1 = src/bgplgd subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ $(am__configure_deps) $(am__DIST_COMMON) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ install-exec-recursive install-html-recursive \ install-info-recursive install-pdf-recursive \ install-ps-recursive install-recursive installcheck-recursive \ installdirs-recursive pdf-recursive ps-recursive \ tags-recursive uninstall-recursive am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive am__recursive_targets = \ $(RECURSIVE_TARGETS) \ $(RECURSIVE_CLEAN_TARGETS) \ $(am__extra_recursive_targets) AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \ cscope distdir distdir-am dist dist-all distcheck am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` DIST_SUBDIRS = include compat src/bgpd src/bgpctl src/bgplgd am__DIST_COMMON = $(srcdir)/Makefile.in AUTHORS INSTALL README.md \ compile config.guess config.sub depcomp install-sh ltmain.sh \ missing ylwrap DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) am__remove_distdir = \ if test -d "$(distdir)"; then \ find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \ && rm -rf "$(distdir)" \ || { sleep 5 && rm -rf "$(distdir)"; }; \ else :; fi am__post_remove_distdir = $(am__remove_distdir) am__relativize = \ dir0=`pwd`; \ sed_first='s,^\([^/]*\)/.*$$,\1,'; \ sed_rest='s,^[^/]*/*,,'; \ sed_last='s,^.*/\([^/]*\)$$,\1,'; \ sed_butlast='s,/*[^/]*$$,,'; \ while test -n "$$dir1"; do \ first=`echo "$$dir1" | sed -e "$$sed_first"`; \ if test "$$first" != "."; then \ if test "$$first" = ".."; then \ dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \ dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \ else \ first2=`echo "$$dir2" | sed -e "$$sed_first"`; \ if test "$$first2" = "$$first"; then \ dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \ else \ dir2="../$$dir2"; \ fi; \ dir0="$$dir0"/"$$first"; \ fi; \ fi; \ dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \ done; \ reldir="$$dir2" DIST_ARCHIVES = $(distdir).tar.gz GZIP_ENV = --best DIST_TARGETS = dist-gzip # Exists only to be overridden by the user if desired. AM_DISTCHECK_DVI_TARGET = dvi distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' distcleancheck_listfiles = find . -type f -print ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LDFLAGS = @AM_LDFLAGS@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BGPD_USER = @BGPD_USER@ BGPLGD_USER = @BGPLGD_USER@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ WWW_USER = @WWW_USER@ YACC = @YACC@ YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwrunstatedir = @wwwrunstatedir@ SUBDIRS = include compat src/bgpd src/bgpctl $(am__append_1) ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = README.md LICENSE VERSION bgpd.conf all: all-recursive .SUFFIXES: am--refresh: Makefile @: $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ echo ' cd $(srcdir) && $(AUTOMAKE) --foreign'; \ $(am__cd) $(srcdir) && $(AUTOMAKE) --foreign \ && exit 0; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ echo ' $(SHELL) ./config.status'; \ $(SHELL) ./config.status;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck $(top_srcdir)/configure: $(am__configure_deps) $(am__cd) $(srcdir) && $(AUTOCONF) $(ACLOCAL_M4): $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs distclean-libtool: -rm -f libtool config.lt # This directory's subdirectories are mostly independent; you can cd # into them and run 'make' without going through this Makefile. # To change the values of 'make' variables: instead of editing Makefiles, # (1) if the variable is set in 'config.status', edit 'config.status' # (which will cause the Makefiles to be regenerated when you run 'make'); # (2) otherwise, pass the desired values on the 'make' command line. $(am__recursive_targets): @fail=; \ if $(am__make_keepgoing); then \ failcom='fail=yes'; \ else \ failcom='exit 1'; \ fi; \ dot_seen=no; \ target=`echo $@ | sed s/-recursive//`; \ case "$@" in \ distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \ *) list='$(SUBDIRS)' ;; \ esac; \ for subdir in $$list; do \ echo "Making $$target in $$subdir"; \ if test "$$subdir" = "."; then \ dot_seen=yes; \ local_target="$$target-am"; \ else \ local_target="$$target"; \ fi; \ ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \ || eval $$failcom; \ done; \ if test "$$dot_seen" = "no"; then \ $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \ fi; test -z "$$fail" ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-recursive TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \ include_option=--etags-include; \ empty_fix=.; \ else \ include_option=--include; \ empty_fix=; \ fi; \ list='$(SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ test ! -f $$subdir/TAGS || \ set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \ fi; \ done; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-recursive CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscope: cscope.files test ! -s cscope.files \ || $(CSCOPE) -b -q $(AM_CSCOPEFLAGS) $(CSCOPEFLAGS) -i cscope.files $(CSCOPE_ARGS) clean-cscope: -rm -f cscope.files cscope.files: clean-cscope cscopelist cscopelist: cscopelist-recursive cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -rm -f cscope.out cscope.in.out cscope.po.out cscope.files distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) $(am__remove_distdir) test -d "$(distdir)" || mkdir "$(distdir)" @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \ if test "$$subdir" = .; then :; else \ $(am__make_dryrun) \ || test -d "$(distdir)/$$subdir" \ || $(MKDIR_P) "$(distdir)/$$subdir" \ || exit 1; \ dir1=$$subdir; dir2="$(distdir)/$$subdir"; \ $(am__relativize); \ new_distdir=$$reldir; \ dir1=$$subdir; dir2="$(top_distdir)"; \ $(am__relativize); \ new_top_distdir=$$reldir; \ echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \ echo " am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \ ($(am__cd) $$subdir && \ $(MAKE) $(AM_MAKEFLAGS) \ top_distdir="$$new_top_distdir" \ distdir="$$new_distdir" \ am__remove_distdir=: \ am__skip_length_check=: \ am__skip_mode_fix=: \ distdir) \ || exit 1; \ fi; \ done -test -n "$(am__skip_mode_fix)" \ || find "$(distdir)" -type d ! -perm -755 \ -exec chmod u+rwx,go+rx {} \; -o \ ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \ ! -type d ! -perm -400 -exec chmod a+r {} \; -o \ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2 $(am__post_remove_distdir) dist-lzip: distdir tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz $(am__post_remove_distdir) dist-xz: distdir tardir=$(distdir) && $(am__tar) | XZ_OPT=$${XZ_OPT--e} xz -c >$(distdir).tar.xz $(am__post_remove_distdir) dist-zstd: distdir tardir=$(distdir) && $(am__tar) | zstd -c $${ZSTD_CLEVEL-$${ZSTD_OPT--19}} >$(distdir).tar.zst $(am__post_remove_distdir) dist-tarZ: distdir @echo WARNING: "Support for distribution archives compressed with" \ "legacy program 'compress' is deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 tardir=$(distdir) && $(am__tar) | compress -c >$(distdir).tar.Z $(am__post_remove_distdir) dist-shar: distdir @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir -rm -f $(distdir).zip zip -rq $(distdir).zip $(distdir) $(am__post_remove_distdir) dist dist-all: $(MAKE) $(AM_MAKEFLAGS) $(DIST_TARGETS) am__post_remove_distdir='@:' $(am__post_remove_distdir) # This target untars the dist file and tries a VPATH configuration. Then # it guarantees that the distribution is self-contained by making another # tarfile. distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ lzip -dc $(distdir).tar.lz | $(am__untar) ;;\ *.tar.xz*) \ xz -dc $(distdir).tar.xz | $(am__untar) ;;\ *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ *.tar.zst*) \ zstd -dc $(distdir).tar.zst | $(am__untar) ;;\ esac chmod -R a-w $(distdir) chmod u+w $(distdir) mkdir $(distdir)/_build $(distdir)/_build/sub $(distdir)/_inst chmod a-w $(distdir) test -d $(distdir)/_build || exit 0; \ dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \ && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \ && am__cwd=`pwd` \ && $(am__cd) $(distdir)/_build/sub \ && ../../configure \ $(AM_DISTCHECK_CONFIGURE_FLAGS) \ $(DISTCHECK_CONFIGURE_FLAGS) \ --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ && $(MAKE) $(AM_MAKEFLAGS) uninstall \ && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \ distuninstallcheck \ && chmod -R a-w "$$dc_install_base" \ && ({ \ (cd ../.. && umask 077 && mkdir "$$dc_destdir") \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \ && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \ distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \ } || { rm -rf "$$dc_destdir"; exit 1; }) \ && rm -rf "$$dc_destdir" \ && $(MAKE) $(AM_MAKEFLAGS) dist \ && rm -rf $(DIST_ARCHIVES) \ && $(MAKE) $(AM_MAKEFLAGS) distcleancheck \ && cd "$$am__cwd" \ || exit 1 $(am__post_remove_distdir) @(echo "$(distdir) archives ready for distribution: "; \ list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \ sed -e 1h -e 1s/./=/g -e 1p -e 1x -e '$$p' -e '$$x' distuninstallcheck: @test -n '$(distuninstallcheck_dir)' || { \ echo 'ERROR: trying to run $@ with an empty' \ '$$(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ $(am__cd) '$(distuninstallcheck_dir)' || { \ echo 'ERROR: cannot chdir into $(distuninstallcheck_dir)' >&2; \ exit 1; \ }; \ test `$(am__distuninstallcheck_listfiles) | wc -l` -eq 0 \ || { echo "ERROR: files left after uninstall:" ; \ if test -n "$(DESTDIR)"; then \ echo " (check DESTDIR support)"; \ fi ; \ $(distuninstallcheck_listfiles) ; \ exit 1; } >&2 distcleancheck: distclean @if test '$(srcdir)' = . ; then \ echo "ERROR: distcleancheck can only run from a VPATH build" ; \ exit 1 ; \ fi @test `$(distcleancheck_listfiles) | wc -l` -eq 0 \ || { echo "ERROR: files left in build directory after distclean:" ; \ $(distcleancheck_listfiles) ; \ exit 1; } >&2 check-am: all-am check: check-recursive all-am: Makefile installdirs: installdirs-recursive installdirs-am: install: install-recursive install-exec: install-exec-recursive install-data: install-data-recursive uninstall: uninstall-recursive install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-recursive install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-recursive clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -f Makefile distclean-am: clean-am distclean-generic distclean-libtool \ distclean-tags dvi: dvi-recursive dvi-am: html: html-recursive html-am: info: info-recursive info-am: install-data-am: @$(NORMAL_INSTALL) $(MAKE) $(AM_MAKEFLAGS) install-data-hook install-dvi: install-dvi-recursive install-dvi-am: install-exec-am: install-html: install-html-recursive install-html-am: install-info: install-info-recursive install-info-am: install-man: install-pdf: install-pdf-recursive install-pdf-am: install-ps: install-ps-recursive install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -rf $(top_srcdir)/autom4te.cache -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-recursive mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-recursive pdf-am: ps: ps-recursive ps-am: uninstall-am: uninstall-local .MAKE: $(am__recursive_targets) install-am install-data-am \ install-strip .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ am--refresh check check-am clean clean-cscope clean-generic \ clean-libtool cscope cscopelist-am ctags ctags-am dist \ dist-all dist-bzip2 dist-gzip dist-lzip dist-shar dist-tarZ \ dist-xz dist-zip dist-zstd distcheck distclean \ distclean-generic distclean-libtool distclean-tags \ distcleancheck distdir distuninstallcheck dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-data-hook install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man install-pdf \ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs installdirs-am \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am uninstall-local .PRECIOUS: Makefile install-data-hook: @if [ ! -d "$(DESTDIR)$(runstatedir)" ]; then \ $(INSTALL) -m 755 -d "$(DESTDIR)$(runstatedir)"; \ fi @if [ X"$(wwwrunstatedir)" != X -a ! -d "$(DESTDIR)$(wwwrunstatedir)" ]; then \ $(INSTALL) -m 755 -d "$(DESTDIR)$(wwwrunstatedir)"; \ fi @if [ ! -d "$(DESTDIR)$(sysconfdir)" ]; then \ $(INSTALL) -m 755 -d "$(DESTDIR)$(sysconfdir)"; \ fi @if [ ! -f "$(DESTDIR)$(sysconfdir)/bgpd.conf" ]; then \ $(INSTALL) -m 644 "$(srcdir)/bgpd.conf" "$(DESTDIR)$(sysconfdir)/bgpd.conf"; \ else \ echo; \ echo " $(DESTDIR)$(sysconfdir)/bgpd.conf already exists, install will not overwrite"; \ fi uninstall-local: @if cmp -s "$(DESTDIR)$(sysconfdir)/bgpd.conf" "$(srcdir)/bgpd.conf"; then \ rm -f "$(DESTDIR)$(sysconfdir)/bgpd.conf"; \ fi # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: openbgpd-8.8/AUTHORS100644 001750 001750 00000000466 13454123001 0007740Credits ------- OpenBSD's native bgpd was written by Henning Brauer and Claudio Jeker in 2004. It has seen improvements from many others as well. Please see the commit logs for an exhaustive list of contributors. This new portable version is based on the LibreSSL / OpenNTPD portable framework by Brent Cook. openbgpd-8.8/INSTALL100644 001750 001750 00000006564 14264017544 00077441. Prerequisites ---------------- You will need an entropy (randomness) source. If your OS has arc4random or getentropy then that is ideal. Otherwise, you can use the builtin arc4random implementation or the one built into LibreSSL. To build bgplgd libevent is required. The Linux netlink support requires libmnl. 2. Building / Installation -------------------------- If you have checked this source using Git, follow these initial steps to prepare the source tree for building: 1. ensure you have the following packages installed: automake, autoconf, git, libtool, yacc or bison 2. run './autogen.sh' to prepare the source tree for building To install OpenBGPD with default options: ./configure make make install This will install the OpenBGPD binary in /usr/local/sbin, configuration files in /usr/local/etc. To specify a different installation prefix, use the --prefix option to configure: ./configure --prefix=/opt make make install Will install OpenBGPD in /opt/{etc,sbin}. You can also override specific paths, for example: ./configure --prefix=/opt --sysconfdir=/etc/bgpd make make install This will install the binaries in /opt/sbin, but will place the configuration files in /etc/bgpd. OpenBGPD always uses Privilege Separation (ie the majority of the processing is done as a chroot'ed, unprivileged user). This requires that a user, group and directory to be created for it. The user should not be permitted to log in, and its home directory should be owned by root and be mode 755. If you do "make install", the Makefile will create the directory with the correct permissions and will prompt you for the rest if required. If, however, you need to perform all of these tasks yourself (eg if you are moving the built binaries to another system) then you will need to do something like the following (although the exact commands required for creating the user and group are system dependant): On most Linux and BSD systems, something like should work: groupadd _bgpd useradd -g _bgpd -s /sbin/nologin -d /var/empty -c 'OpenBGPD daemon' _bgpd mkdir -p /var/empty chown 0 /var/empty chgrp 0 /var/empty chmod 0755 /var/empty OpenBGPD is using the home directory of the _bgpd user (/var/empty by default) as the chroot directory for privilege separation of the session engine and the route decision engine processes. This directory should not contain any files, must be owned by root, and must not be group or world-writable. There are a few options to the configure script in addition to the ones provided by autoconf itself: --with-privsep-user=user Specify unprivileged user used for privilege separation. The default is "_bgpd". --disable-bgplgd Skip build of bgplgd. The default is --enable-bgplgd. --with-bgplgd-user=user Privilege drop user used by bgplgd. The default is "_bgplgd". --with-runstatedir=DIR Location for bgpd control socket [LOCALSTATEDIR/run] If you need to pass special options to the compiler or linker, you can specify these as environment variables before running ./configure. For example: CFLAGS="-O2 " LDFLAGS="-s" ./configure 3. Configuration ---------------- The runtime configuration files are installed by in ${prefix}/etc or whatever you specified as your --sysconfdir (/usr/local/etc by default). 4. Problems? ------------ If you experience problems compiling, installing or running OpenBGPD, please report the problem to the address in the README file. openbgpd-8.8/README.md100644 001750 001750 00000002601 14751151116 0010151

This is a port of OpenBGPD to other operating systems. It is based on portability code from the OpenNTPD, OpenSSH, and LibreSSL portable projects. OpenBGPD has a web site at https://www.openbgpd.org/ Packaging status The current portable tree can be found at https://github.com/openbgpd-portable/openbgpd-portable [![Build Status](https://github.com/openbgpd-portable/openbgpd-portable/workflows/Build%20CI/badge.svg)](https://github.com/openbgpd-portable/openbgpd-portable/actions) Platform Requirements --------------------- At the time of writing the portable version is known to build and work on actively maintained versions of: - Alpine - CentOS/RHEL/Rocky - Debian - Fedora - FreeBSD - NetBSD - OpenBSD - openSUSE - SLE - Ubuntu OpenBGPD may work on other operating systems, newer and older, but the above ones are tested regularly by the developer. Reports (success or otherwise) are welcome. You may report bugs or submit pull requests at the GitHub project: https://github.com/openbgpd-portable Thanks, Claudio Jeker and Brent Cook . openbgpd-8.8/compile100755 001750 001750 00000016350 14751151140 0010253#! /bin/sh # Wrapper for compilers which do not understand '-c -o'. scriptversion=2018-03-07.03; # UTC # Copyright (C) 1999-2021 Free Software Foundation, Inc. # Written by Tom Tromey . # # This program 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. # # This program 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # This file is maintained in Automake, please report # bugs to or send patches to # . nl=' ' # We need space, tab and new line, in precisely that order. Quoting is # there to prevent tools from complaining about whitespace usage. IFS=" "" $nl" file_conv= # func_file_conv build_file lazy # Convert a $build file to $host form and store it in $file # Currently only supports Windows hosts. If the determined conversion # type is listed in (the comma separated) LAZY, no conversion will # take place. func_file_conv () { file=$1 case $file in / | /[!/]*) # absolute file, and not a UNC file if test -z "$file_conv"; then # lazily determine how to convert abs files case `uname -s` in MINGW*) file_conv=mingw ;; CYGWIN* | MSYS*) file_conv=cygwin ;; *) file_conv=wine ;; esac fi case $file_conv/,$2, in *,$file_conv,*) ;; mingw/*) file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` ;; cygwin/* | msys/*) file=`cygpath -m "$file" || echo "$file"` ;; wine/*) file=`winepath -w "$file" || echo "$file"` ;; esac ;; esac } # func_cl_dashL linkdir # Make cl look for libraries in LINKDIR func_cl_dashL () { func_file_conv "$1" if test -z "$lib_path"; then lib_path=$file else lib_path="$lib_path;$file" fi linker_opts="$linker_opts -LIBPATH:$file" } # func_cl_dashl library # Do a library search-path lookup for cl func_cl_dashl () { lib=$1 found=no save_IFS=$IFS IFS=';' for dir in $lib_path $LIB do IFS=$save_IFS if $shared && test -f "$dir/$lib.dll.lib"; then found=yes lib=$dir/$lib.dll.lib break fi if test -f "$dir/$lib.lib"; then found=yes lib=$dir/$lib.lib break fi if test -f "$dir/lib$lib.a"; then found=yes lib=$dir/lib$lib.a break fi done IFS=$save_IFS if test "$found" != yes; then lib=$lib.lib fi } # func_cl_wrapper cl arg... # Adjust compile command to suit cl func_cl_wrapper () { # Assume a capable shell lib_path= shared=: linker_opts= for arg do if test -n "$eat"; then eat= else case $1 in -o) # configure might choose to run compile as 'compile cc -o foo foo.c'. eat=1 case $2 in *.o | *.[oO][bB][jJ]) func_file_conv "$2" set x "$@" -Fo"$file" shift ;; *) func_file_conv "$2" set x "$@" -Fe"$file" shift ;; esac ;; -I) eat=1 func_file_conv "$2" mingw set x "$@" -I"$file" shift ;; -I*) func_file_conv "${1#-I}" mingw set x "$@" -I"$file" shift ;; -l) eat=1 func_cl_dashl "$2" set x "$@" "$lib" shift ;; -l*) func_cl_dashl "${1#-l}" set x "$@" "$lib" shift ;; -L) eat=1 func_cl_dashL "$2" ;; -L*) func_cl_dashL "${1#-L}" ;; -static) shared=false ;; -Wl,*) arg=${1#-Wl,} save_ifs="$IFS"; IFS=',' for flag in $arg; do IFS="$save_ifs" linker_opts="$linker_opts $flag" done IFS="$save_ifs" ;; -Xlinker) eat=1 linker_opts="$linker_opts $2" ;; -*) set x "$@" "$1" shift ;; *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) func_file_conv "$1" set x "$@" -Tp"$file" shift ;; *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) func_file_conv "$1" mingw set x "$@" "$file" shift ;; *) set x "$@" "$1" shift ;; esac fi shift done if test -n "$linker_opts"; then linker_opts="-link$linker_opts" fi exec "$@" $linker_opts exit 1 } eat= case $1 in '') echo "$0: No command. Try '$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: compile [--help] [--version] PROGRAM [ARGS] Wrapper for compilers which do not understand '-c -o'. Remove '-o dest.o' from ARGS, run PROGRAM with the remaining arguments, and rename the output as expected. If you are trying to build a whole package this is not the right script to run: please start by reading the file 'INSTALL'. Report bugs to . EOF exit $? ;; -v | --v*) echo "compile $scriptversion" exit $? ;; cl | *[/\\]cl | cl.exe | *[/\\]cl.exe | \ icl | *[/\\]icl | icl.exe | *[/\\]icl.exe ) func_cl_wrapper "$@" # Doesn't return... ;; esac ofile= cfile= for arg do if test -n "$eat"; then eat= else case $1 in -o) # configure might choose to run compile as 'compile cc -o foo foo.c'. # So we strip '-o arg' only if arg is an object. eat=1 case $2 in *.o | *.obj) ofile=$2 ;; *) set x "$@" -o "$2" shift ;; esac ;; *.c) cfile=$1 set x "$@" "$1" shift ;; *) set x "$@" "$1" shift ;; esac fi shift done if test -z "$ofile" || test -z "$cfile"; then # If no '-o' option was seen then we might have been invoked from a # pattern rule where we don't need one. That is ok -- this is a # normal compilation that the losing compiler can handle. If no # '.c' file was seen then we are probably linking. That is also # ok. exec "$@" fi # Name of file we expect compiler to create. cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` # Create the lock directory. # Note: use '[/\\:.-]' here to ensure that we don't use the same name # that we are using for the .o file. Also, base the name on the expected # object file name, since that is what matters with a parallel build. lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d while true; do if mkdir "$lockdir" >/dev/null 2>&1; then break fi sleep 1 done # FIXME: race condition here if user kills between mkdir and trap. trap "rmdir '$lockdir'; exit 1" 1 2 15 # Run the compile. "$@" ret=$? if test -f "$cofile"; then test "$cofile" = "$ofile" || mv "$cofile" "$ofile" elif test -f "${cofile}bj"; then test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" fi rmdir "$lockdir" exit $ret # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: openbgpd-8.8/config.guess100744 001750 001750 00000143046 14751151141 0011217#! /bin/sh # Attempt to guess a canonical system name. # Copyright 1992-2024 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268 # see below for rationale timestamp='2024-01-01' # This file 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 3 of the License, or # (at your option) any later version. # # This program 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.guess # # Please send patches to . # The "shellcheck disable" line above the timestamp inhibits complaints # about features and limitations of the classic Bourne shell that were # superseded or lifted in POSIX. However, this script identifies a wide # variety of pre-POSIX systems that do not have POSIX shells at all, and # even some reasonably current systems (Solaris 10 as case-in-point) still # have a pre-POSIX /bin/sh. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] Output the configuration name of the system '$me' is run on. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. Copyright 1992-2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try '$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; * ) break ;; esac done if test $# != 0; then echo "$me: too many arguments$help" >&2 exit 1 fi # Just in case it came from the environment. GUESS= # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a # headache to deal with in a portable fashion. # Historically, 'CC_FOR_BUILD' used to be named 'HOST_CC'. We still # use 'HOST_CC' if defined, but it is deprecated. # Portable tmp directory creation inspired by the Autoconf team. tmp= # shellcheck disable=SC2172 trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 set_cc_for_build() { # prevent multiple calls if $tmp is already set test "$tmp" && return 0 : "${TMPDIR=/tmp}" # shellcheck disable=SC2039,SC3028 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } dummy=$tmp/dummy case ${CC_FOR_BUILD-},${HOST_CC-},${CC-} in ,,) echo "int x;" > "$dummy.c" for driver in cc gcc c89 c99 ; do if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then CC_FOR_BUILD=$driver break fi done if test x"$CC_FOR_BUILD" = x ; then CC_FOR_BUILD=no_compiler_found fi ;; ,,*) CC_FOR_BUILD=$CC ;; ,*,*) CC_FOR_BUILD=$HOST_CC ;; esac } # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 1994-08-24) if test -f /.attbin/uname ; then PATH=$PATH:/.attbin ; export PATH fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown case $UNAME_SYSTEM in Linux|GNU|GNU/*) LIBC=unknown set_cc_for_build cat <<-EOF > "$dummy.c" #if defined(__ANDROID__) LIBC=android #else #include #if defined(__UCLIBC__) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc #elif defined(__GLIBC__) LIBC=gnu #elif defined(__LLVM_LIBC__) LIBC=llvm #else #include /* First heuristic to detect musl libc. */ #ifdef __DEFINED_va_list LIBC=musl #endif #endif #endif EOF cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` eval "$cc_set_libc" # Second heuristic to detect musl libc. if [ "$LIBC" = unknown ] && command -v ldd >/dev/null && ldd --version 2>&1 | grep -q ^musl; then LIBC=musl fi # If the system lacks a compiler, then just pick glibc. # We could probably try harder. if [ "$LIBC" = unknown ]; then LIBC=gnu fi ;; esac # Note: order is significant - the case branches are not exclusive. case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ echo unknown)` case $UNAME_MACHINE_ARCH in aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; earmv*) arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` machine=${arch}${endian}-unknown ;; *) machine=$UNAME_MACHINE_ARCH-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently (or will in the future) and ABI. case $UNAME_MACHINE_ARCH in earm*) os=netbsdelf ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ELF__ then # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). # Return netbsd for either. FIX? os=netbsd else os=netbsdelf fi ;; *) os=netbsd ;; esac # Determine ABI tags. case $UNAME_MACHINE_ARCH in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` ;; esac # The OS release # Debian GNU/NetBSD machines have a different userland, and # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. case $UNAME_VERSION in Debian*) release='-gnu' ;; *) release=`echo "$UNAME_RELEASE" | sed -e 's/[-_].*//' | cut -d. -f1,2` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. GUESS=$machine-${os}${release}${abi-} ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE ;; *:SecBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE ;; *:LibertyBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE ;; *:MidnightBSD:*:*) GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE ;; *:ekkoBSD:*:*) GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE ;; *:SolidBSD:*:*) GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE ;; *:OS108:*:*) GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE ;; macppc:MirBSD:*:*) GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE ;; *:MirBSD:*:*) GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE ;; *:Sortix:*:*) GUESS=$UNAME_MACHINE-unknown-sortix ;; *:Twizzler:*:*) GUESS=$UNAME_MACHINE-unknown-twizzler ;; *:Redox:*:*) GUESS=$UNAME_MACHINE-unknown-redox ;; mips:OSF1:*.*) GUESS=mips-dec-osf1 ;; alpha:OSF1:*:*) # Reset EXIT trap before exiting to avoid spurious non-zero exit code. trap '' 0 case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` ;; *5.*) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` ;; esac # According to Compaq, /usr/sbin/psrinfo has been available on # OSF/1 and Tru64 systems produced since 1995. I hope that # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case $ALPHA_CPU_TYPE in "EV4 (21064)") UNAME_MACHINE=alpha ;; "EV4.5 (21064)") UNAME_MACHINE=alpha ;; "LCA4 (21066/21068)") UNAME_MACHINE=alpha ;; "EV5 (21164)") UNAME_MACHINE=alphaev5 ;; "EV5.6 (21164A)") UNAME_MACHINE=alphaev56 ;; "EV5.6 (21164PC)") UNAME_MACHINE=alphapca56 ;; "EV5.7 (21164PC)") UNAME_MACHINE=alphapca57 ;; "EV6 (21264)") UNAME_MACHINE=alphaev6 ;; "EV6.7 (21264A)") UNAME_MACHINE=alphaev67 ;; "EV6.8CB (21264C)") UNAME_MACHINE=alphaev68 ;; "EV6.8AL (21264B)") UNAME_MACHINE=alphaev68 ;; "EV6.8CX (21264D)") UNAME_MACHINE=alphaev68 ;; "EV6.9A (21264/EV69A)") UNAME_MACHINE=alphaev69 ;; "EV7 (21364)") UNAME_MACHINE=alphaev7 ;; "EV7.9 (21364A)") UNAME_MACHINE=alphaev79 ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` GUESS=$UNAME_MACHINE-dec-osf$OSF_REL ;; Amiga*:UNIX_System_V:4.0:*) GUESS=m68k-unknown-sysv4 ;; *:[Aa]miga[Oo][Ss]:*:*) GUESS=$UNAME_MACHINE-unknown-amigaos ;; *:[Mm]orph[Oo][Ss]:*:*) GUESS=$UNAME_MACHINE-unknown-morphos ;; *:OS/390:*:*) GUESS=i370-ibm-openedition ;; *:z/VM:*:*) GUESS=s390-ibm-zvmoe ;; *:OS400:*:*) GUESS=powerpc-ibm-os400 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) GUESS=arm-acorn-riscix$UNAME_RELEASE ;; arm*:riscos:*:*|arm*:RISCOS:*:*) GUESS=arm-unknown-riscos ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) GUESS=hppa1.1-hitachi-hiuxmpp ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. case `(/bin/universe) 2>/dev/null` in att) GUESS=pyramid-pyramid-sysv3 ;; *) GUESS=pyramid-pyramid-bsd ;; esac ;; NILE*:*:*:dcosx) GUESS=pyramid-pyramid-svr4 ;; DRS?6000:unix:4.0:6*) GUESS=sparc-icl-nx6 ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in sparc) GUESS=sparc-icl-nx7 ;; esac ;; s390x:SunOS:*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL ;; sun4H:SunOS:5.*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=sparc-hal-solaris2$SUN_REL ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=sparc-sun-solaris2$SUN_REL ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) GUESS=i386-pc-auroraux$UNAME_RELEASE ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) set_cc_for_build SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH=x86_64 fi fi SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=$SUN_ARCH-pc-solaris2$SUN_REL ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=sparc-sun-solaris3$SUN_REL ;; sun4*:SunOS:*:*) case `/usr/bin/arch -k` in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like '4.1.3-JL'. SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` GUESS=sparc-sun-sunos$SUN_REL ;; sun3*:SunOS:*:*) GUESS=m68k-sun-sunos$UNAME_RELEASE ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 case `/bin/arch` in sun3) GUESS=m68k-sun-sunos$UNAME_RELEASE ;; sun4) GUESS=sparc-sun-sunos$UNAME_RELEASE ;; esac ;; aushp:SunOS:*:*) GUESS=sparc-auspex-sunos$UNAME_RELEASE ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor # > m68000). The system name ranges from "MiNT" over "FreeMiNT" # to the lowercase version "mint" (or "freemint"). Finally # the system name "TOS" denotes a system which is actually not # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) GUESS=m68k-atari-mint$UNAME_RELEASE ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) GUESS=m68k-atari-mint$UNAME_RELEASE ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) GUESS=m68k-atari-mint$UNAME_RELEASE ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) GUESS=m68k-milan-mint$UNAME_RELEASE ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) GUESS=m68k-hades-mint$UNAME_RELEASE ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) GUESS=m68k-unknown-mint$UNAME_RELEASE ;; m68k:machten:*:*) GUESS=m68k-apple-machten$UNAME_RELEASE ;; powerpc:machten:*:*) GUESS=powerpc-apple-machten$UNAME_RELEASE ;; RISC*:Mach:*:*) GUESS=mips-dec-mach_bsd4.3 ;; RISC*:ULTRIX:*:*) GUESS=mips-dec-ultrix$UNAME_RELEASE ;; VAX*:ULTRIX*:*:*) GUESS=vax-dec-ultrix$UNAME_RELEASE ;; 2020:CLIX:*:* | 2430:CLIX:*:*) GUESS=clipper-intergraph-clix$UNAME_RELEASE ;; mips:*:*:UMIPS | mips:*:*:RISCos) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #ifdef __cplusplus #include /* for printf() prototype */ int main (int argc, char *argv[]) { #else int main (argc, argv) int argc; char *argv[]; { #endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_SVR4) printf ("mips-mips-riscos%ssvr4\\n", argv[1]); exit (0); #endif #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) printf ("mips-mips-riscos%sbsd\\n", argv[1]); exit (0); #endif #endif exit (-1); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && SYSTEM_NAME=`"$dummy" "$dummyarg"` && { echo "$SYSTEM_NAME"; exit; } GUESS=mips-mips-riscos$UNAME_RELEASE ;; Motorola:PowerMAX_OS:*:*) GUESS=powerpc-motorola-powermax ;; Motorola:*:4.3:PL8-*) GUESS=powerpc-harris-powermax ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) GUESS=powerpc-harris-powermax ;; Night_Hawk:Power_UNIX:*:*) GUESS=powerpc-harris-powerunix ;; m88k:CX/UX:7*:*) GUESS=m88k-harris-cxux7 ;; m88k:*:4*:R4*) GUESS=m88k-motorola-sysv4 ;; m88k:*:3*:R3*) GUESS=m88k-motorola-sysv3 ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ test "$TARGET_BINARY_INTERFACE"x = x then GUESS=m88k-dg-dgux$UNAME_RELEASE else GUESS=m88k-dg-dguxbcs$UNAME_RELEASE fi else GUESS=i586-dg-dgux$UNAME_RELEASE fi ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) GUESS=m88k-dolphin-sysv3 ;; M88*:*:R3*:*) # Delta 88k system running SVR3 GUESS=m88k-motorola-sysv3 ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) GUESS=m88k-tektronix-sysv3 ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) GUESS=m68k-tektronix-bsd ;; *:IRIX*:*:*) IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` GUESS=mips-sgi-irix$IRIX_REL ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) GUESS=i386-ibm-aix ;; ia64:AIX:*:*) if test -x /usr/bin/oslevel ; then IBM_REV=`/usr/bin/oslevel` else IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #include main() { if (!__power_pc()) exit(1); puts("powerpc-ibm-aix3.2.5"); exit(0); } EOF if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` then GUESS=$SYSTEM_NAME else GUESS=rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then GUESS=rs6000-ibm-aix3.2.4 else GUESS=rs6000-ibm-aix3.2 fi ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then IBM_ARCH=rs6000 else IBM_ARCH=powerpc fi if test -x /usr/bin/lslpp ; then IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` else IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi GUESS=$IBM_ARCH-ibm-aix$IBM_REV ;; *:AIX:*:*) GUESS=rs6000-ibm-aix ;; ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) GUESS=romp-ibm-bsd4.4 ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) GUESS=rs6000-bull-bosx ;; DPX/2?00:B.O.S.:*:*) GUESS=m68k-bull-sysv3 ;; 9000/[34]??:4.3bsd:1.*:*) GUESS=m68k-hp-bsd ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) GUESS=m68k-hp-bsd4.4 ;; 9000/[34678]??:HP-UX:*:*) HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` case $UNAME_MACHINE in 9000/31?) HP_ARCH=m68000 ;; 9000/[34]??) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) if test -x /usr/bin/getconf; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case $sc_cpu_version in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case $sc_kernel_bits in 32) HP_ARCH=hppa2.0n ;; 64) HP_ARCH=hppa2.0w ;; '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi if test "$HP_ARCH" = ""; then set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #define _HPUX_SOURCE #include #include int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); #endif long cpu = sysconf (_SC_CPU_VERSION); switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; default: puts ("hppa2.0"); break; } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; #endif default: puts ("hppa1.0"); break; } exit (0); } EOF (CCOPTS="" $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null) && HP_ARCH=`"$dummy"` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac if test "$HP_ARCH" = hppa2.0w then set_cc_for_build # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler # generating 64-bit code. GNU and HP use different nomenclature: # # $ CC_FOR_BUILD=cc ./config.guess # => hppa2.0w-hp-hpux11.23 # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then HP_ARCH=hppa2.0w else HP_ARCH=hppa64 fi fi GUESS=$HP_ARCH-hp-hpux$HPUX_REV ;; ia64:HP-UX:*:*) HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` GUESS=ia64-hp-hpux$HPUX_REV ;; 3050*:HI-UX:*:*) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" #include int main () { long cpu = sysconf (_SC_CPU_VERSION); /* The order matters, because CPU_IS_HP_MC68K erroneously returns true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct results, however. */ if (CPU_IS_PA_RISC (cpu)) { switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; default: puts ("hppa-hitachi-hiuxwe2"); break; } } else if (CPU_IS_HP_MC68K (cpu)) puts ("m68k-hitachi-hiuxwe2"); else puts ("unknown-hitachi-hiuxwe2"); exit (0); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } GUESS=unknown-hitachi-hiuxwe2 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) GUESS=hppa1.1-hp-bsd ;; 9000/8??:4.3bsd:*:*) GUESS=hppa1.0-hp-bsd ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) GUESS=hppa1.0-hp-mpeix ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) GUESS=hppa1.1-hp-osf ;; hp8??:OSF1:*:*) GUESS=hppa1.0-hp-osf ;; i*86:OSF1:*:*) if test -x /usr/sbin/sysversion ; then GUESS=$UNAME_MACHINE-unknown-osf1mk else GUESS=$UNAME_MACHINE-unknown-osf1 fi ;; parisc*:Lites*:*:*) GUESS=hppa1.1-hp-lites ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) GUESS=c1-convex-bsd ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd else echo c2-convex-bsd fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) GUESS=c34-convex-bsd ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) GUESS=c38-convex-bsd ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) GUESS=c4-convex-bsd ;; CRAY*Y-MP:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=ymp-cray-unicos$CRAY_REL ;; CRAY*[A-Z]90:*:*:*) echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=t90-cray-unicos$CRAY_REL ;; CRAY*T3E:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=alphaev5-cray-unicosmk$CRAY_REL ;; CRAY*SV1:*:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=sv1-cray-unicos$CRAY_REL ;; *:UNICOS/mp:*:*) CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` GUESS=craynv-cray-unicosmp$CRAY_REL ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE ;; sparc*:BSD/OS:*:*) GUESS=sparc-unknown-bsdi$UNAME_RELEASE ;; *:BSD/OS:*:*) GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE ;; arm:FreeBSD:*:*) UNAME_PROCESSOR=`uname -p` set_cc_for_build if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi else FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf fi ;; *:FreeBSD:*:*) UNAME_PROCESSOR=`uname -p` case $UNAME_PROCESSOR in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL ;; i*:CYGWIN*:*) GUESS=$UNAME_MACHINE-pc-cygwin ;; *:MINGW64*:*) GUESS=$UNAME_MACHINE-pc-mingw64 ;; *:MINGW*:*) GUESS=$UNAME_MACHINE-pc-mingw32 ;; *:MSYS*:*) GUESS=$UNAME_MACHINE-pc-msys ;; i*:PW*:*) GUESS=$UNAME_MACHINE-pc-pw32 ;; *:SerenityOS:*:*) GUESS=$UNAME_MACHINE-pc-serenity ;; *:Interix*:*) case $UNAME_MACHINE in x86) GUESS=i586-pc-interix$UNAME_RELEASE ;; authenticamd | genuineintel | EM64T) GUESS=x86_64-unknown-interix$UNAME_RELEASE ;; IA64) GUESS=ia64-unknown-interix$UNAME_RELEASE ;; esac ;; i*:UWIN*:*) GUESS=$UNAME_MACHINE-pc-uwin ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) GUESS=x86_64-pc-cygwin ;; prep*:SunOS:5.*:*) SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` GUESS=powerpcle-unknown-solaris2$SUN_REL ;; *:GNU:*:*) # the GNU system GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL ;; *:GNU/*:*:*) # other systems with GNU libc and userland GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC ;; x86_64:[Mm]anagarm:*:*|i?86:[Mm]anagarm:*:*) GUESS="$UNAME_MACHINE-pc-managarm-mlibc" ;; *:[Mm]anagarm:*:*) GUESS="$UNAME_MACHINE-unknown-managarm-mlibc" ;; *:Minix:*:*) GUESS=$UNAME_MACHINE-unknown-minix ;; aarch64:Linux:*:*) set_cc_for_build CPU=$UNAME_MACHINE LIBCABI=$LIBC if test "$CC_FOR_BUILD" != no_compiler_found; then ABI=64 sed 's/^ //' << EOF > "$dummy.c" #ifdef __ARM_EABI__ #ifdef __ARM_PCS_VFP ABI=eabihf #else ABI=eabi #endif #endif EOF cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` eval "$cc_set_abi" case $ABI in eabi | eabihf) CPU=armv8l; LIBCABI=$LIBC$ABI ;; esac fi GUESS=$CPU-unknown-linux-$LIBCABI ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; alpha:Linux:*:*) case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; PCA57) UNAME_MACHINE=alphapca56 ;; EV6) UNAME_MACHINE=alphaev6 ;; EV67) UNAME_MACHINE=alphaev67 ;; EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; arm*:Linux:*:*) set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then GUESS=$UNAME_MACHINE-unknown-linux-$LIBC else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi else GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf fi fi ;; avr32*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; cris:Linux:*:*) GUESS=$UNAME_MACHINE-axis-linux-$LIBC ;; crisv32:Linux:*:*) GUESS=$UNAME_MACHINE-axis-linux-$LIBC ;; e2k:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; frv:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; hexagon:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; i*86:Linux:*:*) GUESS=$UNAME_MACHINE-pc-linux-$LIBC ;; ia64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; k1om:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; kvx:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; kvx:cos:*:*) GUESS=$UNAME_MACHINE-unknown-cos ;; kvx:mbr:*:*) GUESS=$UNAME_MACHINE-unknown-mbr ;; loongarch32:Linux:*:* | loongarch64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; m32r*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; m68*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; mips:Linux:*:* | mips64:Linux:*:*) set_cc_for_build IS_GLIBC=0 test x"${LIBC}" = xgnu && IS_GLIBC=1 sed 's/^ //' << EOF > "$dummy.c" #undef CPU #undef mips #undef mipsel #undef mips64 #undef mips64el #if ${IS_GLIBC} && defined(_ABI64) LIBCABI=gnuabi64 #else #if ${IS_GLIBC} && defined(_ABIN32) LIBCABI=gnuabin32 #else LIBCABI=${LIBC} #endif #endif #if ${IS_GLIBC} && defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 CPU=mipsisa64r6 #else #if ${IS_GLIBC} && !defined(__mips64) && defined(__mips_isa_rev) && __mips_isa_rev>=6 CPU=mipsisa32r6 #else #if defined(__mips64) CPU=mips64 #else CPU=mips #endif #endif #endif #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) MIPS_ENDIAN=el #else #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) MIPS_ENDIAN= #else MIPS_ENDIAN= #endif #endif EOF cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` eval "$cc_set_vars" test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; openrisc*:Linux:*:*) GUESS=or1k-unknown-linux-$LIBC ;; or32:Linux:*:* | or1k*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; padre:Linux:*:*) GUESS=sparc-unknown-linux-$LIBC ;; parisc64:Linux:*:* | hppa64:Linux:*:*) GUESS=hppa64-unknown-linux-$LIBC ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; *) GUESS=hppa-unknown-linux-$LIBC ;; esac ;; ppc64:Linux:*:*) GUESS=powerpc64-unknown-linux-$LIBC ;; ppc:Linux:*:*) GUESS=powerpc-unknown-linux-$LIBC ;; ppc64le:Linux:*:*) GUESS=powerpc64le-unknown-linux-$LIBC ;; ppcle:Linux:*:*) GUESS=powerpcle-unknown-linux-$LIBC ;; riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; s390:Linux:*:* | s390x:Linux:*:*) GUESS=$UNAME_MACHINE-ibm-linux-$LIBC ;; sh64*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; sh*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; sparc:Linux:*:* | sparc64:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; tile*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; vax:Linux:*:*) GUESS=$UNAME_MACHINE-dec-linux-$LIBC ;; x86_64:Linux:*:*) set_cc_for_build CPU=$UNAME_MACHINE LIBCABI=$LIBC if test "$CC_FOR_BUILD" != no_compiler_found; then ABI=64 sed 's/^ //' << EOF > "$dummy.c" #ifdef __i386__ ABI=x86 #else #ifdef __ILP32__ ABI=x32 #endif #endif EOF cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` eval "$cc_set_abi" case $ABI in x86) CPU=i686 ;; x32) LIBCABI=${LIBC}x32 ;; esac fi GUESS=$CPU-pc-linux-$LIBCABI ;; xtensa*:Linux:*:*) GUESS=$UNAME_MACHINE-unknown-linux-$LIBC ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. GUESS=i386-sequent-sysv4 ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION ;; i*86:OS/2:*:*) # If we were able to find 'uname', then EMX Unix compatibility # is probably installed. GUESS=$UNAME_MACHINE-pc-os2-emx ;; i*86:XTS-300:*:STOP) GUESS=$UNAME_MACHINE-unknown-stop ;; i*86:atheos:*:*) GUESS=$UNAME_MACHINE-unknown-atheos ;; i*86:syllable:*:*) GUESS=$UNAME_MACHINE-pc-syllable ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) GUESS=i386-unknown-lynxos$UNAME_RELEASE ;; i*86:*DOS:*:*) GUESS=$UNAME_MACHINE-pc-msdosdjgpp ;; i*86:*:4.*:*) UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL else GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL fi ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in *486*) UNAME_MACHINE=i486 ;; *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL else GUESS=$UNAME_MACHINE-pc-sysv32 fi ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configure will decide that # this is a cross-build. GUESS=i586-pc-msdosdjgpp ;; Intel:Mach:3*:*) GUESS=i386-pc-mach3 ;; paragon:*:*:*) GUESS=i860-intel-osf1 ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 fi ;; mini*:CTIX:SYS*5:*) # "miniframe" GUESS=m68010-convergent-sysv ;; mc68k:UNIX:SYSTEM5:3.51m) GUESS=m68k-convergent-sysv ;; M680?0:D-NIX:5.3:*) GUESS=m68k-diab-dnix ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) OS_REL='' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4; exit; } ;; NCR*:*:4.2:* | MPRAS*:*:4.2:*) OS_REL='.3' test -r /etc/.relid \ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ && { echo i486-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) GUESS=m68k-unknown-lynxos$UNAME_RELEASE ;; mc68030:UNIX_System_V:4.*:*) GUESS=m68k-atari-sysv4 ;; TSUNAMI:LynxOS:2.*:*) GUESS=sparc-unknown-lynxos$UNAME_RELEASE ;; rs6000:LynxOS:2.*:*) GUESS=rs6000-unknown-lynxos$UNAME_RELEASE ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) GUESS=powerpc-unknown-lynxos$UNAME_RELEASE ;; SM[BE]S:UNIX_SV:*:*) GUESS=mips-dde-sysv$UNAME_RELEASE ;; RM*:ReliantUNIX-*:*:*) GUESS=mips-sni-sysv4 ;; RM*:SINIX-*:*:*) GUESS=mips-sni-sysv4 ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` GUESS=$UNAME_MACHINE-sni-sysv4 else GUESS=ns32k-sni-sysv fi ;; PENTIUM:*:4.0*:*) # Unisys 'ClearPath HMP IX 4000' SVR4/MP effort # says GUESS=i586-unisys-sysv4 ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes . # How about differentiating between stratus architectures? -djm GUESS=hppa1.1-stratus-sysv4 ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. GUESS=i860-stratus-sysv4 ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. GUESS=$UNAME_MACHINE-stratus-vos ;; *:VOS:*:*) # From Paul.Green@stratus.com. GUESS=hppa1.1-stratus-vos ;; mc68*:A/UX:*:*) GUESS=m68k-apple-aux$UNAME_RELEASE ;; news*:NEWS-OS:6*:*) GUESS=mips-sony-newsos6 ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if test -d /usr/nec; then GUESS=mips-nec-sysv$UNAME_RELEASE else GUESS=mips-unknown-sysv$UNAME_RELEASE fi ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. GUESS=powerpc-be-beos ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. GUESS=powerpc-apple-beos ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. GUESS=i586-pc-beos ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. GUESS=i586-pc-haiku ;; ppc:Haiku:*:*) # Haiku running on Apple PowerPC GUESS=powerpc-apple-haiku ;; *:Haiku:*:*) # Haiku modern gcc (not bound by BeOS compat) GUESS=$UNAME_MACHINE-unknown-haiku ;; SX-4:SUPER-UX:*:*) GUESS=sx4-nec-superux$UNAME_RELEASE ;; SX-5:SUPER-UX:*:*) GUESS=sx5-nec-superux$UNAME_RELEASE ;; SX-6:SUPER-UX:*:*) GUESS=sx6-nec-superux$UNAME_RELEASE ;; SX-7:SUPER-UX:*:*) GUESS=sx7-nec-superux$UNAME_RELEASE ;; SX-8:SUPER-UX:*:*) GUESS=sx8-nec-superux$UNAME_RELEASE ;; SX-8R:SUPER-UX:*:*) GUESS=sx8r-nec-superux$UNAME_RELEASE ;; SX-ACE:SUPER-UX:*:*) GUESS=sxace-nec-superux$UNAME_RELEASE ;; Power*:Rhapsody:*:*) GUESS=powerpc-apple-rhapsody$UNAME_RELEASE ;; *:Rhapsody:*:*) GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE ;; arm64:Darwin:*:*) GUESS=aarch64-apple-darwin$UNAME_RELEASE ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` case $UNAME_PROCESSOR in unknown) UNAME_PROCESSOR=powerpc ;; esac if command -v xcode-select > /dev/null 2> /dev/null && \ ! xcode-select --print-path > /dev/null 2> /dev/null ; then # Avoid executing cc if there is no toolchain installed as # cc will be a stub that puts up a graphical alert # prompting the user to install developer tools. CC_FOR_BUILD=no_compiler_found else set_cc_for_build fi if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then case $UNAME_PROCESSOR in i386) UNAME_PROCESSOR=x86_64 ;; powerpc) UNAME_PROCESSOR=powerpc64 ;; esac fi # On 10.4-10.6 one might compile for PowerPC via gcc -arch ppc if (echo '#ifdef __POWERPC__'; echo IS_PPC; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_PPC >/dev/null then UNAME_PROCESSOR=powerpc fi elif test "$UNAME_PROCESSOR" = i386 ; then # uname -m returns i386 or x86_64 UNAME_PROCESSOR=$UNAME_MACHINE fi GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE ;; *:QNX:*:4*) GUESS=i386-pc-qnx ;; NEO-*:NONSTOP_KERNEL:*:*) GUESS=neo-tandem-nsk$UNAME_RELEASE ;; NSE-*:NONSTOP_KERNEL:*:*) GUESS=nse-tandem-nsk$UNAME_RELEASE ;; NSR-*:NONSTOP_KERNEL:*:*) GUESS=nsr-tandem-nsk$UNAME_RELEASE ;; NSV-*:NONSTOP_KERNEL:*:*) GUESS=nsv-tandem-nsk$UNAME_RELEASE ;; NSX-*:NONSTOP_KERNEL:*:*) GUESS=nsx-tandem-nsk$UNAME_RELEASE ;; *:NonStop-UX:*:*) GUESS=mips-compaq-nonstopux ;; BS2000:POSIX*:*:*) GUESS=bs2000-siemens-sysv ;; DS/*:UNIX_System_V:*:*) GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. if test "${cputype-}" = 386; then UNAME_MACHINE=i386 elif test "x${cputype-}" != x; then UNAME_MACHINE=$cputype fi GUESS=$UNAME_MACHINE-unknown-plan9 ;; *:TOPS-10:*:*) GUESS=pdp10-unknown-tops10 ;; *:TENEX:*:*) GUESS=pdp10-unknown-tenex ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) GUESS=pdp10-dec-tops20 ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) GUESS=pdp10-xkl-tops20 ;; *:TOPS-20:*:*) GUESS=pdp10-unknown-tops20 ;; *:ITS:*:*) GUESS=pdp10-unknown-its ;; SEI:*:*:SEIUX) GUESS=mips-sei-seiux$UNAME_RELEASE ;; *:DragonFly:*:*) DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` case $UNAME_MACHINE in A*) GUESS=alpha-dec-vms ;; I*) GUESS=ia64-dec-vms ;; V*) GUESS=vax-dec-vms ;; esac ;; *:XENIX:*:SysV) GUESS=i386-pc-xenix ;; i*86:skyos:*:*) SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL ;; i*86:rdos:*:*) GUESS=$UNAME_MACHINE-pc-rdos ;; i*86:Fiwix:*:*) GUESS=$UNAME_MACHINE-pc-fiwix ;; *:AROS:*:*) GUESS=$UNAME_MACHINE-unknown-aros ;; x86_64:VMkernel:*:*) GUESS=$UNAME_MACHINE-unknown-esx ;; amd64:Isilon\ OneFS:*:*) GUESS=x86_64-unknown-onefs ;; *:Unleashed:*:*) GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE ;; *:Ironclad:*:*) GUESS=$UNAME_MACHINE-unknown-ironclad ;; esac # Do we have a guess based on uname results? if test "x$GUESS" != x; then echo "$GUESS" exit fi # No uname command or uname output not recognized. set_cc_for_build cat > "$dummy.c" < #include #endif #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) #if defined (vax) || defined (__vax) || defined (__vax__) || defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) #include #if defined(_SIZE_T_) || defined(SIGLOST) #include #endif #endif #endif main () { #if defined (sony) #if defined (MIPSEB) /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, I don't know.... */ printf ("mips-sony-bsd\n"); exit (0); #else #include printf ("m68k-sony-newsos%s\n", #ifdef NEWSOS4 "4" #else "" #endif ); exit (0); #endif #endif #if defined (NeXT) #if !defined (__ARCHITECTURE__) #define __ARCHITECTURE__ "m68k" #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; if (version < 4) printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); else printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif #if defined (MULTIMAX) || defined (n16) #if defined (UMAXV) printf ("ns32k-encore-sysv\n"); exit (0); #else #if defined (CMU) printf ("ns32k-encore-mach\n"); exit (0); #else printf ("ns32k-encore-bsd\n"); exit (0); #endif #endif #endif #if defined (__386BSD__) printf ("i386-pc-bsd\n"); exit (0); #endif #if defined (sequent) #if defined (i386) printf ("i386-sequent-dynix\n"); exit (0); #endif #if defined (ns32000) printf ("ns32k-sequent-dynix\n"); exit (0); #endif #endif #if defined (_SEQUENT_) struct utsname un; uname(&un); if (strncmp(un.version, "V2", 2) == 0) { printf ("i386-sequent-ptx2\n"); exit (0); } if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ printf ("i386-sequent-ptx1\n"); exit (0); } printf ("i386-sequent-ptx\n"); exit (0); #endif #if defined (vax) #if !defined (ultrix) #include #if defined (BSD) #if BSD == 43 printf ("vax-dec-bsd4.3\n"); exit (0); #else #if BSD == 199006 printf ("vax-dec-bsd4.3reno\n"); exit (0); #else printf ("vax-dec-bsd\n"); exit (0); #endif #endif #else printf ("vax-dec-bsd\n"); exit (0); #endif #else #if defined(_SIZE_T_) || defined(SIGLOST) struct utsname un; uname (&un); printf ("vax-dec-ultrix%s\n", un.release); exit (0); #else printf ("vax-dec-ultrix\n"); exit (0); #endif #endif #endif #if defined(ultrix) || defined(_ultrix) || defined(__ultrix) || defined(__ultrix__) #if defined(mips) || defined(__mips) || defined(__mips__) || defined(MIPS) || defined(__MIPS__) #if defined(_SIZE_T_) || defined(SIGLOST) struct utsname *un; uname (&un); printf ("mips-dec-ultrix%s\n", un.release); exit (0); #else printf ("mips-dec-ultrix\n"); exit (0); #endif #endif #endif #if defined (alliant) && defined (i860) printf ("i860-alliant-bsd\n"); exit (0); #endif exit (1); } EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } echo "$0: unable to guess system type" >&2 case $UNAME_MACHINE:$UNAME_SYSTEM in mips:Linux | mips64:Linux) # If we got here on MIPS GNU/Linux, output extra information. cat >&2 <&2 <&2 </dev/null || echo unknown` uname -r = `(uname -r) 2>/dev/null || echo unknown` uname -s = `(uname -s) 2>/dev/null || echo unknown` uname -v = `(uname -v) 2>/dev/null || echo unknown` /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` /bin/uname -X = `(/bin/uname -X) 2>/dev/null` hostinfo = `(hostinfo) 2>/dev/null` /bin/universe = `(/bin/universe) 2>/dev/null` /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` /bin/arch = `(/bin/arch) 2>/dev/null` /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` UNAME_MACHINE = "$UNAME_MACHINE" UNAME_RELEASE = "$UNAME_RELEASE" UNAME_SYSTEM = "$UNAME_SYSTEM" UNAME_VERSION = "$UNAME_VERSION" EOF fi exit 1 # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: openbgpd-8.8/config.sub100744 001750 001750 00000107756 14751151141 0010672#! /bin/sh # Configuration validation subroutine script. # Copyright 1992-2024 Free Software Foundation, Inc. # shellcheck disable=SC2006,SC2268 # see below for rationale timestamp='2024-01-01' # This file 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 3 of the License, or # (at your option) any later version. # # This program 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, see . # # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # Please send patches to . # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: # https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases # that are meaningful with *any* GNU software. # Each package is responsible for reporting which valid configurations # it does not support. The user should be able to distinguish # a failure to support a valid configuration from a meaningless # configuration. # The goal of this file is to map all the various variations of a given # machine specification into a single specification in the form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM # or in some cases, the newer four-part form: # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. # The "shellcheck disable" line above the timestamp inhibits complaints # about features and limitations of the classic Bourne shell that were # superseded or lifted in POSIX. However, this script identifies a wide # variety of pre-POSIX systems that do not have POSIX shells at all, and # even some reasonably current systems (Solaris 10 as case-in-point) still # have a pre-POSIX /bin/sh. me=`echo "$0" | sed -e 's,.*/,,'` usage="\ Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS Canonicalize a configuration name. Options: -h, --help print this help, then exit -t, --time-stamp print date of last modification, then exit -v, --version print version number, then exit Report bugs and patches to ." version="\ GNU config.sub ($timestamp) Copyright 1992-2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." help=" Try '$me --help' for more information." # Parse command line while test $# -gt 0 ; do case $1 in --time-stamp | --time* | -t ) echo "$timestamp" ; exit ;; --version | -v ) echo "$version" ; exit ;; --help | --h* | -h ) echo "$usage"; exit ;; -- ) # Stop option processing shift; break ;; - ) # Use stdin as input. break ;; -* ) echo "$me: invalid option $1$help" >&2 exit 1 ;; *local*) # First pass through any local machine types. echo "$1" exit ;; * ) break ;; esac done case $# in 0) echo "$me: missing argument$help" >&2 exit 1;; 1) ;; *) echo "$me: too many arguments$help" >&2 exit 1;; esac # Split fields of configuration type # shellcheck disable=SC2162 saved_IFS=$IFS IFS="-" read field1 field2 field3 field4 <&2 exit 1 ;; *-*-*-*) basic_machine=$field1-$field2 basic_os=$field3-$field4 ;; *-*-*) # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two # parts maybe_os=$field2-$field3 case $maybe_os in nto-qnx* | linux-* | uclinux-uclibc* \ | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ | storm-chaos* | os2-emx* | rtmk-nova* | managarm-* \ | windows-* ) basic_machine=$field1 basic_os=$maybe_os ;; android-linux) basic_machine=$field1-unknown basic_os=linux-android ;; *) basic_machine=$field1-$field2 basic_os=$field3 ;; esac ;; *-*) # A lone config we happen to match not fitting any pattern case $field1-$field2 in decstation-3100) basic_machine=mips-dec basic_os= ;; *-*) # Second component is usually, but not always the OS case $field2 in # Prevent following clause from handling this valid os sun*os*) basic_machine=$field1 basic_os=$field2 ;; zephyr*) basic_machine=$field1-unknown basic_os=$field2 ;; # Manufacturers dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ | att* | 7300* | 3300* | delta* | motorola* | sun[234]* \ | unicom* | ibm* | next | hp | isi* | apollo | altos* \ | convergent* | ncr* | news | 32* | 3600* | 3100* \ | hitachi* | c[123]* | convex* | sun | crds | omron* | dg \ | ultra | tti* | harris | dolphin | highlevel | gould \ | cbm | ns | masscomp | apple | axis | knuth | cray \ | microblaze* | sim | cisco \ | oki | wec | wrs | winbond) basic_machine=$field1-$field2 basic_os= ;; *) basic_machine=$field1 basic_os=$field2 ;; esac ;; esac ;; *) # Convert single-component short-hands not valid as part of # multi-component configurations. case $field1 in 386bsd) basic_machine=i386-pc basic_os=bsd ;; a29khif) basic_machine=a29k-amd basic_os=udi ;; adobe68k) basic_machine=m68010-adobe basic_os=scout ;; alliant) basic_machine=fx80-alliant basic_os= ;; altos | altos3068) basic_machine=m68k-altos basic_os= ;; am29k) basic_machine=a29k-none basic_os=bsd ;; amdahl) basic_machine=580-amdahl basic_os=sysv ;; amiga) basic_machine=m68k-unknown basic_os= ;; amigaos | amigados) basic_machine=m68k-unknown basic_os=amigaos ;; amigaunix | amix) basic_machine=m68k-unknown basic_os=sysv4 ;; apollo68) basic_machine=m68k-apollo basic_os=sysv ;; apollo68bsd) basic_machine=m68k-apollo basic_os=bsd ;; aros) basic_machine=i386-pc basic_os=aros ;; aux) basic_machine=m68k-apple basic_os=aux ;; balance) basic_machine=ns32k-sequent basic_os=dynix ;; blackfin) basic_machine=bfin-unknown basic_os=linux ;; cegcc) basic_machine=arm-unknown basic_os=cegcc ;; convex-c1) basic_machine=c1-convex basic_os=bsd ;; convex-c2) basic_machine=c2-convex basic_os=bsd ;; convex-c32) basic_machine=c32-convex basic_os=bsd ;; convex-c34) basic_machine=c34-convex basic_os=bsd ;; convex-c38) basic_machine=c38-convex basic_os=bsd ;; cray) basic_machine=j90-cray basic_os=unicos ;; crds | unos) basic_machine=m68k-crds basic_os= ;; da30) basic_machine=m68k-da30 basic_os= ;; decstation | pmax | pmin | dec3100 | decstatn) basic_machine=mips-dec basic_os= ;; delta88) basic_machine=m88k-motorola basic_os=sysv3 ;; dicos) basic_machine=i686-pc basic_os=dicos ;; djgpp) basic_machine=i586-pc basic_os=msdosdjgpp ;; ebmon29k) basic_machine=a29k-amd basic_os=ebmon ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson basic_os=ose ;; gmicro) basic_machine=tron-gmicro basic_os=sysv ;; go32) basic_machine=i386-pc basic_os=go32 ;; h8300hms) basic_machine=h8300-hitachi basic_os=hms ;; h8300xray) basic_machine=h8300-hitachi basic_os=xray ;; h8500hms) basic_machine=h8500-hitachi basic_os=hms ;; harris) basic_machine=m88k-harris basic_os=sysv3 ;; hp300 | hp300hpux) basic_machine=m68k-hp basic_os=hpux ;; hp300bsd) basic_machine=m68k-hp basic_os=bsd ;; hppaosf) basic_machine=hppa1.1-hp basic_os=osf ;; hppro) basic_machine=hppa1.1-hp basic_os=proelf ;; i386mach) basic_machine=i386-mach basic_os=mach ;; isi68 | isi) basic_machine=m68k-isi basic_os=sysv ;; m68knommu) basic_machine=m68k-unknown basic_os=linux ;; magnum | m3230) basic_machine=mips-mips basic_os=sysv ;; merlin) basic_machine=ns32k-utek basic_os=sysv ;; mingw64) basic_machine=x86_64-pc basic_os=mingw64 ;; mingw32) basic_machine=i686-pc basic_os=mingw32 ;; mingw32ce) basic_machine=arm-unknown basic_os=mingw32ce ;; monitor) basic_machine=m68k-rom68k basic_os=coff ;; morphos) basic_machine=powerpc-unknown basic_os=morphos ;; moxiebox) basic_machine=moxie-unknown basic_os=moxiebox ;; msdos) basic_machine=i386-pc basic_os=msdos ;; msys) basic_machine=i686-pc basic_os=msys ;; mvs) basic_machine=i370-ibm basic_os=mvs ;; nacl) basic_machine=le32-unknown basic_os=nacl ;; ncr3000) basic_machine=i486-ncr basic_os=sysv4 ;; netbsd386) basic_machine=i386-pc basic_os=netbsd ;; netwinder) basic_machine=armv4l-rebel basic_os=linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony basic_os=newsos ;; news1000) basic_machine=m68030-sony basic_os=newsos ;; necv70) basic_machine=v70-nec basic_os=sysv ;; nh3000) basic_machine=m68k-harris basic_os=cxux ;; nh[45]000) basic_machine=m88k-harris basic_os=cxux ;; nindy960) basic_machine=i960-intel basic_os=nindy ;; mon960) basic_machine=i960-intel basic_os=mon960 ;; nonstopux) basic_machine=mips-compaq basic_os=nonstopux ;; os400) basic_machine=powerpc-ibm basic_os=os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson basic_os=ose ;; os68k) basic_machine=m68k-none basic_os=os68k ;; paragon) basic_machine=i860-intel basic_os=osf ;; parisc) basic_machine=hppa-unknown basic_os=linux ;; psp) basic_machine=mipsallegrexel-sony basic_os=psp ;; pw32) basic_machine=i586-unknown basic_os=pw32 ;; rdos | rdos64) basic_machine=x86_64-pc basic_os=rdos ;; rdos32) basic_machine=i386-pc basic_os=rdos ;; rom68k) basic_machine=m68k-rom68k basic_os=coff ;; sa29200) basic_machine=a29k-amd basic_os=udi ;; sei) basic_machine=mips-sei basic_os=seiux ;; sequent) basic_machine=i386-sequent basic_os= ;; sps7) basic_machine=m68k-bull basic_os=sysv2 ;; st2000) basic_machine=m68k-tandem basic_os= ;; stratus) basic_machine=i860-stratus basic_os=sysv4 ;; sun2) basic_machine=m68000-sun basic_os= ;; sun2os3) basic_machine=m68000-sun basic_os=sunos3 ;; sun2os4) basic_machine=m68000-sun basic_os=sunos4 ;; sun3) basic_machine=m68k-sun basic_os= ;; sun3os3) basic_machine=m68k-sun basic_os=sunos3 ;; sun3os4) basic_machine=m68k-sun basic_os=sunos4 ;; sun4) basic_machine=sparc-sun basic_os= ;; sun4os3) basic_machine=sparc-sun basic_os=sunos3 ;; sun4os4) basic_machine=sparc-sun basic_os=sunos4 ;; sun4sol2) basic_machine=sparc-sun basic_os=solaris2 ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun basic_os= ;; sv1) basic_machine=sv1-cray basic_os=unicos ;; symmetry) basic_machine=i386-sequent basic_os=dynix ;; t3e) basic_machine=alphaev5-cray basic_os=unicos ;; t90) basic_machine=t90-cray basic_os=unicos ;; toad1) basic_machine=pdp10-xkl basic_os=tops20 ;; tpf) basic_machine=s390x-ibm basic_os=tpf ;; udi29k) basic_machine=a29k-amd basic_os=udi ;; ultra3) basic_machine=a29k-nyu basic_os=sym1 ;; v810 | necv810) basic_machine=v810-nec basic_os=none ;; vaxv) basic_machine=vax-dec basic_os=sysv ;; vms) basic_machine=vax-dec basic_os=vms ;; vsta) basic_machine=i386-pc basic_os=vsta ;; vxworks960) basic_machine=i960-wrs basic_os=vxworks ;; vxworks68) basic_machine=m68k-wrs basic_os=vxworks ;; vxworks29k) basic_machine=a29k-wrs basic_os=vxworks ;; xbox) basic_machine=i686-pc basic_os=mingw32 ;; ymp) basic_machine=ymp-cray basic_os=unicos ;; *) basic_machine=$1 basic_os= ;; esac ;; esac # Decode 1-component or ad-hoc basic machines case $basic_machine in # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. w89k) cpu=hppa1.1 vendor=winbond ;; op50n) cpu=hppa1.1 vendor=oki ;; op60c) cpu=hppa1.1 vendor=oki ;; ibm*) cpu=i370 vendor=ibm ;; orion105) cpu=clipper vendor=highlevel ;; mac | mpw | mac-mpw) cpu=m68k vendor=apple ;; pmac | pmac-mpw) cpu=powerpc vendor=apple ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) cpu=m68000 vendor=att ;; 3b*) cpu=we32k vendor=att ;; bluegene*) cpu=powerpc vendor=ibm basic_os=cnk ;; decsystem10* | dec10*) cpu=pdp10 vendor=dec basic_os=tops10 ;; decsystem20* | dec20*) cpu=pdp10 vendor=dec basic_os=tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) cpu=m68k vendor=motorola ;; dpx2*) cpu=m68k vendor=bull basic_os=sysv3 ;; encore | umax | mmax) cpu=ns32k vendor=encore ;; elxsi) cpu=elxsi vendor=elxsi basic_os=${basic_os:-bsd} ;; fx2800) cpu=i860 vendor=alliant ;; genix) cpu=ns32k vendor=ns ;; h3050r* | hiux*) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k2[0-9][0-9] | hp9k31[0-9]) cpu=m68000 vendor=hp ;; hp9k3[2-9][0-9]) cpu=m68k vendor=hp ;; hp9k6[0-9][0-9] | hp6[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; hp9k7[0-79][0-9] | hp7[0-79][0-9]) cpu=hppa1.1 vendor=hp ;; hp9k78[0-9] | hp78[0-9]) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) # FIXME: really hppa2.0-hp cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][13679] | hp8[0-9][13679]) cpu=hppa1.1 vendor=hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) cpu=hppa1.0 vendor=hp ;; i*86v32) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv32 ;; i*86v4*) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv4 ;; i*86v) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=sysv ;; i*86sol2) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc basic_os=solaris2 ;; j90 | j90-cray) cpu=j90 vendor=cray basic_os=${basic_os:-unicos} ;; iris | iris4d) cpu=mips vendor=sgi case $basic_os in irix*) ;; *) basic_os=irix4 ;; esac ;; miniframe) cpu=m68000 vendor=convergent ;; *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) cpu=m68k vendor=atari basic_os=mint ;; news-3600 | risc-news) cpu=mips vendor=sony basic_os=newsos ;; next | m*-next) cpu=m68k vendor=next case $basic_os in openstep*) ;; nextstep*) ;; ns2*) basic_os=nextstep2 ;; *) basic_os=nextstep3 ;; esac ;; np1) cpu=np1 vendor=gould ;; op50n-* | op60c-*) cpu=hppa1.1 vendor=oki basic_os=proelf ;; pa-hitachi) cpu=hppa1.1 vendor=hitachi basic_os=hiuxwe2 ;; pbd) cpu=sparc vendor=tti ;; pbb) cpu=m68k vendor=tti ;; pc532) cpu=ns32k vendor=pc532 ;; pn) cpu=pn vendor=gould ;; power) cpu=power vendor=ibm ;; ps2) cpu=i386 vendor=ibm ;; rm[46]00) cpu=mips vendor=siemens ;; rtpc | rtpc-*) cpu=romp vendor=ibm ;; sde) cpu=mipsisa32 vendor=sde basic_os=${basic_os:-elf} ;; simso-wrs) cpu=sparclite vendor=wrs basic_os=vxworks ;; tower | tower-32) cpu=m68k vendor=ncr ;; vpp*|vx|vx-*) cpu=f301 vendor=fujitsu ;; w65) cpu=w65 vendor=wdc ;; w89k-*) cpu=hppa1.1 vendor=winbond basic_os=proelf ;; none) cpu=none vendor=none ;; leon|leon[3-9]) cpu=sparc vendor=$basic_machine ;; leon-*|leon[3-9]-*) cpu=sparc vendor=`echo "$basic_machine" | sed 's/-.*//'` ;; *-*) # shellcheck disable=SC2162 saved_IFS=$IFS IFS="-" read cpu vendor <&2 exit 1 ;; esac ;; esac # Here we canonicalize certain aliases for manufacturers. case $vendor in digital*) vendor=dec ;; commodore*) vendor=cbm ;; *) ;; esac # Decode manufacturer-specific aliases for certain operating systems. if test x"$basic_os" != x then # First recognize some ad-hoc cases, or perhaps split kernel-os, or else just # set os. obj= case $basic_os in gnu/linux*) kernel=linux os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` ;; os2-emx) kernel=os2 os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` ;; nto-qnx*) kernel=nto os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` ;; *-*) # shellcheck disable=SC2162 saved_IFS=$IFS IFS="-" read kernel os <&2 fi ;; *) echo "Invalid configuration '$1': OS '$os' not recognized" 1>&2 exit 1 ;; esac case $obj in aout* | coff* | elf* | pe*) ;; '') # empty is fine ;; *) echo "Invalid configuration '$1': Machine code format '$obj' not recognized" 1>&2 exit 1 ;; esac # Here we handle the constraint that a (synthetic) cpu and os are # valid only in combination with each other and nowhere else. case $cpu-$os in # The "javascript-unknown-ghcjs" triple is used by GHC; we # accept it here in order to tolerate that, but reject any # variations. javascript-ghcjs) ;; javascript-* | *-ghcjs) echo "Invalid configuration '$1': cpu '$cpu' is not valid with os '$os$obj'" 1>&2 exit 1 ;; esac # As a final step for OS-related things, validate the OS-kernel combination # (given a valid OS), if there is a kernel. case $kernel-$os-$obj in linux-gnu*- | linux-android*- | linux-dietlibc*- | linux-llvm*- \ | linux-mlibc*- | linux-musl*- | linux-newlib*- \ | linux-relibc*- | linux-uclibc*- ) ;; uclinux-uclibc*- ) ;; managarm-mlibc*- | managarm-kernel*- ) ;; windows*-msvc*-) ;; -dietlibc*- | -llvm*- | -mlibc*- | -musl*- | -newlib*- | -relibc*- \ | -uclibc*- ) # These are just libc implementations, not actual OSes, and thus # require a kernel. echo "Invalid configuration '$1': libc '$os' needs explicit kernel." 1>&2 exit 1 ;; -kernel*- ) echo "Invalid configuration '$1': '$os' needs explicit kernel." 1>&2 exit 1 ;; *-kernel*- ) echo "Invalid configuration '$1': '$kernel' does not support '$os'." 1>&2 exit 1 ;; *-msvc*- ) echo "Invalid configuration '$1': '$os' needs 'windows'." 1>&2 exit 1 ;; kfreebsd*-gnu*- | kopensolaris*-gnu*-) ;; vxworks-simlinux- | vxworks-simwindows- | vxworks-spe-) ;; nto-qnx*-) ;; os2-emx-) ;; *-eabi*- | *-gnueabi*-) ;; none--*) # None (no kernel, i.e. freestanding / bare metal), # can be paired with an machine code file format ;; -*-) # Blank kernel with real OS is always fine. ;; --*) # Blank kernel and OS with real machine code file format is always fine. ;; *-*-*) echo "Invalid configuration '$1': Kernel '$kernel' not known to work with OS '$os'." 1>&2 exit 1 ;; esac # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. case $vendor in unknown) case $cpu-$os in *-riscix*) vendor=acorn ;; *-sunos*) vendor=sun ;; *-cnk* | *-aix*) vendor=ibm ;; *-beos*) vendor=be ;; *-hpux*) vendor=hp ;; *-mpeix*) vendor=hp ;; *-hiux*) vendor=hitachi ;; *-unos*) vendor=crds ;; *-dgux*) vendor=dg ;; *-luna*) vendor=omron ;; *-genix*) vendor=ns ;; *-clix*) vendor=intergraph ;; *-mvs* | *-opened*) vendor=ibm ;; *-os400*) vendor=ibm ;; s390-* | s390x-*) vendor=ibm ;; *-ptx*) vendor=sequent ;; *-tpf*) vendor=ibm ;; *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; *-aux*) vendor=apple ;; *-hms*) vendor=hitachi ;; *-mpw* | *-macos*) vendor=apple ;; *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; *-vos*) vendor=stratus ;; esac ;; esac echo "$cpu-$vendor${kernel:+-$kernel}${os:+-$os}${obj:+-$obj}" exit # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "timestamp='" # time-stamp-format: "%:y-%02m-%02d" # time-stamp-end: "'" # End: openbgpd-8.8/depcomp100755 001750 001750 00000056020 14751151141 0010251#! /bin/sh # depcomp - compile a program generating dependencies as side-effects scriptversion=2018-03-07.03; # UTC # Copyright (C) 1999-2021 Free Software Foundation, Inc. # This program 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. # This program 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. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # Originally written by Alexandre Oliva . case $1 in '') echo "$0: No command. Try '$0 --help' for more information." 1>&2 exit 1; ;; -h | --h*) cat <<\EOF Usage: depcomp [--help] [--version] PROGRAM [ARGS] Run PROGRAMS ARGS to compile a file, generating dependencies as side-effects. Environment variables: depmode Dependency tracking mode. source Source file read by 'PROGRAMS ARGS'. object Object file output by 'PROGRAMS ARGS'. DEPDIR directory where to store dependencies. depfile Dependency file to output. tmpdepfile Temporary file to use when outputting dependencies. libtool Whether libtool is used (yes/no). Report bugs to . EOF exit $? ;; -v | --v*) echo "depcomp $scriptversion" exit $? ;; esac # Get the directory component of the given path, and save it in the # global variables '$dir'. Note that this directory component will # be either empty or ending with a '/' character. This is deliberate. set_dir_from () { case $1 in */*) dir=`echo "$1" | sed -e 's|/[^/]*$|/|'`;; *) dir=;; esac } # Get the suffix-stripped basename of the given path, and save it the # global variable '$base'. set_base_from () { base=`echo "$1" | sed -e 's|^.*/||' -e 's/\.[^.]*$//'` } # If no dependency file was actually created by the compiler invocation, # we still have to create a dummy depfile, to avoid errors with the # Makefile "include basename.Plo" scheme. make_dummy_depfile () { echo "#dummy" > "$depfile" } # Factor out some common post-processing of the generated depfile. # Requires the auxiliary global variable '$tmpdepfile' to be set. aix_post_process_depfile () { # If the compiler actually managed to produce a dependency file, # post-process it. if test -f "$tmpdepfile"; then # Each line is of the form 'foo.o: dependency.h'. # Do two passes, one to just change these to # $object: dependency.h # and one to simply output # dependency.h: # which is needed to avoid the deleted-header problem. { sed -e "s,^.*\.[$lower]*:,$object:," < "$tmpdepfile" sed -e "s,^.*\.[$lower]*:[$tab ]*,," -e 's,$,:,' < "$tmpdepfile" } > "$depfile" rm -f "$tmpdepfile" else make_dummy_depfile fi } # A tabulation character. tab=' ' # A newline character. nl=' ' # Character ranges might be problematic outside the C locale. # These definitions help. upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ lower=abcdefghijklmnopqrstuvwxyz digits=0123456789 alpha=${upper}${lower} if test -z "$depmode" || test -z "$source" || test -z "$object"; then echo "depcomp: Variables source, object and depmode must be set" 1>&2 exit 1 fi # Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po. depfile=${depfile-`echo "$object" | sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`} tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} rm -f "$tmpdepfile" # Avoid interferences from the environment. gccflag= dashmflag= # Some modes work just like other modes, but use different flags. We # parameterize here, but still list the modes in the big case below, # to make depend.m4 easier to write. Note that we *cannot* use a case # here, because this file can only contain one case statement. if test "$depmode" = hp; then # HP compiler uses -M and no extra arg. gccflag=-M depmode=gcc fi if test "$depmode" = dashXmstdout; then # This is just like dashmstdout with a different argument. dashmflag=-xM depmode=dashmstdout fi cygpath_u="cygpath -u -f -" if test "$depmode" = msvcmsys; then # This is just like msvisualcpp but w/o cygpath translation. # Just convert the backslash-escaped backslashes to single forward # slashes to satisfy depend.m4 cygpath_u='sed s,\\\\,/,g' depmode=msvisualcpp fi if test "$depmode" = msvc7msys; then # This is just like msvc7 but w/o cygpath translation. # Just convert the backslash-escaped backslashes to single forward # slashes to satisfy depend.m4 cygpath_u='sed s,\\\\,/,g' depmode=msvc7 fi if test "$depmode" = xlc; then # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information. gccflag=-qmakedep=gcc,-MF depmode=gcc fi case "$depmode" in gcc3) ## gcc 3 implements dependency tracking that does exactly what ## we want. Yay! Note: for some reason libtool 1.4 doesn't like ## it if -MD -MP comes after the -MF stuff. Hmm. ## Unfortunately, FreeBSD c89 acceptance of flags depends upon ## the command line argument order; so add the flags where they ## appear in depend2.am. Note that the slowdown incurred here ## affects only configure: in makefiles, %FASTDEP% shortcuts this. for arg do case $arg in -c) set fnord "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" "$arg" ;; *) set fnord "$@" "$arg" ;; esac shift # fnord shift # $arg done "$@" stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi mv "$tmpdepfile" "$depfile" ;; gcc) ## Note that this doesn't just cater to obsosete pre-3.x GCC compilers. ## but also to in-use compilers like IMB xlc/xlC and the HP C compiler. ## (see the conditional assignment to $gccflag above). ## There are various ways to get dependency output from gcc. Here's ## why we pick this rather obscure method: ## - Don't want to use -MD because we'd like the dependencies to end ## up in a subdir. Having to rename by hand is ugly. ## (We might end up doing this anyway to support other compilers.) ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like ## -MM, not -M (despite what the docs say). Also, it might not be ## supported by the other compilers which use the 'gcc' depmode. ## - Using -M directly means running the compiler twice (even worse ## than renaming). if test -z "$gccflag"; then gccflag=-MD, fi "$@" -Wp,"$gccflag$tmpdepfile" stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" # The second -e expression handles DOS-style file names with drive # letters. sed -e 's/^[^:]*: / /' \ -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" ## This next piece of magic avoids the "deleted header file" problem. ## The problem is that when a header file which appears in a .P file ## is deleted, the dependency causes make to die (because there is ## typically no way to rebuild the header). We avoid this by adding ## dummy dependencies for each header file. Too bad gcc doesn't do ## this for us directly. ## Some versions of gcc put a space before the ':'. On the theory ## that the space means something, we add a space to the output as ## well. hp depmode also adds that space, but also prefixes the VPATH ## to the object. Take care to not repeat it in the output. ## Some versions of the HPUX 10.20 sed can't process this invocation ## correctly. Breaking it into two sed invocations is a workaround. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^\\$//' -e '/^$/d' -e "s|.*$object$||" -e '/:$/d' \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; sgi) if test "$libtool" = yes; then "$@" "-Wp,-MDupdate,$tmpdepfile" else "$@" -MDupdate "$tmpdepfile" fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files echo "$object : \\" > "$depfile" # Clip off the initial element (the dependent). Don't try to be # clever and replace this with sed code, as IRIX sed won't handle # lines with more than a fixed number of characters (4096 in # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; # the IRIX cc adds comments like '#:fec' to the end of the # dependency line. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' \ | tr "$nl" ' ' >> "$depfile" echo >> "$depfile" # The second pass generates a dummy entry for each header file. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ >> "$depfile" else make_dummy_depfile fi rm -f "$tmpdepfile" ;; xlc) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; aix) # The C for AIX Compiler uses -M and outputs the dependencies # in a .u file. In older versions, this file always lives in the # current directory. Also, the AIX compiler puts '$object:' at the # start of each line; $object doesn't have directory information. # Version 6 uses the directory in both cases. set_dir_from "$object" set_base_from "$object" if test "$libtool" = yes; then tmpdepfile1=$dir$base.u tmpdepfile2=$base.u tmpdepfile3=$dir.libs/$base.u "$@" -Wc,-M else tmpdepfile1=$dir$base.u tmpdepfile2=$dir$base.u tmpdepfile3=$dir$base.u "$@" -M fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" do test -f "$tmpdepfile" && break done aix_post_process_depfile ;; tcc) # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26 # FIXME: That version still under development at the moment of writing. # Make that this statement remains true also for stable, released # versions. # It will wrap lines (doesn't matter whether long or short) with a # trailing '\', as in: # # foo.o : \ # foo.c \ # foo.h \ # # It will put a trailing '\' even on the last line, and will use leading # spaces rather than leading tabs (at least since its commit 0394caf7 # "Emit spaces for -MD"). "$@" -MD -MF "$tmpdepfile" stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" # Each non-empty line is of the form 'foo.o : \' or ' dep.h \'. # We have to change lines of the first kind to '$object: \'. sed -e "s|.*:|$object :|" < "$tmpdepfile" > "$depfile" # And for each line of the second kind, we have to emit a 'dep.h:' # dummy dependency, to avoid the deleted-header problem. sed -n -e 's|^ *\(.*\) *\\$|\1:|p' < "$tmpdepfile" >> "$depfile" rm -f "$tmpdepfile" ;; ## The order of this option in the case statement is important, since the ## shell code in configure will try each of these formats in the order ## listed in this file. A plain '-MD' option would be understood by many ## compilers, so we must ensure this comes after the gcc and icc options. pgcc) # Portland's C compiler understands '-MD'. # Will always output deps to 'file.d' where file is the root name of the # source file under compilation, even if file resides in a subdirectory. # The object file name does not affect the name of the '.d' file. # pgcc 10.2 will output # foo.o: sub/foo.c sub/foo.h # and will wrap long lines using '\' : # foo.o: sub/foo.c ... \ # sub/foo.h ... \ # ... set_dir_from "$object" # Use the source, not the object, to determine the base name, since # that's sadly what pgcc will do too. set_base_from "$source" tmpdepfile=$base.d # For projects that build the same source file twice into different object # files, the pgcc approach of using the *source* file root name can cause # problems in parallel builds. Use a locking strategy to avoid stomping on # the same $tmpdepfile. lockdir=$base.d-lock trap " echo '$0: caught signal, cleaning up...' >&2 rmdir '$lockdir' exit 1 " 1 2 13 15 numtries=100 i=$numtries while test $i -gt 0; do # mkdir is a portable test-and-set. if mkdir "$lockdir" 2>/dev/null; then # This process acquired the lock. "$@" -MD stat=$? # Release the lock. rmdir "$lockdir" break else # If the lock is being held by a different process, wait # until the winning process is done or we timeout. while test -d "$lockdir" && test $i -gt 0; do sleep 1 i=`expr $i - 1` done fi i=`expr $i - 1` done trap - 1 2 13 15 if test $i -le 0; then echo "$0: failed to acquire lock after $numtries attempts" >&2 echo "$0: check lockdir '$lockdir'" >&2 exit 1 fi if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" # Each line is of the form `foo.o: dependent.h', # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'. # Do two passes, one to just change these to # `$object: dependent.h' and one to simply `dependent.h:'. sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process this invocation # correctly. Breaking it into two sed invocations is a workaround. sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; hp2) # The "hp" stanza above does not work with aCC (C++) and HP's ia64 # compilers, which have integrated preprocessors. The correct option # to use with these is +Maked; it writes dependencies to a file named # 'foo.d', which lands next to the object file, wherever that # happens to be. # Much of this is similar to the tru64 case; see comments there. set_dir_from "$object" set_base_from "$object" if test "$libtool" = yes; then tmpdepfile1=$dir$base.d tmpdepfile2=$dir.libs/$base.d "$@" -Wc,+Maked else tmpdepfile1=$dir$base.d tmpdepfile2=$dir$base.d "$@" +Maked fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile1" "$tmpdepfile2" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" do test -f "$tmpdepfile" && break done if test -f "$tmpdepfile"; then sed -e "s,^.*\.[$lower]*:,$object:," "$tmpdepfile" > "$depfile" # Add 'dependent.h:' lines. sed -ne '2,${ s/^ *// s/ \\*$// s/$/:/ p }' "$tmpdepfile" >> "$depfile" else make_dummy_depfile fi rm -f "$tmpdepfile" "$tmpdepfile2" ;; tru64) # The Tru64 compiler uses -MD to generate dependencies as a side # effect. 'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'. # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put # dependencies in 'foo.d' instead, so we check for that too. # Subdirectories are respected. set_dir_from "$object" set_base_from "$object" if test "$libtool" = yes; then # Libtool generates 2 separate objects for the 2 libraries. These # two compilations output dependencies in $dir.libs/$base.o.d and # in $dir$base.o.d. We have to check for both files, because # one of the two compilations can be disabled. We should prefer # $dir$base.o.d over $dir.libs/$base.o.d because the latter is # automatically cleaned when .libs/ is deleted, while ignoring # the former would cause a distcleancheck panic. tmpdepfile1=$dir$base.o.d # libtool 1.5 tmpdepfile2=$dir.libs/$base.o.d # Likewise. tmpdepfile3=$dir.libs/$base.d # Compaq CCC V6.2-504 "$@" -Wc,-MD else tmpdepfile1=$dir$base.d tmpdepfile2=$dir$base.d tmpdepfile3=$dir$base.d "$@" -MD fi stat=$? if test $stat -ne 0; then rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" exit $stat fi for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" do test -f "$tmpdepfile" && break done # Same post-processing that is required for AIX mode. aix_post_process_depfile ;; msvc7) if test "$libtool" = yes; then showIncludes=-Wc,-showIncludes else showIncludes=-showIncludes fi "$@" $showIncludes > "$tmpdepfile" stat=$? grep -v '^Note: including file: ' "$tmpdepfile" if test $stat -ne 0; then rm -f "$tmpdepfile" exit $stat fi rm -f "$depfile" echo "$object : \\" > "$depfile" # The first sed program below extracts the file names and escapes # backslashes for cygpath. The second sed program outputs the file # name when reading, but also accumulates all include files in the # hold buffer in order to output them again at the end. This only # works with sed implementations that can handle large buffers. sed < "$tmpdepfile" -n ' /^Note: including file: *\(.*\)/ { s//\1/ s/\\/\\\\/g p }' | $cygpath_u | sort -u | sed -n ' s/ /\\ /g s/\(.*\)/'"$tab"'\1 \\/p s/.\(.*\) \\/\1:/ H $ { s/.*/'"$tab"'/ G p }' >> "$depfile" echo >> "$depfile" # make sure the fragment doesn't end with a backslash rm -f "$tmpdepfile" ;; msvc7msys) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; #nosideeffect) # This comment above is used by automake to tell side-effect # dependency tracking mechanisms from slower ones. dashmstdout) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout, regardless of -o. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove '-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done test -z "$dashmflag" && dashmflag=-M # Require at least two characters before searching for ':' # in the target name. This is to cope with DOS-style filenames: # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise. "$@" $dashmflag | sed "s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |" > "$tmpdepfile" rm -f "$depfile" cat < "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process this sed invocation # correctly. Breaking it into two sed invocations is a workaround. tr ' ' "$nl" < "$tmpdepfile" \ | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; dashXmstdout) # This case only exists to satisfy depend.m4. It is never actually # run, as this mode is specially recognized in the preamble. exit 1 ;; makedepend) "$@" || exit $? # Remove any Libtool call if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # X makedepend shift cleared=no eat=no for arg do case $cleared in no) set ""; shift cleared=yes ;; esac if test $eat = yes; then eat=no continue fi case "$arg" in -D*|-I*) set fnord "$@" "$arg"; shift ;; # Strip any option that makedepend may not understand. Remove # the object too, otherwise makedepend will parse it as a source file. -arch) eat=yes ;; -*|$object) ;; *) set fnord "$@" "$arg"; shift ;; esac done obj_suffix=`echo "$object" | sed 's/^.*\././'` touch "$tmpdepfile" ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" rm -f "$depfile" # makedepend may prepend the VPATH from the source file name to the object. # No need to regex-escape $object, excess matching of '.' is harmless. sed "s|^.*\($object *:\)|\1|" "$tmpdepfile" > "$depfile" # Some versions of the HPUX 10.20 sed can't process the last invocation # correctly. Breaking it into two sed invocations is a workaround. sed '1,2d' "$tmpdepfile" \ | tr ' ' "$nl" \ | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' \ | sed -e 's/$/ :/' >> "$depfile" rm -f "$tmpdepfile" "$tmpdepfile".bak ;; cpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi # Remove '-o $object'. IFS=" " for arg do case $arg in -o) shift ;; $object) shift ;; *) set fnord "$@" "$arg" shift # fnord shift # $arg ;; esac done "$@" -E \ | sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \ | sed '$ s: \\$::' > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" cat < "$tmpdepfile" >> "$depfile" sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" rm -f "$tmpdepfile" ;; msvisualcpp) # Important note: in order to support this mode, a compiler *must* # always write the preprocessed file to stdout. "$@" || exit $? # Remove the call to Libtool. if test "$libtool" = yes; then while test "X$1" != 'X--mode=compile'; do shift done shift fi IFS=" " for arg do case "$arg" in -o) shift ;; $object) shift ;; "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") set fnord "$@" shift shift ;; *) set fnord "$@" "$arg" shift shift ;; esac done "$@" -E 2>/dev/null | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::\1:p' | $cygpath_u | sort -u > "$tmpdepfile" rm -f "$depfile" echo "$object : \\" > "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::'"$tab"'\1 \\:p' >> "$depfile" echo "$tab" >> "$depfile" sed < "$tmpdepfile" -n -e 's% %\\ %g' -e '/^\(.*\)$/ s::\1\::p' >> "$depfile" rm -f "$tmpdepfile" ;; msvcmsys) # This case exists only to let depend.m4 do its work. It works by # looking at the text of this script. This case will never be run, # since it is checked for above. exit 1 ;; none) exec "$@" ;; *) echo "Unknown depmode $depmode" 1>&2 exit 1 ;; esac exit 0 # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: openbgpd-8.8/install-sh100744 001750 001750 00000036101 14751151141 0010674#!/bin/sh # install - install a program, script, or datafile scriptversion=2023-11-23.18; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the # following copyright and license. # # Copyright (C) 1994 X Consortium # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # # Except as contained in this notice, the name of the X Consortium shall not # be used in advertising or otherwise to promote the sale, use or other deal- # ings in this Software without prior written authorization from the X Consor- # tium. # # # FSF changes to this file are in the public domain. # # Calling this script install-sh is preferred over install.sh, to prevent # 'make' implicit rules from creating a file called install from it # when there is no Makefile. # # This script is compatible with the BSD install script, but was written # from scratch. tab=' ' nl=' ' IFS=" $tab$nl" # Set DOITPROG to "echo" to test this script. doit=${DOITPROG-} doit_exec=${doit:-exec} # Put in absolute file names if you don't have them in your path; # or use environment vars. chgrpprog=${CHGRPPROG-chgrp} chmodprog=${CHMODPROG-chmod} chownprog=${CHOWNPROG-chown} cmpprog=${CMPPROG-cmp} cpprog=${CPPROG-cp} mkdirprog=${MKDIRPROG-mkdir} mvprog=${MVPROG-mv} rmprog=${RMPROG-rm} stripprog=${STRIPPROG-strip} posix_mkdir= # Desired mode of installed file. mode=0755 # Create dirs (including intermediate dirs) using mode 755. # This is like GNU 'install' as of coreutils 8.32 (2020). mkdir_umask=22 backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= mvcmd=$mvprog rmcmd="$rmprog -f" stripcmd= src= dst= dir_arg= dst_arg= copy_on_change=false is_target_a_directory=possibly usage="\ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE or: $0 [OPTION]... SRCFILES... DIRECTORY or: $0 [OPTION]... -t DIRECTORY SRCFILES... or: $0 [OPTION]... -d DIRECTORIES... In the 1st form, copy SRCFILE to DSTFILE. In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. In the 4th, create DIRECTORIES. Options: --help display this help and exit. --version display version info and exit. -c (ignored) -C install only if different (preserve data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. -p pass -p to $cpprog. -s $stripprog installed files. -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG By default, rm is invoked with -f; when overridden with RMPROG, it's up to you to specify -f if you want it. If -S is not specified, no backups are attempted. Report bugs to . GNU Automake home page: . General help using GNU software: ." while test $# -ne 0; do case $1 in -c) ;; -C) copy_on_change=true;; -d) dir_arg=true;; -g) chgrpcmd="$chgrpprog $2" shift;; --help) echo "$usage"; exit $?;; -m) mode=$2 case $mode in *' '* | *"$tab"* | *"$nl"* | *'*'* | *'?'* | *'['*) echo "$0: invalid mode: $mode" >&2 exit 1;; esac shift;; -o) chowncmd="$chownprog $2" shift;; -p) cpprog="$cpprog -p";; -s) stripcmd=$stripprog;; -S) backupsuffix="$2" shift;; -t) is_target_a_directory=always dst_arg=$2 # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac shift;; -T) is_target_a_directory=never;; --version) echo "$0 $scriptversion"; exit $?;; --) shift break;; -*) echo "$0: invalid option: $1" >&2 exit 1;; *) break;; esac shift done # We allow the use of options -d and -T together, by making -d # take the precedence; this is for compatibility with GNU install. if test -n "$dir_arg"; then if test -n "$dst_arg"; then echo "$0: target directory not allowed when installing a directory." >&2 exit 1 fi fi if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then # When -d is used, all remaining arguments are directories to create. # When -t is used, the destination is already specified. # Otherwise, the last argument is the destination. Remove it from $@. for arg do if test -n "$dst_arg"; then # $@ is not empty: it contains at least $arg. set fnord "$@" "$dst_arg" shift # fnord fi shift # arg dst_arg=$arg # Protect names problematic for 'test' and other utilities. case $dst_arg in -* | [=\(\)!]) dst_arg=./$dst_arg;; esac done fi if test $# -eq 0; then if test -z "$dir_arg"; then echo "$0: no input file specified." >&2 exit 1 fi # It's OK to call 'install-sh -d' without argument. # This can happen when creating conditional directories. exit 0 fi if test -z "$dir_arg"; then if test $# -gt 1 || test "$is_target_a_directory" = always; then if test ! -d "$dst_arg"; then echo "$0: $dst_arg: Is not a directory." >&2 exit 1 fi fi fi if test -z "$dir_arg"; then do_exit='(exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 # Set umask so as not to create temps with too-generous modes. # However, 'strip' requires both read and write access to temps. case $mode in # Optimize common cases. *644) cp_umask=133;; *755) cp_umask=22;; *[0-7]) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw='% 200' fi cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; *) if test -z "$stripcmd"; then u_plus_rw= else u_plus_rw=,u+rw fi cp_umask=$mode$u_plus_rw;; esac fi for src do # Protect names problematic for 'test' and other utilities. case $src in -* | [=\(\)!]) src=./$src;; esac if test -n "$dir_arg"; then dst=$src dstdir=$dst test -d "$dstdir" dstdir_status=$? # Don't chown directories that already exist. if test $dstdir_status = 0; then chowncmd="" fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command # might cause directories to be created, which would be especially bad # if $src (and thus $dsttmp) contains '*'. if test ! -f "$src" && test ! -d "$src"; then echo "$0: $src does not exist." >&2 exit 1 fi if test -z "$dst_arg"; then echo "$0: no destination specified." >&2 exit 1 fi dst=$dst_arg # If destination is a directory, append the input filename. if test -d "$dst"; then if test "$is_target_a_directory" = never; then echo "$0: $dst_arg: Is a directory" >&2 exit 1 fi dstdir=$dst dstbase=`basename "$src"` case $dst in */) dst=$dst$dstbase;; *) dst=$dst/$dstbase;; esac dstdir_status=0 else dstdir=`dirname "$dst"` test -d "$dstdir" dstdir_status=$? fi fi case $dstdir in */) dstdirslash=$dstdir;; *) dstdirslash=$dstdir/;; esac obsolete_mkdir_used=false if test $dstdir_status != 0; then case $posix_mkdir in '') # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then mkdir_mode=-m$mode else mkdir_mode= fi posix_mkdir=false # The $RANDOM variable is not portable (e.g., dash). Use it # here however when possible just to lower collision chance. tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ trap ' ret=$? rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null exit $ret ' 0 # Because "mkdir -p" follows existing symlinks and we likely work # directly in world-writeable /tmp, make sure that the '$tmpdir' # directory is successfully created first before we actually test # 'mkdir -p'. if (umask $mkdir_umask && $mkdirprog $mkdir_mode "$tmpdir" && exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. test_tmpdir="$tmpdir/a" ls_ld_tmpdir=`ls -ld "$test_tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null fi trap '' 0;; esac if $posix_mkdir && ( umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" ) then : else # mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. case $dstdir in /*) prefix='/';; [-=\(\)!]*) prefix='./';; *) prefix='';; esac oIFS=$IFS IFS=/ set -f set fnord $dstdir shift set +f IFS=$oIFS prefixes= for d do test X"$d" = X && continue prefix=$prefix$d if test -d "$prefix"; then prefixes= else if $posix_mkdir; then (umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 else case $prefix in *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; *) qprefix=$prefix;; esac prefixes="$prefixes '$qprefix'" fi fi prefix=$prefix/ done if test -n "$prefixes"; then # Don't fail if two instances are running concurrently. (umask $mkdir_umask && eval "\$doit_exec \$mkdirprog $prefixes") || test -d "$dstdir" || exit 1 obsolete_mkdir_used=true fi fi fi if test -n "$dir_arg"; then { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 else # Make a couple of temp file names in the proper directory. dsttmp=${dstdirslash}_inst.$$_ rmtmp=${dstdirslash}_rm.$$_ # Trap to clean up those temp files at exit. trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 # Copy the file name to the temp name. (umask $cp_umask && { test -z "$stripcmd" || { # Create $dsttmp read-write so that cp doesn't create it read-only, # which would cause strip to fail. if test -z "$doit"; then : >"$dsttmp" # No need to fork-exec 'touch'. else $doit touch "$dsttmp" fi } } && $doit_exec $cpprog "$src" "$dsttmp") && # and set any options; do chmod last to preserve setuid bits. # # If any of these fail, we abort the whole thing. If we want to # ignore errors from any of these, just make sure not to ignore # errors from the above "$doit $cpprog $src $dsttmp" command. # { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && # If -C, don't bother to copy if it wouldn't change the file. if $copy_on_change && old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && set -f && set X $old && old=:$2:$4:$5:$6 && set X $new && new=:$2:$4:$5:$6 && set +f && test "$old" = "$new" && $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 then rm -f "$dsttmp" else # If $backupsuffix is set, and the file being installed # already exists, attempt a backup. Don't worry if it fails, # e.g., if mv doesn't support -f. if test -n "$backupsuffix" && test -f "$dst"; then $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null fi # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || # The rename failed, perhaps because mv can't rename something else # to itself, or perhaps because mv is so ancient that it does not # support -f. { # Now remove or move aside any old file at destination location. # We try this two ways since rm can't unlink itself on some # systems and the destination file might be busy for other # reasons. In this case, the final cleanup might fail but the new # file should still install successfully. { test ! -f "$dst" || $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 } } && # Now rename the file to the real destination. $doit $mvcmd "$dsttmp" "$dst" } fi || exit 1 trap '' 0 fi done # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: openbgpd-8.8/ltmain.sh100644 001750 001750 00001047746 14751151141 0010534 # libtool (GNU libtool) 2.4.2 # Written by Gordon Matzigkeit , 1996 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, # 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # GNU Libtool 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 of the License, or # (at your option) any later version. # # As a special exception to the GNU General Public License, # if you distribute this file as part of a program or library that # is built using GNU Libtool, you may include this file under the # same distribution terms that you use for the rest of that program. # # GNU Libtool 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. # # You should have received a copy of the GNU General Public License # along with GNU Libtool; see the file COPYING. If not, a copy # can be downloaded from http://www.gnu.org/licenses/gpl.html, # or obtained by writing to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Usage: $progname [OPTION]... [MODE-ARG]... # # Provide generalized library-building support services. # # --config show all configuration variables # --debug enable verbose shell tracing # -n, --dry-run display commands without modifying any files # --features display basic configuration information and exit # --mode=MODE use operation mode MODE # --preserve-dup-deps don't remove duplicate dependency libraries # --quiet, --silent don't print informational messages # --no-quiet, --no-silent # print informational messages (default) # --no-warn don't display warning messages # --tag=TAG use configuration variables from tag TAG # -v, --verbose print more informational messages than default # --no-verbose don't print the extra informational messages # --version print version information # -h, --help, --help-all print short, long, or detailed help message # # MODE must be one of the following: # # clean remove files from the build directory # compile compile a source file into a libtool object # execute automatically set library path, then run a program # finish complete the installation of libtool libraries # install install libraries or executables # link create a library or an executable # uninstall remove libraries from an installed directory # # MODE-ARGS vary depending on the MODE. When passed as first option, # `--mode=MODE' may be abbreviated as `MODE' or a unique abbreviation of that. # Try `$progname --help --mode=MODE' for a more detailed description of MODE. # # When reporting a bug, please describe a test case to reproduce it and # include the following information: # # host-triplet: $host # shell: $SHELL # compiler: $LTCC # compiler flags: $LTCFLAGS # linker: $LD (gnu? $with_gnu_ld) # $progname: (GNU libtool) 2.4.2 # automake: $automake_version # autoconf: $autoconf_version # # Report bugs to . # GNU libtool home page: . # General help using GNU software: . PROGRAM=libtool PACKAGE=libtool VERSION=2.4.2 TIMESTAMP="" package_revision=1.3337 # Be Bourne compatible if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST else case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac fi BIN_SH=xpg4; export BIN_SH # for Tru64 DUALCASE=1; export DUALCASE # for MKS sh # A function that is used when there is no print builtin or printf. func_fallback_echo () { eval 'cat <<_LTECHO_EOF $1 _LTECHO_EOF' } # NLS nuisances: We save the old values to restore during execute mode. lt_user_locale= lt_safe_locale= for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${$lt_var+set}\" = set; then save_$lt_var=\$$lt_var $lt_var=C export $lt_var lt_user_locale=\"$lt_var=\\\$save_\$lt_var; \$lt_user_locale\" lt_safe_locale=\"$lt_var=C; \$lt_safe_locale\" fi" done LC_ALL=C LANGUAGE=C export LANGUAGE LC_ALL $lt_unset CDPATH # Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh # is ksh but when the shell is invoked as "sh" and the current value of # the _XPG environment variable is not equal to 1 (one), the special # positional parameter $0, within a function call, is the name of the # function. progpath="$0" : ${CP="cp -f"} test "${ECHO+set}" = set || ECHO=${as_echo-'printf %s\n'} : ${MAKE="make"} : ${MKDIR="mkdir"} : ${MV="mv -f"} : ${RM="rm -f"} : ${SHELL="${CONFIG_SHELL-/bin/sh}"} : ${Xsed="$SED -e 1s/^X//"} # Global variables: EXIT_SUCCESS=0 EXIT_FAILURE=1 EXIT_MISMATCH=63 # $? = 63 is used to indicate version mismatch to missing. EXIT_SKIP=77 # $? = 77 is used to indicate a skipped test to automake. exit_status=$EXIT_SUCCESS # Make sure IFS has a sensible default lt_nl=' ' IFS=" $lt_nl" dirname="s,/[^/]*$,," basename="s,^.*/,," # func_dirname file append nondir_replacement # Compute the dirname of FILE. If nonempty, add APPEND to the result, # otherwise set result to NONDIR_REPLACEMENT. func_dirname () { func_dirname_result=`$ECHO "${1}" | $SED "$dirname"` if test "X$func_dirname_result" = "X${1}"; then func_dirname_result="${3}" else func_dirname_result="$func_dirname_result${2}" fi } # func_dirname may be replaced by extended shell implementation # func_basename file func_basename () { func_basename_result=`$ECHO "${1}" | $SED "$basename"` } # func_basename may be replaced by extended shell implementation # func_dirname_and_basename file append nondir_replacement # perform func_basename and func_dirname in a single function # call: # dirname: Compute the dirname of FILE. If nonempty, # add APPEND to the result, otherwise set result # to NONDIR_REPLACEMENT. # value returned in "$func_dirname_result" # basename: Compute filename of FILE. # value retuned in "$func_basename_result" # Implementation must be kept synchronized with func_dirname # and func_basename. For efficiency, we do not delegate to # those functions but instead duplicate the functionality here. func_dirname_and_basename () { # Extract subdirectory from the argument. func_dirname_result=`$ECHO "${1}" | $SED -e "$dirname"` if test "X$func_dirname_result" = "X${1}"; then func_dirname_result="${3}" else func_dirname_result="$func_dirname_result${2}" fi func_basename_result=`$ECHO "${1}" | $SED -e "$basename"` } # func_dirname_and_basename may be replaced by extended shell implementation # func_stripname prefix suffix name # strip PREFIX and SUFFIX off of NAME. # PREFIX and SUFFIX must not contain globbing or regex special # characters, hashes, percent signs, but SUFFIX may contain a leading # dot (in which case that matches only a dot). # func_strip_suffix prefix name func_stripname () { case ${2} in .*) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%\\\\${2}\$%%"`;; *) func_stripname_result=`$ECHO "${3}" | $SED "s%^${1}%%; s%${2}\$%%"`;; esac } # func_stripname may be replaced by extended shell implementation # These SED scripts presuppose an absolute path with a trailing slash. pathcar='s,^/\([^/]*\).*$,\1,' pathcdr='s,^/[^/]*,,' removedotparts=':dotsl s@/\./@/@g t dotsl s,/\.$,/,' collapseslashes='s@/\{1,\}@/@g' finalslash='s,/*$,/,' # func_normal_abspath PATH # Remove doubled-up and trailing slashes, "." path components, # and cancel out any ".." path components in PATH after making # it an absolute path. # value returned in "$func_normal_abspath_result" func_normal_abspath () { # Start from root dir and reassemble the path. func_normal_abspath_result= func_normal_abspath_tpath=$1 func_normal_abspath_altnamespace= case $func_normal_abspath_tpath in "") # Empty path, that just means $cwd. func_stripname '' '/' "`pwd`" func_normal_abspath_result=$func_stripname_result return ;; # The next three entries are used to spot a run of precisely # two leading slashes without using negated character classes; # we take advantage of case's first-match behaviour. ///*) # Unusual form of absolute path, do nothing. ;; //*) # Not necessarily an ordinary path; POSIX reserves leading '//' # and for example Cygwin uses it to access remote file shares # over CIFS/SMB, so we conserve a leading double slash if found. func_normal_abspath_altnamespace=/ ;; /*) # Absolute path, do nothing. ;; *) # Relative path, prepend $cwd. func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath ;; esac # Cancel out all the simple stuff to save iterations. We also want # the path to end with a slash for ease of parsing, so make sure # there is one (and only one) here. func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$removedotparts" -e "$collapseslashes" -e "$finalslash"` while :; do # Processed it all yet? if test "$func_normal_abspath_tpath" = / ; then # If we ascended to the root using ".." the result may be empty now. if test -z "$func_normal_abspath_result" ; then func_normal_abspath_result=/ fi break fi func_normal_abspath_tcomponent=`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$pathcar"` func_normal_abspath_tpath=`$ECHO "$func_normal_abspath_tpath" | $SED \ -e "$pathcdr"` # Figure out what to do with it case $func_normal_abspath_tcomponent in "") # Trailing empty path component, ignore it. ;; ..) # Parent dir; strip last assembled component from result. func_dirname "$func_normal_abspath_result" func_normal_abspath_result=$func_dirname_result ;; *) # Actual path component, append it. func_normal_abspath_result=$func_normal_abspath_result/$func_normal_abspath_tcomponent ;; esac done # Restore leading double-slash if one was found on entry. func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result } # func_relative_path SRCDIR DSTDIR # generates a relative path from SRCDIR to DSTDIR, with a trailing # slash if non-empty, suitable for immediately appending a filename # without needing to append a separator. # value returned in "$func_relative_path_result" func_relative_path () { func_relative_path_result= func_normal_abspath "$1" func_relative_path_tlibdir=$func_normal_abspath_result func_normal_abspath "$2" func_relative_path_tbindir=$func_normal_abspath_result # Ascend the tree starting from libdir while :; do # check if we have found a prefix of bindir case $func_relative_path_tbindir in $func_relative_path_tlibdir) # found an exact match func_relative_path_tcancelled= break ;; $func_relative_path_tlibdir*) # found a matching prefix func_stripname "$func_relative_path_tlibdir" '' "$func_relative_path_tbindir" func_relative_path_tcancelled=$func_stripname_result if test -z "$func_relative_path_result"; then func_relative_path_result=. fi break ;; *) func_dirname $func_relative_path_tlibdir func_relative_path_tlibdir=${func_dirname_result} if test "x$func_relative_path_tlibdir" = x ; then # Have to descend all the way to the root! func_relative_path_result=../$func_relative_path_result func_relative_path_tcancelled=$func_relative_path_tbindir break fi func_relative_path_result=../$func_relative_path_result ;; esac done # Now calculate path; take care to avoid doubling-up slashes. func_stripname '' '/' "$func_relative_path_result" func_relative_path_result=$func_stripname_result func_stripname '/' '/' "$func_relative_path_tcancelled" if test "x$func_stripname_result" != x ; then func_relative_path_result=${func_relative_path_result}/${func_stripname_result} fi # Normalisation. If bindir is libdir, return empty string, # else relative path ending with a slash; either way, target # file name can be directly appended. if test ! -z "$func_relative_path_result"; then func_stripname './' '' "$func_relative_path_result/" func_relative_path_result=$func_stripname_result fi } # The name of this program: func_dirname_and_basename "$progpath" progname=$func_basename_result # Make sure we have an absolute path for reexecution: case $progpath in [\\/]*|[A-Za-z]:\\*) ;; *[\\/]*) progdir=$func_dirname_result progdir=`cd "$progdir" && pwd` progpath="$progdir/$progname" ;; *) save_IFS="$IFS" IFS=${PATH_SEPARATOR-:} for progdir in $PATH; do IFS="$save_IFS" test -x "$progdir/$progname" && break done IFS="$save_IFS" test -n "$progdir" || progdir=`pwd` progpath="$progdir/$progname" ;; esac # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. Xsed="${SED}"' -e 1s/^X//' sed_quote_subst='s/\([`"$\\]\)/\\\1/g' # Same as above, but do not quote variable references. double_quote_subst='s/\(["`\\]\)/\\\1/g' # Sed substitution that turns a string into a regex matching for the # string literally. sed_make_literal_regex='s,[].[^$\\*\/],\\&,g' # Sed substitution that converts a w32 file name or path # which contains forward slashes, into one that contains # (escaped) backslashes. A very naive implementation. lt_sed_naive_backslashify='s|\\\\*|\\|g;s|/|\\|g;s|\\|\\\\|g' # Re-`\' parameter expansions in output of double_quote_subst that were # `\'-ed in input to the same. If an odd number of `\' preceded a '$' # in input to double_quote_subst, that '$' was protected from expansion. # Since each input `\' is now two `\'s, look for any number of runs of # four `\'s followed by two `\'s and then a '$'. `\' that '$'. bs='\\' bs2='\\\\' bs4='\\\\\\\\' dollar='\$' sed_double_backslash="\ s/$bs4/&\\ /g s/^$bs2$dollar/$bs&/ s/\\([^$bs]\\)$bs2$dollar/\\1$bs2$bs$dollar/g s/\n//g" # Standard options: opt_dry_run=false opt_help=false opt_quiet=false opt_verbose=false opt_warning=: # func_echo arg... # Echo program name prefixed message, along with the current mode # name if it has been set yet. func_echo () { $ECHO "$progname: ${opt_mode+$opt_mode: }$*" } # func_verbose arg... # Echo program name prefixed message in verbose mode only. func_verbose () { $opt_verbose && func_echo ${1+"$@"} # A bug in bash halts the script if the last line of a function # fails when set -e is in force, so we need another command to # work around that: : } # func_echo_all arg... # Invoke $ECHO with all args, space-separated. func_echo_all () { $ECHO "$*" } # func_error arg... # Echo program name prefixed message to standard error. func_error () { $ECHO "$progname: ${opt_mode+$opt_mode: }"${1+"$@"} 1>&2 } # func_warning arg... # Echo program name prefixed warning message to standard error. func_warning () { $opt_warning && $ECHO "$progname: ${opt_mode+$opt_mode: }warning: "${1+"$@"} 1>&2 # bash bug again: : } # func_fatal_error arg... # Echo program name prefixed message to standard error, and exit. func_fatal_error () { func_error ${1+"$@"} exit $EXIT_FAILURE } # func_fatal_help arg... # Echo program name prefixed message to standard error, followed by # a help hint, and exit. func_fatal_help () { func_error ${1+"$@"} func_fatal_error "$help" } help="Try \`$progname --help' for more information." ## default # func_grep expression filename # Check whether EXPRESSION matches any line of FILENAME, without output. func_grep () { $GREP "$1" "$2" >/dev/null 2>&1 } # func_mkdir_p directory-path # Make sure the entire path to DIRECTORY-PATH is available. func_mkdir_p () { my_directory_path="$1" my_dir_list= if test -n "$my_directory_path" && test "$opt_dry_run" != ":"; then # Protect directory names starting with `-' case $my_directory_path in -*) my_directory_path="./$my_directory_path" ;; esac # While some portion of DIR does not yet exist... while test ! -d "$my_directory_path"; do # ...make a list in topmost first order. Use a colon delimited # list incase some portion of path contains whitespace. my_dir_list="$my_directory_path:$my_dir_list" # If the last portion added has no slash in it, the list is done case $my_directory_path in */*) ;; *) break ;; esac # ...otherwise throw away the child directory and loop my_directory_path=`$ECHO "$my_directory_path" | $SED -e "$dirname"` done my_dir_list=`$ECHO "$my_dir_list" | $SED 's,:*$,,'` save_mkdir_p_IFS="$IFS"; IFS=':' for my_dir in $my_dir_list; do IFS="$save_mkdir_p_IFS" # mkdir can fail with a `File exist' error if two processes # try to create one of the directories concurrently. Don't # stop in that case! $MKDIR "$my_dir" 2>/dev/null || : done IFS="$save_mkdir_p_IFS" # Bail out if we (or some other process) failed to create a directory. test -d "$my_directory_path" || \ func_fatal_error "Failed to create \`$1'" fi } # func_mktempdir [string] # Make a temporary directory that won't clash with other running # libtool processes, and avoids race conditions if possible. If # given, STRING is the basename for that directory. func_mktempdir () { my_template="${TMPDIR-/tmp}/${1-$progname}" if test "$opt_dry_run" = ":"; then # Return a directory name, but don't create it in dry-run mode my_tmpdir="${my_template}-$$" else # If mktemp works, use that first and foremost my_tmpdir=`mktemp -d "${my_template}-XXXXXXXX" 2>/dev/null` if test ! -d "$my_tmpdir"; then # Failing that, at least try and use $RANDOM to avoid a race my_tmpdir="${my_template}-${RANDOM-0}$$" save_mktempdir_umask=`umask` umask 0077 $MKDIR "$my_tmpdir" umask $save_mktempdir_umask fi # If we're not in dry-run mode, bomb out on failure test -d "$my_tmpdir" || \ func_fatal_error "cannot create temporary directory \`$my_tmpdir'" fi $ECHO "$my_tmpdir" } # func_quote_for_eval arg # Aesthetically quote ARG to be evaled later. # This function returns two values: FUNC_QUOTE_FOR_EVAL_RESULT # is double-quoted, suitable for a subsequent eval, whereas # FUNC_QUOTE_FOR_EVAL_UNQUOTED_RESULT has merely all characters # which are still active within double quotes backslashified. func_quote_for_eval () { case $1 in *[\\\`\"\$]*) func_quote_for_eval_unquoted_result=`$ECHO "$1" | $SED "$sed_quote_subst"` ;; *) func_quote_for_eval_unquoted_result="$1" ;; esac case $func_quote_for_eval_unquoted_result in # Double-quote args containing shell metacharacters to delay # word splitting, command substitution and and variable # expansion for a subsequent eval. # Many Bourne shells cannot handle close brackets correctly # in scan sets, so we specify it separately. *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") func_quote_for_eval_result="\"$func_quote_for_eval_unquoted_result\"" ;; *) func_quote_for_eval_result="$func_quote_for_eval_unquoted_result" esac } # func_quote_for_expand arg # Aesthetically quote ARG to be evaled later; same as above, # but do not quote variable references. func_quote_for_expand () { case $1 in *[\\\`\"]*) my_arg=`$ECHO "$1" | $SED \ -e "$double_quote_subst" -e "$sed_double_backslash"` ;; *) my_arg="$1" ;; esac case $my_arg in # Double-quote args containing shell metacharacters to delay # word splitting and command substitution for a subsequent eval. # Many Bourne shells cannot handle close brackets correctly # in scan sets, so we specify it separately. *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") my_arg="\"$my_arg\"" ;; esac func_quote_for_expand_result="$my_arg" } # func_show_eval cmd [fail_exp] # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP # is given, then evaluate it. func_show_eval () { my_cmd="$1" my_fail_exp="${2-:}" ${opt_silent-false} || { func_quote_for_expand "$my_cmd" eval "func_echo $func_quote_for_expand_result" } if ${opt_dry_run-false}; then :; else eval "$my_cmd" my_status=$? if test "$my_status" -eq 0; then :; else eval "(exit $my_status); $my_fail_exp" fi fi } # func_show_eval_locale cmd [fail_exp] # Unless opt_silent is true, then output CMD. Then, if opt_dryrun is # not true, evaluate CMD. If the evaluation of CMD fails, and FAIL_EXP # is given, then evaluate it. Use the saved locale for evaluation. func_show_eval_locale () { my_cmd="$1" my_fail_exp="${2-:}" ${opt_silent-false} || { func_quote_for_expand "$my_cmd" eval "func_echo $func_quote_for_expand_result" } if ${opt_dry_run-false}; then :; else eval "$lt_user_locale $my_cmd" my_status=$? eval "$lt_safe_locale" if test "$my_status" -eq 0; then :; else eval "(exit $my_status); $my_fail_exp" fi fi } # func_tr_sh # Turn $1 into a string suitable for a shell variable name. # Result is stored in $func_tr_sh_result. All characters # not in the set a-zA-Z0-9_ are replaced with '_'. Further, # if $1 begins with a digit, a '_' is prepended as well. func_tr_sh () { case $1 in [0-9]* | *[!a-zA-Z0-9_]*) func_tr_sh_result=`$ECHO "$1" | $SED 's/^\([0-9]\)/_\1/; s/[^a-zA-Z0-9_]/_/g'` ;; * ) func_tr_sh_result=$1 ;; esac } # func_version # Echo version message to standard output and exit. func_version () { $opt_debug $SED -n '/(C)/!b go :more /\./!{ N s/\n# / / b more } :go /^# '$PROGRAM' (GNU /,/# warranty; / { s/^# // s/^# *$// s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/ p }' < "$progpath" exit $? } # func_usage # Echo short help message to standard output and exit. func_usage () { $opt_debug $SED -n '/^# Usage:/,/^# *.*--help/ { s/^# // s/^# *$// s/\$progname/'$progname'/ p }' < "$progpath" echo $ECHO "run \`$progname --help | more' for full usage" exit $? } # func_help [NOEXIT] # Echo long help message to standard output and exit, # unless 'noexit' is passed as argument. func_help () { $opt_debug $SED -n '/^# Usage:/,/# Report bugs to/ { :print s/^# // s/^# *$// s*\$progname*'$progname'* s*\$host*'"$host"'* s*\$SHELL*'"$SHELL"'* s*\$LTCC*'"$LTCC"'* s*\$LTCFLAGS*'"$LTCFLAGS"'* s*\$LD*'"$LD"'* s/\$with_gnu_ld/'"$with_gnu_ld"'/ s/\$automake_version/'"`(${AUTOMAKE-automake} --version) 2>/dev/null |$SED 1q`"'/ s/\$autoconf_version/'"`(${AUTOCONF-autoconf} --version) 2>/dev/null |$SED 1q`"'/ p d } /^# .* home page:/b print /^# General help using/b print ' < "$progpath" ret=$? if test -z "$1"; then exit $ret fi } # func_missing_arg argname # Echo program name prefixed message to standard error and set global # exit_cmd. func_missing_arg () { $opt_debug func_error "missing argument for $1." exit_cmd=exit } # func_split_short_opt shortopt # Set func_split_short_opt_name and func_split_short_opt_arg shell # variables after splitting SHORTOPT after the 2nd character. func_split_short_opt () { my_sed_short_opt='1s/^\(..\).*$/\1/;q' my_sed_short_rest='1s/^..\(.*\)$/\1/;q' func_split_short_opt_name=`$ECHO "$1" | $SED "$my_sed_short_opt"` func_split_short_opt_arg=`$ECHO "$1" | $SED "$my_sed_short_rest"` } # func_split_short_opt may be replaced by extended shell implementation # func_split_long_opt longopt # Set func_split_long_opt_name and func_split_long_opt_arg shell # variables after splitting LONGOPT at the `=' sign. func_split_long_opt () { my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q' my_sed_long_arg='1s/^--[^=]*=//' func_split_long_opt_name=`$ECHO "$1" | $SED "$my_sed_long_opt"` func_split_long_opt_arg=`$ECHO "$1" | $SED "$my_sed_long_arg"` } # func_split_long_opt may be replaced by extended shell implementation exit_cmd=: magic="%%%MAGIC variable%%%" magic_exe="%%%MAGIC EXE variable%%%" # Global variables. nonopt= preserve_args= lo2o="s/\\.lo\$/.${objext}/" o2lo="s/\\.${objext}\$/.lo/" extracted_archives= extracted_serial=0 # If this variable is set in any of the actions, the command in it # will be execed at the end. This prevents here-documents from being # left over by shells. exec_cmd= # func_append var value # Append VALUE to the end of shell variable VAR. func_append () { eval "${1}=\$${1}\${2}" } # func_append may be replaced by extended shell implementation # func_append_quoted var value # Quote VALUE and append to the end of shell variable VAR, separated # by a space. func_append_quoted () { func_quote_for_eval "${2}" eval "${1}=\$${1}\\ \$func_quote_for_eval_result" } # func_append_quoted may be replaced by extended shell implementation # func_arith arithmetic-term... func_arith () { func_arith_result=`expr "${@}"` } # func_arith may be replaced by extended shell implementation # func_len string # STRING may not start with a hyphen. func_len () { func_len_result=`expr "${1}" : ".*" 2>/dev/null || echo $max_cmd_len` } # func_len may be replaced by extended shell implementation # func_lo2o object func_lo2o () { func_lo2o_result=`$ECHO "${1}" | $SED "$lo2o"` } # func_lo2o may be replaced by extended shell implementation # func_xform libobj-or-source func_xform () { func_xform_result=`$ECHO "${1}" | $SED 's/\.[^.]*$/.lo/'` } # func_xform may be replaced by extended shell implementation # func_fatal_configuration arg... # Echo program name prefixed message to standard error, followed by # a configuration failure hint, and exit. func_fatal_configuration () { func_error ${1+"$@"} func_error "See the $PACKAGE documentation for more information." func_fatal_error "Fatal configuration error." } # func_config # Display the configuration for all the tags in this script. func_config () { re_begincf='^# ### BEGIN LIBTOOL' re_endcf='^# ### END LIBTOOL' # Default configuration. $SED "1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\$d" < "$progpath" # Now print the configurations for the tags. for tagname in $taglist; do $SED -n "/$re_begincf TAG CONFIG: $tagname\$/,/$re_endcf TAG CONFIG: $tagname\$/p" < "$progpath" done exit $? } # func_features # Display the features supported by this script. func_features () { echo "host: $host" if test "$build_libtool_libs" = yes; then echo "enable shared libraries" else echo "disable shared libraries" fi if test "$build_old_libs" = yes; then echo "enable static libraries" else echo "disable static libraries" fi exit $? } # func_enable_tag tagname # Verify that TAGNAME is valid, and either flag an error and exit, or # enable the TAGNAME tag. We also add TAGNAME to the global $taglist # variable here. func_enable_tag () { # Global variable: tagname="$1" re_begincf="^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\$" re_endcf="^# ### END LIBTOOL TAG CONFIG: $tagname\$" sed_extractcf="/$re_begincf/,/$re_endcf/p" # Validate tagname. case $tagname in *[!-_A-Za-z0-9,/]*) func_fatal_error "invalid tag name: $tagname" ;; esac # Don't test for the "default" C tag, as we know it's # there but not specially marked. case $tagname in CC) ;; *) if $GREP "$re_begincf" "$progpath" >/dev/null 2>&1; then taglist="$taglist $tagname" # Evaluate the configuration. Be careful to quote the path # and the sed script, to avoid splitting on whitespace, but # also don't use non-portable quotes within backquotes within # quotes we have to do it in 2 steps: extractedcf=`$SED -n -e "$sed_extractcf" < "$progpath"` eval "$extractedcf" else func_error "ignoring unknown tag $tagname" fi ;; esac } # func_check_version_match # Ensure that we are using m4 macros, and libtool script from the same # release of libtool. func_check_version_match () { if test "$package_revision" != "$macro_revision"; then if test "$VERSION" != "$macro_version"; then if test -z "$macro_version"; then cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, but the $progname: definition of this LT_INIT comes from an older release. $progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION $progname: and run autoconf again. _LT_EOF else cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, but the $progname: definition of this LT_INIT comes from $PACKAGE $macro_version. $progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION $progname: and run autoconf again. _LT_EOF fi else cat >&2 <<_LT_EOF $progname: Version mismatch error. This is $PACKAGE $VERSION, revision $package_revision, $progname: but the definition of this LT_INIT comes from revision $macro_revision. $progname: You should recreate aclocal.m4 with macros from revision $package_revision $progname: of $PACKAGE $VERSION and run autoconf again. _LT_EOF fi exit $EXIT_MISMATCH fi } # Shorthand for --mode=foo, only valid as the first argument case $1 in clean|clea|cle|cl) shift; set dummy --mode clean ${1+"$@"}; shift ;; compile|compil|compi|comp|com|co|c) shift; set dummy --mode compile ${1+"$@"}; shift ;; execute|execut|execu|exec|exe|ex|e) shift; set dummy --mode execute ${1+"$@"}; shift ;; finish|finis|fini|fin|fi|f) shift; set dummy --mode finish ${1+"$@"}; shift ;; install|instal|insta|inst|ins|in|i) shift; set dummy --mode install ${1+"$@"}; shift ;; link|lin|li|l) shift; set dummy --mode link ${1+"$@"}; shift ;; uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) shift; set dummy --mode uninstall ${1+"$@"}; shift ;; esac # Option defaults: opt_debug=: opt_dry_run=false opt_config=false opt_preserve_dup_deps=false opt_features=false opt_finish=false opt_help=false opt_help_all=false opt_silent=: opt_warning=: opt_verbose=: opt_silent=false opt_verbose=false # Parse options once, thoroughly. This comes as soon as possible in the # script to make things like `--version' happen as quickly as we can. { # this just eases exit handling while test $# -gt 0; do opt="$1" shift case $opt in --debug|-x) opt_debug='set -x' func_echo "enabling shell trace mode" $opt_debug ;; --dry-run|--dryrun|-n) opt_dry_run=: ;; --config) opt_config=: func_config ;; --dlopen|-dlopen) optarg="$1" opt_dlopen="${opt_dlopen+$opt_dlopen }$optarg" shift ;; --preserve-dup-deps) opt_preserve_dup_deps=: ;; --features) opt_features=: func_features ;; --finish) opt_finish=: set dummy --mode finish ${1+"$@"}; shift ;; --help) opt_help=: ;; --help-all) opt_help_all=: opt_help=': help-all' ;; --mode) test $# = 0 && func_missing_arg $opt && break optarg="$1" opt_mode="$optarg" case $optarg in # Valid mode arguments: clean|compile|execute|finish|install|link|relink|uninstall) ;; # Catch anything else as an error *) func_error "invalid argument for $opt" exit_cmd=exit break ;; esac shift ;; --no-silent|--no-quiet) opt_silent=false func_append preserve_args " $opt" ;; --no-warning|--no-warn) opt_warning=false func_append preserve_args " $opt" ;; --no-verbose) opt_verbose=false func_append preserve_args " $opt" ;; --silent|--quiet) opt_silent=: func_append preserve_args " $opt" opt_verbose=false ;; --verbose|-v) opt_verbose=: func_append preserve_args " $opt" opt_silent=false ;; --tag) test $# = 0 && func_missing_arg $opt && break optarg="$1" opt_tag="$optarg" func_append preserve_args " $opt $optarg" func_enable_tag "$optarg" shift ;; -\?|-h) func_usage ;; --help) func_help ;; --version) func_version ;; # Separate optargs to long options: --*=*) func_split_long_opt "$opt" set dummy "$func_split_long_opt_name" "$func_split_long_opt_arg" ${1+"$@"} shift ;; # Separate non-argument short options: -\?*|-h*|-n*|-v*) func_split_short_opt "$opt" set dummy "$func_split_short_opt_name" "-$func_split_short_opt_arg" ${1+"$@"} shift ;; --) break ;; -*) func_fatal_help "unrecognized option \`$opt'" ;; *) set dummy "$opt" ${1+"$@"}; shift; break ;; esac done # Validate options: # save first non-option argument if test "$#" -gt 0; then nonopt="$opt" shift fi # preserve --debug test "$opt_debug" = : || func_append preserve_args " --debug" case $host in *cygwin* | *mingw* | *pw32* | *cegcc*) # don't eliminate duplications in $postdeps and $predeps opt_duplicate_compiler_generated_deps=: ;; *) opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps ;; esac $opt_help || { # Sanity checks first: func_check_version_match if test "$build_libtool_libs" != yes && test "$build_old_libs" != yes; then func_fatal_configuration "not configured to build any kind of library" fi # Darwin sucks eval std_shrext=\"$shrext_cmds\" # Only execute mode is allowed to have -dlopen flags. if test -n "$opt_dlopen" && test "$opt_mode" != execute; then func_error "unrecognized option \`-dlopen'" $ECHO "$help" 1>&2 exit $EXIT_FAILURE fi # Change the help message to a mode-specific one. generic_help="$help" help="Try \`$progname --help --mode=$opt_mode' for more information." } # Bail if the options were screwed $exit_cmd $EXIT_FAILURE } ## ----------- ## ## Main. ## ## ----------- ## # func_lalib_p file # True iff FILE is a libtool `.la' library or `.lo' object file. # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_lalib_p () { test -f "$1" && $SED -e 4q "$1" 2>/dev/null \ | $GREP "^# Generated by .*$PACKAGE" > /dev/null 2>&1 } # func_lalib_unsafe_p file # True iff FILE is a libtool `.la' library or `.lo' object file. # This function implements the same check as func_lalib_p without # resorting to external programs. To this end, it redirects stdin and # closes it afterwards, without saving the original file descriptor. # As a safety measure, use it only where a negative result would be # fatal anyway. Works if `file' does not exist. func_lalib_unsafe_p () { lalib_p=no if test -f "$1" && test -r "$1" && exec 5<&0 <"$1"; then for lalib_p_l in 1 2 3 4 do read lalib_p_line case "$lalib_p_line" in \#\ Generated\ by\ *$PACKAGE* ) lalib_p=yes; break;; esac done exec 0<&5 5<&- fi test "$lalib_p" = yes } # func_ltwrapper_script_p file # True iff FILE is a libtool wrapper script # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_script_p () { func_lalib_p "$1" } # func_ltwrapper_executable_p file # True iff FILE is a libtool wrapper executable # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_executable_p () { func_ltwrapper_exec_suffix= case $1 in *.exe) ;; *) func_ltwrapper_exec_suffix=.exe ;; esac $GREP "$magic_exe" "$1$func_ltwrapper_exec_suffix" >/dev/null 2>&1 } # func_ltwrapper_scriptname file # Assumes file is an ltwrapper_executable # uses $file to determine the appropriate filename for a # temporary ltwrapper_script. func_ltwrapper_scriptname () { func_dirname_and_basename "$1" "" "." func_stripname '' '.exe' "$func_basename_result" func_ltwrapper_scriptname_result="$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper" } # func_ltwrapper_p file # True iff FILE is a libtool wrapper script or wrapper executable # This function is only a basic sanity check; it will hardly flush out # determined imposters. func_ltwrapper_p () { func_ltwrapper_script_p "$1" || func_ltwrapper_executable_p "$1" } # func_execute_cmds commands fail_cmd # Execute tilde-delimited COMMANDS. # If FAIL_CMD is given, eval that upon failure. # FAIL_CMD may read-access the current command in variable CMD! func_execute_cmds () { $opt_debug save_ifs=$IFS; IFS='~' for cmd in $1; do IFS=$save_ifs eval cmd=\"$cmd\" func_show_eval "$cmd" "${2-:}" done IFS=$save_ifs } # func_source file # Source FILE, adding directory component if necessary. # Note that it is not necessary on cygwin/mingw to append a dot to # FILE even if both FILE and FILE.exe exist: automatic-append-.exe # behavior happens only for exec(3), not for open(2)! Also, sourcing # `FILE.' does not work on cygwin managed mounts. func_source () { $opt_debug case $1 in */* | *\\*) . "$1" ;; *) . "./$1" ;; esac } # func_resolve_sysroot PATH # Replace a leading = in PATH with a sysroot. Store the result into # func_resolve_sysroot_result func_resolve_sysroot () { func_resolve_sysroot_result=$1 case $func_resolve_sysroot_result in =*) func_stripname '=' '' "$func_resolve_sysroot_result" func_resolve_sysroot_result=$lt_sysroot$func_stripname_result ;; esac } # func_replace_sysroot PATH # If PATH begins with the sysroot, replace it with = and # store the result into func_replace_sysroot_result. func_replace_sysroot () { case "$lt_sysroot:$1" in ?*:"$lt_sysroot"*) func_stripname "$lt_sysroot" '' "$1" func_replace_sysroot_result="=$func_stripname_result" ;; *) # Including no sysroot. func_replace_sysroot_result=$1 ;; esac } # func_infer_tag arg # Infer tagged configuration to use if any are available and # if one wasn't chosen via the "--tag" command line option. # Only attempt this if the compiler in the base compile # command doesn't match the default compiler. # arg is usually of the form 'gcc ...' func_infer_tag () { $opt_debug if test -n "$available_tags" && test -z "$tagname"; then CC_quoted= for arg in $CC; do func_append_quoted CC_quoted "$arg" done CC_expanded=`func_echo_all $CC` CC_quoted_expanded=`func_echo_all $CC_quoted` case $@ in # Blanks in the command may have been stripped by the calling shell, # but not from the CC environment variable when configure was run. " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) ;; # Blanks at the start of $base_compile will cause this to fail # if we don't check for them as well. *) for z in $available_tags; do if $GREP "^# ### BEGIN LIBTOOL TAG CONFIG: $z$" < "$progpath" > /dev/null; then # Evaluate the configuration. eval "`${SED} -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`" CC_quoted= for arg in $CC; do # Double-quote args containing other shell metacharacters. func_append_quoted CC_quoted "$arg" done CC_expanded=`func_echo_all $CC` CC_quoted_expanded=`func_echo_all $CC_quoted` case "$@ " in " $CC "* | "$CC "* | " $CC_expanded "* | "$CC_expanded "* | \ " $CC_quoted"* | "$CC_quoted "* | " $CC_quoted_expanded "* | "$CC_quoted_expanded "*) # The compiler in the base compile command matches # the one in the tagged configuration. # Assume this is the tagged configuration we want. tagname=$z break ;; esac fi done # If $tagname still isn't set, then no tagged configuration # was found and let the user know that the "--tag" command # line option must be used. if test -z "$tagname"; then func_echo "unable to infer tagged configuration" func_fatal_error "specify a tag with \`--tag'" # else # func_verbose "using $tagname tagged configuration" fi ;; esac fi } # func_write_libtool_object output_name pic_name nonpic_name # Create a libtool object file (analogous to a ".la" file), # but don't create it if we're doing a dry run. func_write_libtool_object () { write_libobj=${1} if test "$build_libtool_libs" = yes; then write_lobj=\'${2}\' else write_lobj=none fi if test "$build_old_libs" = yes; then write_oldobj=\'${3}\' else write_oldobj=none fi $opt_dry_run || { cat >${write_libobj}T </dev/null` if test "$?" -eq 0 && test -n "${func_convert_core_file_wine_to_w32_tmp}"; then func_convert_core_file_wine_to_w32_result=`$ECHO "$func_convert_core_file_wine_to_w32_tmp" | $SED -e "$lt_sed_naive_backslashify"` else func_convert_core_file_wine_to_w32_result= fi fi } # end: func_convert_core_file_wine_to_w32 # func_convert_core_path_wine_to_w32 ARG # Helper function used by path conversion functions when $build is *nix, and # $host is mingw, cygwin, or some other w32 environment. Relies on a correctly # configured wine environment available, with the winepath program in $build's # $PATH. Assumes ARG has no leading or trailing path separator characters. # # ARG is path to be converted from $build format to win32. # Result is available in $func_convert_core_path_wine_to_w32_result. # Unconvertible file (directory) names in ARG are skipped; if no directory names # are convertible, then the result may be empty. func_convert_core_path_wine_to_w32 () { $opt_debug # unfortunately, winepath doesn't convert paths, only file names func_convert_core_path_wine_to_w32_result="" if test -n "$1"; then oldIFS=$IFS IFS=: for func_convert_core_path_wine_to_w32_f in $1; do IFS=$oldIFS func_convert_core_file_wine_to_w32 "$func_convert_core_path_wine_to_w32_f" if test -n "$func_convert_core_file_wine_to_w32_result" ; then if test -z "$func_convert_core_path_wine_to_w32_result"; then func_convert_core_path_wine_to_w32_result="$func_convert_core_file_wine_to_w32_result" else func_append func_convert_core_path_wine_to_w32_result ";$func_convert_core_file_wine_to_w32_result" fi fi done IFS=$oldIFS fi } # end: func_convert_core_path_wine_to_w32 # func_cygpath ARGS... # Wrapper around calling the cygpath program via LT_CYGPATH. This is used when # when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2) # $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or # (2), returns the Cygwin file name or path in func_cygpath_result (input # file name or path is assumed to be in w32 format, as previously converted # from $build's *nix or MSYS format). In case (3), returns the w32 file name # or path in func_cygpath_result (input file name or path is assumed to be in # Cygwin format). Returns an empty string on error. # # ARGS are passed to cygpath, with the last one being the file name or path to # be converted. # # Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH # environment variable; do not put it in $PATH. func_cygpath () { $opt_debug if test -n "$LT_CYGPATH" && test -f "$LT_CYGPATH"; then func_cygpath_result=`$LT_CYGPATH "$@" 2>/dev/null` if test "$?" -ne 0; then # on failure, ensure result is empty func_cygpath_result= fi else func_cygpath_result= func_error "LT_CYGPATH is empty or specifies non-existent file: \`$LT_CYGPATH'" fi } #end: func_cygpath # func_convert_core_msys_to_w32 ARG # Convert file name or path ARG from MSYS format to w32 format. Return # result in func_convert_core_msys_to_w32_result. func_convert_core_msys_to_w32 () { $opt_debug # awkward: cmd appends spaces to result func_convert_core_msys_to_w32_result=`( cmd //c echo "$1" ) 2>/dev/null | $SED -e 's/[ ]*$//' -e "$lt_sed_naive_backslashify"` } #end: func_convert_core_msys_to_w32 # func_convert_file_check ARG1 ARG2 # Verify that ARG1 (a file name in $build format) was converted to $host # format in ARG2. Otherwise, emit an error message, but continue (resetting # func_to_host_file_result to ARG1). func_convert_file_check () { $opt_debug if test -z "$2" && test -n "$1" ; then func_error "Could not determine host file name corresponding to" func_error " \`$1'" func_error "Continuing, but uninstalled executables may not work." # Fallback: func_to_host_file_result="$1" fi } # end func_convert_file_check # func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH # Verify that FROM_PATH (a path in $build format) was converted to $host # format in TO_PATH. Otherwise, emit an error message, but continue, resetting # func_to_host_file_result to a simplistic fallback value (see below). func_convert_path_check () { $opt_debug if test -z "$4" && test -n "$3"; then func_error "Could not determine the host path corresponding to" func_error " \`$3'" func_error "Continuing, but uninstalled executables may not work." # Fallback. This is a deliberately simplistic "conversion" and # should not be "improved". See libtool.info. if test "x$1" != "x$2"; then lt_replace_pathsep_chars="s|$1|$2|g" func_to_host_path_result=`echo "$3" | $SED -e "$lt_replace_pathsep_chars"` else func_to_host_path_result="$3" fi fi } # end func_convert_path_check # func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG # Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT # and appending REPL if ORIG matches BACKPAT. func_convert_path_front_back_pathsep () { $opt_debug case $4 in $1 ) func_to_host_path_result="$3$func_to_host_path_result" ;; esac case $4 in $2 ) func_append func_to_host_path_result "$3" ;; esac } # end func_convert_path_front_back_pathsep ################################################## # $build to $host FILE NAME CONVERSION FUNCTIONS # ################################################## # invoked via `$to_host_file_cmd ARG' # # In each case, ARG is the path to be converted from $build to $host format. # Result will be available in $func_to_host_file_result. # func_to_host_file ARG # Converts the file name ARG from $build format to $host format. Return result # in func_to_host_file_result. func_to_host_file () { $opt_debug $to_host_file_cmd "$1" } # end func_to_host_file # func_to_tool_file ARG LAZY # converts the file name ARG from $build format to toolchain format. Return # result in func_to_tool_file_result. If the conversion in use is listed # in (the comma separated) LAZY, no conversion takes place. func_to_tool_file () { $opt_debug case ,$2, in *,"$to_tool_file_cmd",*) func_to_tool_file_result=$1 ;; *) $to_tool_file_cmd "$1" func_to_tool_file_result=$func_to_host_file_result ;; esac } # end func_to_tool_file # func_convert_file_noop ARG # Copy ARG to func_to_host_file_result. func_convert_file_noop () { func_to_host_file_result="$1" } # end func_convert_file_noop # func_convert_file_msys_to_w32 ARG # Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic # conversion to w32 is not available inside the cwrapper. Returns result in # func_to_host_file_result. func_convert_file_msys_to_w32 () { $opt_debug func_to_host_file_result="$1" if test -n "$1"; then func_convert_core_msys_to_w32 "$1" func_to_host_file_result="$func_convert_core_msys_to_w32_result" fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_msys_to_w32 # func_convert_file_cygwin_to_w32 ARG # Convert file name ARG from Cygwin to w32 format. Returns result in # func_to_host_file_result. func_convert_file_cygwin_to_w32 () { $opt_debug func_to_host_file_result="$1" if test -n "$1"; then # because $build is cygwin, we call "the" cygpath in $PATH; no need to use # LT_CYGPATH in this case. func_to_host_file_result=`cygpath -m "$1"` fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_cygwin_to_w32 # func_convert_file_nix_to_w32 ARG # Convert file name ARG from *nix to w32 format. Requires a wine environment # and a working winepath. Returns result in func_to_host_file_result. func_convert_file_nix_to_w32 () { $opt_debug func_to_host_file_result="$1" if test -n "$1"; then func_convert_core_file_wine_to_w32 "$1" func_to_host_file_result="$func_convert_core_file_wine_to_w32_result" fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_nix_to_w32 # func_convert_file_msys_to_cygwin ARG # Convert file name ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. # Returns result in func_to_host_file_result. func_convert_file_msys_to_cygwin () { $opt_debug func_to_host_file_result="$1" if test -n "$1"; then func_convert_core_msys_to_w32 "$1" func_cygpath -u "$func_convert_core_msys_to_w32_result" func_to_host_file_result="$func_cygpath_result" fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_msys_to_cygwin # func_convert_file_nix_to_cygwin ARG # Convert file name ARG from *nix to Cygwin format. Requires Cygwin installed # in a wine environment, working winepath, and LT_CYGPATH set. Returns result # in func_to_host_file_result. func_convert_file_nix_to_cygwin () { $opt_debug func_to_host_file_result="$1" if test -n "$1"; then # convert from *nix to w32, then use cygpath to convert from w32 to cygwin. func_convert_core_file_wine_to_w32 "$1" func_cygpath -u "$func_convert_core_file_wine_to_w32_result" func_to_host_file_result="$func_cygpath_result" fi func_convert_file_check "$1" "$func_to_host_file_result" } # end func_convert_file_nix_to_cygwin ############################################# # $build to $host PATH CONVERSION FUNCTIONS # ############################################# # invoked via `$to_host_path_cmd ARG' # # In each case, ARG is the path to be converted from $build to $host format. # The result will be available in $func_to_host_path_result. # # Path separators are also converted from $build format to $host format. If # ARG begins or ends with a path separator character, it is preserved (but # converted to $host format) on output. # # All path conversion functions are named using the following convention: # file name conversion function : func_convert_file_X_to_Y () # path conversion function : func_convert_path_X_to_Y () # where, for any given $build/$host combination the 'X_to_Y' value is the # same. If conversion functions are added for new $build/$host combinations, # the two new functions must follow this pattern, or func_init_to_host_path_cmd # will break. # func_init_to_host_path_cmd # Ensures that function "pointer" variable $to_host_path_cmd is set to the # appropriate value, based on the value of $to_host_file_cmd. to_host_path_cmd= func_init_to_host_path_cmd () { $opt_debug if test -z "$to_host_path_cmd"; then func_stripname 'func_convert_file_' '' "$to_host_file_cmd" to_host_path_cmd="func_convert_path_${func_stripname_result}" fi } # func_to_host_path ARG # Converts the path ARG from $build format to $host format. Return result # in func_to_host_path_result. func_to_host_path () { $opt_debug func_init_to_host_path_cmd $to_host_path_cmd "$1" } # end func_to_host_path # func_convert_path_noop ARG # Copy ARG to func_to_host_path_result. func_convert_path_noop () { func_to_host_path_result="$1" } # end func_convert_path_noop # func_convert_path_msys_to_w32 ARG # Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic # conversion to w32 is not available inside the cwrapper. Returns result in # func_to_host_path_result. func_convert_path_msys_to_w32 () { $opt_debug func_to_host_path_result="$1" if test -n "$1"; then # Remove leading and trailing path separator characters from ARG. MSYS # behavior is inconsistent here; cygpath turns them into '.;' and ';.'; # and winepath ignores them completely. func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" func_to_host_path_result="$func_convert_core_msys_to_w32_result" func_convert_path_check : ";" \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" fi } # end func_convert_path_msys_to_w32 # func_convert_path_cygwin_to_w32 ARG # Convert path ARG from Cygwin to w32 format. Returns result in # func_to_host_file_result. func_convert_path_cygwin_to_w32 () { $opt_debug func_to_host_path_result="$1" if test -n "$1"; then # See func_convert_path_msys_to_w32: func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_to_host_path_result=`cygpath -m -p "$func_to_host_path_tmp1"` func_convert_path_check : ";" \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" fi } # end func_convert_path_cygwin_to_w32 # func_convert_path_nix_to_w32 ARG # Convert path ARG from *nix to w32 format. Requires a wine environment and # a working winepath. Returns result in func_to_host_file_result. func_convert_path_nix_to_w32 () { $opt_debug func_to_host_path_result="$1" if test -n "$1"; then # See func_convert_path_msys_to_w32: func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" func_to_host_path_result="$func_convert_core_path_wine_to_w32_result" func_convert_path_check : ";" \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" ";" "$1" fi } # end func_convert_path_nix_to_w32 # func_convert_path_msys_to_cygwin ARG # Convert path ARG from MSYS to Cygwin format. Requires LT_CYGPATH set. # Returns result in func_to_host_file_result. func_convert_path_msys_to_cygwin () { $opt_debug func_to_host_path_result="$1" if test -n "$1"; then # See func_convert_path_msys_to_w32: func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_msys_to_w32 "$func_to_host_path_tmp1" func_cygpath -u -p "$func_convert_core_msys_to_w32_result" func_to_host_path_result="$func_cygpath_result" func_convert_path_check : : \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" : "$1" fi } # end func_convert_path_msys_to_cygwin # func_convert_path_nix_to_cygwin ARG # Convert path ARG from *nix to Cygwin format. Requires Cygwin installed in a # a wine environment, working winepath, and LT_CYGPATH set. Returns result in # func_to_host_file_result. func_convert_path_nix_to_cygwin () { $opt_debug func_to_host_path_result="$1" if test -n "$1"; then # Remove leading and trailing path separator characters from # ARG. msys behavior is inconsistent here, cygpath turns them # into '.;' and ';.', and winepath ignores them completely. func_stripname : : "$1" func_to_host_path_tmp1=$func_stripname_result func_convert_core_path_wine_to_w32 "$func_to_host_path_tmp1" func_cygpath -u -p "$func_convert_core_path_wine_to_w32_result" func_to_host_path_result="$func_cygpath_result" func_convert_path_check : : \ "$func_to_host_path_tmp1" "$func_to_host_path_result" func_convert_path_front_back_pathsep ":*" "*:" : "$1" fi } # end func_convert_path_nix_to_cygwin # func_mode_compile arg... func_mode_compile () { $opt_debug # Get the compilation command and the source file. base_compile= srcfile="$nonopt" # always keep a non-empty value in "srcfile" suppress_opt=yes suppress_output= arg_mode=normal libobj= later= pie_flag= for arg do case $arg_mode in arg ) # do not "continue". Instead, add this to base_compile lastarg="$arg" arg_mode=normal ;; target ) libobj="$arg" arg_mode=normal continue ;; normal ) # Accept any command-line options. case $arg in -o) test -n "$libobj" && \ func_fatal_error "you cannot specify \`-o' more than once" arg_mode=target continue ;; -pie | -fpie | -fPIE) func_append pie_flag " $arg" continue ;; -shared | -static | -prefer-pic | -prefer-non-pic) func_append later " $arg" continue ;; -no-suppress) suppress_opt=no continue ;; -Xcompiler) arg_mode=arg # the next one goes into the "base_compile" arg list continue # The current "srcfile" will either be retained or ;; # replaced later. I would guess that would be a bug. -Wc,*) func_stripname '-Wc,' '' "$arg" args=$func_stripname_result lastarg= save_ifs="$IFS"; IFS=',' for arg in $args; do IFS="$save_ifs" func_append_quoted lastarg "$arg" done IFS="$save_ifs" func_stripname ' ' '' "$lastarg" lastarg=$func_stripname_result # Add the arguments to base_compile. func_append base_compile " $lastarg" continue ;; *) # Accept the current argument as the source file. # The previous "srcfile" becomes the current argument. # lastarg="$srcfile" srcfile="$arg" ;; esac # case $arg ;; esac # case $arg_mode # Aesthetically quote the previous argument. func_append_quoted base_compile "$lastarg" done # for arg case $arg_mode in arg) func_fatal_error "you must specify an argument for -Xcompile" ;; target) func_fatal_error "you must specify a target with \`-o'" ;; *) # Get the name of the library object. test -z "$libobj" && { func_basename "$srcfile" libobj="$func_basename_result" } ;; esac # Recognize several different file suffixes. # If the user specifies -o file.o, it is replaced with file.lo case $libobj in *.[cCFSifmso] | \ *.ada | *.adb | *.ads | *.asm | \ *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \ *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup) func_xform "$libobj" libobj=$func_xform_result ;; esac case $libobj in *.lo) func_lo2o "$libobj"; obj=$func_lo2o_result ;; *) func_fatal_error "cannot determine name of library object from \`$libobj'" ;; esac func_infer_tag $base_compile for arg in $later; do case $arg in -shared) test "$build_libtool_libs" != yes && \ func_fatal_configuration "can not build a shared library" build_old_libs=no continue ;; -static) build_libtool_libs=no build_old_libs=yes continue ;; -prefer-pic) pic_mode=yes continue ;; -prefer-non-pic) pic_mode=no continue ;; esac done func_quote_for_eval "$libobj" test "X$libobj" != "X$func_quote_for_eval_result" \ && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"' &()|`$[]' \ && func_warning "libobj name \`$libobj' may not contain shell special characters." func_dirname_and_basename "$obj" "/" "" objname="$func_basename_result" xdir="$func_dirname_result" lobj=${xdir}$objdir/$objname test -z "$base_compile" && \ func_fatal_help "you must specify a compilation command" # Delete any leftover library objects. if test "$build_old_libs" = yes; then removelist="$obj $lobj $libobj ${libobj}T" else removelist="$lobj $libobj ${libobj}T" fi # On Cygwin there's no "real" PIC flag so we must build both object types case $host_os in cygwin* | mingw* | pw32* | os2* | cegcc*) pic_mode=default ;; esac if test "$pic_mode" = no && test "$deplibs_check_method" != pass_all; then # non-PIC code in shared libraries is not supported pic_mode=default fi # Calculate the filename of the output object if compiler does # not support -o with -c if test "$compiler_c_o" = no; then output_obj=`$ECHO "$srcfile" | $SED 's%^.*/%%; s%\.[^.]*$%%'`.${objext} lockfile="$output_obj.lock" else output_obj= need_locks=no lockfile= fi # Lock this critical section if it is needed # We use this script file to make the link, it avoids creating a new file if test "$need_locks" = yes; then until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do func_echo "Waiting for $lockfile to be removed" sleep 2 done elif test "$need_locks" = warn; then if test -f "$lockfile"; then $ECHO "\ *** ERROR, $lockfile exists and contains: `cat $lockfile 2>/dev/null` This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support \`-c' and \`-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi func_append removelist " $output_obj" $ECHO "$srcfile" > "$lockfile" fi $opt_dry_run || $RM $removelist func_append removelist " $lockfile" trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15 func_to_tool_file "$srcfile" func_convert_file_msys_to_w32 srcfile=$func_to_tool_file_result func_quote_for_eval "$srcfile" qsrcfile=$func_quote_for_eval_result # Only build a PIC object if we are building libtool libraries. if test "$build_libtool_libs" = yes; then # Without this assignment, base_compile gets emptied. fbsd_hideous_sh_bug=$base_compile if test "$pic_mode" != no; then command="$base_compile $qsrcfile $pic_flag" else # Don't build PIC code command="$base_compile $qsrcfile" fi func_mkdir_p "$xdir$objdir" if test -z "$output_obj"; then # Place PIC objects in $objdir func_append command " -o $lobj" fi func_show_eval_locale "$command" \ 'test -n "$output_obj" && $RM $removelist; exit $EXIT_FAILURE' if test "$need_locks" = warn && test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then $ECHO "\ *** ERROR, $lockfile contains: `cat $lockfile 2>/dev/null` but it should contain: $srcfile This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support \`-c' and \`-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi # Just move the object if needed, then go on to compile the next one if test -n "$output_obj" && test "X$output_obj" != "X$lobj"; then func_show_eval '$MV "$output_obj" "$lobj"' \ 'error=$?; $opt_dry_run || $RM $removelist; exit $error' fi # Allow error messages only from the first compilation. if test "$suppress_opt" = yes; then suppress_output=' >/dev/null 2>&1' fi fi # Only build a position-dependent object if we build old libraries. if test "$build_old_libs" = yes; then if test "$pic_mode" != yes; then # Don't build PIC code command="$base_compile $qsrcfile$pie_flag" else command="$base_compile $qsrcfile $pic_flag" fi if test "$compiler_c_o" = yes; then func_append command " -o $obj" fi # Suppress compiler output if we already did a PIC compilation. func_append command "$suppress_output" func_show_eval_locale "$command" \ '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' if test "$need_locks" = warn && test "X`cat $lockfile 2>/dev/null`" != "X$srcfile"; then $ECHO "\ *** ERROR, $lockfile contains: `cat $lockfile 2>/dev/null` but it should contain: $srcfile This indicates that another process is trying to use the same temporary object file, and libtool could not work around it because your compiler does not support \`-c' and \`-o' together. If you repeat this compilation, it may succeed, by chance, but you had better avoid parallel builds (make -j) in this platform, or get a better compiler." $opt_dry_run || $RM $removelist exit $EXIT_FAILURE fi # Just move the object if needed if test -n "$output_obj" && test "X$output_obj" != "X$obj"; then func_show_eval '$MV "$output_obj" "$obj"' \ 'error=$?; $opt_dry_run || $RM $removelist; exit $error' fi fi $opt_dry_run || { func_write_libtool_object "$libobj" "$objdir/$objname" "$objname" # Unlock the critical section if it was locked if test "$need_locks" != no; then removelist=$lockfile $RM "$lockfile" fi } exit $EXIT_SUCCESS } $opt_help || { test "$opt_mode" = compile && func_mode_compile ${1+"$@"} } func_mode_help () { # We need to display help for each of the modes. case $opt_mode in "") # Generic help is extracted from the usage comments # at the start of this file. func_help ;; clean) $ECHO \ "Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE... Remove files from the build directory. RM is the name of the program to use to delete files associated with each FILE (typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed to RM. If FILE is a libtool library, object or program, all the files associated with it are deleted. Otherwise, only FILE itself is deleted using RM." ;; compile) $ECHO \ "Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE Compile a source file into a libtool library object. This mode accepts the following additional options: -o OUTPUT-FILE set the output file name to OUTPUT-FILE -no-suppress do not suppress compiler output for multiple passes -prefer-pic try to build PIC objects only -prefer-non-pic try to build non-PIC objects only -shared do not build a \`.o' file suitable for static linking -static only build a \`.o' file suitable for static linking -Wc,FLAG pass FLAG directly to the compiler COMPILE-COMMAND is a command to be used in creating a \`standard' object file from the given SOURCEFILE. The output file name is determined by removing the directory component from SOURCEFILE, then substituting the C source code suffix \`.c' with the library object suffix, \`.lo'." ;; execute) $ECHO \ "Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]... Automatically set library path, then run a program. This mode accepts the following additional options: -dlopen FILE add the directory containing FILE to the library path This mode sets the library path environment variable according to \`-dlopen' flags. If any of the ARGS are libtool executable wrappers, then they are translated into their corresponding uninstalled binary, and any of their required library directories are added to the library path. Then, COMMAND is executed, with ARGS as arguments." ;; finish) $ECHO \ "Usage: $progname [OPTION]... --mode=finish [LIBDIR]... Complete the installation of libtool libraries. Each LIBDIR is a directory that contains libtool libraries. The commands that this mode executes may require superuser privileges. Use the \`--dry-run' option if you just want to see what would be executed." ;; install) $ECHO \ "Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND... Install executables or libraries. INSTALL-COMMAND is the installation command. The first component should be either the \`install' or \`cp' program. The following components of INSTALL-COMMAND are treated specially: -inst-prefix-dir PREFIX-DIR Use PREFIX-DIR as a staging area for installation The rest of the components are interpreted as arguments to that command (only BSD-compatible install options are recognized)." ;; link) $ECHO \ "Usage: $progname [OPTION]... --mode=link LINK-COMMAND... Link object files or libraries together to form another library, or to create an executable program. LINK-COMMAND is a command using the C compiler that you would use to create a program from several object files. The following components of LINK-COMMAND are treated specially: -all-static do not do any dynamic linking at all -avoid-version do not add a version suffix if possible -bindir BINDIR specify path to binaries directory (for systems where libraries must be found in the PATH setting at runtime) -dlopen FILE \`-dlpreopen' FILE if it cannot be dlopened at runtime -dlpreopen FILE link in FILE and add its symbols to lt_preloaded_symbols -export-dynamic allow symbols from OUTPUT-FILE to be resolved with dlsym(3) -export-symbols SYMFILE try to export only the symbols listed in SYMFILE -export-symbols-regex REGEX try to export only the symbols matching REGEX -LLIBDIR search LIBDIR for required installed libraries -lNAME OUTPUT-FILE requires the installed library libNAME -module build a library that can dlopened -no-fast-install disable the fast-install mode -no-install link a not-installable executable -no-undefined declare that a library does not refer to external symbols -o OUTPUT-FILE create OUTPUT-FILE from the specified objects -objectlist FILE Use a list of object files found in FILE to specify objects -precious-files-regex REGEX don't remove output files matching REGEX -release RELEASE specify package release information -rpath LIBDIR the created library will eventually be installed in LIBDIR -R[ ]LIBDIR add LIBDIR to the runtime path of programs and libraries -shared only do dynamic linking of libtool libraries -shrext SUFFIX override the standard shared library file extension -static do not do any dynamic linking of uninstalled libtool libraries -static-libtool-libs do not do any dynamic linking of libtool libraries -version-info CURRENT[:REVISION[:AGE]] specify library version info [each variable defaults to 0] -weak LIBNAME declare that the target provides the LIBNAME interface -Wc,FLAG -Xcompiler FLAG pass linker-specific FLAG directly to the compiler -Wl,FLAG -Xlinker FLAG pass linker-specific FLAG directly to the linker -XCClinker FLAG pass link-specific FLAG to the compiler driver (CC) All other options (arguments beginning with \`-') are ignored. Every other argument is treated as a filename. Files ending in \`.la' are treated as uninstalled libtool libraries, other files are standard or library object files. If the OUTPUT-FILE ends in \`.la', then a libtool library is created, only library objects (\`.lo' files) may be specified, and \`-rpath' is required, except when creating a convenience library. If OUTPUT-FILE ends in \`.a' or \`.lib', then a standard library is created using \`ar' and \`ranlib', or on Windows using \`lib'. If OUTPUT-FILE ends in \`.lo' or \`.${objext}', then a reloadable object file is created, otherwise an executable program is created." ;; uninstall) $ECHO \ "Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE... Remove libraries from an installation directory. RM is the name of the program to use to delete files associated with each FILE (typically \`/bin/rm'). RM-OPTIONS are options (such as \`-f') to be passed to RM. If FILE is a libtool library, all the files associated with it are deleted. Otherwise, only FILE itself is deleted using RM." ;; *) func_fatal_help "invalid operation mode \`$opt_mode'" ;; esac echo $ECHO "Try \`$progname --help' for more information about other modes." } # Now that we've collected a possible --mode arg, show help if necessary if $opt_help; then if test "$opt_help" = :; then func_mode_help else { func_help noexit for opt_mode in compile link execute install finish uninstall clean; do func_mode_help done } | sed -n '1p; 2,$s/^Usage:/ or: /p' { func_help noexit for opt_mode in compile link execute install finish uninstall clean; do echo func_mode_help done } | sed '1d /^When reporting/,/^Report/{ H d } $x /information about other modes/d /more detailed .*MODE/d s/^Usage:.*--mode=\([^ ]*\) .*/Description of \1 mode:/' fi exit $? fi # func_mode_execute arg... func_mode_execute () { $opt_debug # The first argument is the command name. cmd="$nonopt" test -z "$cmd" && \ func_fatal_help "you must specify a COMMAND" # Handle -dlopen flags immediately. for file in $opt_dlopen; do test -f "$file" \ || func_fatal_help "\`$file' is not a file" dir= case $file in *.la) func_resolve_sysroot "$file" file=$func_resolve_sysroot_result # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$file" \ || func_fatal_help "\`$lib' is not a valid libtool archive" # Read the libtool library. dlname= library_names= func_source "$file" # Skip this library if it cannot be dlopened. if test -z "$dlname"; then # Warn if it was a shared library. test -n "$library_names" && \ func_warning "\`$file' was not linked with \`-export-dynamic'" continue fi func_dirname "$file" "" "." dir="$func_dirname_result" if test -f "$dir/$objdir/$dlname"; then func_append dir "/$objdir" else if test ! -f "$dir/$dlname"; then func_fatal_error "cannot find \`$dlname' in \`$dir' or \`$dir/$objdir'" fi fi ;; *.lo) # Just add the directory containing the .lo file. func_dirname "$file" "" "." dir="$func_dirname_result" ;; *) func_warning "\`-dlopen' is ignored for non-libtool libraries and objects" continue ;; esac # Get the absolute pathname. absdir=`cd "$dir" && pwd` test -n "$absdir" && dir="$absdir" # Now add the directory to shlibpath_var. if eval "test -z \"\$$shlibpath_var\""; then eval "$shlibpath_var=\"\$dir\"" else eval "$shlibpath_var=\"\$dir:\$$shlibpath_var\"" fi done # This variable tells wrapper scripts just to set shlibpath_var # rather than running their programs. libtool_execute_magic="$magic" # Check if any of the arguments is a wrapper script. args= for file do case $file in -* | *.la | *.lo ) ;; *) # Do a test to see if this is really a libtool program. if func_ltwrapper_script_p "$file"; then func_source "$file" # Transform arg to wrapped name. file="$progdir/$program" elif func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" func_source "$func_ltwrapper_scriptname_result" # Transform arg to wrapped name. file="$progdir/$program" fi ;; esac # Quote arguments (to preserve shell metacharacters). func_append_quoted args "$file" done if test "X$opt_dry_run" = Xfalse; then if test -n "$shlibpath_var"; then # Export the shlibpath_var. eval "export $shlibpath_var" fi # Restore saved environment variables for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES do eval "if test \"\${save_$lt_var+set}\" = set; then $lt_var=\$save_$lt_var; export $lt_var else $lt_unset $lt_var fi" done # Now prepare to actually exec the command. exec_cmd="\$cmd$args" else # Display what would be done. if test -n "$shlibpath_var"; then eval "\$ECHO \"\$shlibpath_var=\$$shlibpath_var\"" echo "export $shlibpath_var" fi $ECHO "$cmd$args" exit $EXIT_SUCCESS fi } test "$opt_mode" = execute && func_mode_execute ${1+"$@"} # func_mode_finish arg... func_mode_finish () { $opt_debug libs= libdirs= admincmds= for opt in "$nonopt" ${1+"$@"} do if test -d "$opt"; then func_append libdirs " $opt" elif test -f "$opt"; then if func_lalib_unsafe_p "$opt"; then func_append libs " $opt" else func_warning "\`$opt' is not a valid libtool archive" fi else func_fatal_error "invalid argument \`$opt'" fi done if test -n "$libs"; then if test -n "$lt_sysroot"; then sysroot_regex=`$ECHO "$lt_sysroot" | $SED "$sed_make_literal_regex"` sysroot_cmd="s/\([ ']\)$sysroot_regex/\1/g;" else sysroot_cmd= fi # Remove sysroot references if $opt_dry_run; then for lib in $libs; do echo "removing references to $lt_sysroot and \`=' prefixes from $lib" done else tmpdir=`func_mktempdir` for lib in $libs; do sed -e "${sysroot_cmd} s/\([ ']-[LR]\)=/\1/g; s/\([ ']\)=/\1/g" $lib \ > $tmpdir/tmp-la mv -f $tmpdir/tmp-la $lib done ${RM}r "$tmpdir" fi fi if test -n "$finish_cmds$finish_eval" && test -n "$libdirs"; then for libdir in $libdirs; do if test -n "$finish_cmds"; then # Do each command in the finish commands. func_execute_cmds "$finish_cmds" 'admincmds="$admincmds '"$cmd"'"' fi if test -n "$finish_eval"; then # Do the single finish_eval. eval cmds=\"$finish_eval\" $opt_dry_run || eval "$cmds" || func_append admincmds " $cmds" fi done fi # Exit here if they wanted silent mode. $opt_silent && exit $EXIT_SUCCESS exit $EXIT_SUCCESS } test "$opt_mode" = finish && func_mode_finish ${1+"$@"} # func_mode_install arg... func_mode_install () { $opt_debug # There may be an optional sh(1) argument at the beginning of # install_prog (especially on Windows NT). if test "$nonopt" = "$SHELL" || test "$nonopt" = /bin/sh || # Allow the use of GNU shtool's install command. case $nonopt in *shtool*) :;; *) false;; esac; then # Aesthetically quote it. func_quote_for_eval "$nonopt" install_prog="$func_quote_for_eval_result " arg=$1 shift else install_prog= arg=$nonopt fi # The real first argument should be the name of the installation program. # Aesthetically quote it. func_quote_for_eval "$arg" func_append install_prog "$func_quote_for_eval_result" install_shared_prog=$install_prog case " $install_prog " in *[\\\ /]cp\ *) install_cp=: ;; *) install_cp=false ;; esac # We need to accept at least all the BSD install flags. dest= files= opts= prev= install_type= isdir=no stripme= no_mode=: for arg do arg2= if test -n "$dest"; then func_append files " $dest" dest=$arg continue fi case $arg in -d) isdir=yes ;; -f) if $install_cp; then :; else prev=$arg fi ;; -g | -m | -o) prev=$arg ;; -s) stripme=" -s" continue ;; -*) ;; *) # If the previous option needed an argument, then skip it. if test -n "$prev"; then if test "x$prev" = x-m && test -n "$install_override_mode"; then arg2=$install_override_mode no_mode=false fi prev= else dest=$arg continue fi ;; esac # Aesthetically quote the argument. func_quote_for_eval "$arg" func_append install_prog " $func_quote_for_eval_result" if test -n "$arg2"; then func_quote_for_eval "$arg2" fi func_append install_shared_prog " $func_quote_for_eval_result" done case " $install_prog " in *[\\\ /]cp\ *) extra_mode=;; *) extra_mode='-m 644';; esac test -z "$install_prog" && \ func_fatal_help "you must specify an install program" test -n "$prev" && \ func_fatal_help "the \`$prev' option requires an argument" if test -n "$install_override_mode" && $no_mode; then if $install_cp; then :; else func_quote_for_eval "$install_override_mode" func_append install_shared_prog " -m $func_quote_for_eval_result" fi fi if test -z "$files"; then if test -z "$dest"; then func_fatal_help "no file or destination specified" else func_fatal_help "you must specify a destination" fi fi # Strip any trailing slash from the destination. func_stripname '' '/' "$dest" dest=$func_stripname_result # Check to see that the destination is a directory. test -d "$dest" && isdir=yes if test "$isdir" = yes; then destdir="$dest" destname= else func_dirname_and_basename "$dest" "" "." destdir="$func_dirname_result" destname="$func_basename_result" # Not a directory, so check to see that there is only one file specified. set dummy $files; shift test "$#" -gt 1 && \ func_fatal_help "\`$dest' is not a directory" fi case $destdir in [\\/]* | [A-Za-z]:[\\/]*) ;; *) for file in $files; do case $file in *.lo) ;; *) func_fatal_help "\`$destdir' must be an absolute directory name" ;; esac done ;; esac # This variable tells wrapper scripts just to set variables rather # than running their programs. libtool_install_magic="$magic" staticlibs= future_libdirs= current_libdirs= for file in $files; do # Do each installation. case $file in *.$libext) # Do the static libraries later. func_append staticlibs " $file" ;; *.la) func_resolve_sysroot "$file" file=$func_resolve_sysroot_result # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$file" \ || func_fatal_help "\`$file' is not a valid libtool archive" library_names= old_library= relink_command= func_source "$file" # Add the libdir to current_libdirs if it is the destination. if test "X$destdir" = "X$libdir"; then case "$current_libdirs " in *" $libdir "*) ;; *) func_append current_libdirs " $libdir" ;; esac else # Note the libdir as a future libdir. case "$future_libdirs " in *" $libdir "*) ;; *) func_append future_libdirs " $libdir" ;; esac fi func_dirname "$file" "/" "" dir="$func_dirname_result" func_append dir "$objdir" if test -n "$relink_command"; then # Determine the prefix the user has applied to our future dir. inst_prefix_dir=`$ECHO "$destdir" | $SED -e "s%$libdir\$%%"` # Don't allow the user to place us outside of our expected # location b/c this prevents finding dependent libraries that # are installed to the same prefix. # At present, this check doesn't affect windows .dll's that # are installed into $libdir/../bin (currently, that works fine) # but it's something to keep an eye on. test "$inst_prefix_dir" = "$destdir" && \ func_fatal_error "error: cannot install \`$file' to a directory not ending in $libdir" if test -n "$inst_prefix_dir"; then # Stick the inst_prefix_dir data into the link command. relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%"` else relink_command=`$ECHO "$relink_command" | $SED "s%@inst_prefix_dir@%%"` fi func_warning "relinking \`$file'" func_show_eval "$relink_command" \ 'func_fatal_error "error: relink \`$file'\'' with the above command before installing it"' fi # See the names of the shared library. set dummy $library_names; shift if test -n "$1"; then realname="$1" shift srcname="$realname" test -n "$relink_command" && srcname="$realname"T # Install the shared library and build the symlinks. func_show_eval "$install_shared_prog $extra_mode $dir/$srcname $destdir/$realname" \ 'exit $?' tstripme="$stripme" case $host_os in cygwin* | mingw* | pw32* | cegcc*) case $realname in *.dll.a) tstripme="" ;; esac ;; esac if test -n "$tstripme" && test -n "$striplib"; then func_show_eval "$striplib $destdir/$realname" 'exit $?' fi if test "$#" -gt 0; then # Delete the old symlinks, and create new ones. # Try `ln -sf' first, because the `ln' binary might depend on # the symlink we replace! Solaris /bin/ln does not understand -f, # so we also need to try rm && ln -s. for linkname do test "$linkname" != "$realname" \ && func_show_eval "(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })" done fi # Do each command in the postinstall commands. lib="$destdir/$realname" func_execute_cmds "$postinstall_cmds" 'exit $?' fi # Install the pseudo-library for information purposes. func_basename "$file" name="$func_basename_result" instname="$dir/$name"i func_show_eval "$install_prog $extra_mode $instname $destdir/$name" 'exit $?' # Maybe install the static library, too. test -n "$old_library" && func_append staticlibs " $dir/$old_library" ;; *.lo) # Install (i.e. copy) a libtool object. # Figure out destination file name, if it wasn't already specified. if test -n "$destname"; then destfile="$destdir/$destname" else func_basename "$file" destfile="$func_basename_result" destfile="$destdir/$destfile" fi # Deduce the name of the destination old-style object file. case $destfile in *.lo) func_lo2o "$destfile" staticdest=$func_lo2o_result ;; *.$objext) staticdest="$destfile" destfile= ;; *) func_fatal_help "cannot copy a libtool object to \`$destfile'" ;; esac # Install the libtool object if requested. test -n "$destfile" && \ func_show_eval "$install_prog $extra_mode $file $destfile" 'exit $?' # Install the old object if enabled. if test "$build_old_libs" = yes; then # Deduce the name of the old-style object file. func_lo2o "$file" staticobj=$func_lo2o_result func_show_eval "$install_prog $extra_mode \$staticobj \$staticdest" 'exit $?' fi exit $EXIT_SUCCESS ;; *) # Figure out destination file name, if it wasn't already specified. if test -n "$destname"; then destfile="$destdir/$destname" else func_basename "$file" destfile="$func_basename_result" destfile="$destdir/$destfile" fi # If the file is missing, and there is a .exe on the end, strip it # because it is most likely a libtool script we actually want to # install stripped_ext="" case $file in *.exe) if test ! -f "$file"; then func_stripname '' '.exe' "$file" file=$func_stripname_result stripped_ext=".exe" fi ;; esac # Do a test to see if this is really a libtool program. case $host in *cygwin* | *mingw*) if func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" wrapper=$func_ltwrapper_scriptname_result else func_stripname '' '.exe' "$file" wrapper=$func_stripname_result fi ;; *) wrapper=$file ;; esac if func_ltwrapper_script_p "$wrapper"; then notinst_deplibs= relink_command= func_source "$wrapper" # Check the variables that should have been set. test -z "$generated_by_libtool_version" && \ func_fatal_error "invalid libtool wrapper script \`$wrapper'" finalize=yes for lib in $notinst_deplibs; do # Check to see that each library is installed. libdir= if test -f "$lib"; then func_source "$lib" fi libfile="$libdir/"`$ECHO "$lib" | $SED 's%^.*/%%g'` ### testsuite: skip nested quoting test if test -n "$libdir" && test ! -f "$libfile"; then func_warning "\`$lib' has not been installed in \`$libdir'" finalize=no fi done relink_command= func_source "$wrapper" outputname= if test "$fast_install" = no && test -n "$relink_command"; then $opt_dry_run || { if test "$finalize" = yes; then tmpdir=`func_mktempdir` func_basename "$file$stripped_ext" file="$func_basename_result" outputname="$tmpdir/$file" # Replace the output file specification. relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'` $opt_silent || { func_quote_for_expand "$relink_command" eval "func_echo $func_quote_for_expand_result" } if eval "$relink_command"; then : else func_error "error: relink \`$file' with the above command before installing it" $opt_dry_run || ${RM}r "$tmpdir" continue fi file="$outputname" else func_warning "cannot relink \`$file'" fi } else # Install the binary that we compiled earlier. file=`$ECHO "$file$stripped_ext" | $SED "s%\([^/]*\)$%$objdir/\1%"` fi fi # remove .exe since cygwin /usr/bin/install will append another # one anyway case $install_prog,$host in */usr/bin/install*,*cygwin*) case $file:$destfile in *.exe:*.exe) # this is ok ;; *.exe:*) destfile=$destfile.exe ;; *:*.exe) func_stripname '' '.exe' "$destfile" destfile=$func_stripname_result ;; esac ;; esac func_show_eval "$install_prog\$stripme \$file \$destfile" 'exit $?' $opt_dry_run || if test -n "$outputname"; then ${RM}r "$tmpdir" fi ;; esac done for file in $staticlibs; do func_basename "$file" name="$func_basename_result" # Set up the ranlib parameters. oldlib="$destdir/$name" func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 tool_oldlib=$func_to_tool_file_result func_show_eval "$install_prog \$file \$oldlib" 'exit $?' if test -n "$stripme" && test -n "$old_striplib"; then func_show_eval "$old_striplib $tool_oldlib" 'exit $?' fi # Do each command in the postinstall commands. func_execute_cmds "$old_postinstall_cmds" 'exit $?' done test -n "$future_libdirs" && \ func_warning "remember to run \`$progname --finish$future_libdirs'" if test -n "$current_libdirs"; then # Maybe just do a dry run. $opt_dry_run && current_libdirs=" -n$current_libdirs" exec_cmd='$SHELL $progpath $preserve_args --finish$current_libdirs' else exit $EXIT_SUCCESS fi } test "$opt_mode" = install && func_mode_install ${1+"$@"} # func_generate_dlsyms outputname originator pic_p # Extract symbols from dlprefiles and create ${outputname}S.o with # a dlpreopen symbol table. func_generate_dlsyms () { $opt_debug my_outputname="$1" my_originator="$2" my_pic_p="${3-no}" my_prefix=`$ECHO "$my_originator" | sed 's%[^a-zA-Z0-9]%_%g'` my_dlsyms= if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then if test -n "$NM" && test -n "$global_symbol_pipe"; then my_dlsyms="${my_outputname}S.c" else func_error "not configured to extract global symbols from dlpreopened files" fi fi if test -n "$my_dlsyms"; then case $my_dlsyms in "") ;; *.c) # Discover the nlist of each of the dlfiles. nlist="$output_objdir/${my_outputname}.nm" func_show_eval "$RM $nlist ${nlist}S ${nlist}T" # Parse the name list into a source file. func_verbose "creating $output_objdir/$my_dlsyms" $opt_dry_run || $ECHO > "$output_objdir/$my_dlsyms" "\ /* $my_dlsyms - symbol resolution table for \`$my_outputname' dlsym emulation. */ /* Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION */ #ifdef __cplusplus extern \"C\" { #endif #if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4)) #pragma GCC diagnostic ignored \"-Wstrict-prototypes\" #endif /* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE) /* DATA imports from DLLs on WIN32 con't be const, because runtime relocations are performed -- see ld's documentation on pseudo-relocs. */ # define LT_DLSYM_CONST #elif defined(__osf__) /* This system does not cope well with relocations in const data. */ # define LT_DLSYM_CONST #else # define LT_DLSYM_CONST const #endif /* External symbol declarations for the compiler. */\ " if test "$dlself" = yes; then func_verbose "generating symbol list for \`$output'" $opt_dry_run || echo ': @PROGRAM@ ' > "$nlist" # Add our own program objects to the symbol list. progfiles=`$ECHO "$objs$old_deplibs" | $SP2NL | $SED "$lo2o" | $NL2SP` for progfile in $progfiles; do func_to_tool_file "$progfile" func_convert_file_msys_to_w32 func_verbose "extracting global C symbols from \`$func_to_tool_file_result'" $opt_dry_run || eval "$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'" done if test -n "$exclude_expsyms"; then $opt_dry_run || { eval '$EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' } fi if test -n "$export_symbols_regex"; then $opt_dry_run || { eval '$EGREP -e "$export_symbols_regex" "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' } fi # Prepare the list of exported symbols if test -z "$export_symbols"; then export_symbols="$output_objdir/$outputname.exp" $opt_dry_run || { $RM $export_symbols eval "${SED} -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' case $host in *cygwin* | *mingw* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' ;; esac } else $opt_dry_run || { eval "${SED} -e 's/\([].[*^$]\)/\\\\\1/g' -e 's/^/ /' -e 's/$/$/'"' < "$export_symbols" > "$output_objdir/$outputname.exp"' eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' case $host in *cygwin* | *mingw* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' ;; esac } fi fi for dlprefile in $dlprefiles; do func_verbose "extracting global C symbols from \`$dlprefile'" func_basename "$dlprefile" name="$func_basename_result" case $host in *cygwin* | *mingw* | *cegcc* ) # if an import library, we need to obtain dlname if func_win32_import_lib_p "$dlprefile"; then func_tr_sh "$dlprefile" eval "curr_lafile=\$libfile_$func_tr_sh_result" dlprefile_dlbasename="" if test -n "$curr_lafile" && func_lalib_p "$curr_lafile"; then # Use subshell, to avoid clobbering current variable values dlprefile_dlname=`source "$curr_lafile" && echo "$dlname"` if test -n "$dlprefile_dlname" ; then func_basename "$dlprefile_dlname" dlprefile_dlbasename="$func_basename_result" else # no lafile. user explicitly requested -dlpreopen . $sharedlib_from_linklib_cmd "$dlprefile" dlprefile_dlbasename=$sharedlib_from_linklib_result fi fi $opt_dry_run || { if test -n "$dlprefile_dlbasename" ; then eval '$ECHO ": $dlprefile_dlbasename" >> "$nlist"' else func_warning "Could not compute DLL name from $name" eval '$ECHO ": $name " >> "$nlist"' fi func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" } else # not an import lib $opt_dry_run || { eval '$ECHO ": $name " >> "$nlist"' func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" } fi ;; *) $opt_dry_run || { eval '$ECHO ": $name " >> "$nlist"' func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe >> '$nlist'" } ;; esac done $opt_dry_run || { # Make sure we have at least an empty file. test -f "$nlist" || : > "$nlist" if test -n "$exclude_expsyms"; then $EGREP -v " ($exclude_expsyms)$" "$nlist" > "$nlist"T $MV "$nlist"T "$nlist" fi # Try sorting and uniquifying the output. if $GREP -v "^: " < "$nlist" | if sort -k 3 /dev/null 2>&1; then sort -k 3 else sort +2 fi | uniq > "$nlist"S; then : else $GREP -v "^: " < "$nlist" > "$nlist"S fi if test -f "$nlist"S; then eval "$global_symbol_to_cdecl"' < "$nlist"S >> "$output_objdir/$my_dlsyms"' else echo '/* NONE */' >> "$output_objdir/$my_dlsyms" fi echo >> "$output_objdir/$my_dlsyms" "\ /* The mapping between symbol names and symbols. */ typedef struct { const char *name; void *address; } lt_dlsymlist; extern LT_DLSYM_CONST lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[]; LT_DLSYM_CONST lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[] = {\ { \"$my_originator\", (void *) 0 }," case $need_lib_prefix in no) eval "$global_symbol_to_c_name_address" < "$nlist" >> "$output_objdir/$my_dlsyms" ;; *) eval "$global_symbol_to_c_name_address_lib_prefix" < "$nlist" >> "$output_objdir/$my_dlsyms" ;; esac echo >> "$output_objdir/$my_dlsyms" "\ {0, (void *) 0} }; /* This works around a problem in FreeBSD linker */ #ifdef FREEBSD_WORKAROUND static const void *lt_preloaded_setup() { return lt_${my_prefix}_LTX_preloaded_symbols; } #endif #ifdef __cplusplus } #endif\ " } # !$opt_dry_run pic_flag_for_symtable= case "$compile_command " in *" -static "*) ;; *) case $host in # compiling the symbol table file with pic_flag works around # a FreeBSD bug that causes programs to crash when -lm is # linked before any other PIC object. But we must not use # pic_flag when linking with -static. The problem exists in # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1. *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*) pic_flag_for_symtable=" $pic_flag -DFREEBSD_WORKAROUND" ;; *-*-hpux*) pic_flag_for_symtable=" $pic_flag" ;; *) if test "X$my_pic_p" != Xno; then pic_flag_for_symtable=" $pic_flag" fi ;; esac ;; esac symtab_cflags= for arg in $LTCFLAGS; do case $arg in -pie | -fpie | -fPIE) ;; *) func_append symtab_cflags " $arg" ;; esac done # Now compile the dynamic symbol file. func_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable "$my_dlsyms")' 'exit $?' # Clean up the generated files. func_show_eval '$RM "$output_objdir/$my_dlsyms" "$nlist" "${nlist}S" "${nlist}T"' # Transform the symbol file into the correct name. symfileobj="$output_objdir/${my_outputname}S.$objext" case $host in *cygwin* | *mingw* | *cegcc* ) if test -f "$output_objdir/$my_outputname.def"; then compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` else compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` fi ;; *) compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$symfileobj%"` ;; esac ;; *) func_fatal_error "unknown suffix for \`$my_dlsyms'" ;; esac else # We keep going just in case the user didn't refer to # lt_preloaded_symbols. The linker will fail if global_symbol_pipe # really was required. # Nullify the symbol file. compile_command=`$ECHO "$compile_command" | $SED "s% @SYMFILE@%%"` finalize_command=`$ECHO "$finalize_command" | $SED "s% @SYMFILE@%%"` fi } # func_win32_libid arg # return the library type of file 'arg' # # Need a lot of goo to handle *both* DLLs and import libs # Has to be a shell function in order to 'eat' the argument # that is supplied when $file_magic_command is called. # Despite the name, also deal with 64 bit binaries. func_win32_libid () { $opt_debug win32_libid_type="unknown" win32_fileres=`file -L $1 2>/dev/null` case $win32_fileres in *ar\ archive\ import\ library*) # definitely import win32_libid_type="x86 archive import" ;; *ar\ archive*) # could be an import, or static # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD. if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then func_to_tool_file "$1" func_convert_file_msys_to_w32 win32_nmres=`eval $NM -f posix -A \"$func_to_tool_file_result\" | $SED -n -e ' 1,100{ / I /{ s,.*,import, p q } }'` case $win32_nmres in import*) win32_libid_type="x86 archive import";; *) win32_libid_type="x86 archive static";; esac fi ;; *DLL*) win32_libid_type="x86 DLL" ;; *executable*) # but shell scripts are "executable" too... case $win32_fileres in *MS\ Windows\ PE\ Intel*) win32_libid_type="x86 DLL" ;; esac ;; esac $ECHO "$win32_libid_type" } # func_cygming_dll_for_implib ARG # # Platform-specific function to extract the # name of the DLL associated with the specified # import library ARG. # Invoked by eval'ing the libtool variable # $sharedlib_from_linklib_cmd # Result is available in the variable # $sharedlib_from_linklib_result func_cygming_dll_for_implib () { $opt_debug sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify "$1"` } # func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs # # The is the core of a fallback implementation of a # platform-specific function to extract the name of the # DLL associated with the specified import library LIBNAME. # # SECTION_NAME is either .idata$6 or .idata$7, depending # on the platform and compiler that created the implib. # # Echos the name of the DLL associated with the # specified import library. func_cygming_dll_for_implib_fallback_core () { $opt_debug match_literal=`$ECHO "$1" | $SED "$sed_make_literal_regex"` $OBJDUMP -s --section "$1" "$2" 2>/dev/null | $SED '/^Contents of section '"$match_literal"':/{ # Place marker at beginning of archive member dllname section s/.*/====MARK====/ p d } # These lines can sometimes be longer than 43 characters, but # are always uninteresting /:[ ]*file format pe[i]\{,1\}-/d /^In archive [^:]*:/d # Ensure marker is printed /^====MARK====/p # Remove all lines with less than 43 characters /^.\{43\}/!d # From remaining lines, remove first 43 characters s/^.\{43\}//' | $SED -n ' # Join marker and all lines until next marker into a single line /^====MARK====/ b para H $ b para b :para x s/\n//g # Remove the marker s/^====MARK====// # Remove trailing dots and whitespace s/[\. \t]*$// # Print /./p' | # we now have a list, one entry per line, of the stringified # contents of the appropriate section of all members of the # archive which possess that section. Heuristic: eliminate # all those which have a first or second character that is # a '.' (that is, objdump's representation of an unprintable # character.) This should work for all archives with less than # 0x302f exports -- but will fail for DLLs whose name actually # begins with a literal '.' or a single character followed by # a '.'. # # Of those that remain, print the first one. $SED -e '/^\./d;/^.\./d;q' } # func_cygming_gnu_implib_p ARG # This predicate returns with zero status (TRUE) if # ARG is a GNU/binutils-style import library. Returns # with nonzero status (FALSE) otherwise. func_cygming_gnu_implib_p () { $opt_debug func_to_tool_file "$1" func_convert_file_msys_to_w32 func_cygming_gnu_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'` test -n "$func_cygming_gnu_implib_tmp" } # func_cygming_ms_implib_p ARG # This predicate returns with zero status (TRUE) if # ARG is an MS-style import library. Returns # with nonzero status (FALSE) otherwise. func_cygming_ms_implib_p () { $opt_debug func_to_tool_file "$1" func_convert_file_msys_to_w32 func_cygming_ms_implib_tmp=`$NM "$func_to_tool_file_result" | eval "$global_symbol_pipe" | $GREP '_NULL_IMPORT_DESCRIPTOR'` test -n "$func_cygming_ms_implib_tmp" } # func_cygming_dll_for_implib_fallback ARG # Platform-specific function to extract the # name of the DLL associated with the specified # import library ARG. # # This fallback implementation is for use when $DLLTOOL # does not support the --identify-strict option. # Invoked by eval'ing the libtool variable # $sharedlib_from_linklib_cmd # Result is available in the variable # $sharedlib_from_linklib_result func_cygming_dll_for_implib_fallback () { $opt_debug if func_cygming_gnu_implib_p "$1" ; then # binutils import library sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' "$1"` elif func_cygming_ms_implib_p "$1" ; then # ms-generated import library sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' "$1"` else # unknown sharedlib_from_linklib_result="" fi } # func_extract_an_archive dir oldlib func_extract_an_archive () { $opt_debug f_ex_an_ar_dir="$1"; shift f_ex_an_ar_oldlib="$1" if test "$lock_old_archive_extraction" = yes; then lockfile=$f_ex_an_ar_oldlib.lock until $opt_dry_run || ln "$progpath" "$lockfile" 2>/dev/null; do func_echo "Waiting for $lockfile to be removed" sleep 2 done fi func_show_eval "(cd \$f_ex_an_ar_dir && $AR x \"\$f_ex_an_ar_oldlib\")" \ 'stat=$?; rm -f "$lockfile"; exit $stat' if test "$lock_old_archive_extraction" = yes; then $opt_dry_run || rm -f "$lockfile" fi if ($AR t "$f_ex_an_ar_oldlib" | sort | sort -uc >/dev/null 2>&1); then : else func_fatal_error "object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib" fi } # func_extract_archives gentop oldlib ... func_extract_archives () { $opt_debug my_gentop="$1"; shift my_oldlibs=${1+"$@"} my_oldobjs="" my_xlib="" my_xabs="" my_xdir="" for my_xlib in $my_oldlibs; do # Extract the objects. case $my_xlib in [\\/]* | [A-Za-z]:[\\/]*) my_xabs="$my_xlib" ;; *) my_xabs=`pwd`"/$my_xlib" ;; esac func_basename "$my_xlib" my_xlib="$func_basename_result" my_xlib_u=$my_xlib while :; do case " $extracted_archives " in *" $my_xlib_u "*) func_arith $extracted_serial + 1 extracted_serial=$func_arith_result my_xlib_u=lt$extracted_serial-$my_xlib ;; *) break ;; esac done extracted_archives="$extracted_archives $my_xlib_u" my_xdir="$my_gentop/$my_xlib_u" func_mkdir_p "$my_xdir" case $host in *-darwin*) func_verbose "Extracting $my_xabs" # Do not bother doing anything if just a dry run $opt_dry_run || { darwin_orig_dir=`pwd` cd $my_xdir || exit $? darwin_archive=$my_xabs darwin_curdir=`pwd` darwin_base_archive=`basename "$darwin_archive"` darwin_arches=`$LIPO -info "$darwin_archive" 2>/dev/null | $GREP Architectures 2>/dev/null || true` if test -n "$darwin_arches"; then darwin_arches=`$ECHO "$darwin_arches" | $SED -e 's/.*are://'` darwin_arch= func_verbose "$darwin_base_archive has multiple architectures $darwin_arches" for darwin_arch in $darwin_arches ; do func_mkdir_p "unfat-$$/${darwin_base_archive}-${darwin_arch}" $LIPO -thin $darwin_arch -output "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" "${darwin_archive}" cd "unfat-$$/${darwin_base_archive}-${darwin_arch}" func_extract_an_archive "`pwd`" "${darwin_base_archive}" cd "$darwin_curdir" $RM "unfat-$$/${darwin_base_archive}-${darwin_arch}/${darwin_base_archive}" done # $darwin_arches ## Okay now we've a bunch of thin objects, gotta fatten them up :) darwin_filelist=`find unfat-$$ -type f -name \*.o -print -o -name \*.lo -print | $SED -e "$basename" | sort -u` darwin_file= darwin_files= for darwin_file in $darwin_filelist; do darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP` $LIPO -create -output "$darwin_file" $darwin_files done # $darwin_filelist $RM -rf unfat-$$ cd "$darwin_orig_dir" else cd $darwin_orig_dir func_extract_an_archive "$my_xdir" "$my_xabs" fi # $darwin_arches } # !$opt_dry_run ;; *) func_extract_an_archive "$my_xdir" "$my_xabs" ;; esac my_oldobjs="$my_oldobjs "`find $my_xdir -name \*.$objext -print -o -name \*.lo -print | sort | $NL2SP` done func_extract_archives_result="$my_oldobjs" } # func_emit_wrapper [arg=no] # # Emit a libtool wrapper script on stdout. # Don't directly open a file because we may want to # incorporate the script contents within a cygwin/mingw # wrapper executable. Must ONLY be called from within # func_mode_link because it depends on a number of variables # set therein. # # ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR # variable will take. If 'yes', then the emitted script # will assume that the directory in which it is stored is # the $objdir directory. This is a cygwin/mingw-specific # behavior. func_emit_wrapper () { func_emit_wrapper_arg1=${1-no} $ECHO "\ #! $SHELL # $output - temporary wrapper script for $objdir/$outputname # Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION # # The $output program cannot be directly executed until all the libtool # libraries that it depends on are installed. # # This wrapper script should never be moved out of the build directory. # If it is, it will not operate correctly. # Sed substitution that helps us do robust quoting. It backslashifies # metacharacters that are still active within double-quoted strings. sed_quote_subst='$sed_quote_subst' # Be Bourne compatible if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then emulate sh NULLCMD=: # Zsh 3.x and 4.x performs word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST else case \`(set -o) 2>/dev/null\` in *posix*) set -o posix;; esac fi BIN_SH=xpg4; export BIN_SH # for Tru64 DUALCASE=1; export DUALCASE # for MKS sh # The HP-UX ksh and POSIX shell print the target directory to stdout # if CDPATH is set. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH relink_command=\"$relink_command\" # This environment variable determines our operation mode. if test \"\$libtool_install_magic\" = \"$magic\"; then # install mode needs the following variables: generated_by_libtool_version='$macro_version' notinst_deplibs='$notinst_deplibs' else # When we are sourced in execute mode, \$file and \$ECHO are already set. if test \"\$libtool_execute_magic\" != \"$magic\"; then file=\"\$0\"" qECHO=`$ECHO "$ECHO" | $SED "$sed_quote_subst"` $ECHO "\ # A function that is used when there is no print builtin or printf. func_fallback_echo () { eval 'cat <<_LTECHO_EOF \$1 _LTECHO_EOF' } ECHO=\"$qECHO\" fi # Very basic option parsing. These options are (a) specific to # the libtool wrapper, (b) are identical between the wrapper # /script/ and the wrapper /executable/ which is used only on # windows platforms, and (c) all begin with the string "--lt-" # (application programs are unlikely to have options which match # this pattern). # # There are only two supported options: --lt-debug and # --lt-dump-script. There is, deliberately, no --lt-help. # # The first argument to this parsing function should be the # script's $0 value, followed by "$@". lt_option_debug= func_parse_lt_options () { lt_script_arg0=\$0 shift for lt_opt do case \"\$lt_opt\" in --lt-debug) lt_option_debug=1 ;; --lt-dump-script) lt_dump_D=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\` test \"X\$lt_dump_D\" = \"X\$lt_script_arg0\" && lt_dump_D=. lt_dump_F=\`\$ECHO \"X\$lt_script_arg0\" | $SED -e 's/^X//' -e 's%^.*/%%'\` cat \"\$lt_dump_D/\$lt_dump_F\" exit 0 ;; --lt-*) \$ECHO \"Unrecognized --lt- option: '\$lt_opt'\" 1>&2 exit 1 ;; esac done # Print the debug banner immediately: if test -n \"\$lt_option_debug\"; then echo \"${outputname}:${output}:\${LINENO}: libtool wrapper (GNU $PACKAGE$TIMESTAMP) $VERSION\" 1>&2 fi } # Used when --lt-debug. Prints its arguments to stdout # (redirection is the responsibility of the caller) func_lt_dump_args () { lt_dump_args_N=1; for lt_arg do \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[\$lt_dump_args_N]: \$lt_arg\" lt_dump_args_N=\`expr \$lt_dump_args_N + 1\` done } # Core function for launching the target application func_exec_program_core () { " case $host in # Backslashes separate directories on plain windows *-*-mingw | *-*-os2* | *-cegcc*) $ECHO "\ if test -n \"\$lt_option_debug\"; then \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[0]: \$progdir\\\\\$program\" 1>&2 func_lt_dump_args \${1+\"\$@\"} 1>&2 fi exec \"\$progdir\\\\\$program\" \${1+\"\$@\"} " ;; *) $ECHO "\ if test -n \"\$lt_option_debug\"; then \$ECHO \"${outputname}:${output}:\${LINENO}: newargv[0]: \$progdir/\$program\" 1>&2 func_lt_dump_args \${1+\"\$@\"} 1>&2 fi exec \"\$progdir/\$program\" \${1+\"\$@\"} " ;; esac $ECHO "\ \$ECHO \"\$0: cannot exec \$program \$*\" 1>&2 exit 1 } # A function to encapsulate launching the target application # Strips options in the --lt-* namespace from \$@ and # launches target application with the remaining arguments. func_exec_program () { case \" \$* \" in *\\ --lt-*) for lt_wr_arg do case \$lt_wr_arg in --lt-*) ;; *) set x \"\$@\" \"\$lt_wr_arg\"; shift;; esac shift done ;; esac func_exec_program_core \${1+\"\$@\"} } # Parse options func_parse_lt_options \"\$0\" \${1+\"\$@\"} # Find the directory that this script lives in. thisdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*$%%'\` test \"x\$thisdir\" = \"x\$file\" && thisdir=. # Follow symbolic links until we get to the real thisdir. file=\`ls -ld \"\$file\" | $SED -n 's/.*-> //p'\` while test -n \"\$file\"; do destdir=\`\$ECHO \"\$file\" | $SED 's%/[^/]*\$%%'\` # If there was a directory component, then change thisdir. if test \"x\$destdir\" != \"x\$file\"; then case \"\$destdir\" in [\\\\/]* | [A-Za-z]:[\\\\/]*) thisdir=\"\$destdir\" ;; *) thisdir=\"\$thisdir/\$destdir\" ;; esac fi file=\`\$ECHO \"\$file\" | $SED 's%^.*/%%'\` file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\` done # Usually 'no', except on cygwin/mingw when embedded into # the cwrapper. WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1 if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then # special case for '.' if test \"\$thisdir\" = \".\"; then thisdir=\`pwd\` fi # remove .libs from thisdir case \"\$thisdir\" in *[\\\\/]$objdir ) thisdir=\`\$ECHO \"\$thisdir\" | $SED 's%[\\\\/][^\\\\/]*$%%'\` ;; $objdir ) thisdir=. ;; esac fi # Try to get the absolute directory name. absdir=\`cd \"\$thisdir\" && pwd\` test -n \"\$absdir\" && thisdir=\"\$absdir\" " if test "$fast_install" = yes; then $ECHO "\ program=lt-'$outputname'$exeext progdir=\"\$thisdir/$objdir\" if test ! -f \"\$progdir/\$program\" || { file=\`ls -1dt \"\$progdir/\$program\" \"\$progdir/../\$program\" 2>/dev/null | ${SED} 1q\`; \\ test \"X\$file\" != \"X\$progdir/\$program\"; }; then file=\"\$\$-\$program\" if test ! -d \"\$progdir\"; then $MKDIR \"\$progdir\" else $RM \"\$progdir/\$file\" fi" $ECHO "\ # relink executable if necessary if test -n \"\$relink_command\"; then if relink_command_output=\`eval \$relink_command 2>&1\`; then : else $ECHO \"\$relink_command_output\" >&2 $RM \"\$progdir/\$file\" exit 1 fi fi $MV \"\$progdir/\$file\" \"\$progdir/\$program\" 2>/dev/null || { $RM \"\$progdir/\$program\"; $MV \"\$progdir/\$file\" \"\$progdir/\$program\"; } $RM \"\$progdir/\$file\" fi" else $ECHO "\ program='$outputname' progdir=\"\$thisdir/$objdir\" " fi $ECHO "\ if test -f \"\$progdir/\$program\"; then" # fixup the dll searchpath if we need to. # # Fix the DLL searchpath if we need to. Do this before prepending # to shlibpath, because on Windows, both are PATH and uninstalled # libraries must come first. if test -n "$dllsearchpath"; then $ECHO "\ # Add the dll search path components to the executable PATH PATH=$dllsearchpath:\$PATH " fi # Export our shlibpath_var if we have one. if test "$shlibpath_overrides_runpath" = yes && test -n "$shlibpath_var" && test -n "$temp_rpath"; then $ECHO "\ # Add our own library path to $shlibpath_var $shlibpath_var=\"$temp_rpath\$$shlibpath_var\" # Some systems cannot cope with colon-terminated $shlibpath_var # The second colon is a workaround for a bug in BeOS R4 sed $shlibpath_var=\`\$ECHO \"\$$shlibpath_var\" | $SED 's/::*\$//'\` export $shlibpath_var " fi $ECHO "\ if test \"\$libtool_execute_magic\" != \"$magic\"; then # Run the actual program with our arguments. func_exec_program \${1+\"\$@\"} fi else # The program doesn't exist. \$ECHO \"\$0: error: \\\`\$progdir/\$program' does not exist\" 1>&2 \$ECHO \"This script is just a wrapper for \$program.\" 1>&2 \$ECHO \"See the $PACKAGE documentation for more information.\" 1>&2 exit 1 fi fi\ " } # func_emit_cwrapperexe_src # emit the source code for a wrapper executable on stdout # Must ONLY be called from within func_mode_link because # it depends on a number of variable set therein. func_emit_cwrapperexe_src () { cat < #include #ifdef _MSC_VER # include # include # include #else # include # include # ifdef __CYGWIN__ # include # endif #endif #include #include #include #include #include #include #include #include /* declarations of non-ANSI functions */ #if defined(__MINGW32__) # ifdef __STRICT_ANSI__ int _putenv (const char *); # endif #elif defined(__CYGWIN__) # ifdef __STRICT_ANSI__ char *realpath (const char *, char *); int putenv (char *); int setenv (const char *, const char *, int); # endif /* #elif defined (other platforms) ... */ #endif /* portability defines, excluding path handling macros */ #if defined(_MSC_VER) # define setmode _setmode # define stat _stat # define chmod _chmod # define getcwd _getcwd # define putenv _putenv # define S_IXUSR _S_IEXEC # ifndef _INTPTR_T_DEFINED # define _INTPTR_T_DEFINED # define intptr_t int # endif #elif defined(__MINGW32__) # define setmode _setmode # define stat _stat # define chmod _chmod # define getcwd _getcwd # define putenv _putenv #elif defined(__CYGWIN__) # define HAVE_SETENV # define FOPEN_WB "wb" /* #elif defined (other platforms) ... */ #endif #if defined(PATH_MAX) # define LT_PATHMAX PATH_MAX #elif defined(MAXPATHLEN) # define LT_PATHMAX MAXPATHLEN #else # define LT_PATHMAX 1024 #endif #ifndef S_IXOTH # define S_IXOTH 0 #endif #ifndef S_IXGRP # define S_IXGRP 0 #endif /* path handling portability macros */ #ifndef DIR_SEPARATOR # define DIR_SEPARATOR '/' # define PATH_SEPARATOR ':' #endif #if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \ defined (__OS2__) # define HAVE_DOS_BASED_FILE_SYSTEM # define FOPEN_WB "wb" # ifndef DIR_SEPARATOR_2 # define DIR_SEPARATOR_2 '\\' # endif # ifndef PATH_SEPARATOR_2 # define PATH_SEPARATOR_2 ';' # endif #endif #ifndef DIR_SEPARATOR_2 # define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) #else /* DIR_SEPARATOR_2 */ # define IS_DIR_SEPARATOR(ch) \ (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) #endif /* DIR_SEPARATOR_2 */ #ifndef PATH_SEPARATOR_2 # define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR) #else /* PATH_SEPARATOR_2 */ # define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2) #endif /* PATH_SEPARATOR_2 */ #ifndef FOPEN_WB # define FOPEN_WB "w" #endif #ifndef _O_BINARY # define _O_BINARY 0 #endif #define XMALLOC(type, num) ((type *) xmalloc ((num) * sizeof(type))) #define XFREE(stale) do { \ if (stale) { free ((void *) stale); stale = 0; } \ } while (0) #if defined(LT_DEBUGWRAPPER) static int lt_debug = 1; #else static int lt_debug = 0; #endif const char *program_name = "libtool-wrapper"; /* in case xstrdup fails */ void *xmalloc (size_t num); char *xstrdup (const char *string); const char *base_name (const char *name); char *find_executable (const char *wrapper); char *chase_symlinks (const char *pathspec); int make_executable (const char *path); int check_executable (const char *path); char *strendzap (char *str, const char *pat); void lt_debugprintf (const char *file, int line, const char *fmt, ...); void lt_fatal (const char *file, int line, const char *message, ...); static const char *nonnull (const char *s); static const char *nonempty (const char *s); void lt_setenv (const char *name, const char *value); char *lt_extend_str (const char *orig_value, const char *add, int to_end); void lt_update_exe_path (const char *name, const char *value); void lt_update_lib_path (const char *name, const char *value); char **prepare_spawn (char **argv); void lt_dump_script (FILE *f); EOF cat <= 0) && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))) return 1; else return 0; } int make_executable (const char *path) { int rval = 0; struct stat st; lt_debugprintf (__FILE__, __LINE__, "(make_executable): %s\n", nonempty (path)); if ((!path) || (!*path)) return 0; if (stat (path, &st) >= 0) { rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR); } return rval; } /* Searches for the full path of the wrapper. Returns newly allocated full path name if found, NULL otherwise Does not chase symlinks, even on platforms that support them. */ char * find_executable (const char *wrapper) { int has_slash = 0; const char *p; const char *p_next; /* static buffer for getcwd */ char tmp[LT_PATHMAX + 1]; int tmp_len; char *concat_name; lt_debugprintf (__FILE__, __LINE__, "(find_executable): %s\n", nonempty (wrapper)); if ((wrapper == NULL) || (*wrapper == '\0')) return NULL; /* Absolute path? */ #if defined (HAVE_DOS_BASED_FILE_SYSTEM) if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':') { concat_name = xstrdup (wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } else { #endif if (IS_DIR_SEPARATOR (wrapper[0])) { concat_name = xstrdup (wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } #if defined (HAVE_DOS_BASED_FILE_SYSTEM) } #endif for (p = wrapper; *p; p++) if (*p == '/') { has_slash = 1; break; } if (!has_slash) { /* no slashes; search PATH */ const char *path = getenv ("PATH"); if (path != NULL) { for (p = path; *p; p = p_next) { const char *q; size_t p_len; for (q = p; *q; q++) if (IS_PATH_SEPARATOR (*q)) break; p_len = q - p; p_next = (*q == '\0' ? q : q + 1); if (p_len == 0) { /* empty path: current directory */ if (getcwd (tmp, LT_PATHMAX) == NULL) lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", nonnull (strerror (errno))); tmp_len = strlen (tmp); concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, tmp, tmp_len); concat_name[tmp_len] = '/'; strcpy (concat_name + tmp_len + 1, wrapper); } else { concat_name = XMALLOC (char, p_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, p, p_len); concat_name[p_len] = '/'; strcpy (concat_name + p_len + 1, wrapper); } if (check_executable (concat_name)) return concat_name; XFREE (concat_name); } } /* not found in PATH; assume curdir */ } /* Relative path | not found in path: prepend cwd */ if (getcwd (tmp, LT_PATHMAX) == NULL) lt_fatal (__FILE__, __LINE__, "getcwd failed: %s", nonnull (strerror (errno))); tmp_len = strlen (tmp); concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1); memcpy (concat_name, tmp, tmp_len); concat_name[tmp_len] = '/'; strcpy (concat_name + tmp_len + 1, wrapper); if (check_executable (concat_name)) return concat_name; XFREE (concat_name); return NULL; } char * chase_symlinks (const char *pathspec) { #ifndef S_ISLNK return xstrdup (pathspec); #else char buf[LT_PATHMAX]; struct stat s; char *tmp_pathspec = xstrdup (pathspec); char *p; int has_symlinks = 0; while (strlen (tmp_pathspec) && !has_symlinks) { lt_debugprintf (__FILE__, __LINE__, "checking path component for symlinks: %s\n", tmp_pathspec); if (lstat (tmp_pathspec, &s) == 0) { if (S_ISLNK (s.st_mode) != 0) { has_symlinks = 1; break; } /* search backwards for last DIR_SEPARATOR */ p = tmp_pathspec + strlen (tmp_pathspec) - 1; while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) p--; if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p))) { /* no more DIR_SEPARATORS left */ break; } *p = '\0'; } else { lt_fatal (__FILE__, __LINE__, "error accessing file \"%s\": %s", tmp_pathspec, nonnull (strerror (errno))); } } XFREE (tmp_pathspec); if (!has_symlinks) { return xstrdup (pathspec); } tmp_pathspec = realpath (pathspec, buf); if (tmp_pathspec == 0) { lt_fatal (__FILE__, __LINE__, "could not follow symlinks for %s", pathspec); } return xstrdup (tmp_pathspec); #endif } char * strendzap (char *str, const char *pat) { size_t len, patlen; assert (str != NULL); assert (pat != NULL); len = strlen (str); patlen = strlen (pat); if (patlen <= len) { str += len - patlen; if (strcmp (str, pat) == 0) *str = '\0'; } return str; } void lt_debugprintf (const char *file, int line, const char *fmt, ...) { va_list args; if (lt_debug) { (void) fprintf (stderr, "%s:%s:%d: ", program_name, file, line); va_start (args, fmt); (void) vfprintf (stderr, fmt, args); va_end (args); } } static void lt_error_core (int exit_status, const char *file, int line, const char *mode, const char *message, va_list ap) { fprintf (stderr, "%s:%s:%d: %s: ", program_name, file, line, mode); vfprintf (stderr, message, ap); fprintf (stderr, ".\n"); if (exit_status >= 0) exit (exit_status); } void lt_fatal (const char *file, int line, const char *message, ...) { va_list ap; va_start (ap, message); lt_error_core (EXIT_FAILURE, file, line, "FATAL", message, ap); va_end (ap); } static const char * nonnull (const char *s) { return s ? s : "(null)"; } static const char * nonempty (const char *s) { return (s && !*s) ? "(empty)" : nonnull (s); } void lt_setenv (const char *name, const char *value) { lt_debugprintf (__FILE__, __LINE__, "(lt_setenv) setting '%s' to '%s'\n", nonnull (name), nonnull (value)); { #ifdef HAVE_SETENV /* always make a copy, for consistency with !HAVE_SETENV */ char *str = xstrdup (value); setenv (name, str, 1); #else int len = strlen (name) + 1 + strlen (value) + 1; char *str = XMALLOC (char, len); sprintf (str, "%s=%s", name, value); if (putenv (str) != EXIT_SUCCESS) { XFREE (str); } #endif } } char * lt_extend_str (const char *orig_value, const char *add, int to_end) { char *new_value; if (orig_value && *orig_value) { int orig_value_len = strlen (orig_value); int add_len = strlen (add); new_value = XMALLOC (char, add_len + orig_value_len + 1); if (to_end) { strcpy (new_value, orig_value); strcpy (new_value + orig_value_len, add); } else { strcpy (new_value, add); strcpy (new_value + add_len, orig_value); } } else { new_value = xstrdup (add); } return new_value; } void lt_update_exe_path (const char *name, const char *value) { lt_debugprintf (__FILE__, __LINE__, "(lt_update_exe_path) modifying '%s' by prepending '%s'\n", nonnull (name), nonnull (value)); if (name && *name && value && *value) { char *new_value = lt_extend_str (getenv (name), value, 0); /* some systems can't cope with a ':'-terminated path #' */ int len = strlen (new_value); while (((len = strlen (new_value)) > 0) && IS_PATH_SEPARATOR (new_value[len-1])) { new_value[len-1] = '\0'; } lt_setenv (name, new_value); XFREE (new_value); } } void lt_update_lib_path (const char *name, const char *value) { lt_debugprintf (__FILE__, __LINE__, "(lt_update_lib_path) modifying '%s' by prepending '%s'\n", nonnull (name), nonnull (value)); if (name && *name && value && *value) { char *new_value = lt_extend_str (getenv (name), value, 0); lt_setenv (name, new_value); XFREE (new_value); } } EOF case $host_os in mingw*) cat <<"EOF" /* Prepares an argument vector before calling spawn(). Note that spawn() does not by itself call the command interpreter (getenv ("COMSPEC") != NULL ? getenv ("COMSPEC") : ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&v); v.dwPlatformId == VER_PLATFORM_WIN32_NT; }) ? "cmd.exe" : "command.com"). Instead it simply concatenates the arguments, separated by ' ', and calls CreateProcess(). We must quote the arguments since Win32 CreateProcess() interprets characters like ' ', '\t', '\\', '"' (but not '<' and '>') in a special way: - Space and tab are interpreted as delimiters. They are not treated as delimiters if they are surrounded by double quotes: "...". - Unescaped double quotes are removed from the input. Their only effect is that within double quotes, space and tab are treated like normal characters. - Backslashes not followed by double quotes are not special. - But 2*n+1 backslashes followed by a double quote become n backslashes followed by a double quote (n >= 0): \" -> " \\\" -> \" \\\\\" -> \\" */ #define SHELL_SPECIAL_CHARS "\"\\ \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" #define SHELL_SPACE_CHARS " \001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037" char ** prepare_spawn (char **argv) { size_t argc; char **new_argv; size_t i; /* Count number of arguments. */ for (argc = 0; argv[argc] != NULL; argc++) ; /* Allocate new argument vector. */ new_argv = XMALLOC (char *, argc + 1); /* Put quoted arguments into the new argument vector. */ for (i = 0; i < argc; i++) { const char *string = argv[i]; if (string[0] == '\0') new_argv[i] = xstrdup ("\"\""); else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL) { int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL); size_t length; unsigned int backslashes; const char *s; char *quoted_string; char *p; length = 0; backslashes = 0; if (quote_around) length++; for (s = string; *s != '\0'; s++) { char c = *s; if (c == '"') length += backslashes + 1; length++; if (c == '\\') backslashes++; else backslashes = 0; } if (quote_around) length += backslashes + 1; quoted_string = XMALLOC (char, length + 1); p = quoted_string; backslashes = 0; if (quote_around) *p++ = '"'; for (s = string; *s != '\0'; s++) { char c = *s; if (c == '"') { unsigned int j; for (j = backslashes + 1; j > 0; j--) *p++ = '\\'; } *p++ = c; if (c == '\\') backslashes++; else backslashes = 0; } if (quote_around) { unsigned int j; for (j = backslashes; j > 0; j--) *p++ = '\\'; *p++ = '"'; } *p = '\0'; new_argv[i] = quoted_string; } else new_argv[i] = (char *) string; } new_argv[argc] = NULL; return new_argv; } EOF ;; esac cat <<"EOF" void lt_dump_script (FILE* f) { EOF func_emit_wrapper yes | $SED -n -e ' s/^\(.\{79\}\)\(..*\)/\1\ \2/ h s/\([\\"]\)/\\\1/g s/$/\\n/ s/\([^\n]*\).*/ fputs ("\1", f);/p g D' cat <<"EOF" } EOF } # end: func_emit_cwrapperexe_src # func_win32_import_lib_p ARG # True if ARG is an import lib, as indicated by $file_magic_cmd func_win32_import_lib_p () { $opt_debug case `eval $file_magic_cmd \"\$1\" 2>/dev/null | $SED -e 10q` in *import*) : ;; *) false ;; esac } # func_mode_link arg... func_mode_link () { $opt_debug case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) # It is impossible to link a dll without this setting, and # we shouldn't force the makefile maintainer to figure out # which system we are compiling for in order to pass an extra # flag for every libtool invocation. # allow_undefined=no # FIXME: Unfortunately, there are problems with the above when trying # to make a dll which has undefined symbols, in which case not # even a static library is built. For now, we need to specify # -no-undefined on the libtool link line when we can be certain # that all symbols are satisfied, otherwise we get a static library. allow_undefined=yes ;; *) allow_undefined=yes ;; esac libtool_args=$nonopt base_compile="$nonopt $@" compile_command=$nonopt finalize_command=$nonopt compile_rpath= finalize_rpath= compile_shlibpath= finalize_shlibpath= convenience= old_convenience= deplibs= old_deplibs= compiler_flags= linker_flags= dllsearchpath= lib_search_path=`pwd` inst_prefix_dir= new_inherited_linker_flags= avoid_version=no bindir= dlfiles= dlprefiles= dlself=no export_dynamic=no export_symbols= export_symbols_regex= generated= libobjs= ltlibs= module=no no_install=no objs= non_pic_objects= precious_files_regex= prefer_static_libs=no preload=no prev= prevarg= release= rpath= xrpath= perm_rpath= temp_rpath= thread_safe=no vinfo= vinfo_number=no weak_libs= single_module="${wl}-single_module" func_infer_tag $base_compile # We need to know -static, to get the right output filenames. for arg do case $arg in -shared) test "$build_libtool_libs" != yes && \ func_fatal_configuration "can not build a shared library" build_old_libs=no break ;; -all-static | -static | -static-libtool-libs) case $arg in -all-static) if test "$build_libtool_libs" = yes && test -z "$link_static_flag"; then func_warning "complete static linking is impossible in this configuration" fi if test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=yes ;; -static) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=built ;; -static-libtool-libs) if test -z "$pic_flag" && test -n "$link_static_flag"; then dlopen_self=$dlopen_self_static fi prefer_static_libs=yes ;; esac build_libtool_libs=no build_old_libs=yes break ;; esac done # See if our shared archives depend on static archives. test -n "$old_archive_from_new_cmds" && build_old_libs=yes # Go through the arguments, transforming them on the way. while test "$#" -gt 0; do arg="$1" shift func_quote_for_eval "$arg" qarg=$func_quote_for_eval_unquoted_result func_append libtool_args " $func_quote_for_eval_result" # If the previous option needs an argument, assign it. if test -n "$prev"; then case $prev in output) func_append compile_command " @OUTPUT@" func_append finalize_command " @OUTPUT@" ;; esac case $prev in bindir) bindir="$arg" prev= continue ;; dlfiles|dlprefiles) if test "$preload" = no; then # Add the symbol object into the linking commands. func_append compile_command " @SYMFILE@" func_append finalize_command " @SYMFILE@" preload=yes fi case $arg in *.la | *.lo) ;; # We handle these cases below. force) if test "$dlself" = no; then dlself=needless export_dynamic=yes fi prev= continue ;; self) if test "$prev" = dlprefiles; then dlself=yes elif test "$prev" = dlfiles && test "$dlopen_self" != yes; then dlself=yes else dlself=needless export_dynamic=yes fi prev= continue ;; *) if test "$prev" = dlfiles; then func_append dlfiles " $arg" else func_append dlprefiles " $arg" fi prev= continue ;; esac ;; expsyms) export_symbols="$arg" test -f "$arg" \ || func_fatal_error "symbol file \`$arg' does not exist" prev= continue ;; expsyms_regex) export_symbols_regex="$arg" prev= continue ;; framework) case $host in *-*-darwin*) case "$deplibs " in *" $qarg.ltframework "*) ;; *) func_append deplibs " $qarg.ltframework" # this is fixed later ;; esac ;; esac prev= continue ;; inst_prefix) inst_prefix_dir="$arg" prev= continue ;; objectlist) if test -f "$arg"; then save_arg=$arg moreargs= for fil in `cat "$save_arg"` do # func_append moreargs " $fil" arg=$fil # A libtool-controlled object. # Check to see that this really is a libtool object. if func_lalib_unsafe_p "$arg"; then pic_object= non_pic_object= # Read the .lo file func_source "$arg" if test -z "$pic_object" || test -z "$non_pic_object" || test "$pic_object" = none && test "$non_pic_object" = none; then func_fatal_error "cannot find name of object for \`$arg'" fi # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" if test "$pic_object" != none; then # Prepend the subdirectory the object is found in. pic_object="$xdir$pic_object" if test "$prev" = dlfiles; then if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then func_append dlfiles " $pic_object" prev= continue else # If libtool objects are unsupported, then we need to preload. prev=dlprefiles fi fi # CHECK ME: I think I busted this. -Ossama if test "$prev" = dlprefiles; then # Preload the old-style object. func_append dlprefiles " $pic_object" prev= fi # A PIC object. func_append libobjs " $pic_object" arg="$pic_object" fi # Non-PIC object. if test "$non_pic_object" != none; then # Prepend the subdirectory the object is found in. non_pic_object="$xdir$non_pic_object" # A standard non-PIC object func_append non_pic_objects " $non_pic_object" if test -z "$pic_object" || test "$pic_object" = none ; then arg="$non_pic_object" fi else # If the PIC object exists, use it instead. # $xdir was prepended to $pic_object above. non_pic_object="$pic_object" func_append non_pic_objects " $non_pic_object" fi else # Only an error if not doing a dry-run. if $opt_dry_run; then # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" func_lo2o "$arg" pic_object=$xdir$objdir/$func_lo2o_result non_pic_object=$xdir$func_lo2o_result func_append libobjs " $pic_object" func_append non_pic_objects " $non_pic_object" else func_fatal_error "\`$arg' is not a valid libtool object" fi fi done else func_fatal_error "link input file \`$arg' does not exist" fi arg=$save_arg prev= continue ;; precious_regex) precious_files_regex="$arg" prev= continue ;; release) release="-$arg" prev= continue ;; rpath | xrpath) # We need an absolute path. case $arg in [\\/]* | [A-Za-z]:[\\/]*) ;; *) func_fatal_error "only absolute run-paths are allowed" ;; esac if test "$prev" = rpath; then case "$rpath " in *" $arg "*) ;; *) func_append rpath " $arg" ;; esac else case "$xrpath " in *" $arg "*) ;; *) func_append xrpath " $arg" ;; esac fi prev= continue ;; shrext) shrext_cmds="$arg" prev= continue ;; weak) func_append weak_libs " $arg" prev= continue ;; xcclinker) func_append linker_flags " $qarg" func_append compiler_flags " $qarg" prev= func_append compile_command " $qarg" func_append finalize_command " $qarg" continue ;; xcompiler) func_append compiler_flags " $qarg" prev= func_append compile_command " $qarg" func_append finalize_command " $qarg" continue ;; xlinker) func_append linker_flags " $qarg" func_append compiler_flags " $wl$qarg" prev= func_append compile_command " $wl$qarg" func_append finalize_command " $wl$qarg" continue ;; *) eval "$prev=\"\$arg\"" prev= continue ;; esac fi # test -n "$prev" prevarg="$arg" case $arg in -all-static) if test -n "$link_static_flag"; then # See comment for -static flag below, for more details. func_append compile_command " $link_static_flag" func_append finalize_command " $link_static_flag" fi continue ;; -allow-undefined) # FIXME: remove this flag sometime in the future. func_fatal_error "\`-allow-undefined' must not be used because it is the default" ;; -avoid-version) avoid_version=yes continue ;; -bindir) prev=bindir continue ;; -dlopen) prev=dlfiles continue ;; -dlpreopen) prev=dlprefiles continue ;; -export-dynamic) export_dynamic=yes continue ;; -export-symbols | -export-symbols-regex) if test -n "$export_symbols" || test -n "$export_symbols_regex"; then func_fatal_error "more than one -exported-symbols argument is not allowed" fi if test "X$arg" = "X-export-symbols"; then prev=expsyms else prev=expsyms_regex fi continue ;; -framework) prev=framework continue ;; -inst-prefix-dir) prev=inst_prefix continue ;; # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:* # so, if we see these flags be careful not to treat them like -L -L[A-Z][A-Z]*:*) case $with_gcc/$host in no/*-*-irix* | /*-*-irix*) func_append compile_command " $arg" func_append finalize_command " $arg" ;; esac continue ;; -L*) func_stripname "-L" '' "$arg" if test -z "$func_stripname_result"; then if test "$#" -gt 0; then func_fatal_error "require no space between \`-L' and \`$1'" else func_fatal_error "need path for \`-L' option" fi fi func_resolve_sysroot "$func_stripname_result" dir=$func_resolve_sysroot_result # We need an absolute path. case $dir in [\\/]* | [A-Za-z]:[\\/]*) ;; *) absdir=`cd "$dir" && pwd` test -z "$absdir" && \ func_fatal_error "cannot determine absolute directory name of \`$dir'" dir="$absdir" ;; esac case "$deplibs " in *" -L$dir "* | *" $arg "*) # Will only happen for absolute or sysroot arguments ;; *) # Preserve sysroot, but never include relative directories case $dir in [\\/]* | [A-Za-z]:[\\/]* | =*) func_append deplibs " $arg" ;; *) func_append deplibs " -L$dir" ;; esac func_append lib_search_path " $dir" ;; esac case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'` case :$dllsearchpath: in *":$dir:"*) ;; ::) dllsearchpath=$dir;; *) func_append dllsearchpath ":$dir";; esac case :$dllsearchpath: in *":$testbindir:"*) ;; ::) dllsearchpath=$testbindir;; *) func_append dllsearchpath ":$testbindir";; esac ;; esac continue ;; -l*) if test "X$arg" = "X-lc" || test "X$arg" = "X-lm"; then case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) # These systems don't actually have a C or math library (as such) continue ;; *-*-os2*) # These systems don't actually have a C library (as such) test "X$arg" = "X-lc" && continue ;; *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) # Do not include libc due to us having libc/libc_r. test "X$arg" = "X-lc" && continue ;; *-*-rhapsody* | *-*-darwin1.[012]) # Rhapsody C and math libraries are in the System framework func_append deplibs " System.ltframework" continue ;; *-*-sco3.2v5* | *-*-sco5v6*) # Causes problems with __ctype test "X$arg" = "X-lc" && continue ;; *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) # Compiler inserts libc in the correct place for threads to work test "X$arg" = "X-lc" && continue ;; esac elif test "X$arg" = "X-lc_r"; then case $host in *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) # Do not include libc_r directly, use -pthread flag. continue ;; esac fi func_append deplibs " $arg" continue ;; -module) module=yes continue ;; # Tru64 UNIX uses -model [arg] to determine the layout of C++ # classes, name mangling, and exception handling. # Darwin uses the -arch flag to determine output architecture. -model|-arch|-isysroot|--sysroot) func_append compiler_flags " $arg" func_append compile_command " $arg" func_append finalize_command " $arg" prev=xcompiler continue ;; -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) func_append compiler_flags " $arg" func_append compile_command " $arg" func_append finalize_command " $arg" func_append deplibs " $arg" case "$new_inherited_linker_flags " in *" $arg "*) ;; * ) func_append new_inherited_linker_flags " $arg" ;; esac continue ;; -multi_module) single_module="${wl}-multi_module" continue ;; -no-fast-install) fast_install=no continue ;; -no-install) case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) # The PATH hackery in wrapper scripts is required on Windows # and Darwin in order for the loader to find any dlls it needs. func_warning "\`-no-install' is ignored for $host" func_warning "assuming \`-no-fast-install' instead" fast_install=no ;; *) no_install=yes ;; esac continue ;; -no-undefined) allow_undefined=no continue ;; -objectlist) prev=objectlist continue ;; -o) prev=output ;; -precious-files-regex) prev=precious_regex continue ;; -release) prev=release continue ;; -rpath) prev=rpath continue ;; -R) prev=xrpath continue ;; -R*) func_stripname '-R' '' "$arg" dir=$func_stripname_result # We need an absolute path. case $dir in [\\/]* | [A-Za-z]:[\\/]*) ;; =*) func_stripname '=' '' "$dir" dir=$lt_sysroot$func_stripname_result ;; *) func_fatal_error "only absolute run-paths are allowed" ;; esac case "$xrpath " in *" $dir "*) ;; *) func_append xrpath " $dir" ;; esac continue ;; -shared) # The effects of -shared are defined in a previous loop. continue ;; -shrext) prev=shrext continue ;; -static | -static-libtool-libs) # The effects of -static are defined in a previous loop. # We used to do the same as -all-static on platforms that # didn't have a PIC flag, but the assumption that the effects # would be equivalent was wrong. It would break on at least # Digital Unix and AIX. continue ;; -thread-safe) thread_safe=yes continue ;; -version-info) prev=vinfo continue ;; -version-number) prev=vinfo vinfo_number=yes continue ;; -weak) prev=weak continue ;; -Wc,*) func_stripname '-Wc,' '' "$arg" args=$func_stripname_result arg= save_ifs="$IFS"; IFS=',' for flag in $args; do IFS="$save_ifs" func_quote_for_eval "$flag" func_append arg " $func_quote_for_eval_result" func_append compiler_flags " $func_quote_for_eval_result" done IFS="$save_ifs" func_stripname ' ' '' "$arg" arg=$func_stripname_result ;; -Wl,*) func_stripname '-Wl,' '' "$arg" args=$func_stripname_result arg= save_ifs="$IFS"; IFS=',' for flag in $args; do IFS="$save_ifs" func_quote_for_eval "$flag" func_append arg " $wl$func_quote_for_eval_result" func_append compiler_flags " $wl$func_quote_for_eval_result" func_append linker_flags " $func_quote_for_eval_result" done IFS="$save_ifs" func_stripname ' ' '' "$arg" arg=$func_stripname_result ;; -Xcompiler) prev=xcompiler continue ;; -Xlinker) prev=xlinker continue ;; -XCClinker) prev=xcclinker continue ;; # -msg_* for osf cc -msg_*) func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" ;; # Flags to be passed through unchanged, with rationale: # -64, -mips[0-9] enable 64-bit mode for the SGI compiler # -r[0-9][0-9]* specify processor for the SGI compiler # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler # +DA*, +DD* enable 64-bit mode for the HP compiler # -q* compiler args for the IBM compiler # -m*, -t[45]*, -txscale* architecture-specific flags for GCC # -F/path path to uninstalled frameworks, gcc on darwin # -p, -pg, --coverage, -fprofile-* profiling flags for GCC # @file GCC response files # -tp=* Portland pgcc target processor selection # --sysroot=* for sysroot support # -O*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ -O*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*) func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" func_append compile_command " $arg" func_append finalize_command " $arg" func_append compiler_flags " $arg" continue ;; # Some other compiler flag. -* | +*) func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" ;; *.$objext) # A standard object. func_append objs " $arg" ;; *.lo) # A libtool-controlled object. # Check to see that this really is a libtool object. if func_lalib_unsafe_p "$arg"; then pic_object= non_pic_object= # Read the .lo file func_source "$arg" if test -z "$pic_object" || test -z "$non_pic_object" || test "$pic_object" = none && test "$non_pic_object" = none; then func_fatal_error "cannot find name of object for \`$arg'" fi # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" if test "$pic_object" != none; then # Prepend the subdirectory the object is found in. pic_object="$xdir$pic_object" if test "$prev" = dlfiles; then if test "$build_libtool_libs" = yes && test "$dlopen_support" = yes; then func_append dlfiles " $pic_object" prev= continue else # If libtool objects are unsupported, then we need to preload. prev=dlprefiles fi fi # CHECK ME: I think I busted this. -Ossama if test "$prev" = dlprefiles; then # Preload the old-style object. func_append dlprefiles " $pic_object" prev= fi # A PIC object. func_append libobjs " $pic_object" arg="$pic_object" fi # Non-PIC object. if test "$non_pic_object" != none; then # Prepend the subdirectory the object is found in. non_pic_object="$xdir$non_pic_object" # A standard non-PIC object func_append non_pic_objects " $non_pic_object" if test -z "$pic_object" || test "$pic_object" = none ; then arg="$non_pic_object" fi else # If the PIC object exists, use it instead. # $xdir was prepended to $pic_object above. non_pic_object="$pic_object" func_append non_pic_objects " $non_pic_object" fi else # Only an error if not doing a dry-run. if $opt_dry_run; then # Extract subdirectory from the argument. func_dirname "$arg" "/" "" xdir="$func_dirname_result" func_lo2o "$arg" pic_object=$xdir$objdir/$func_lo2o_result non_pic_object=$xdir$func_lo2o_result func_append libobjs " $pic_object" func_append non_pic_objects " $non_pic_object" else func_fatal_error "\`$arg' is not a valid libtool object" fi fi ;; *.$libext) # An archive. func_append deplibs " $arg" func_append old_deplibs " $arg" continue ;; *.la) # A libtool-controlled library. func_resolve_sysroot "$arg" if test "$prev" = dlfiles; then # This library was specified with -dlopen. func_append dlfiles " $func_resolve_sysroot_result" prev= elif test "$prev" = dlprefiles; then # The library was specified with -dlpreopen. func_append dlprefiles " $func_resolve_sysroot_result" prev= else func_append deplibs " $func_resolve_sysroot_result" fi continue ;; # Some other compiler argument. *) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. func_quote_for_eval "$arg" arg="$func_quote_for_eval_result" ;; esac # arg # Now actually substitute the argument into the commands. if test -n "$arg"; then func_append compile_command " $arg" func_append finalize_command " $arg" fi done # argument parsing loop test -n "$prev" && \ func_fatal_help "the \`$prevarg' option requires an argument" if test "$export_dynamic" = yes && test -n "$export_dynamic_flag_spec"; then eval arg=\"$export_dynamic_flag_spec\" func_append compile_command " $arg" func_append finalize_command " $arg" fi oldlibs= # calculate the name of the file, without its directory func_basename "$output" outputname="$func_basename_result" libobjs_save="$libobjs" if test -n "$shlibpath_var"; then # get the directories listed in $shlibpath_var eval shlib_search_path=\`\$ECHO \"\${$shlibpath_var}\" \| \$SED \'s/:/ /g\'\` else shlib_search_path= fi eval sys_lib_search_path=\"$sys_lib_search_path_spec\" eval sys_lib_dlsearch_path=\"$sys_lib_dlsearch_path_spec\" func_dirname "$output" "/" "" output_objdir="$func_dirname_result$objdir" func_to_tool_file "$output_objdir/" tool_output_objdir=$func_to_tool_file_result # Create the object directory. func_mkdir_p "$output_objdir" # Determine the type of output case $output in "") func_fatal_help "you must specify an output file" ;; *.$libext) linkmode=oldlib ;; *.lo | *.$objext) linkmode=obj ;; *.la) linkmode=lib ;; *) linkmode=prog ;; # Anything else should be a program. esac specialdeplibs= libs= # Find all interdependent deplibs by searching for libraries # that are linked more than once (e.g. -la -lb -la) for deplib in $deplibs; do if $opt_preserve_dup_deps ; then case "$libs " in *" $deplib "*) func_append specialdeplibs " $deplib" ;; esac fi func_append libs " $deplib" done if test "$linkmode" = lib; then libs="$predeps $libs $compiler_lib_search_path $postdeps" # Compute libraries that are listed more than once in $predeps # $postdeps and mark them as special (i.e., whose duplicates are # not to be eliminated). pre_post_deps= if $opt_duplicate_compiler_generated_deps; then for pre_post_dep in $predeps $postdeps; do case "$pre_post_deps " in *" $pre_post_dep "*) func_append specialdeplibs " $pre_post_deps" ;; esac func_append pre_post_deps " $pre_post_dep" done fi pre_post_deps= fi deplibs= newdependency_libs= newlib_search_path= need_relink=no # whether we're linking any uninstalled libtool libraries notinst_deplibs= # not-installed libtool libraries notinst_path= # paths that contain not-installed libtool libraries case $linkmode in lib) passes="conv dlpreopen link" for file in $dlfiles $dlprefiles; do case $file in *.la) ;; *) func_fatal_help "libraries can \`-dlopen' only libtool libraries: $file" ;; esac done ;; prog) compile_deplibs= finalize_deplibs= alldeplibs=no newdlfiles= newdlprefiles= passes="conv scan dlopen dlpreopen link" ;; *) passes="conv" ;; esac for pass in $passes; do # The preopen pass in lib mode reverses $deplibs; put it back here # so that -L comes before libs that need it for instance... if test "$linkmode,$pass" = "lib,link"; then ## FIXME: Find the place where the list is rebuilt in the wrong ## order, and fix it there properly tmp_deplibs= for deplib in $deplibs; do tmp_deplibs="$deplib $tmp_deplibs" done deplibs="$tmp_deplibs" fi if test "$linkmode,$pass" = "lib,link" || test "$linkmode,$pass" = "prog,scan"; then libs="$deplibs" deplibs= fi if test "$linkmode" = prog; then case $pass in dlopen) libs="$dlfiles" ;; dlpreopen) libs="$dlprefiles" ;; link) libs="$deplibs %DEPLIBS% $dependency_libs" ;; esac fi if test "$linkmode,$pass" = "lib,dlpreopen"; then # Collect and forward deplibs of preopened libtool libs for lib in $dlprefiles; do # Ignore non-libtool-libs dependency_libs= func_resolve_sysroot "$lib" case $lib in *.la) func_source "$func_resolve_sysroot_result" ;; esac # Collect preopened libtool deplibs, except any this library # has declared as weak libs for deplib in $dependency_libs; do func_basename "$deplib" deplib_base=$func_basename_result case " $weak_libs " in *" $deplib_base "*) ;; *) func_append deplibs " $deplib" ;; esac done done libs="$dlprefiles" fi if test "$pass" = dlopen; then # Collect dlpreopened libraries save_deplibs="$deplibs" deplibs= fi for deplib in $libs; do lib= found=no case $deplib in -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else func_append compiler_flags " $deplib" test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" if test "$linkmode" = lib ; then case "$new_inherited_linker_flags " in *" $deplib "*) ;; * ) func_append new_inherited_linker_flags " $deplib" ;; esac fi fi continue ;; -l*) if test "$linkmode" != lib && test "$linkmode" != prog; then func_warning "\`-l' is ignored for archives/objects" continue fi func_stripname '-l' '' "$deplib" name=$func_stripname_result if test "$linkmode" = lib; then searchdirs="$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path" else searchdirs="$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path" fi for searchdir in $searchdirs; do for search_ext in .la $std_shrext .so .a; do # Search the libtool library lib="$searchdir/lib${name}${search_ext}" if test -f "$lib"; then if test "$search_ext" = ".la"; then found=yes else found=no fi break 2 fi done done if test "$found" != yes; then # deplib doesn't seem to be a libtool library if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else deplibs="$deplib $deplibs" test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" fi continue else # deplib is a libtool library # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib, # We need to do some special things here, and not later. if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then case " $predeps $postdeps " in *" $deplib "*) if func_lalib_p "$lib"; then library_names= old_library= func_source "$lib" for l in $old_library $library_names; do ll="$l" done if test "X$ll" = "X$old_library" ; then # only static version available found=no func_dirname "$lib" "" "." ladir="$func_dirname_result" lib=$ladir/$old_library if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else deplibs="$deplib $deplibs" test "$linkmode" = lib && newdependency_libs="$deplib $newdependency_libs" fi continue fi fi ;; *) ;; esac fi fi ;; # -l *.ltframework) if test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else deplibs="$deplib $deplibs" if test "$linkmode" = lib ; then case "$new_inherited_linker_flags " in *" $deplib "*) ;; * ) func_append new_inherited_linker_flags " $deplib" ;; esac fi fi continue ;; -L*) case $linkmode in lib) deplibs="$deplib $deplibs" test "$pass" = conv && continue newdependency_libs="$deplib $newdependency_libs" func_stripname '-L' '' "$deplib" func_resolve_sysroot "$func_stripname_result" func_append newlib_search_path " $func_resolve_sysroot_result" ;; prog) if test "$pass" = conv; then deplibs="$deplib $deplibs" continue fi if test "$pass" = scan; then deplibs="$deplib $deplibs" else compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" fi func_stripname '-L' '' "$deplib" func_resolve_sysroot "$func_stripname_result" func_append newlib_search_path " $func_resolve_sysroot_result" ;; *) func_warning "\`-L' is ignored for archives/objects" ;; esac # linkmode continue ;; # -L -R*) if test "$pass" = link; then func_stripname '-R' '' "$deplib" func_resolve_sysroot "$func_stripname_result" dir=$func_resolve_sysroot_result # Make sure the xrpath contains only unique directories. case "$xrpath " in *" $dir "*) ;; *) func_append xrpath " $dir" ;; esac fi deplibs="$deplib $deplibs" continue ;; *.la) func_resolve_sysroot "$deplib" lib=$func_resolve_sysroot_result ;; *.$libext) if test "$pass" = conv; then deplibs="$deplib $deplibs" continue fi case $linkmode in lib) # Linking convenience modules into shared libraries is allowed, # but linking other static libraries is non-portable. case " $dlpreconveniencelibs " in *" $deplib "*) ;; *) valid_a_lib=no case $deplibs_check_method in match_pattern*) set dummy $deplibs_check_method; shift match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` if eval "\$ECHO \"$deplib\"" 2>/dev/null | $SED 10q \ | $EGREP "$match_pattern_regex" > /dev/null; then valid_a_lib=yes fi ;; pass_all) valid_a_lib=yes ;; esac if test "$valid_a_lib" != yes; then echo $ECHO "*** Warning: Trying to link with static lib archive $deplib." echo "*** I have the capability to make that library automatically link in when" echo "*** you link to this library. But I can only do this if you have a" echo "*** shared version of the library, which you do not appear to have" echo "*** because the file extensions .$libext of this argument makes me believe" echo "*** that it is just a static archive that I should not use here." else echo $ECHO "*** Warning: Linking the shared library $output against the" $ECHO "*** static library $deplib is not portable!" deplibs="$deplib $deplibs" fi ;; esac continue ;; prog) if test "$pass" != link; then deplibs="$deplib $deplibs" else compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" fi continue ;; esac # linkmode ;; # *.$libext *.lo | *.$objext) if test "$pass" = conv; then deplibs="$deplib $deplibs" elif test "$linkmode" = prog; then if test "$pass" = dlpreopen || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then # If there is no dlopen support or we're linking statically, # we need to preload. func_append newdlprefiles " $deplib" compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" else func_append newdlfiles " $deplib" fi fi continue ;; %DEPLIBS%) alldeplibs=yes continue ;; esac # case $deplib if test "$found" = yes || test -f "$lib"; then : else func_fatal_error "cannot find the library \`$lib' or unhandled argument \`$deplib'" fi # Check to see that this really is a libtool archive. func_lalib_unsafe_p "$lib" \ || func_fatal_error "\`$lib' is not a valid libtool archive" func_dirname "$lib" "" "." ladir="$func_dirname_result" dlname= dlopen= dlpreopen= libdir= library_names= old_library= inherited_linker_flags= # If the library was installed with an old release of libtool, # it will not redefine variables installed, or shouldnotlink installed=yes shouldnotlink=no avoidtemprpath= # Read the .la file func_source "$lib" # Convert "-framework foo" to "foo.ltframework" if test -n "$inherited_linker_flags"; then tmp_inherited_linker_flags=`$ECHO "$inherited_linker_flags" | $SED 's/-framework \([^ $]*\)/\1.ltframework/g'` for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do case " $new_inherited_linker_flags " in *" $tmp_inherited_linker_flag "*) ;; *) func_append new_inherited_linker_flags " $tmp_inherited_linker_flag";; esac done fi dependency_libs=`$ECHO " $dependency_libs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` if test "$linkmode,$pass" = "lib,link" || test "$linkmode,$pass" = "prog,scan" || { test "$linkmode" != prog && test "$linkmode" != lib; }; then test -n "$dlopen" && func_append dlfiles " $dlopen" test -n "$dlpreopen" && func_append dlprefiles " $dlpreopen" fi if test "$pass" = conv; then # Only check for convenience libraries deplibs="$lib $deplibs" if test -z "$libdir"; then if test -z "$old_library"; then func_fatal_error "cannot find name of link library for \`$lib'" fi # It is a libtool convenience library, so add in its objects. func_append convenience " $ladir/$objdir/$old_library" func_append old_convenience " $ladir/$objdir/$old_library" elif test "$linkmode" != prog && test "$linkmode" != lib; then func_fatal_error "\`$lib' is not a convenience library" fi tmp_libs= for deplib in $dependency_libs; do deplibs="$deplib $deplibs" if $opt_preserve_dup_deps ; then case "$tmp_libs " in *" $deplib "*) func_append specialdeplibs " $deplib" ;; esac fi func_append tmp_libs " $deplib" done continue fi # $pass = conv # Get the name of the library we link against. linklib= if test -n "$old_library" && { test "$prefer_static_libs" = yes || test "$prefer_static_libs,$installed" = "built,no"; }; then linklib=$old_library else for l in $old_library $library_names; do linklib="$l" done fi if test -z "$linklib"; then func_fatal_error "cannot find name of link library for \`$lib'" fi # This library was specified with -dlopen. if test "$pass" = dlopen; then if test -z "$libdir"; then func_fatal_error "cannot -dlopen a convenience library: \`$lib'" fi if test -z "$dlname" || test "$dlopen_support" != yes || test "$build_libtool_libs" = no; then # If there is no dlname, no dlopen support or we're linking # statically, we need to preload. We also need to preload any # dependent libraries so libltdl's deplib preloader doesn't # bomb out in the load deplibs phase. func_append dlprefiles " $lib $dependency_libs" else func_append newdlfiles " $lib" fi continue fi # $pass = dlopen # We need an absolute path. case $ladir in [\\/]* | [A-Za-z]:[\\/]*) abs_ladir="$ladir" ;; *) abs_ladir=`cd "$ladir" && pwd` if test -z "$abs_ladir"; then func_warning "cannot determine absolute directory name of \`$ladir'" func_warning "passing it literally to the linker, although it might fail" abs_ladir="$ladir" fi ;; esac func_basename "$lib" laname="$func_basename_result" # Find the relevant object directory and library name. if test "X$installed" = Xyes; then if test ! -f "$lt_sysroot$libdir/$linklib" && test -f "$abs_ladir/$linklib"; then func_warning "library \`$lib' was moved." dir="$ladir" absdir="$abs_ladir" libdir="$abs_ladir" else dir="$lt_sysroot$libdir" absdir="$lt_sysroot$libdir" fi test "X$hardcode_automatic" = Xyes && avoidtemprpath=yes else if test ! -f "$ladir/$objdir/$linklib" && test -f "$abs_ladir/$linklib"; then dir="$ladir" absdir="$abs_ladir" # Remove this search path later func_append notinst_path " $abs_ladir" else dir="$ladir/$objdir" absdir="$abs_ladir/$objdir" # Remove this search path later func_append notinst_path " $abs_ladir" fi fi # $installed = yes func_stripname 'lib' '.la' "$laname" name=$func_stripname_result # This library was specified with -dlpreopen. if test "$pass" = dlpreopen; then if test -z "$libdir" && test "$linkmode" = prog; then func_fatal_error "only libraries may -dlpreopen a convenience library: \`$lib'" fi case "$host" in # special handling for platforms with PE-DLLs. *cygwin* | *mingw* | *cegcc* ) # Linker will automatically link against shared library if both # static and shared are present. Therefore, ensure we extract # symbols from the import library if a shared library is present # (otherwise, the dlopen module name will be incorrect). We do # this by putting the import library name into $newdlprefiles. # We recover the dlopen module name by 'saving' the la file # name in a special purpose variable, and (later) extracting the # dlname from the la file. if test -n "$dlname"; then func_tr_sh "$dir/$linklib" eval "libfile_$func_tr_sh_result=\$abs_ladir/\$laname" func_append newdlprefiles " $dir/$linklib" else func_append newdlprefiles " $dir/$old_library" # Keep a list of preopened convenience libraries to check # that they are being used correctly in the link pass. test -z "$libdir" && \ func_append dlpreconveniencelibs " $dir/$old_library" fi ;; * ) # Prefer using a static library (so that no silly _DYNAMIC symbols # are required to link). if test -n "$old_library"; then func_append newdlprefiles " $dir/$old_library" # Keep a list of preopened convenience libraries to check # that they are being used correctly in the link pass. test -z "$libdir" && \ func_append dlpreconveniencelibs " $dir/$old_library" # Otherwise, use the dlname, so that lt_dlopen finds it. elif test -n "$dlname"; then func_append newdlprefiles " $dir/$dlname" else func_append newdlprefiles " $dir/$linklib" fi ;; esac fi # $pass = dlpreopen if test -z "$libdir"; then # Link the convenience library if test "$linkmode" = lib; then deplibs="$dir/$old_library $deplibs" elif test "$linkmode,$pass" = "prog,link"; then compile_deplibs="$dir/$old_library $compile_deplibs" finalize_deplibs="$dir/$old_library $finalize_deplibs" else deplibs="$lib $deplibs" # used for prog,scan pass fi continue fi if test "$linkmode" = prog && test "$pass" != link; then func_append newlib_search_path " $ladir" deplibs="$lib $deplibs" linkalldeplibs=no if test "$link_all_deplibs" != no || test -z "$library_names" || test "$build_libtool_libs" = no; then linkalldeplibs=yes fi tmp_libs= for deplib in $dependency_libs; do case $deplib in -L*) func_stripname '-L' '' "$deplib" func_resolve_sysroot "$func_stripname_result" func_append newlib_search_path " $func_resolve_sysroot_result" ;; esac # Need to link against all dependency_libs? if test "$linkalldeplibs" = yes; then deplibs="$deplib $deplibs" else # Need to hardcode shared library paths # or/and link against static libraries newdependency_libs="$deplib $newdependency_libs" fi if $opt_preserve_dup_deps ; then case "$tmp_libs " in *" $deplib "*) func_append specialdeplibs " $deplib" ;; esac fi func_append tmp_libs " $deplib" done # for deplib continue fi # $linkmode = prog... if test "$linkmode,$pass" = "prog,link"; then if test -n "$library_names" && { { test "$prefer_static_libs" = no || test "$prefer_static_libs,$installed" = "built,yes"; } || test -z "$old_library"; }; then # We need to hardcode the library path if test -n "$shlibpath_var" && test -z "$avoidtemprpath" ; then # Make sure the rpath contains only unique directories. case "$temp_rpath:" in *"$absdir:"*) ;; *) func_append temp_rpath "$absdir:" ;; esac fi # Hardcode the library path. # Skip directories that are in the system default run-time # search path. case " $sys_lib_dlsearch_path " in *" $absdir "*) ;; *) case "$compile_rpath " in *" $absdir "*) ;; *) func_append compile_rpath " $absdir" ;; esac ;; esac case " $sys_lib_dlsearch_path " in *" $libdir "*) ;; *) case "$finalize_rpath " in *" $libdir "*) ;; *) func_append finalize_rpath " $libdir" ;; esac ;; esac fi # $linkmode,$pass = prog,link... if test "$alldeplibs" = yes && { test "$deplibs_check_method" = pass_all || { test "$build_libtool_libs" = yes && test -n "$library_names"; }; }; then # We only need to search for static libraries continue fi fi link_static=no # Whether the deplib will be linked statically use_static_libs=$prefer_static_libs if test "$use_static_libs" = built && test "$installed" = yes; then use_static_libs=no fi if test -n "$library_names" && { test "$use_static_libs" = no || test -z "$old_library"; }; then case $host in *cygwin* | *mingw* | *cegcc*) # No point in relinking DLLs because paths are not encoded func_append notinst_deplibs " $lib" need_relink=no ;; *) if test "$installed" = no; then func_append notinst_deplibs " $lib" test -z "$DESTDIR" && need_relink=yes fi ;; esac # This is a shared library # Warn about portability, can't link against -module's on some # systems (darwin). Don't bleat about dlopened modules though! dlopenmodule="" for dlpremoduletest in $dlprefiles; do if test "X$dlpremoduletest" = "X$lib"; then dlopenmodule="$dlpremoduletest" break fi done if test -z "$dlopenmodule" && test "$shouldnotlink" = yes && test "$pass" = link; then echo if test "$linkmode" = prog; then $ECHO "*** Warning: Linking the executable $output against the loadable module" else $ECHO "*** Warning: Linking the shared library $output against the loadable module" fi $ECHO "*** $linklib is not portable!" fi if test "$linkmode" = lib && test "$hardcode_into_libs" = yes; then # Hardcode the library path. # Skip directories that are in the system default run-time # search path. case " $sys_lib_dlsearch_path " in *" $absdir "*) ;; *) case "$compile_rpath " in *" $absdir "*) ;; *) func_append compile_rpath " $absdir" ;; esac ;; esac case " $sys_lib_dlsearch_path " in *" $libdir "*) ;; *) case "$finalize_rpath " in *" $libdir "*) ;; *) func_append finalize_rpath " $libdir" ;; esac ;; esac fi if test -n "$old_archive_from_expsyms_cmds"; then # figure out the soname set dummy $library_names shift realname="$1" shift libname=`eval "\\$ECHO \"$libname_spec\""` # use dlname if we got it. it's perfectly good, no? if test -n "$dlname"; then soname="$dlname" elif test -n "$soname_spec"; then # bleh windows case $host in *cygwin* | mingw* | *cegcc*) func_arith $current - $age major=$func_arith_result versuffix="-$major" ;; esac eval soname=\"$soname_spec\" else soname="$realname" fi # Make a new name for the extract_expsyms_cmds to use soroot="$soname" func_basename "$soroot" soname="$func_basename_result" func_stripname 'lib' '.dll' "$soname" newlib=libimp-$func_stripname_result.a # If the library has no export list, then create one now if test -f "$output_objdir/$soname-def"; then : else func_verbose "extracting exported symbol list from \`$soname'" func_execute_cmds "$extract_expsyms_cmds" 'exit $?' fi # Create $newlib if test -f "$output_objdir/$newlib"; then :; else func_verbose "generating import library for \`$soname'" func_execute_cmds "$old_archive_from_expsyms_cmds" 'exit $?' fi # make sure the library variables are pointing to the new library dir=$output_objdir linklib=$newlib fi # test -n "$old_archive_from_expsyms_cmds" if test "$linkmode" = prog || test "$opt_mode" != relink; then add_shlibpath= add_dir= add= lib_linked=yes case $hardcode_action in immediate | unsupported) if test "$hardcode_direct" = no; then add="$dir/$linklib" case $host in *-*-sco3.2v5.0.[024]*) add_dir="-L$dir" ;; *-*-sysv4*uw2*) add_dir="-L$dir" ;; *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \ *-*-unixware7*) add_dir="-L$dir" ;; *-*-darwin* ) # if the lib is a (non-dlopened) module then we can not # link against it, someone is ignoring the earlier warnings if /usr/bin/file -L $add 2> /dev/null | $GREP ": [^:]* bundle" >/dev/null ; then if test "X$dlopenmodule" != "X$lib"; then $ECHO "*** Warning: lib $linklib is a module, not a shared library" if test -z "$old_library" ; then echo echo "*** And there doesn't seem to be a static archive available" echo "*** The link will probably fail, sorry" else add="$dir/$old_library" fi elif test -n "$old_library"; then add="$dir/$old_library" fi fi esac elif test "$hardcode_minus_L" = no; then case $host in *-*-sunos*) add_shlibpath="$dir" ;; esac add_dir="-L$dir" add="-l$name" elif test "$hardcode_shlibpath_var" = no; then add_shlibpath="$dir" add="-l$name" else lib_linked=no fi ;; relink) if test "$hardcode_direct" = yes && test "$hardcode_direct_absolute" = no; then add="$dir/$linklib" elif test "$hardcode_minus_L" = yes; then add_dir="-L$absdir" # Try looking first in the location we're being installed to. if test -n "$inst_prefix_dir"; then case $libdir in [\\/]*) func_append add_dir " -L$inst_prefix_dir$libdir" ;; esac fi add="-l$name" elif test "$hardcode_shlibpath_var" = yes; then add_shlibpath="$dir" add="-l$name" else lib_linked=no fi ;; *) lib_linked=no ;; esac if test "$lib_linked" != yes; then func_fatal_configuration "unsupported hardcode properties" fi if test -n "$add_shlibpath"; then case :$compile_shlibpath: in *":$add_shlibpath:"*) ;; *) func_append compile_shlibpath "$add_shlibpath:" ;; esac fi if test "$linkmode" = prog; then test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs" test -n "$add" && compile_deplibs="$add $compile_deplibs" else test -n "$add_dir" && deplibs="$add_dir $deplibs" test -n "$add" && deplibs="$add $deplibs" if test "$hardcode_direct" != yes && test "$hardcode_minus_L" != yes && test "$hardcode_shlibpath_var" = yes; then case :$finalize_shlibpath: in *":$libdir:"*) ;; *) func_append finalize_shlibpath "$libdir:" ;; esac fi fi fi if test "$linkmode" = prog || test "$opt_mode" = relink; then add_shlibpath= add_dir= add= # Finalize command for both is simple: just hardcode it. if test "$hardcode_direct" = yes && test "$hardcode_direct_absolute" = no; then add="$libdir/$linklib" elif test "$hardcode_minus_L" = yes; then add_dir="-L$libdir" add="-l$name" elif test "$hardcode_shlibpath_var" = yes; then case :$finalize_shlibpath: in *":$libdir:"*) ;; *) func_append finalize_shlibpath "$libdir:" ;; esac add="-l$name" elif test "$hardcode_automatic" = yes; then if test -n "$inst_prefix_dir" && test -f "$inst_prefix_dir$libdir/$linklib" ; then add="$inst_prefix_dir$libdir/$linklib" else add="$libdir/$linklib" fi else # We cannot seem to hardcode it, guess we'll fake it. add_dir="-L$libdir" # Try looking first in the location we're being installed to. if test -n "$inst_prefix_dir"; then case $libdir in [\\/]*) func_append add_dir " -L$inst_prefix_dir$libdir" ;; esac fi add="-l$name" fi if test "$linkmode" = prog; then test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs" test -n "$add" && finalize_deplibs="$add $finalize_deplibs" else test -n "$add_dir" && deplibs="$add_dir $deplibs" test -n "$add" && deplibs="$add $deplibs" fi fi elif test "$linkmode" = prog; then # Here we assume that one of hardcode_direct or hardcode_minus_L # is not unsupported. This is valid on all known static and # shared platforms. if test "$hardcode_direct" != unsupported; then test -n "$old_library" && linklib="$old_library" compile_deplibs="$dir/$linklib $compile_deplibs" finalize_deplibs="$dir/$linklib $finalize_deplibs" else compile_deplibs="-l$name -L$dir $compile_deplibs" finalize_deplibs="-l$name -L$dir $finalize_deplibs" fi elif test "$build_libtool_libs" = yes; then # Not a shared library if test "$deplibs_check_method" != pass_all; then # We're trying link a shared library against a static one # but the system doesn't support it. # Just print a warning and add the library to dependency_libs so # that the program can be linked against the static library. echo $ECHO "*** Warning: This system can not link to static lib archive $lib." echo "*** I have the capability to make that library automatically link in when" echo "*** you link to this library. But I can only do this if you have a" echo "*** shared version of the library, which you do not appear to have." if test "$module" = yes; then echo "*** But as you try to build a module library, libtool will still create " echo "*** a static module, that should work as long as the dlopening application" echo "*** is linked with the -dlopen flag to resolve symbols at runtime." if test -z "$global_symbol_pipe"; then echo echo "*** However, this would only work if libtool was able to extract symbol" echo "*** lists from a program, using \`nm' or equivalent, but libtool could" echo "*** not find such a program. So, this module is probably useless." echo "*** \`nm' from GNU binutils and a full rebuild may help." fi if test "$build_old_libs" = no; then build_libtool_libs=module build_old_libs=yes else build_libtool_libs=no fi fi else deplibs="$dir/$old_library $deplibs" link_static=yes fi fi # link shared/static library? if test "$linkmode" = lib; then if test -n "$dependency_libs" && { test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes || test "$link_static" = yes; }; then # Extract -R from dependency_libs temp_deplibs= for libdir in $dependency_libs; do case $libdir in -R*) func_stripname '-R' '' "$libdir" temp_xrpath=$func_stripname_result case " $xrpath " in *" $temp_xrpath "*) ;; *) func_append xrpath " $temp_xrpath";; esac;; *) func_append temp_deplibs " $libdir";; esac done dependency_libs="$temp_deplibs" fi func_append newlib_search_path " $absdir" # Link against this library test "$link_static" = no && newdependency_libs="$abs_ladir/$laname $newdependency_libs" # ... and its dependency_libs tmp_libs= for deplib in $dependency_libs; do newdependency_libs="$deplib $newdependency_libs" case $deplib in -L*) func_stripname '-L' '' "$deplib" func_resolve_sysroot "$func_stripname_result";; *) func_resolve_sysroot "$deplib" ;; esac if $opt_preserve_dup_deps ; then case "$tmp_libs " in *" $func_resolve_sysroot_result "*) func_append specialdeplibs " $func_resolve_sysroot_result" ;; esac fi func_append tmp_libs " $func_resolve_sysroot_result" done if test "$link_all_deplibs" != no; then # Add the search paths of all dependency libraries for deplib in $dependency_libs; do path= case $deplib in -L*) path="$deplib" ;; *.la) func_resolve_sysroot "$deplib" deplib=$func_resolve_sysroot_result func_dirname "$deplib" "" "." dir=$func_dirname_result # We need an absolute path. case $dir in [\\/]* | [A-Za-z]:[\\/]*) absdir="$dir" ;; *) absdir=`cd "$dir" && pwd` if test -z "$absdir"; then func_warning "cannot determine absolute directory name of \`$dir'" absdir="$dir" fi ;; esac if $GREP "^installed=no" $deplib > /dev/null; then case $host in *-*-darwin*) depdepl= eval deplibrary_names=`${SED} -n -e 's/^library_names=\(.*\)$/\1/p' $deplib` if test -n "$deplibrary_names" ; then for tmp in $deplibrary_names ; do depdepl=$tmp done if test -f "$absdir/$objdir/$depdepl" ; then depdepl="$absdir/$objdir/$depdepl" darwin_install_name=`${OTOOL} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` if test -z "$darwin_install_name"; then darwin_install_name=`${OTOOL64} -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'` fi func_append compiler_flags " ${wl}-dylib_file ${wl}${darwin_install_name}:${depdepl}" func_append linker_flags " -dylib_file ${darwin_install_name}:${depdepl}" path= fi fi ;; *) path="-L$absdir/$objdir" ;; esac else eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $deplib` test -z "$libdir" && \ func_fatal_error "\`$deplib' is not a valid libtool archive" test "$absdir" != "$libdir" && \ func_warning "\`$deplib' seems to be moved" path="-L$absdir" fi ;; esac case " $deplibs " in *" $path "*) ;; *) deplibs="$path $deplibs" ;; esac done fi # link_all_deplibs != no fi # linkmode = lib done # for deplib in $libs if test "$pass" = link; then if test "$linkmode" = "prog"; then compile_deplibs="$new_inherited_linker_flags $compile_deplibs" finalize_deplibs="$new_inherited_linker_flags $finalize_deplibs" else compiler_flags="$compiler_flags "`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` fi fi dependency_libs="$newdependency_libs" if test "$pass" = dlpreopen; then # Link the dlpreopened libraries before other libraries for deplib in $save_deplibs; do deplibs="$deplib $deplibs" done fi if test "$pass" != dlopen; then if test "$pass" != conv; then # Make sure lib_search_path contains only unique directories. lib_search_path= for dir in $newlib_search_path; do case "$lib_search_path " in *" $dir "*) ;; *) func_append lib_search_path " $dir" ;; esac done newlib_search_path= fi if test "$linkmode,$pass" != "prog,link"; then vars="deplibs" else vars="compile_deplibs finalize_deplibs" fi for var in $vars dependency_libs; do # Add libraries to $var in reverse order eval tmp_libs=\"\$$var\" new_libs= for deplib in $tmp_libs; do # FIXME: Pedantically, this is the right thing to do, so # that some nasty dependency loop isn't accidentally # broken: #new_libs="$deplib $new_libs" # Pragmatically, this seems to cause very few problems in # practice: case $deplib in -L*) new_libs="$deplib $new_libs" ;; -R*) ;; *) # And here is the reason: when a library appears more # than once as an explicit dependence of a library, or # is implicitly linked in more than once by the # compiler, it is considered special, and multiple # occurrences thereof are not removed. Compare this # with having the same library being listed as a # dependency of multiple other libraries: in this case, # we know (pedantically, we assume) the library does not # need to be listed more than once, so we keep only the # last copy. This is not always right, but it is rare # enough that we require users that really mean to play # such unportable linking tricks to link the library # using -Wl,-lname, so that libtool does not consider it # for duplicate removal. case " $specialdeplibs " in *" $deplib "*) new_libs="$deplib $new_libs" ;; *) case " $new_libs " in *" $deplib "*) ;; *) new_libs="$deplib $new_libs" ;; esac ;; esac ;; esac done tmp_libs= for deplib in $new_libs; do case $deplib in -L*) case " $tmp_libs " in *" $deplib "*) ;; *) func_append tmp_libs " $deplib" ;; esac ;; *) func_append tmp_libs " $deplib" ;; esac done eval $var=\"$tmp_libs\" done # for var fi # Last step: remove runtime libs from dependency_libs # (they stay in deplibs) tmp_libs= for i in $dependency_libs ; do case " $predeps $postdeps $compiler_lib_search_path " in *" $i "*) i="" ;; esac if test -n "$i" ; then func_append tmp_libs " $i" fi done dependency_libs=$tmp_libs done # for pass if test "$linkmode" = prog; then dlfiles="$newdlfiles" fi if test "$linkmode" = prog || test "$linkmode" = lib; then dlprefiles="$newdlprefiles" fi case $linkmode in oldlib) if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then func_warning "\`-dlopen' is ignored for archives" fi case " $deplibs" in *\ -l* | *\ -L*) func_warning "\`-l' and \`-L' are ignored for archives" ;; esac test -n "$rpath" && \ func_warning "\`-rpath' is ignored for archives" test -n "$xrpath" && \ func_warning "\`-R' is ignored for archives" test -n "$vinfo" && \ func_warning "\`-version-info/-version-number' is ignored for archives" test -n "$release" && \ func_warning "\`-release' is ignored for archives" test -n "$export_symbols$export_symbols_regex" && \ func_warning "\`-export-symbols' is ignored for archives" # Now set the variables for building old libraries. build_libtool_libs=no oldlibs="$output" func_append objs "$old_deplibs" ;; lib) # Make sure we only generate libraries of the form `libNAME.la'. case $outputname in lib*) func_stripname 'lib' '.la' "$outputname" name=$func_stripname_result eval shared_ext=\"$shrext_cmds\" eval libname=\"$libname_spec\" ;; *) test "$module" = no && \ func_fatal_help "libtool library \`$output' must begin with \`lib'" if test "$need_lib_prefix" != no; then # Add the "lib" prefix for modules if required func_stripname '' '.la' "$outputname" name=$func_stripname_result eval shared_ext=\"$shrext_cmds\" eval libname=\"$libname_spec\" else func_stripname '' '.la' "$outputname" libname=$func_stripname_result fi ;; esac if test -n "$objs"; then if test "$deplibs_check_method" != pass_all; then func_fatal_error "cannot build libtool library \`$output' from non-libtool objects on this host:$objs" else echo $ECHO "*** Warning: Linking the shared library $output against the non-libtool" $ECHO "*** objects $objs is not portable!" func_append libobjs " $objs" fi fi test "$dlself" != no && \ func_warning "\`-dlopen self' is ignored for libtool libraries" set dummy $rpath shift test "$#" -gt 1 && \ func_warning "ignoring multiple \`-rpath's for a libtool library" install_libdir="$1" oldlibs= if test -z "$rpath"; then if test "$build_libtool_libs" = yes; then # Building a libtool convenience library. # Some compilers have problems with a `.al' extension so # convenience libraries should have the same extension an # archive normally would. oldlibs="$output_objdir/$libname.$libext $oldlibs" build_libtool_libs=convenience build_old_libs=yes fi test -n "$vinfo" && \ func_warning "\`-version-info/-version-number' is ignored for convenience libraries" test -n "$release" && \ func_warning "\`-release' is ignored for convenience libraries" else # Parse the version information argument. save_ifs="$IFS"; IFS=':' set dummy $vinfo 0 0 0 shift IFS="$save_ifs" test -n "$7" && \ func_fatal_help "too many parameters to \`-version-info'" # convert absolute version numbers to libtool ages # this retains compatibility with .la files and attempts # to make the code below a bit more comprehensible case $vinfo_number in yes) number_major="$1" number_minor="$2" number_revision="$3" # # There are really only two kinds -- those that # use the current revision as the major version # and those that subtract age and use age as # a minor version. But, then there is irix # which has an extra 1 added just for fun # case $version_type in # correct linux to gnu/linux during the next big refactor darwin|linux|osf|windows|none) func_arith $number_major + $number_minor current=$func_arith_result age="$number_minor" revision="$number_revision" ;; freebsd-aout|freebsd-elf|qnx|sunos) current="$number_major" revision="$number_minor" age="0" ;; irix|nonstopux) func_arith $number_major + $number_minor current=$func_arith_result age="$number_minor" revision="$number_minor" lt_irix_increment=no ;; esac ;; no) current="$1" revision="$2" age="$3" ;; esac # Check that each of the things are valid numbers. case $current in 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; *) func_error "CURRENT \`$current' must be a nonnegative integer" func_fatal_error "\`$vinfo' is not valid version information" ;; esac case $revision in 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; *) func_error "REVISION \`$revision' must be a nonnegative integer" func_fatal_error "\`$vinfo' is not valid version information" ;; esac case $age in 0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;; *) func_error "AGE \`$age' must be a nonnegative integer" func_fatal_error "\`$vinfo' is not valid version information" ;; esac if test "$age" -gt "$current"; then func_error "AGE \`$age' is greater than the current interface number \`$current'" func_fatal_error "\`$vinfo' is not valid version information" fi # Calculate the version variables. major= versuffix= verstring= case $version_type in none) ;; darwin) # Like Linux, but with the current version available in # verstring for coding it into the library header func_arith $current - $age major=.$func_arith_result versuffix="$major.$age.$revision" # Darwin ld doesn't like 0 for these options... func_arith $current + 1 minor_current=$func_arith_result xlcverstring="${wl}-compatibility_version ${wl}$minor_current ${wl}-current_version ${wl}$minor_current.$revision" verstring="-compatibility_version $minor_current -current_version $minor_current.$revision" ;; freebsd-aout) major=".$current" versuffix=".$current.$revision"; ;; freebsd-elf) major=".$current" versuffix=".$current" ;; irix | nonstopux) if test "X$lt_irix_increment" = "Xno"; then func_arith $current - $age else func_arith $current - $age + 1 fi major=$func_arith_result case $version_type in nonstopux) verstring_prefix=nonstopux ;; *) verstring_prefix=sgi ;; esac verstring="$verstring_prefix$major.$revision" # Add in all the interfaces that we are compatible with. loop=$revision while test "$loop" -ne 0; do func_arith $revision - $loop iface=$func_arith_result func_arith $loop - 1 loop=$func_arith_result verstring="$verstring_prefix$major.$iface:$verstring" done # Before this point, $major must not contain `.'. major=.$major versuffix="$major.$revision" ;; linux) # correct to gnu/linux during the next big refactor func_arith $current - $age major=.$func_arith_result versuffix="$major.$age.$revision" ;; osf) func_arith $current - $age major=.$func_arith_result versuffix=".$current.$age.$revision" verstring="$current.$age.$revision" # Add in all the interfaces that we are compatible with. loop=$age while test "$loop" -ne 0; do func_arith $current - $loop iface=$func_arith_result func_arith $loop - 1 loop=$func_arith_result verstring="$verstring:${iface}.0" done # Make executables depend on our current version. func_append verstring ":${current}.0" ;; qnx) major=".$current" versuffix=".$current" ;; sunos) major=".$current" versuffix=".$current.$revision" ;; windows) # Use '-' rather than '.', since we only want one # extension on DOS 8.3 filesystems. func_arith $current - $age major=$func_arith_result versuffix="-$major" ;; *) func_fatal_configuration "unknown library version type \`$version_type'" ;; esac # Clear the version info if we defaulted, and they specified a release. if test -z "$vinfo" && test -n "$release"; then major= case $version_type in darwin) # we can't check for "0.0" in archive_cmds due to quoting # problems, so we reset it completely verstring= ;; *) verstring="0.0" ;; esac if test "$need_version" = no; then versuffix= else versuffix=".0.0" fi fi # Remove version info from name if versioning should be avoided if test "$avoid_version" = yes && test "$need_version" = no; then major= versuffix= verstring="" else # XXX tmp=`echo $libname|sed -e 's,+,_,g' -e 's,-,_,g' -e 's,\.,_,g'` eval tmp2=\$${tmp}_ltversion if ! test -z "${SHARED_LIBS_LOG}"; then if ! test -f ${SHARED_LIBS_LOG}; then echo "# SHARED_LIBS+= # " >${SHARED_LIBS_LOG} fi tmp4=`echo $libname|sed -e 's/^lib//'` printf "SHARED_LIBS +=\t%-20s %-8s # %s\n" "$tmp4" "$tmp2" "$versuffix" >>${SHARED_LIBS_LOG} fi if test -n "$versuffix" && test -n "$tmp2"; then versuffix=".$tmp2" fi fi # Check to see if the archive will have undefined symbols. if test "$allow_undefined" = yes; then if test "$allow_undefined_flag" = unsupported; then func_warning "undefined symbols not allowed in $host shared libraries" build_libtool_libs=no build_old_libs=yes fi else # Don't allow undefined symbols. allow_undefined_flag="$no_undefined_flag" fi fi func_generate_dlsyms "$libname" "$libname" "yes" func_append libobjs " $symfileobj" test "X$libobjs" = "X " && libobjs= if test "$opt_mode" != relink; then # Remove our outputs, but don't remove object files since they # may have been created when compiling PIC objects. removelist= tempremovelist=`$ECHO "$output_objdir/*"` for p in $tempremovelist; do case $p in *.$objext | *.gcno) ;; $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/${libname}${release}.*) if test "X$precious_files_regex" != "X"; then if $ECHO "$p" | $EGREP -e "$precious_files_regex" >/dev/null 2>&1 then continue fi fi func_append removelist " $p" ;; *) ;; esac done test -n "$removelist" && \ func_show_eval "${RM}r \$removelist" fi # Now set the variables for building old libraries. if test "$build_old_libs" = yes && test "$build_libtool_libs" != convenience ; then func_append oldlibs " $output_objdir/$libname.$libext" # Transform .lo files to .o files. oldobjs="$objs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.${libext}$/d; $lo2o" | $NL2SP` fi # Eliminate all temporary directories. #for path in $notinst_path; do # lib_search_path=`$ECHO "$lib_search_path " | $SED "s% $path % %g"` # deplibs=`$ECHO "$deplibs " | $SED "s% -L$path % %g"` # dependency_libs=`$ECHO "$dependency_libs " | $SED "s% -L$path % %g"` #done if test -n "$xrpath"; then # If the user specified any rpath flags, then add them. temp_xrpath= for libdir in $xrpath; do func_replace_sysroot "$libdir" func_append temp_xrpath " -R$func_replace_sysroot_result" case "$finalize_rpath " in *" $libdir "*) ;; *) func_append finalize_rpath " $libdir" ;; esac done if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then dependency_libs="$temp_xrpath $dependency_libs" fi fi # Make sure dlfiles contains only unique files that won't be dlpreopened old_dlfiles="$dlfiles" dlfiles= for lib in $old_dlfiles; do case " $dlprefiles $dlfiles " in *" $lib "*) ;; *) func_append dlfiles " $lib" ;; esac done # Make sure dlprefiles contains only unique files old_dlprefiles="$dlprefiles" dlprefiles= for lib in $old_dlprefiles; do case "$dlprefiles " in *" $lib "*) ;; *) func_append dlprefiles " $lib" ;; esac done if test "$build_libtool_libs" = yes; then if test -n "$rpath"; then case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) # these systems don't actually have a c library (as such)! ;; *-*-rhapsody* | *-*-darwin1.[012]) # Rhapsody C library is in the System framework func_append deplibs " System.ltframework" ;; *-*-netbsd*) # Don't link with libc until the a.out ld.so is fixed. ;; *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) # Do not include libc due to us having libc/libc_r. ;; *-*-sco3.2v5* | *-*-sco5v6*) # Causes problems with __ctype ;; *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*) # Compiler inserts libc in the correct place for threads to work ;; *) # Add libc to deplibs on all other systems if necessary. if test "$build_libtool_need_lc" = "yes"; then func_append deplibs " -lc" fi ;; esac fi # Transform deplibs into only deplibs that can be linked in shared. name_save=$name libname_save=$libname release_save=$release versuffix_save=$versuffix major_save=$major # I'm not sure if I'm treating the release correctly. I think # release should show up in the -l (ie -lgmp5) so we don't want to # add it in twice. Is that correct? release="" versuffix="" major="" newdeplibs= droppeddeps=no case $deplibs_check_method in pass_all) # Don't check for shared/static. Everything works. # This might be a little naive. We might want to check # whether the library exists or not. But this is on # osf3 & osf4 and I'm not really sure... Just # implementing what was already the behavior. newdeplibs=$deplibs ;; test_compile) # This code stresses the "libraries are programs" paradigm to its # limits. Maybe even breaks it. We compile a program, linking it # against the deplibs as a proxy for the library. Then we can check # whether they linked in statically or dynamically with ldd. $opt_dry_run || $RM conftest.c cat > conftest.c </dev/null` $nocaseglob else potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null` fi for potent_lib in $potential_libs; do # Follow soft links. if ls -lLd "$potent_lib" 2>/dev/null | $GREP " -> " >/dev/null; then continue fi # The statement above tries to avoid entering an # endless loop below, in case of cyclic links. # We might still enter an endless loop, since a link # loop can be closed while we follow links, # but so what? potlib="$potent_lib" while test -h "$potlib" 2>/dev/null; do potliblink=`ls -ld $potlib | ${SED} 's/.* -> //'` case $potliblink in [\\/]* | [A-Za-z]:[\\/]*) potlib="$potliblink";; *) potlib=`$ECHO "$potlib" | $SED 's,[^/]*$,,'`"$potliblink";; esac done if eval $file_magic_cmd \"\$potlib\" 2>/dev/null | $SED -e 10q | $EGREP "$file_magic_regex" > /dev/null; then func_append newdeplibs " $a_deplib" a_deplib="" break 2 fi done done fi if test -n "$a_deplib" ; then droppeddeps=yes echo $ECHO "*** Warning: linker path does not have real file for library $a_deplib." echo "*** I have the capability to make that library automatically link in when" echo "*** you link to this library. But I can only do this if you have a" echo "*** shared version of the library, which you do not appear to have" echo "*** because I did check the linker path looking for a file starting" if test -z "$potlib" ; then $ECHO "*** with $libname but no candidates were found. (...for file magic test)" else $ECHO "*** with $libname and none of the candidates passed a file format test" $ECHO "*** using a file magic. Last file checked: $potlib" fi fi ;; *) # Add a -L argument. func_append newdeplibs " $a_deplib" ;; esac done # Gone through all deplibs. ;; match_pattern*) set dummy $deplibs_check_method; shift match_pattern_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` for a_deplib in $deplibs; do case $a_deplib in -l*) func_stripname -l '' "$a_deplib" name=$func_stripname_result if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then case " $predeps $postdeps " in *" $a_deplib "*) func_append newdeplibs " $a_deplib" a_deplib="" ;; esac fi if test -n "$a_deplib" ; then libname=`eval "\\$ECHO \"$libname_spec\""` for i in $lib_search_path $sys_lib_search_path $shlib_search_path; do potential_libs=`ls $i/$libname[.-]* 2>/dev/null` for potent_lib in $potential_libs; do potlib="$potent_lib" # see symlink-check above in file_magic test if eval "\$ECHO \"$potent_lib\"" 2>/dev/null | $SED 10q | \ $EGREP "$match_pattern_regex" > /dev/null; then func_append newdeplibs " $a_deplib" a_deplib="" break 2 fi done done fi if test -n "$a_deplib" ; then droppeddeps=yes echo $ECHO "*** Warning: linker path does not have real file for library $a_deplib." echo "*** I have the capability to make that library automatically link in when" echo "*** you link to this library. But I can only do this if you have a" echo "*** shared version of the library, which you do not appear to have" echo "*** because I did check the linker path looking for a file starting" if test -z "$potlib" ; then $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)" else $ECHO "*** with $libname and none of the candidates passed a file format test" $ECHO "*** using a regex pattern. Last file checked: $potlib" fi fi ;; *) # Add a -L argument. func_append newdeplibs " $a_deplib" ;; esac done # Gone through all deplibs. ;; none | unknown | *) newdeplibs="" tmp_deplibs=`$ECHO " $deplibs" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'` if test "X$allow_libtool_libs_with_static_runtimes" = "Xyes" ; then for i in $predeps $postdeps ; do # can't use Xsed below, because $i might contain '/' tmp_deplibs=`$ECHO " $tmp_deplibs" | $SED "s,$i,,"` done fi case $tmp_deplibs in *[!\ \ ]*) echo if test "X$deplibs_check_method" = "Xnone"; then echo "*** Warning: inter-library dependencies are not supported in this platform." else echo "*** Warning: inter-library dependencies are not known to be supported." fi echo "*** All declared inter-library dependencies are being dropped." droppeddeps=yes ;; esac ;; esac versuffix=$versuffix_save major=$major_save release=$release_save libname=$libname_save name=$name_save case $host in *-*-rhapsody* | *-*-darwin1.[012]) # On Rhapsody replace the C library with the System framework newdeplibs=`$ECHO " $newdeplibs" | $SED 's/ -lc / System.ltframework /'` ;; esac if test "$droppeddeps" = yes; then if test "$module" = yes; then echo echo "*** Warning: libtool could not satisfy all declared inter-library" $ECHO "*** dependencies of module $libname. Therefore, libtool will create" echo "*** a static module, that should work as long as the dlopening" echo "*** application is linked with the -dlopen flag." if test -z "$global_symbol_pipe"; then echo echo "*** However, this would only work if libtool was able to extract symbol" echo "*** lists from a program, using \`nm' or equivalent, but libtool could" echo "*** not find such a program. So, this module is probably useless." echo "*** \`nm' from GNU binutils and a full rebuild may help." fi if test "$build_old_libs" = no; then oldlibs="$output_objdir/$libname.$libext" build_libtool_libs=module build_old_libs=yes else build_libtool_libs=no fi else echo "*** The inter-library dependencies that have been dropped here will be" echo "*** automatically added whenever a program is linked with this library" echo "*** or is declared to -dlopen it." if test "$allow_undefined" = no; then echo echo "*** Since this library must not contain undefined symbols," echo "*** because either the platform does not support them or" echo "*** it was explicitly requested with -no-undefined," echo "*** libtool will only create a static version of it." if test "$build_old_libs" = no; then oldlibs="$output_objdir/$libname.$libext" build_libtool_libs=module build_old_libs=yes else build_libtool_libs=no fi fi fi fi # Done checking deplibs! deplibs=$newdeplibs fi # Time to change all our "foo.ltframework" stuff back to "-framework foo" case $host in *-*-darwin*) newdeplibs=`$ECHO " $newdeplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` new_inherited_linker_flags=`$ECHO " $new_inherited_linker_flags" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` deplibs=`$ECHO " $deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` ;; esac # move library search paths that coincide with paths to not yet # installed libraries to the beginning of the library search list new_libs= for path in $notinst_path; do case " $new_libs " in *" -L$path/$objdir "*) ;; *) case " $deplibs " in *" -L$path/$objdir "*) func_append new_libs " -L$path/$objdir" ;; esac ;; esac done for deplib in $deplibs; do case $deplib in -L*) case " $new_libs " in *" $deplib "*) ;; *) func_append new_libs " $deplib" ;; esac ;; *) func_append new_libs " $deplib" ;; esac done deplibs="$new_libs" # All the library-specific variables (install_libdir is set above). library_names= old_library= dlname= # Test again, we may have decided not to build it any more if test "$build_libtool_libs" = yes; then # Remove ${wl} instances when linking with ld. # FIXME: should test the right _cmds variable. case $archive_cmds in *\$LD\ *) wl= ;; esac if test "$hardcode_into_libs" = yes; then # Hardcode the library paths hardcode_libdirs= dep_rpath= rpath="$finalize_rpath" test "$opt_mode" != relink && rpath="$compile_rpath$rpath" for libdir in $rpath; do if test -n "$hardcode_libdir_flag_spec"; then if test -n "$hardcode_libdir_separator"; then func_replace_sysroot "$libdir" libdir=$func_replace_sysroot_result if test -z "$hardcode_libdirs"; then hardcode_libdirs="$libdir" else # Just accumulate the unique libdirs. case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) ;; *) func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" ;; esac fi else eval flag=\"$hardcode_libdir_flag_spec\" func_append dep_rpath " $flag" fi elif test -n "$runpath_var"; then case "$perm_rpath " in *" $libdir "*) ;; *) func_append perm_rpath " $libdir" ;; esac fi done # Substitute the hardcoded libdirs into the rpath. if test -n "$hardcode_libdir_separator" && test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" eval "dep_rpath=\"$hardcode_libdir_flag_spec\"" fi if test -n "$runpath_var" && test -n "$perm_rpath"; then # We should set the runpath_var. rpath= for dir in $perm_rpath; do func_append rpath "$dir:" done eval "$runpath_var='$rpath\$$runpath_var'; export $runpath_var" fi test -n "$dep_rpath" && deplibs="$dep_rpath $deplibs" fi shlibpath="$finalize_shlibpath" test "$opt_mode" != relink && shlibpath="$compile_shlibpath$shlibpath" if test -n "$shlibpath"; then eval "$shlibpath_var='$shlibpath\$$shlibpath_var'; export $shlibpath_var" fi # Get the real and link names of the library. eval shared_ext=\"$shrext_cmds\" eval library_names=\"$library_names_spec\" set dummy $library_names shift realname="$1" shift if test -n "$soname_spec"; then eval soname=\"$soname_spec\" else soname="$realname" fi if test -z "$dlname"; then dlname=$soname fi lib="$output_objdir/$realname" linknames= for link do func_append linknames " $link" done # Use standard objects if they are pic test -z "$pic_flag" && libobjs=`$ECHO "$libobjs" | $SP2NL | $SED "$lo2o" | $NL2SP` test "X$libobjs" = "X " && libobjs= delfiles= if test -n "$export_symbols" && test -n "$include_expsyms"; then $opt_dry_run || cp "$export_symbols" "$output_objdir/$libname.uexp" export_symbols="$output_objdir/$libname.uexp" func_append delfiles " $export_symbols" fi orig_export_symbols= case $host_os in cygwin* | mingw* | cegcc*) if test -n "$export_symbols" && test -z "$export_symbols_regex"; then # exporting using user supplied symfile if test "x`$SED 1q $export_symbols`" != xEXPORTS; then # and it's NOT already a .def file. Must figure out # which of the given symbols are data symbols and tag # them as such. So, trigger use of export_symbols_cmds. # export_symbols gets reassigned inside the "prepare # the list of exported symbols" if statement, so the # include_expsyms logic still works. orig_export_symbols="$export_symbols" export_symbols= always_export_symbols=yes fi fi ;; esac # Prepare the list of exported symbols if test -z "$export_symbols"; then if test "$always_export_symbols" = yes || test -n "$export_symbols_regex"; then func_verbose "generating symbol list for \`$libname.la'" export_symbols="$output_objdir/$libname.exp" $opt_dry_run || $RM $export_symbols cmds=$export_symbols_cmds save_ifs="$IFS"; IFS='~' for cmd1 in $cmds; do IFS="$save_ifs" # Take the normal branch if the nm_file_list_spec branch # doesn't work or if tool conversion is not needed. case $nm_file_list_spec~$to_tool_file_cmd in *~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*) try_normal_branch=yes eval cmd=\"$cmd1\" func_len " $cmd" len=$func_len_result ;; *) try_normal_branch=no ;; esac if test "$try_normal_branch" = yes \ && { test "$len" -lt "$max_cmd_len" \ || test "$max_cmd_len" -le -1; } then func_show_eval "$cmd" 'exit $?' skipped_export=false elif test -n "$nm_file_list_spec"; then func_basename "$output" output_la=$func_basename_result save_libobjs=$libobjs save_output=$output output=${output_objdir}/${output_la}.nm func_to_tool_file "$output" libobjs=$nm_file_list_spec$func_to_tool_file_result func_append delfiles " $output" func_verbose "creating $NM input file list: $output" for obj in $save_libobjs; do func_to_tool_file "$obj" $ECHO "$func_to_tool_file_result" done > "$output" eval cmd=\"$cmd1\" func_show_eval "$cmd" 'exit $?' output=$save_output libobjs=$save_libobjs skipped_export=false else # The command line is too long to execute in one step. func_verbose "using reloadable object file for export list..." skipped_export=: # Break out early, otherwise skipped_export may be # set to false by a later but shorter cmd. break fi done IFS="$save_ifs" if test -n "$export_symbols_regex" && test "X$skipped_export" != "X:"; then func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' func_show_eval '$MV "${export_symbols}T" "$export_symbols"' fi fi fi if test -n "$export_symbols" && test -n "$include_expsyms"; then tmp_export_symbols="$export_symbols" test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols" $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' fi if test "X$skipped_export" != "X:" && test -n "$orig_export_symbols"; then # The given exports_symbols file has to be filtered, so filter it. func_verbose "filter symbol list for \`$libname.la' to tag DATA exports" # FIXME: $output_objdir/$libname.filter potentially contains lots of # 's' commands which not all seds can handle. GNU sed should be fine # though. Also, the filter scales superlinearly with the number of # global variables. join(1) would be nice here, but unfortunately # isn't a blessed tool. $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter func_append delfiles " $export_symbols $output_objdir/$libname.filter" export_symbols=$output_objdir/$libname.def $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols fi tmp_deplibs= for test_deplib in $deplibs; do case " $convenience " in *" $test_deplib "*) ;; *) func_append tmp_deplibs " $test_deplib" ;; esac done deplibs="$tmp_deplibs" if test -n "$convenience"; then if test -n "$whole_archive_flag_spec" && test "$compiler_needs_object" = yes && test -z "$libobjs"; then # extract the archives, so we have objects to list. # TODO: could optimize this to just extract one archive. whole_archive_flag_spec= fi if test -n "$whole_archive_flag_spec"; then save_libobjs=$libobjs eval libobjs=\"\$libobjs $whole_archive_flag_spec\" test "X$libobjs" = "X " && libobjs= else gentop="$output_objdir/${outputname}x" func_append generated " $gentop" func_extract_archives $gentop $convenience func_append libobjs " $func_extract_archives_result" test "X$libobjs" = "X " && libobjs= fi fi if test "$thread_safe" = yes && test -n "$thread_safe_flag_spec"; then eval flag=\"$thread_safe_flag_spec\" func_append linker_flags " $flag" fi # Make a backup of the uninstalled library when relinking if test "$opt_mode" = relink; then $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $? fi # Do each of the archive commands. if test "$module" = yes && test -n "$module_cmds" ; then if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then eval test_cmds=\"$module_expsym_cmds\" cmds=$module_expsym_cmds else eval test_cmds=\"$module_cmds\" cmds=$module_cmds fi else if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then eval test_cmds=\"$archive_expsym_cmds\" cmds=$archive_expsym_cmds else eval test_cmds=\"$archive_cmds\" cmds=$archive_cmds fi fi if test "X$skipped_export" != "X:" && func_len " $test_cmds" && len=$func_len_result && test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then : else # The command line is too long to link in one step, link piecewise # or, if using GNU ld and skipped_export is not :, use a linker # script. # Save the value of $output and $libobjs because we want to # use them later. If we have whole_archive_flag_spec, we # want to use save_libobjs as it was before # whole_archive_flag_spec was expanded, because we can't # assume the linker understands whole_archive_flag_spec. # This may have to be revisited, in case too many # convenience libraries get linked in and end up exceeding # the spec. if test -z "$convenience" || test -z "$whole_archive_flag_spec"; then save_libobjs=$libobjs fi save_output=$output func_basename "$output" output_la=$func_basename_result # Clear the reloadable object creation command queue and # initialize k to one. test_cmds= concat_cmds= objlist= last_robj= k=1 if test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "$with_gnu_ld" = yes; then output=${output_objdir}/${output_la}.lnkscript func_verbose "creating GNU ld script: $output" echo 'INPUT (' > $output for obj in $save_libobjs do func_to_tool_file "$obj" $ECHO "$func_to_tool_file_result" >> $output done echo ')' >> $output func_append delfiles " $output" func_to_tool_file "$output" output=$func_to_tool_file_result elif test -n "$save_libobjs" && test "X$skipped_export" != "X:" && test "X$file_list_spec" != X; then output=${output_objdir}/${output_la}.lnk func_verbose "creating linker input file list: $output" : > $output set x $save_libobjs shift firstobj= if test "$compiler_needs_object" = yes; then firstobj="$1 " shift fi for obj do func_to_tool_file "$obj" $ECHO "$func_to_tool_file_result" >> $output done func_append delfiles " $output" func_to_tool_file "$output" output=$firstobj\"$file_list_spec$func_to_tool_file_result\" else if test -n "$save_libobjs"; then func_verbose "creating reloadable object files..." output=$output_objdir/$output_la-${k}.$objext eval test_cmds=\"$reload_cmds\" func_len " $test_cmds" len0=$func_len_result len=$len0 # Loop over the list of objects to be linked. for obj in $save_libobjs do func_len " $obj" func_arith $len + $func_len_result len=$func_arith_result if test "X$objlist" = X || test "$len" -lt "$max_cmd_len"; then func_append objlist " $obj" else # The command $test_cmds is almost too long, add a # command to the queue. if test "$k" -eq 1 ; then # The first file doesn't have a previous command to add. reload_objs=$objlist eval concat_cmds=\"$reload_cmds\" else # All subsequent reloadable object files will link in # the last one created. reload_objs="$objlist $last_robj" eval concat_cmds=\"\$concat_cmds~$reload_cmds~\$RM $last_robj\" fi last_robj=$output_objdir/$output_la-${k}.$objext func_arith $k + 1 k=$func_arith_result output=$output_objdir/$output_la-${k}.$objext objlist=" $obj" func_len " $last_robj" func_arith $len0 + $func_len_result len=$func_arith_result fi done # Handle the remaining objects by creating one last # reloadable object file. All subsequent reloadable object # files will link in the last one created. test -z "$concat_cmds" || concat_cmds=$concat_cmds~ reload_objs="$objlist $last_robj" eval concat_cmds=\"\${concat_cmds}$reload_cmds\" if test -n "$last_robj"; then eval concat_cmds=\"\${concat_cmds}~\$RM $last_robj\" fi func_append delfiles " $output" else output= fi if ${skipped_export-false}; then func_verbose "generating symbol list for \`$libname.la'" export_symbols="$output_objdir/$libname.exp" $opt_dry_run || $RM $export_symbols libobjs=$output # Append the command to create the export file. test -z "$concat_cmds" || concat_cmds=$concat_cmds~ eval concat_cmds=\"\$concat_cmds$export_symbols_cmds\" if test -n "$last_robj"; then eval concat_cmds=\"\$concat_cmds~\$RM $last_robj\" fi fi test -n "$save_libobjs" && func_verbose "creating a temporary reloadable object file: $output" # Loop through the commands generated above and execute them. save_ifs="$IFS"; IFS='~' for cmd in $concat_cmds; do IFS="$save_ifs" $opt_silent || { func_quote_for_expand "$cmd" eval "func_echo $func_quote_for_expand_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? # Restore the uninstalled library and exit if test "$opt_mode" = relink; then ( cd "$output_objdir" && \ $RM "${realname}T" && \ $MV "${realname}U" "$realname" ) fi exit $lt_exit } done IFS="$save_ifs" if test -n "$export_symbols_regex" && ${skipped_export-false}; then func_show_eval '$EGREP -e "$export_symbols_regex" "$export_symbols" > "${export_symbols}T"' func_show_eval '$MV "${export_symbols}T" "$export_symbols"' fi fi if ${skipped_export-false}; then if test -n "$export_symbols" && test -n "$include_expsyms"; then tmp_export_symbols="$export_symbols" test -n "$orig_export_symbols" && tmp_export_symbols="$orig_export_symbols" $opt_dry_run || eval '$ECHO "$include_expsyms" | $SP2NL >> "$tmp_export_symbols"' fi if test -n "$orig_export_symbols"; then # The given exports_symbols file has to be filtered, so filter it. func_verbose "filter symbol list for \`$libname.la' to tag DATA exports" # FIXME: $output_objdir/$libname.filter potentially contains lots of # 's' commands which not all seds can handle. GNU sed should be fine # though. Also, the filter scales superlinearly with the number of # global variables. join(1) would be nice here, but unfortunately # isn't a blessed tool. $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\(.*\)\([ \,].*\),s|^\1$|\1\2|,' < $export_symbols > $output_objdir/$libname.filter func_append delfiles " $export_symbols $output_objdir/$libname.filter" export_symbols=$output_objdir/$libname.def $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols fi fi libobjs=$output # Restore the value of output. output=$save_output if test -n "$convenience" && test -n "$whole_archive_flag_spec"; then eval libobjs=\"\$libobjs $whole_archive_flag_spec\" test "X$libobjs" = "X " && libobjs= fi # Expand the library linking commands again to reset the # value of $libobjs for piecewise linking. # Do each of the archive commands. if test "$module" = yes && test -n "$module_cmds" ; then if test -n "$export_symbols" && test -n "$module_expsym_cmds"; then cmds=$module_expsym_cmds else cmds=$module_cmds fi else if test -n "$export_symbols" && test -n "$archive_expsym_cmds"; then cmds=$archive_expsym_cmds else cmds=$archive_cmds fi fi fi if test -n "$delfiles"; then # Append the command to remove temporary files to $cmds. eval cmds=\"\$cmds~\$RM $delfiles\" fi # Add any objects from preloaded convenience libraries if test -n "$dlprefiles"; then gentop="$output_objdir/${outputname}x" func_append generated " $gentop" func_extract_archives $gentop $dlprefiles func_append libobjs " $func_extract_archives_result" test "X$libobjs" = "X " && libobjs= fi save_ifs="$IFS"; IFS='~' for cmd in $cmds; do IFS="$save_ifs" eval cmd=\"$cmd\" $opt_silent || { func_quote_for_expand "$cmd" eval "func_echo $func_quote_for_expand_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? # Restore the uninstalled library and exit if test "$opt_mode" = relink; then ( cd "$output_objdir" && \ $RM "${realname}T" && \ $MV "${realname}U" "$realname" ) fi exit $lt_exit } done IFS="$save_ifs" # Restore the uninstalled library and exit if test "$opt_mode" = relink; then $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $? if test -n "$convenience"; then if test -z "$whole_archive_flag_spec"; then func_show_eval '${RM}r "$gentop"' fi fi exit $EXIT_SUCCESS fi # Create links to the real library. for linkname in $linknames; do if test "$realname" != "$linkname"; then func_show_eval '(cd "$output_objdir" && $RM "$linkname" && $LN_S "$realname" "$linkname")' 'exit $?' fi done # If -module or -export-dynamic was specified, set the dlname. if test "$module" = yes || test "$export_dynamic" = yes; then # On all known operating systems, these are identical. dlname="$soname" fi fi ;; obj) if test -n "$dlfiles$dlprefiles" || test "$dlself" != no; then func_warning "\`-dlopen' is ignored for objects" fi case " $deplibs" in *\ -l* | *\ -L*) func_warning "\`-l' and \`-L' are ignored for objects" ;; esac test -n "$rpath" && \ func_warning "\`-rpath' is ignored for objects" test -n "$xrpath" && \ func_warning "\`-R' is ignored for objects" test -n "$vinfo" && \ func_warning "\`-version-info' is ignored for objects" test -n "$release" && \ func_warning "\`-release' is ignored for objects" case $output in *.lo) test -n "$objs$old_deplibs" && \ func_fatal_error "cannot build library object \`$output' from non-libtool objects" libobj=$output func_lo2o "$libobj" obj=$func_lo2o_result ;; *) libobj= obj="$output" ;; esac # Delete the old objects. $opt_dry_run || $RM $obj $libobj # Objects from convenience libraries. This assumes # single-version convenience libraries. Whenever we create # different ones for PIC/non-PIC, this we'll have to duplicate # the extraction. reload_conv_objs= gentop= # reload_cmds runs $LD directly, so let us get rid of # -Wl from whole_archive_flag_spec and hope we can get by with # turning comma into space.. wl= if test -n "$convenience"; then if test -n "$whole_archive_flag_spec"; then eval tmp_whole_archive_flags=\"$whole_archive_flag_spec\" reload_conv_objs=$reload_objs\ `$ECHO "$tmp_whole_archive_flags" | $SED 's|,| |g'` else gentop="$output_objdir/${obj}x" func_append generated " $gentop" func_extract_archives $gentop $convenience reload_conv_objs="$reload_objs $func_extract_archives_result" fi fi # If we're not building shared, we need to use non_pic_objs test "$build_libtool_libs" != yes && libobjs="$non_pic_objects" # Create the old-style object. reload_objs="$objs$old_deplibs "`$ECHO "$libobjs" | $SP2NL | $SED "/\.${libext}$/d; /\.lib$/d; $lo2o" | $NL2SP`" $reload_conv_objs" ### testsuite: skip nested quoting test output="$obj" func_execute_cmds "$reload_cmds" 'exit $?' # Exit if we aren't doing a library object file. if test -z "$libobj"; then if test -n "$gentop"; then func_show_eval '${RM}r "$gentop"' fi exit $EXIT_SUCCESS fi if test "$build_libtool_libs" != yes; then if test -n "$gentop"; then func_show_eval '${RM}r "$gentop"' fi # Create an invalid libtool object if no PIC, so that we don't # accidentally link it into a program. # $show "echo timestamp > $libobj" # $opt_dry_run || eval "echo timestamp > $libobj" || exit $? exit $EXIT_SUCCESS fi if test -n "$pic_flag" || test "$pic_mode" != default; then # Only do commands if we really have different PIC objects. reload_objs="$libobjs $reload_conv_objs" output="$libobj" func_execute_cmds "$reload_cmds" 'exit $?' fi if test -n "$gentop"; then func_show_eval '${RM}r "$gentop"' fi exit $EXIT_SUCCESS ;; prog) case $host in *cygwin*) func_stripname '' '.exe' "$output" output=$func_stripname_result.exe;; esac test -n "$vinfo" && \ func_warning "\`-version-info' is ignored for programs" test -n "$release" && \ func_warning "\`-release' is ignored for programs" test "$preload" = yes \ && test "$dlopen_support" = unknown \ && test "$dlopen_self" = unknown \ && test "$dlopen_self_static" = unknown && \ func_warning "\`LT_INIT([dlopen])' not used. Assuming no dlopen support." case $host in *-*-rhapsody* | *-*-darwin1.[012]) # On Rhapsody replace the C library is the System framework compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's/ -lc / System.ltframework /'` finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's/ -lc / System.ltframework /'` ;; esac case $host in *-*-darwin*) # Don't allow lazy linking, it breaks C++ global constructors # But is supposedly fixed on 10.4 or later (yay!). if test "$tagname" = CXX ; then case ${MACOSX_DEPLOYMENT_TARGET-10.0} in 10.[0123]) func_append compile_command " ${wl}-bind_at_load" func_append finalize_command " ${wl}-bind_at_load" ;; esac fi # Time to change all our "foo.ltframework" stuff back to "-framework foo" compile_deplibs=`$ECHO " $compile_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` finalize_deplibs=`$ECHO " $finalize_deplibs" | $SED 's% \([^ $]*\).ltframework% -framework \1%g'` ;; esac # move library search paths that coincide with paths to not yet # installed libraries to the beginning of the library search list new_libs= for path in $notinst_path; do case " $new_libs " in *" -L$path/$objdir "*) ;; *) case " $compile_deplibs " in *" -L$path/$objdir "*) func_append new_libs " -L$path/$objdir" ;; esac ;; esac done for deplib in $compile_deplibs; do case $deplib in -L*) case " $new_libs " in *" $deplib "*) ;; *) func_append new_libs " $deplib" ;; esac ;; *) func_append new_libs " $deplib" ;; esac done compile_deplibs="$new_libs" func_append compile_command " $compile_deplibs" func_append finalize_command " $finalize_deplibs" if test -n "$rpath$xrpath"; then # If the user specified any rpath flags, then add them. for libdir in $rpath $xrpath; do # This is the magic to use -rpath. case "$finalize_rpath " in *" $libdir "*) ;; *) func_append finalize_rpath " $libdir" ;; esac done fi # Now hardcode the library paths rpath= hardcode_libdirs= for libdir in $compile_rpath $finalize_rpath; do if test -n "$hardcode_libdir_flag_spec"; then if test -n "$hardcode_libdir_separator"; then if test -z "$hardcode_libdirs"; then hardcode_libdirs="$libdir" else # Just accumulate the unique libdirs. case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) ;; *) func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" ;; esac fi else eval flag=\"$hardcode_libdir_flag_spec\" func_append rpath " $flag" fi elif test -n "$runpath_var"; then case "$perm_rpath " in *" $libdir "*) ;; *) func_append perm_rpath " $libdir" ;; esac fi case $host in *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`${ECHO} "$libdir" | ${SED} -e 's*/lib$*/bin*'` case :$dllsearchpath: in *":$libdir:"*) ;; ::) dllsearchpath=$libdir;; *) func_append dllsearchpath ":$libdir";; esac case :$dllsearchpath: in *":$testbindir:"*) ;; ::) dllsearchpath=$testbindir;; *) func_append dllsearchpath ":$testbindir";; esac ;; esac done # Substitute the hardcoded libdirs into the rpath. if test -n "$hardcode_libdir_separator" && test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" eval rpath=\" $hardcode_libdir_flag_spec\" fi compile_rpath="$rpath" rpath= hardcode_libdirs= for libdir in $finalize_rpath; do if test -n "$hardcode_libdir_flag_spec"; then if test -n "$hardcode_libdir_separator"; then if test -z "$hardcode_libdirs"; then hardcode_libdirs="$libdir" else # Just accumulate the unique libdirs. case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in *"$hardcode_libdir_separator$libdir$hardcode_libdir_separator"*) ;; *) func_append hardcode_libdirs "$hardcode_libdir_separator$libdir" ;; esac fi else eval flag=\"$hardcode_libdir_flag_spec\" func_append rpath " $flag" fi elif test -n "$runpath_var"; then case "$finalize_perm_rpath " in *" $libdir "*) ;; *) func_append finalize_perm_rpath " $libdir" ;; esac fi done # Substitute the hardcoded libdirs into the rpath. if test -n "$hardcode_libdir_separator" && test -n "$hardcode_libdirs"; then libdir="$hardcode_libdirs" eval rpath=\" $hardcode_libdir_flag_spec\" fi finalize_rpath="$rpath" if test -n "$libobjs" && test "$build_old_libs" = yes; then # Transform all the library objects into standard objects. compile_command=`$ECHO "$compile_command" | $SP2NL | $SED "$lo2o" | $NL2SP` finalize_command=`$ECHO "$finalize_command" | $SP2NL | $SED "$lo2o" | $NL2SP` fi func_generate_dlsyms "$outputname" "@PROGRAM@" "no" # template prelinking step if test -n "$prelink_cmds"; then func_execute_cmds "$prelink_cmds" 'exit $?' fi wrappers_required=yes case $host in *cegcc* | *mingw32ce*) # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway. wrappers_required=no ;; *cygwin* | *mingw* ) if test "$build_libtool_libs" != yes; then wrappers_required=no fi ;; *) if test "$need_relink" = no || test "$build_libtool_libs" != yes; then wrappers_required=no fi ;; esac if test "$wrappers_required" = no; then # Replace the output file specification. compile_command=`$ECHO "$compile_command" | $SED 's%@OUTPUT@%'"$output"'%g'` link_command="$compile_command$compile_rpath" # We have no uninstalled library dependencies, so finalize right now. exit_status=0 func_show_eval "$link_command" 'exit_status=$?' if test -n "$postlink_cmds"; then func_to_tool_file "$output" postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` func_execute_cmds "$postlink_cmds" 'exit $?' fi # Delete the generated files. if test -f "$output_objdir/${outputname}S.${objext}"; then func_show_eval '$RM "$output_objdir/${outputname}S.${objext}"' fi exit $exit_status fi if test -n "$compile_shlibpath$finalize_shlibpath"; then compile_command="$shlibpath_var=\"$compile_shlibpath$finalize_shlibpath\$$shlibpath_var\" $compile_command" fi if test -n "$finalize_shlibpath"; then finalize_command="$shlibpath_var=\"$finalize_shlibpath\$$shlibpath_var\" $finalize_command" fi compile_var= finalize_var= if test -n "$runpath_var"; then if test -n "$perm_rpath"; then # We should set the runpath_var. rpath= for dir in $perm_rpath; do func_append rpath "$dir:" done compile_var="$runpath_var=\"$rpath\$$runpath_var\" " fi if test -n "$finalize_perm_rpath"; then # We should set the runpath_var. rpath= for dir in $finalize_perm_rpath; do func_append rpath "$dir:" done finalize_var="$runpath_var=\"$rpath\$$runpath_var\" " fi fi if test "$no_install" = yes; then # We don't need to create a wrapper script. link_command="$compile_var$compile_command$compile_rpath" # Replace the output file specification. link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output"'%g'` # Delete the old output file. $opt_dry_run || $RM $output # Link the executable and exit func_show_eval "$link_command" 'exit $?' if test -n "$postlink_cmds"; then func_to_tool_file "$output" postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` func_execute_cmds "$postlink_cmds" 'exit $?' fi exit $EXIT_SUCCESS fi if test "$hardcode_action" = relink; then # Fast installation is not supported link_command="$compile_var$compile_command$compile_rpath" relink_command="$finalize_var$finalize_command$finalize_rpath" func_warning "this platform does not like uninstalled shared libraries" func_warning "\`$output' will be relinked during installation" else if test "$fast_install" != no; then link_command="$finalize_var$compile_command$finalize_rpath" if test "$fast_install" = yes; then relink_command=`$ECHO "$compile_var$compile_command$compile_rpath" | $SED 's%@OUTPUT@%\$progdir/\$file%g'` else # fast_install is set to needless relink_command= fi else link_command="$compile_var$compile_command$compile_rpath" relink_command="$finalize_var$finalize_command$finalize_rpath" fi fi # Replace the output file specification. link_command=`$ECHO "$link_command" | $SED 's%@OUTPUT@%'"$output_objdir/$outputname"'%g'` # Delete the old output files. $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname func_show_eval "$link_command" 'exit $?' if test -n "$postlink_cmds"; then func_to_tool_file "$output_objdir/$outputname" postlink_cmds=`func_echo_all "$postlink_cmds" | $SED -e 's%@OUTPUT@%'"$output_objdir/$outputname"'%g' -e 's%@TOOL_OUTPUT@%'"$func_to_tool_file_result"'%g'` func_execute_cmds "$postlink_cmds" 'exit $?' fi # Now create the wrapper script. func_verbose "creating $output" # Quote the relink command for shipping. if test -n "$relink_command"; then # Preserve any variables that may affect compiler behavior for var in $variables_saved_for_relink; do if eval test -z \"\${$var+set}\"; then relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else func_quote_for_eval "$var_value" relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" fi done relink_command="(cd `pwd`; $relink_command)" relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` fi # Only actually do things if not in dry run mode. $opt_dry_run || { # win32 will think the script is a binary if it has # a .exe suffix, so we strip it off here. case $output in *.exe) func_stripname '' '.exe' "$output" output=$func_stripname_result ;; esac # test for cygwin because mv fails w/o .exe extensions case $host in *cygwin*) exeext=.exe func_stripname '' '.exe' "$outputname" outputname=$func_stripname_result ;; *) exeext= ;; esac case $host in *cygwin* | *mingw* ) func_dirname_and_basename "$output" "" "." output_name=$func_basename_result output_path=$func_dirname_result cwrappersource="$output_path/$objdir/lt-$output_name.c" cwrapper="$output_path/$output_name.exe" $RM $cwrappersource $cwrapper trap "$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE" 1 2 15 func_emit_cwrapperexe_src > $cwrappersource # The wrapper executable is built using the $host compiler, # because it contains $host paths and files. If cross- # compiling, it, like the target executable, must be # executed on the $host or under an emulation environment. $opt_dry_run || { $LTCC $LTCFLAGS -o $cwrapper $cwrappersource $STRIP $cwrapper } # Now, create the wrapper script for func_source use: func_ltwrapper_scriptname $cwrapper $RM $func_ltwrapper_scriptname_result trap "$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE" 1 2 15 $opt_dry_run || { # note: this script will not be executed, so do not chmod. if test "x$build" = "x$host" ; then $cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result else func_emit_wrapper no > $func_ltwrapper_scriptname_result fi } ;; * ) $RM $output trap "$RM $output; exit $EXIT_FAILURE" 1 2 15 func_emit_wrapper no > $output chmod +x $output ;; esac } exit $EXIT_SUCCESS ;; esac # See if we need to build an old-fashioned archive. for oldlib in $oldlibs; do if test "$build_libtool_libs" = convenience; then oldobjs="$libobjs_save $symfileobj" addlibs="$convenience" build_libtool_libs=no else if test "$build_libtool_libs" = module; then oldobjs="$libobjs_save" build_libtool_libs=no else oldobjs="$old_deplibs $non_pic_objects" if test "$preload" = yes && test -f "$symfileobj"; then func_append oldobjs " $symfileobj" fi fi addlibs="$old_convenience" fi if test -n "$addlibs"; then gentop="$output_objdir/${outputname}x" func_append generated " $gentop" func_extract_archives $gentop $addlibs func_append oldobjs " $func_extract_archives_result" fi # Do each command in the archive commands. if test -n "$old_archive_from_new_cmds" && test "$build_libtool_libs" = yes; then cmds=$old_archive_from_new_cmds else # Add any objects from preloaded convenience libraries if test -n "$dlprefiles"; then gentop="$output_objdir/${outputname}x" func_append generated " $gentop" func_extract_archives $gentop $dlprefiles func_append oldobjs " $func_extract_archives_result" fi # POSIX demands no paths to be encoded in archives. We have # to avoid creating archives with duplicate basenames if we # might have to extract them afterwards, e.g., when creating a # static archive out of a convenience library, or when linking # the entirety of a libtool archive into another (currently # not supported by libtool). if (for obj in $oldobjs do func_basename "$obj" $ECHO "$func_basename_result" done | sort | sort -uc >/dev/null 2>&1); then : else echo "copying selected object files to avoid basename conflicts..." gentop="$output_objdir/${outputname}x" func_append generated " $gentop" func_mkdir_p "$gentop" save_oldobjs=$oldobjs oldobjs= counter=1 for obj in $save_oldobjs do func_basename "$obj" objbase="$func_basename_result" case " $oldobjs " in " ") oldobjs=$obj ;; *[\ /]"$objbase "*) while :; do # Make sure we don't pick an alternate name that also # overlaps. newobj=lt$counter-$objbase func_arith $counter + 1 counter=$func_arith_result case " $oldobjs " in *[\ /]"$newobj "*) ;; *) if test ! -f "$gentop/$newobj"; then break; fi ;; esac done func_show_eval "ln $obj $gentop/$newobj || cp $obj $gentop/$newobj" func_append oldobjs " $gentop/$newobj" ;; *) func_append oldobjs " $obj" ;; esac done fi func_to_tool_file "$oldlib" func_convert_file_msys_to_w32 tool_oldlib=$func_to_tool_file_result eval cmds=\"$old_archive_cmds\" func_len " $cmds" len=$func_len_result if test "$len" -lt "$max_cmd_len" || test "$max_cmd_len" -le -1; then cmds=$old_archive_cmds elif test -n "$archiver_list_spec"; then func_verbose "using command file archive linking..." for obj in $oldobjs do func_to_tool_file "$obj" $ECHO "$func_to_tool_file_result" done > $output_objdir/$libname.libcmd func_to_tool_file "$output_objdir/$libname.libcmd" oldobjs=" $archiver_list_spec$func_to_tool_file_result" cmds=$old_archive_cmds else # the command line is too long to link in one step, link in parts func_verbose "using piecewise archive linking..." save_RANLIB=$RANLIB RANLIB=: objlist= concat_cmds= save_oldobjs=$oldobjs oldobjs= # Is there a better way of finding the last object in the list? for obj in $save_oldobjs do last_oldobj=$obj done eval test_cmds=\"$old_archive_cmds\" func_len " $test_cmds" len0=$func_len_result len=$len0 for obj in $save_oldobjs do func_len " $obj" func_arith $len + $func_len_result len=$func_arith_result func_append objlist " $obj" if test "$len" -lt "$max_cmd_len"; then : else # the above command should be used before it gets too long oldobjs=$objlist if test "$obj" = "$last_oldobj" ; then RANLIB=$save_RANLIB fi test -z "$concat_cmds" || concat_cmds=$concat_cmds~ eval concat_cmds=\"\${concat_cmds}$old_archive_cmds\" objlist= len=$len0 fi done RANLIB=$save_RANLIB oldobjs=$objlist if test "X$oldobjs" = "X" ; then eval cmds=\"\$concat_cmds\" else eval cmds=\"\$concat_cmds~\$old_archive_cmds\" fi fi fi func_execute_cmds "$cmds" 'exit $?' done test -n "$generated" && \ func_show_eval "${RM}r$generated" # Now create the libtool archive. case $output in *.la) old_library= test "$build_old_libs" = yes && old_library="$libname.$libext" func_verbose "creating $output" # Preserve any variables that may affect compiler behavior for var in $variables_saved_for_relink; do if eval test -z \"\${$var+set}\"; then relink_command="{ test -z \"\${$var+set}\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command" elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else func_quote_for_eval "$var_value" relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" fi done # Quote the link command for shipping. relink_command="(cd `pwd`; $SHELL $progpath $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" relink_command=`$ECHO "$relink_command" | $SED "$sed_quote_subst"` if test "$hardcode_automatic" = yes ; then relink_command= fi # Only create the output if not a dry run. $opt_dry_run || { for installed in no yes; do if test "$installed" = yes; then if test -z "$install_libdir"; then break fi output="$output_objdir/$outputname"i # Replace all uninstalled libtool libraries with the installed ones newdependency_libs= for deplib in $dependency_libs; do case $deplib in *.la) func_basename "$deplib" name="$func_basename_result" func_resolve_sysroot "$deplib" eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $func_resolve_sysroot_result` test -z "$libdir" && \ func_fatal_error "\`$deplib' is not a valid libtool archive" func_append newdependency_libs " ${lt_sysroot:+=}$libdir/$name" ;; -L*) func_stripname -L '' "$deplib" func_replace_sysroot "$func_stripname_result" func_append newdependency_libs " -L$func_replace_sysroot_result" ;; -R*) func_stripname -R '' "$deplib" func_replace_sysroot "$func_stripname_result" func_append newdependency_libs " -R$func_replace_sysroot_result" ;; *) func_append newdependency_libs " $deplib" ;; esac done dependency_libs="$newdependency_libs" newdlfiles= for lib in $dlfiles; do case $lib in *.la) func_basename "$lib" name="$func_basename_result" eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` test -z "$libdir" && \ func_fatal_error "\`$lib' is not a valid libtool archive" func_append newdlfiles " ${lt_sysroot:+=}$libdir/$name" ;; *) func_append newdlfiles " $lib" ;; esac done dlfiles="$newdlfiles" newdlprefiles= for lib in $dlprefiles; do case $lib in *.la) # Only pass preopened files to the pseudo-archive (for # eventual linking with the app. that links it) if we # didn't already link the preopened objects directly into # the library: func_basename "$lib" name="$func_basename_result" eval libdir=`${SED} -n -e 's/^libdir=\(.*\)$/\1/p' $lib` test -z "$libdir" && \ func_fatal_error "\`$lib' is not a valid libtool archive" func_append newdlprefiles " ${lt_sysroot:+=}$libdir/$name" ;; esac done dlprefiles="$newdlprefiles" else newdlfiles= for lib in $dlfiles; do case $lib in [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; *) abs=`pwd`"/$lib" ;; esac func_append newdlfiles " $abs" done dlfiles="$newdlfiles" newdlprefiles= for lib in $dlprefiles; do case $lib in [\\/]* | [A-Za-z]:[\\/]*) abs="$lib" ;; *) abs=`pwd`"/$lib" ;; esac func_append newdlprefiles " $abs" done dlprefiles="$newdlprefiles" fi $RM $output # place dlname in correct position for cygwin # In fact, it would be nice if we could use this code for all target # systems that can't hard-code library paths into their executables # and that have no shared library path variable independent of PATH, # but it turns out we can't easily determine that from inspecting # libtool variables, so we have to hard-code the OSs to which it # applies here; at the moment, that means platforms that use the PE # object format with DLL files. See the long comment at the top of # tests/bindir.at for full details. tdlname=$dlname case $host,$output,$installed,$module,$dlname in *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) # If a -bindir argument was supplied, place the dll there. if test "x$bindir" != x ; then func_relative_path "$install_libdir" "$bindir" tdlname=$func_relative_path_result$dlname else # Otherwise fall back on heuristic. tdlname=../bin/$dlname fi ;; esac $ECHO > $output "\ # $outputname - a libtool library file # Generated by $PROGRAM (GNU $PACKAGE$TIMESTAMP) $VERSION # # Please DO NOT delete this file! # It is necessary for linking the library. # The name that we can dlopen(3). dlname='$tdlname' # Names of this library. library_names='$library_names' # The name of the static archive. old_library='$old_library' # Linker flags that can not go in dependency_libs. inherited_linker_flags='$new_inherited_linker_flags' # Libraries that this one depends upon. dependency_libs='$dependency_libs' # Names of additional weak libraries provided by this library weak_library_names='$weak_libs' # Version information for $libname. current=$current age=$age revision=$revision # Is this an already installed library? installed=$installed # Should we warn about portability when linking against -modules? shouldnotlink=$module # Files to dlopen/dlpreopen dlopen='$dlfiles' dlpreopen='$dlprefiles' # Directory that this library needs to be installed in: libdir='$install_libdir'" if test "$installed" = no && test "$need_relink" = yes; then $ECHO >> $output "\ relink_command=\"$relink_command\"" fi done } # Do a symbolic link so that the libtool archive can be found in # LD_LIBRARY_PATH before the program is installed. func_show_eval '( cd "$output_objdir" && $RM "$outputname" && $LN_S "../$outputname" "$outputname" )' 'exit $?' ;; esac exit $EXIT_SUCCESS } { test "$opt_mode" = link || test "$opt_mode" = relink; } && func_mode_link ${1+"$@"} # func_mode_uninstall arg... func_mode_uninstall () { $opt_debug RM="$nonopt" files= rmforce= exit_status=0 # This variable tells wrapper scripts just to set variables rather # than running their programs. libtool_install_magic="$magic" for arg do case $arg in -f) func_append RM " $arg"; rmforce=yes ;; -*) func_append RM " $arg" ;; *) func_append files " $arg" ;; esac done test -z "$RM" && \ func_fatal_help "you must specify an RM program" rmdirs= for file in $files; do func_dirname "$file" "" "." dir="$func_dirname_result" if test "X$dir" = X.; then odir="$objdir" else odir="$dir/$objdir" fi func_basename "$file" name="$func_basename_result" test "$opt_mode" = uninstall && odir="$dir" # Remember odir for removal later, being careful to avoid duplicates if test "$opt_mode" = clean; then case " $rmdirs " in *" $odir "*) ;; *) func_append rmdirs " $odir" ;; esac fi # Don't error if the file doesn't exist and rm -f was used. if { test -L "$file"; } >/dev/null 2>&1 || { test -h "$file"; } >/dev/null 2>&1 || test -f "$file"; then : elif test -d "$file"; then exit_status=1 continue elif test "$rmforce" = yes; then continue fi rmfiles="$file" case $name in *.la) # Possibly a libtool archive, so verify it. if func_lalib_p "$file"; then func_source $dir/$name # Delete the libtool libraries and symlinks. for n in $library_names; do func_append rmfiles " $odir/$n" done test -n "$old_library" && func_append rmfiles " $odir/$old_library" case "$opt_mode" in clean) case " $library_names " in *" $dlname "*) ;; *) test -n "$dlname" && func_append rmfiles " $odir/$dlname" ;; esac test -n "$libdir" && func_append rmfiles " $odir/$name $odir/${name}i" ;; uninstall) if test -n "$library_names"; then # Do each command in the postuninstall commands. func_execute_cmds "$postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1' fi if test -n "$old_library"; then # Do each command in the old_postuninstall commands. func_execute_cmds "$old_postuninstall_cmds" 'test "$rmforce" = yes || exit_status=1' fi # FIXME: should reinstall the best remaining shared library. ;; esac fi ;; *.lo) # Possibly a libtool object, so verify it. if func_lalib_p "$file"; then # Read the .lo file func_source $dir/$name # Add PIC object to the list of files to remove. if test -n "$pic_object" && test "$pic_object" != none; then func_append rmfiles " $dir/$pic_object" fi # Add non-PIC object to the list of files to remove. if test -n "$non_pic_object" && test "$non_pic_object" != none; then func_append rmfiles " $dir/$non_pic_object" fi fi ;; *) if test "$opt_mode" = clean ; then noexename=$name case $file in *.exe) func_stripname '' '.exe' "$file" file=$func_stripname_result func_stripname '' '.exe' "$name" noexename=$func_stripname_result # $file with .exe has already been added to rmfiles, # add $file without .exe func_append rmfiles " $file" ;; esac # Do a test to see if this is a libtool program. if func_ltwrapper_p "$file"; then if func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" relink_command= func_source $func_ltwrapper_scriptname_result func_append rmfiles " $func_ltwrapper_scriptname_result" else relink_command= func_source $dir/$noexename fi # note $name still contains .exe if it was in $file originally # as does the version of $file that was added into $rmfiles func_append rmfiles " $odir/$name $odir/${name}S.${objext}" if test "$fast_install" = yes && test -n "$relink_command"; then func_append rmfiles " $odir/lt-$name" fi if test "X$noexename" != "X$name" ; then func_append rmfiles " $odir/lt-${noexename}.c" fi fi fi ;; esac func_show_eval "$RM $rmfiles" 'exit_status=1' done # Try to remove the ${objdir}s in the directories where we deleted files for dir in $rmdirs; do if test -d "$dir"; then func_show_eval "rmdir $dir >/dev/null 2>&1" fi done exit $exit_status } { test "$opt_mode" = uninstall || test "$opt_mode" = clean; } && func_mode_uninstall ${1+"$@"} test -z "$opt_mode" && { help="$generic_help" func_fatal_help "you must specify a MODE" } test -z "$exec_cmd" && \ func_fatal_help "invalid operation mode \`$opt_mode'" if test -n "$exec_cmd"; then eval exec "$exec_cmd" exit $EXIT_FAILURE fi exit $exit_status # The TAGs below are defined such that we never get into a situation # in which we disable both kinds of libraries. Given conflicting # choices, we go for a static library, that is the most portable, # since we can't tell whether shared libraries were disabled because # the user asked for that or because the platform doesn't support # them. This is particularly important on AIX, because we don't # support having both static and shared libraries enabled at the same # time on that platform, so we default to a shared-only configuration. # If a disable-shared tag is given, we'll fallback to a static-only # configuration. But we'll never go from static-only to shared-only. # ### BEGIN LIBTOOL TAG CONFIG: disable-shared build_libtool_libs=no build_old_libs=yes # ### END LIBTOOL TAG CONFIG: disable-shared # ### BEGIN LIBTOOL TAG CONFIG: disable-static build_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac` # ### END LIBTOOL TAG CONFIG: disable-static # Local Variables: # mode:shell-script # sh-indentation:2 # End: # vi:sw=2 openbgpd-8.8/missing100755 001750 001750 00000015336 14751151140 0010277#! /bin/sh # Common wrapper for a few potentially missing GNU programs. scriptversion=2018-03-07.03; # UTC # Copyright (C) 1996-2021 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard , 1996. # This program 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. # This program 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. # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. if test $# -eq 0; then echo 1>&2 "Try '$0 --help' for more information" exit 1 fi case $1 in --is-lightweight) # Used by our autoconf macros to check whether the available missing # script is modern enough. exit 0 ;; --run) # Back-compat with the calling convention used by older automake. shift ;; -h|--h|--he|--hel|--help) echo "\ $0 [OPTION]... PROGRAM [ARGUMENT]... Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due to PROGRAM being missing or too old. Options: -h, --help display this help and exit -v, --version output version information and exit Supported PROGRAM values: aclocal autoconf autoheader autom4te automake makeinfo bison yacc flex lex help2man Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and 'g' are ignored when checking the name. Send bug reports to ." exit $? ;; -v|--v|--ve|--ver|--vers|--versi|--versio|--version) echo "missing $scriptversion (GNU Automake)" exit $? ;; -*) echo 1>&2 "$0: unknown '$1' option" echo 1>&2 "Try '$0 --help' for more information" exit 1 ;; esac # Run the given program, remember its exit status. "$@"; st=$? # If it succeeded, we are done. test $st -eq 0 && exit 0 # Also exit now if we it failed (or wasn't found), and '--version' was # passed; such an option is passed most likely to detect whether the # program is present and works. case $2 in --version|--help) exit $st;; esac # Exit code 63 means version mismatch. This often happens when the user # tries to use an ancient version of a tool on a file that requires a # minimum version. if test $st -eq 63; then msg="probably too old" elif test $st -eq 127; then # Program was missing. msg="missing on your system" else # Program was found and executed, but failed. Give up. exit $st fi perl_URL=https://www.perl.org/ flex_URL=https://github.com/westes/flex gnu_software_URL=https://www.gnu.org/software program_details () { case $1 in aclocal|automake) echo "The '$1' program is part of the GNU Automake package:" echo "<$gnu_software_URL/automake>" echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" echo "<$gnu_software_URL/autoconf>" echo "<$gnu_software_URL/m4/>" echo "<$perl_URL>" ;; autoconf|autom4te|autoheader) echo "The '$1' program is part of the GNU Autoconf package:" echo "<$gnu_software_URL/autoconf/>" echo "It also requires GNU m4 and Perl in order to run:" echo "<$gnu_software_URL/m4/>" echo "<$perl_URL>" ;; esac } give_advice () { # Normalize program name to check for. normalized_program=`echo "$1" | sed ' s/^gnu-//; t s/^gnu//; t s/^g//; t'` printf '%s\n' "'$1' is $msg." configure_deps="'configure.ac' or m4 files included by 'configure.ac'" case $normalized_program in autoconf*) echo "You should only need it if you modified 'configure.ac'," echo "or m4 files included by it." program_details 'autoconf' ;; autoheader*) echo "You should only need it if you modified 'acconfig.h' or" echo "$configure_deps." program_details 'autoheader' ;; automake*) echo "You should only need it if you modified 'Makefile.am' or" echo "$configure_deps." program_details 'automake' ;; aclocal*) echo "You should only need it if you modified 'acinclude.m4' or" echo "$configure_deps." program_details 'aclocal' ;; autom4te*) echo "You might have modified some maintainer files that require" echo "the 'autom4te' program to be rebuilt." program_details 'autom4te' ;; bison*|yacc*) echo "You should only need it if you modified a '.y' file." echo "You may want to install the GNU Bison package:" echo "<$gnu_software_URL/bison/>" ;; lex*|flex*) echo "You should only need it if you modified a '.l' file." echo "You may want to install the Fast Lexical Analyzer package:" echo "<$flex_URL>" ;; help2man*) echo "You should only need it if you modified a dependency" \ "of a man page." echo "You may want to install the GNU Help2man package:" echo "<$gnu_software_URL/help2man/>" ;; makeinfo*) echo "You should only need it if you modified a '.texi' file, or" echo "any other file indirectly affecting the aspect of the manual." echo "You might want to install the Texinfo package:" echo "<$gnu_software_URL/texinfo/>" echo "The spurious makeinfo call might also be the consequence of" echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" echo "want to install GNU make:" echo "<$gnu_software_URL/make/>" ;; *) echo "You might have modified some files without having the proper" echo "tools for further handling them. Check the 'README' file, it" echo "often tells you about the needed prerequisites for installing" echo "this package. You may also peek at any GNU archive site, in" echo "case some other package contains this missing '$1' program." ;; esac } give_advice "$1" | sed -e '1s/^/WARNING: /' \ -e '2,$s/^/ /' >&2 # Propagate the correct exit status (expected to be 127 for a program # not found, 63 for a program that failed due to version mismatch). exit $st # Local variables: # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: openbgpd-8.8/ylwrap100755 001750 001750 00000015314 14751151141 0010141#! /bin/sh # ylwrap - wrapper for lex/yacc invocations. scriptversion=2018-03-07.03; # UTC # Copyright (C) 1996-2021 Free Software Foundation, Inc. # # Written by Tom Tromey . # # This program 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. # # This program 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # As a special exception to the GNU General Public License, if you # distribute this file as part of a program that contains a # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. # This file is maintained in Automake, please report # bugs to or send patches to # . get_dirname () { case $1 in */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';; # Otherwise, we want the empty string (not "."). esac } # guard FILE # ---------- # The CPP macro used to guard inclusion of FILE. guard () { printf '%s\n' "$1" \ | sed \ -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \ -e 's/__*/_/g' } # quote_for_sed [STRING] # ---------------------- # Return STRING (or stdin) quoted to be used as a sed pattern. quote_for_sed () { case $# in 0) cat;; 1) printf '%s\n' "$1";; esac \ | sed -e 's|[][\\.*]|\\&|g' } case "$1" in '') echo "$0: No files given. Try '$0 --help' for more information." 1>&2 exit 1 ;; --basedir) basedir=$2 shift 2 ;; -h|--h*) cat <<\EOF Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]... Wrapper for lex/yacc invocations, renaming files as desired. INPUT is the input file OUTPUT is one file PROG generates DESIRED is the file we actually want instead of OUTPUT PROGRAM is program to run ARGS are passed to PROG Any number of OUTPUT,DESIRED pairs may be used. Report bugs to . EOF exit $? ;; -v|--v*) echo "ylwrap $scriptversion" exit $? ;; esac # The input. input=$1 shift # We'll later need for a correct munging of "#line" directives. input_sub_rx=`get_dirname "$input" | quote_for_sed` case $input in [\\/]* | ?:[\\/]*) # Absolute path; do nothing. ;; *) # Relative path. Make it absolute. input=`pwd`/$input ;; esac input_rx=`get_dirname "$input" | quote_for_sed` # Since DOS filename conventions don't allow two dots, # the DOS version of Bison writes out y_tab.c instead of y.tab.c # and y_tab.h instead of y.tab.h. Test to see if this is the case. y_tab_nodot=false if test -f y_tab.c || test -f y_tab.h; then y_tab_nodot=true fi # The parser itself, the first file, is the destination of the .y.c # rule in the Makefile. parser=$1 # A sed program to s/FROM/TO/g for all the FROM/TO so that, for # instance, we rename #include "y.tab.h" into #include "parse.h" # during the conversion from y.tab.c to parse.c. sed_fix_filenames= # Also rename header guards, as Bison 2.7 for instance uses its header # guard in its implementation file. sed_fix_header_guards= while test $# -ne 0; do if test x"$1" = x"--"; then shift break fi from=$1 # Handle y_tab.c and y_tab.h output by DOS if $y_tab_nodot; then case $from in "y.tab.c") from=y_tab.c;; "y.tab.h") from=y_tab.h;; esac fi shift to=$1 shift sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;" sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;" done # The program to run. prog=$1 shift # Make any relative path in $prog absolute. case $prog in [\\/]* | ?:[\\/]*) ;; *[\\/]*) prog=`pwd`/$prog ;; esac dirname=ylwrap$$ do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret' trap "ret=129; $do_exit" 1 trap "ret=130; $do_exit" 2 trap "ret=141; $do_exit" 13 trap "ret=143; $do_exit" 15 mkdir $dirname || exit 1 cd $dirname case $# in 0) "$prog" "$input" ;; *) "$prog" "$@" "$input" ;; esac ret=$? if test $ret -eq 0; then for from in * do to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"` if test -f "$from"; then # If $2 is an absolute path name, then just use that, # otherwise prepend '../'. case $to in [\\/]* | ?:[\\/]*) target=$to;; *) target=../$to;; esac # Do not overwrite unchanged header files to avoid useless # recompilations. Always update the parser itself: it is the # destination of the .y.c rule in the Makefile. Divert the # output of all other files to a temporary file so we can # compare them to existing versions. if test $from != $parser; then realtarget=$target target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'` fi # Munge "#line" or "#" directives. Don't let the resulting # debug information point at an absolute srcdir. Use the real # output file name, not yy.lex.c for instance. Adjust the # include guards too. sed -e "/^#/!b" \ -e "s|$input_rx|$input_sub_rx|" \ -e "$sed_fix_filenames" \ -e "$sed_fix_header_guards" \ "$from" >"$target" || ret=$? # Check whether files must be updated. if test "$from" != "$parser"; then if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then echo "$to is unchanged" rm -f "$target" else echo "updating $to" mv -f "$target" "$realtarget" fi fi else # A missing file is only an error for the parser. This is a # blatant hack to let us support using "yacc -d". If -d is not # specified, don't fail when the header file is "missing". if test "$from" = "$parser"; then ret=1 fi fi done fi # Remove the directory. cd .. rm -rf $dirname exit $ret # Local Variables: # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'before-save-hook 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" # time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: openbgpd-8.8/LICENSE100644 001750 001750 00000001343 13654222605 0007704/* * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ openbgpd-8.8/VERSION100644 001750 001750 00000000004 14751151130 00077318.8 openbgpd-8.8/bgpd.conf100644 001750 001750 00000010602 14751151130 0010451# $OpenBSD: bgpd.conf,v 1.26 2024/12/18 16:00:26 claudio Exp $ # example bgpd configuration file, see bgpd.conf(5) # define our own ASN as a macro ASN="4200000001" # global configuration AS $ASN router-id 192.0.2.1 # list of networks that may be originated by our ASN prefix-set mynetworks { 192.0.2.0/24 2001:db8:abcd::/48 } include "/var/db/rpki-client/openbgpd" # define bogon prefixes which should not be part of the DFZ prefix-set bogons { 0.0.0.0/8 or-longer # 'this' network [RFC1122] 10.0.0.0/8 or-longer # private space [RFC1918] 100.64.0.0/10 or-longer # CGN Shared [RFC6598] 127.0.0.0/8 or-longer # localhost [RFC1122] 169.254.0.0/16 or-longer # link local [RFC3927] 172.16.0.0/12 or-longer # private space [RFC1918] 192.0.2.0/24 or-longer # TEST-NET-1 [RFC5737] 192.88.99.0/24 or-longer # 6to4 anycast relay [RFC7526] 192.168.0.0/16 or-longer # private space [RFC1918] 198.18.0.0/15 or-longer # benchmarking [RFC2544] 198.51.100.0/24 or-longer # TEST-NET-2 [RFC5737] 203.0.113.0/24 or-longer # TEST-NET-3 [RFC5737] 224.0.0.0/4 or-longer # multicast 240.0.0.0/4 or-longer # reserved for future use ::/8 or-longer # RFC 4291 IPv4-compatible, loopback, et al 0100::/64 or-longer # Discard-Only [RFC6666] 2001:2::/48 or-longer # BMWG [RFC5180] 2001:10::/28 or-longer # ORCHID [RFC4843] 2001:db8::/32 or-longer # docu range [RFC3849] 2002::/16 or-longer # 6to4 anycast relay [RFC7526] 3ffe::/16 or-longer # old 6bone 3fff::/20 or-longer # docu range [RFC9637] 5f00::/16 or-longer # segment routing SRv6 SIDs [RFC9602] fc00::/7 or-longer # unique local unicast fe80::/10 or-longer # link local unicast fec0::/10 or-longer # old site local unicast ff00::/8 or-longer # multicast } # Generate routes for the networks our ASN will originate. # The communities (read 'tags') are later used to match on what # is announced to EBGP neighbors network prefix-set mynetworks set large-community local-as:1:1 # assume simple network with 3 routers in IBGP full mesh group "ibgp mesh" { remote-as $ASN # use loopback for IBGP sessions, assume it's distributed in OSPF local-address 192.0.2.1 local-address 2001:db8:abcd::1 neighbor 192.0.2.2 # router 2 ipv4 neighbor 2001:db8:abcd::2 # router 2 ipv6 neighbor 192.0.2.3 # router 3 ipv4 neighbor 2001:db8:abcd::3 # router 3 ipv6 } # upstream providers group "upstreams" { neighbor 203.0.113.1 { remote-as 65002 descr "upstream1" } neighbor 198.51.100.0 { remote-as 65123 descr "upstream2-4" } neighbor 2001:db8:666::2 { remote-as 65123 descr "upstream2-6" } } ## rules section # uncomment the following two lines to accept a default route from upstreams #allow from group upstreams prefix 0.0.0.0/0 #allow from group upstreams prefix ::/0 ### for simple BGP setups, no editing below this line is required ### # Outbound EBGP: only allow self originated networks to ebgp peers # Don't leak any routes from upstream or peering sessions. This is done # by checking for routes that are tagged with the large-community local-as:1:1 allow to ebgp prefix-set mynetworks large-community local-as:1:1 # deny more-specifics of our own originated prefixes deny quick from ebgp prefix-set mynetworks or-longer # IBGP: allow all updates to and from our IBGP neighbors allow from ibgp allow to ibgp # Scrub normal and large communities relevant to our ASN from EBGP neighbors # https://tools.ietf.org/html/rfc7454#section-11 match from ebgp set { community delete local-as:* } match from ebgp set { large-community delete local-as:*:* } # filter out prefixes longer than 24 or shorter than 8 bits for IPv4 # and longer than 48 or shorter than 16 bits for IPv6. allow from any inet prefixlen 8 - 24 allow from any inet6 prefixlen 16 - 48 # Honor requests to gracefully shutdown BGP sessions # https://tools.ietf.org/html/rfc8326 match from ebgp community GRACEFUL_SHUTDOWN set { localpref 0 } deny quick from any prefix-set bogons # deny RPKI invalid, built by rpki-client(8), see root crontab deny quick from ebgp ovs invalid # filter bogon AS numbers # AS_TRANS (23456) is not supposed to show up in any path and indicates a # misconfiguration. Additionally Private or Reserved ASNs have no place in # the public DFZ. https://www.iana.org/assignments/as-numbers/as-numbers.xhtml deny quick from any AS 23456 deny quick from any AS 64496 - 131071 deny quick from any AS 4200000000 - 4294967295 # filter out too long paths deny from any max-as-len 100 openbgpd-8.8/include/linux/rtnetlink.h100644 001750 001750 00000000370 14252050061 0013631/* * Public domain * linux/rtnetlink.h compatibility shim */ #include_next #ifndef LIBCOMPAT_LINUX_RTNETLINK_H #define LIBCOMPAT_LINUX_RTNETLINK_H #ifndef RTPROT_BGP #define RTPROT_BGP 186 /* BGP Routes */ #endif #endif openbgpd-8.8/include/netinet/icmp6.h100644 001750 001750 00000003063 14422736660 0013165/* * Public domain * netinet/icmp6.h compatibility shim */ #include_next #ifndef ICMP6_MEMBERSHIP_QUERY #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */ #endif #ifndef ICMP6_MEMBERSHIP_REPORT #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */ #endif #ifndef ICMP6_MEMBERSHIP_REDUCTION #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */ #endif #ifndef ICMP6_ROUTER_RENUMBERING #define ICMP6_ROUTER_RENUMBERING 138 /* router renumbering */ #endif #ifndef ICMP6_WRUREQUEST #define ICMP6_WRUREQUEST 139 /* who are you request */ #endif #ifndef ICMP6_WRUREPLY #define ICMP6_WRUREPLY 140 /* who are you reply */ #endif #ifndef ICMP6_FQDN_QUERY #define ICMP6_FQDN_QUERY 139 /* FQDN query */ #endif #ifndef ICMP6_FQDN_REPLY #define ICMP6_FQDN_REPLY 140 /* FQDN reply */ #endif #ifndef ICMP6_NI_QUERY #define ICMP6_NI_QUERY 139 /* node information request */ #endif #ifndef ICMP6_NI_REPLY #define ICMP6_NI_REPLY 140 /* node information reply */ #endif #ifndef MLD_LISTENER_DONE #define MLD_LISTENER_DONE 132 /* multicast listener done */ #endif #ifndef MLDV2_LISTENER_REPORT #define MLDV2_LISTENER_REPORT 143 /* RFC3810 listener report */ #endif #ifndef MLD_MTRACE_RESP #define MLD_MTRACE_RESP 200 /* mtrace response(to sender) */ #endif #ifndef MLD_MTRACE #define MLD_MTRACE 201 /* mtrace messages */ #endif #ifndef ND_REDIRECT_ONLINK #define ND_REDIRECT_ONLINK 0 /* redirect to an on-link node */ #endif #ifndef ND_REDIRECT_ROUTER #define ND_REDIRECT_ROUTER 1 /* redirect to a better router */ #endif openbgpd-8.8/include/netinet/in.h100644 001750 001750 00000000375 14316576623 0012563/* * Public domain * netinet/in.h compatibility shim */ #include_next #ifdef HAVE_LINUX_IN6_H #include #include #endif #ifndef HAVE_INET_NET_PTON int inet_net_pton(int, const char *, void *, size_t); #endif openbgpd-8.8/include/netinet/ip.h100644 001750 001750 00000002600 14422733275 0012552/* * Public domain * netinet/ip.h compatibility shim */ #include_next #ifndef IPTOS_DSCP_CS0 #define IPTOS_DSCP_CS0 0x00 #endif #ifndef IPTOS_DSCP_LE #define IPTOS_DSCP_LE 0x04 #endif #ifndef IPTOS_DSCP_CS1 #define IPTOS_DSCP_CS1 0x20 #endif #ifndef IPTOS_DSCP_AF11 #define IPTOS_DSCP_AF11 0x28 #endif #ifndef IPTOS_DSCP_AF12 #define IPTOS_DSCP_AF12 0x30 #endif #ifndef IPTOS_DSCP_AF13 #define IPTOS_DSCP_AF13 0x38 #endif #ifndef IPTOS_DSCP_CS2 #define IPTOS_DSCP_CS2 0x40 #endif #ifndef IPTOS_DSCP_AF21 #define IPTOS_DSCP_AF21 0x48 #endif #ifndef IPTOS_DSCP_AF22 #define IPTOS_DSCP_AF22 0x50 #endif #ifndef IPTOS_DSCP_AF23 #define IPTOS_DSCP_AF23 0x58 #endif #ifndef IPTOS_DSCP_CS3 #define IPTOS_DSCP_CS3 0x60 #endif #ifndef IPTOS_DSCP_AF31 #define IPTOS_DSCP_AF31 0x68 #endif #ifndef IPTOS_DSCP_AF32 #define IPTOS_DSCP_AF32 0x70 #endif #ifndef IPTOS_DSCP_AF33 #define IPTOS_DSCP_AF33 0x78 #endif #ifndef IPTOS_DSCP_CS4 #define IPTOS_DSCP_CS4 0x80 #endif #ifndef IPTOS_DSCP_AF41 #define IPTOS_DSCP_AF41 0x88 #endif #ifndef IPTOS_DSCP_AF42 #define IPTOS_DSCP_AF42 0x90 #endif #ifndef IPTOS_DSCP_AF43 #define IPTOS_DSCP_AF43 0x98 #endif #ifndef IPTOS_DSCP_CS5 #define IPTOS_DSCP_CS5 0xa0 #endif #ifndef IPTOS_DSCP_EF #define IPTOS_DSCP_EF 0xb8 #endif #ifndef IPTOS_DSCP_CS6 #define IPTOS_DSCP_CS6 0xc0 #endif #ifndef IPTOS_DSCP_CS7 #define IPTOS_DSCP_CS7 0xe0 #endif openbgpd-8.8/include/netinet/ip_icmp.h100644 001750 001750 00000003700 14636734651 0013572/* * Public domain * netinet/ip_icmp.h compatibility shim */ #include_next #ifndef ICMP_ALTHOSTADDR #define ICMP_ALTHOSTADDR 6 /* alternate host address */ #endif #ifndef ICMP_TRACEROUTE #define ICMP_TRACEROUTE 30 /* traceroute */ #endif #ifndef ICMP_DATACONVERR #define ICMP_DATACONVERR 31 /* data conversion error */ #endif #ifndef ICMP_MOBILE_REDIRECT #define ICMP_MOBILE_REDIRECT 32 /* mobile host redirect */ #endif #ifndef ICMP_IPV6_WHEREAREYOU #define ICMP_IPV6_WHEREAREYOU 33 /* IPv6 where-are-you */ #endif #ifndef ICMP_IPV6_IAMHERE #define ICMP_IPV6_IAMHERE 34 /* IPv6 i-am-here */ #endif #ifndef ICMP_MOBILE_REGREQUEST #define ICMP_MOBILE_REGREQUEST 35 /* mobile registration req */ #endif #ifndef ICMP_MOBILE_REGREPLY #define ICMP_MOBILE_REGREPLY 36 /* mobile registration reply */ #endif #ifndef ICMP_SKIP #define ICMP_SKIP 39 /* SKIP */ #endif #ifndef ICMP_PHOTURIS #define ICMP_PHOTURIS 40 /* Photuris */ #define ICMP_PHOTURIS_UNKNOWN_INDEX 1 /* unknown sec index */ #define ICMP_PHOTURIS_AUTH_FAILED 2 /* auth failed */ #define ICMP_PHOTURIS_DECRYPT_FAILED 3 /* decrypt failed */ #endif #ifndef ICMP_UNREACH_FILTER_PROHIB #define ICMP_UNREACH_FILTER_PROHIB 13 /* precedence violat'n*/ #endif #ifndef ICMP_UNREACH_HOST_PRECEDENCE #define ICMP_UNREACH_HOST_PRECEDENCE 14 /* precedence violat'n*/ #endif #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* precedence cutoff */ #endif #ifndef ICMP_ROUTERADVERT_NORMAL #define ICMP_ROUTERADVERT_NORMAL 0 /* normal advertisement */ #endif #ifndef ICMP_ROUTERADVERT_NOROUTE_COMMON #define ICMP_ROUTERADVERT_NOROUTE_COMMON 16 /* selective routing */ #endif #ifndef ICMP_PARAMPROB_ERRATPTR #define ICMP_PARAMPROB_ERRATPTR 0 /* req. opt. absent */ #endif #ifndef ICMP_PARAMPROB_OPTABSENT #define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ #endif #ifndef ICMP_PARAMPROB_LENGTH #define ICMP_PARAMPROB_LENGTH 2 /* bad length */ #endif openbgpd-8.8/include/netinet/ip_ipsp.h100644 001750 001750 00000000253 13441160747 0013605/* * Public domain * netinet/ip_ipsp.h compatibility shim */ #ifdef HAVE_NETINET_IP_IPSP_H #include_next #else #define SPI_RESERVED_MAX 255 #endif openbgpd-8.8/include/sys/_null.h100644 001750 001750 00000000515 13421757372 0012430/* $OpenBSD: _null.h,v 1.2 2016/09/09 22:07:58 millert Exp $ */ /* * Written by Todd C. Miller, September 9, 2016 * Public domain. */ #ifndef NULL #if !defined(__cplusplus) #define NULL ((void *)0) #elif __cplusplus >= 201103L #define NULL nullptr #elif defined(__GNUG__) #define NULL __null #else #define NULL 0L #endif #endif openbgpd-8.8/include/sys/queue.h100644 001750 001750 00000051727 14403051252 0012437/* $OpenBSD: queue.h,v 1.46 2020/12/30 13:33:12 millert Exp $ */ /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ /* * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)queue.h 8.5 (Berkeley) 8/20/94 */ #ifndef _SYS_QUEUE_H_ #define _SYS_QUEUE_H_ #include /* * This file defines five types of data structures: singly-linked lists, * lists, simple queues, tail queues and XOR simple queues. * * * A singly-linked list is headed by a single forward pointer. The elements * are singly linked for minimum space and pointer manipulation overhead at * the expense of O(n) removal for arbitrary elements. New elements can be * added to the list after an existing element or at the head of the list. * Elements being removed from the head of the list should use the explicit * macro for this purpose for optimum efficiency. A singly-linked list may * only be traversed in the forward direction. Singly-linked lists are ideal * for applications with large datasets and few or no removals or for * implementing a LIFO queue. * * A list is headed by a single forward pointer (or an array of forward * pointers for a hash table header). The elements are doubly linked * so that an arbitrary element can be removed without a need to * traverse the list. New elements can be added to the list before * or after an existing element or at the head of the list. A list * may only be traversed in the forward direction. * * A simple queue is headed by a pair of pointers, one to the head of the * list and the other to the tail of the list. The elements are singly * linked to save space, so elements can only be removed from the * head of the list. New elements can be added to the list before or after * an existing element, at the head of the list, or at the end of the * list. A simple queue may only be traversed in the forward direction. * * A tail queue is headed by a pair of pointers, one to the head of the * list and the other to the tail of the list. The elements are doubly * linked so that an arbitrary element can be removed without a need to * traverse the list. New elements can be added to the list before or * after an existing element, at the head of the list, or at the end of * the list. A tail queue may be traversed in either direction. * * An XOR simple queue is used in the same way as a regular simple queue. * The difference is that the head structure also includes a "cookie" that * is XOR'd with the queue pointer (first, last or next) to generate the * real pointer value. * * For details on the use of these macros, see the queue(3) manual page. */ #if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC)) #define _Q_INVALID ((void *)-1) #define _Q_INVALIDATE(a) (a) = _Q_INVALID #else #define _Q_INVALIDATE(a) #endif /* * Singly-linked List definitions. */ #define SLIST_HEAD(name, type) \ struct name { \ struct type *slh_first; /* first element */ \ } #define SLIST_HEAD_INITIALIZER(head) \ { NULL } #define SLIST_ENTRY(type) \ struct { \ struct type *sle_next; /* next element */ \ } /* * Singly-linked List access methods. */ #define SLIST_FIRST(head) ((head)->slh_first) #define SLIST_END(head) NULL #define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) #define SLIST_FOREACH(var, head, field) \ for((var) = SLIST_FIRST(head); \ (var) != SLIST_END(head); \ (var) = SLIST_NEXT(var, field)) #define SLIST_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = SLIST_FIRST(head); \ (var) && ((tvar) = SLIST_NEXT(var, field), 1); \ (var) = (tvar)) /* * Singly-linked List functions. */ #define SLIST_INIT(head) { \ SLIST_FIRST(head) = SLIST_END(head); \ } #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ (elm)->field.sle_next = (slistelm)->field.sle_next; \ (slistelm)->field.sle_next = (elm); \ } while (0) #define SLIST_INSERT_HEAD(head, elm, field) do { \ (elm)->field.sle_next = (head)->slh_first; \ (head)->slh_first = (elm); \ } while (0) #define SLIST_REMOVE_AFTER(elm, field) do { \ (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \ } while (0) #define SLIST_REMOVE_HEAD(head, field) do { \ (head)->slh_first = (head)->slh_first->field.sle_next; \ } while (0) #define SLIST_REMOVE(head, elm, type, field) do { \ if ((head)->slh_first == (elm)) { \ SLIST_REMOVE_HEAD((head), field); \ } else { \ struct type *curelm = (head)->slh_first; \ \ while (curelm->field.sle_next != (elm)) \ curelm = curelm->field.sle_next; \ curelm->field.sle_next = \ curelm->field.sle_next->field.sle_next; \ } \ _Q_INVALIDATE((elm)->field.sle_next); \ } while (0) /* * List definitions. */ #define LIST_HEAD(name, type) \ struct name { \ struct type *lh_first; /* first element */ \ } #define LIST_HEAD_INITIALIZER(head) \ { NULL } #define LIST_ENTRY(type) \ struct { \ struct type *le_next; /* next element */ \ struct type **le_prev; /* address of previous next element */ \ } /* * List access methods. */ #define LIST_FIRST(head) ((head)->lh_first) #define LIST_END(head) NULL #define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) #define LIST_NEXT(elm, field) ((elm)->field.le_next) #define LIST_FOREACH(var, head, field) \ for((var) = LIST_FIRST(head); \ (var)!= LIST_END(head); \ (var) = LIST_NEXT(var, field)) #define LIST_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = LIST_FIRST(head); \ (var) && ((tvar) = LIST_NEXT(var, field), 1); \ (var) = (tvar)) /* * List functions. */ #define LIST_INIT(head) do { \ LIST_FIRST(head) = LIST_END(head); \ } while (0) #define LIST_INSERT_AFTER(listelm, elm, field) do { \ if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ (listelm)->field.le_next->field.le_prev = \ &(elm)->field.le_next; \ (listelm)->field.le_next = (elm); \ (elm)->field.le_prev = &(listelm)->field.le_next; \ } while (0) #define LIST_INSERT_BEFORE(listelm, elm, field) do { \ (elm)->field.le_prev = (listelm)->field.le_prev; \ (elm)->field.le_next = (listelm); \ *(listelm)->field.le_prev = (elm); \ (listelm)->field.le_prev = &(elm)->field.le_next; \ } while (0) #define LIST_INSERT_HEAD(head, elm, field) do { \ if (((elm)->field.le_next = (head)->lh_first) != NULL) \ (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ (head)->lh_first = (elm); \ (elm)->field.le_prev = &(head)->lh_first; \ } while (0) #define LIST_REMOVE(elm, field) do { \ if ((elm)->field.le_next != NULL) \ (elm)->field.le_next->field.le_prev = \ (elm)->field.le_prev; \ *(elm)->field.le_prev = (elm)->field.le_next; \ _Q_INVALIDATE((elm)->field.le_prev); \ _Q_INVALIDATE((elm)->field.le_next); \ } while (0) #define LIST_REPLACE(elm, elm2, field) do { \ if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ (elm2)->field.le_next->field.le_prev = \ &(elm2)->field.le_next; \ (elm2)->field.le_prev = (elm)->field.le_prev; \ *(elm2)->field.le_prev = (elm2); \ _Q_INVALIDATE((elm)->field.le_prev); \ _Q_INVALIDATE((elm)->field.le_next); \ } while (0) /* * Simple queue definitions. */ #define SIMPLEQ_HEAD(name, type) \ struct name { \ struct type *sqh_first; /* first element */ \ struct type **sqh_last; /* addr of last next element */ \ } #define SIMPLEQ_HEAD_INITIALIZER(head) \ { NULL, &(head).sqh_first } #define SIMPLEQ_ENTRY(type) \ struct { \ struct type *sqe_next; /* next element */ \ } /* * Simple queue access methods. */ #define SIMPLEQ_FIRST(head) ((head)->sqh_first) #define SIMPLEQ_END(head) NULL #define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) #define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) #define SIMPLEQ_FOREACH(var, head, field) \ for((var) = SIMPLEQ_FIRST(head); \ (var) != SIMPLEQ_END(head); \ (var) = SIMPLEQ_NEXT(var, field)) #define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = SIMPLEQ_FIRST(head); \ (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \ (var) = (tvar)) /* * Simple queue functions. */ #define SIMPLEQ_INIT(head) do { \ (head)->sqh_first = NULL; \ (head)->sqh_last = &(head)->sqh_first; \ } while (0) #define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ (head)->sqh_last = &(elm)->field.sqe_next; \ (head)->sqh_first = (elm); \ } while (0) #define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ (elm)->field.sqe_next = NULL; \ *(head)->sqh_last = (elm); \ (head)->sqh_last = &(elm)->field.sqe_next; \ } while (0) #define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ (head)->sqh_last = &(elm)->field.sqe_next; \ (listelm)->field.sqe_next = (elm); \ } while (0) #define SIMPLEQ_REMOVE_HEAD(head, field) do { \ if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \ (head)->sqh_last = &(head)->sqh_first; \ } while (0) #define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \ == NULL) \ (head)->sqh_last = &(elm)->field.sqe_next; \ } while (0) #define SIMPLEQ_CONCAT(head1, head2) do { \ if (!SIMPLEQ_EMPTY((head2))) { \ *(head1)->sqh_last = (head2)->sqh_first; \ (head1)->sqh_last = (head2)->sqh_last; \ SIMPLEQ_INIT((head2)); \ } \ } while (0) /* * XOR Simple queue definitions. */ #define XSIMPLEQ_HEAD(name, type) \ struct name { \ struct type *sqx_first; /* first element */ \ struct type **sqx_last; /* addr of last next element */ \ unsigned long sqx_cookie; \ } #define XSIMPLEQ_ENTRY(type) \ struct { \ struct type *sqx_next; /* next element */ \ } /* * XOR Simple queue access methods. */ #define XSIMPLEQ_XOR(head, ptr) ((__typeof(ptr))((head)->sqx_cookie ^ \ (unsigned long)(ptr))) #define XSIMPLEQ_FIRST(head) XSIMPLEQ_XOR(head, ((head)->sqx_first)) #define XSIMPLEQ_END(head) NULL #define XSIMPLEQ_EMPTY(head) (XSIMPLEQ_FIRST(head) == XSIMPLEQ_END(head)) #define XSIMPLEQ_NEXT(head, elm, field) XSIMPLEQ_XOR(head, ((elm)->field.sqx_next)) #define XSIMPLEQ_FOREACH(var, head, field) \ for ((var) = XSIMPLEQ_FIRST(head); \ (var) != XSIMPLEQ_END(head); \ (var) = XSIMPLEQ_NEXT(head, var, field)) #define XSIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = XSIMPLEQ_FIRST(head); \ (var) && ((tvar) = XSIMPLEQ_NEXT(head, var, field), 1); \ (var) = (tvar)) /* * XOR Simple queue functions. */ #define XSIMPLEQ_INIT(head) do { \ arc4random_buf(&(head)->sqx_cookie, sizeof((head)->sqx_cookie)); \ (head)->sqx_first = XSIMPLEQ_XOR(head, NULL); \ (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ } while (0) #define XSIMPLEQ_INSERT_HEAD(head, elm, field) do { \ if (((elm)->field.sqx_next = (head)->sqx_first) == \ XSIMPLEQ_XOR(head, NULL)) \ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ (head)->sqx_first = XSIMPLEQ_XOR(head, (elm)); \ } while (0) #define XSIMPLEQ_INSERT_TAIL(head, elm, field) do { \ (elm)->field.sqx_next = XSIMPLEQ_XOR(head, NULL); \ *(XSIMPLEQ_XOR(head, (head)->sqx_last)) = XSIMPLEQ_XOR(head, (elm)); \ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ } while (0) #define XSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ if (((elm)->field.sqx_next = (listelm)->field.sqx_next) == \ XSIMPLEQ_XOR(head, NULL)) \ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ (listelm)->field.sqx_next = XSIMPLEQ_XOR(head, (elm)); \ } while (0) #define XSIMPLEQ_REMOVE_HEAD(head, field) do { \ if (((head)->sqx_first = XSIMPLEQ_XOR(head, \ (head)->sqx_first)->field.sqx_next) == XSIMPLEQ_XOR(head, NULL)) \ (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \ } while (0) #define XSIMPLEQ_REMOVE_AFTER(head, elm, field) do { \ if (((elm)->field.sqx_next = XSIMPLEQ_XOR(head, \ (elm)->field.sqx_next)->field.sqx_next) \ == XSIMPLEQ_XOR(head, NULL)) \ (head)->sqx_last = \ XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \ } while (0) /* * Tail queue definitions. */ #define TAILQ_HEAD(name, type) \ struct name { \ struct type *tqh_first; /* first element */ \ struct type **tqh_last; /* addr of last next element */ \ } #define TAILQ_HEAD_INITIALIZER(head) \ { NULL, &(head).tqh_first } #define TAILQ_ENTRY(type) \ struct { \ struct type *tqe_next; /* next element */ \ struct type **tqe_prev; /* address of previous next element */ \ } /* * Tail queue access methods. */ #define TAILQ_FIRST(head) ((head)->tqh_first) #define TAILQ_END(head) NULL #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) #define TAILQ_LAST(head, headname) \ (*(((struct headname *)((head)->tqh_last))->tqh_last)) /* XXX */ #define TAILQ_PREV(elm, headname, field) \ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) #define TAILQ_EMPTY(head) \ (TAILQ_FIRST(head) == TAILQ_END(head)) #define TAILQ_FOREACH(var, head, field) \ for((var) = TAILQ_FIRST(head); \ (var) != TAILQ_END(head); \ (var) = TAILQ_NEXT(var, field)) #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = TAILQ_FIRST(head); \ (var) != TAILQ_END(head) && \ ((tvar) = TAILQ_NEXT(var, field), 1); \ (var) = (tvar)) #define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ for((var) = TAILQ_LAST(head, headname); \ (var) != TAILQ_END(head); \ (var) = TAILQ_PREV(var, headname, field)) #define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ for ((var) = TAILQ_LAST(head, headname); \ (var) != TAILQ_END(head) && \ ((tvar) = TAILQ_PREV(var, headname, field), 1); \ (var) = (tvar)) /* * Tail queue functions. */ #define TAILQ_INIT(head) do { \ (head)->tqh_first = NULL; \ (head)->tqh_last = &(head)->tqh_first; \ } while (0) #define TAILQ_INSERT_HEAD(head, elm, field) do { \ if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ (head)->tqh_first->field.tqe_prev = \ &(elm)->field.tqe_next; \ else \ (head)->tqh_last = &(elm)->field.tqe_next; \ (head)->tqh_first = (elm); \ (elm)->field.tqe_prev = &(head)->tqh_first; \ } while (0) #define TAILQ_INSERT_TAIL(head, elm, field) do { \ (elm)->field.tqe_next = NULL; \ (elm)->field.tqe_prev = (head)->tqh_last; \ *(head)->tqh_last = (elm); \ (head)->tqh_last = &(elm)->field.tqe_next; \ } while (0) #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ (elm)->field.tqe_next->field.tqe_prev = \ &(elm)->field.tqe_next; \ else \ (head)->tqh_last = &(elm)->field.tqe_next; \ (listelm)->field.tqe_next = (elm); \ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ } while (0) #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ (elm)->field.tqe_next = (listelm); \ *(listelm)->field.tqe_prev = (elm); \ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ } while (0) #define TAILQ_REMOVE(head, elm, field) do { \ if (((elm)->field.tqe_next) != NULL) \ (elm)->field.tqe_next->field.tqe_prev = \ (elm)->field.tqe_prev; \ else \ (head)->tqh_last = (elm)->field.tqe_prev; \ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ _Q_INVALIDATE((elm)->field.tqe_prev); \ _Q_INVALIDATE((elm)->field.tqe_next); \ } while (0) #define TAILQ_REPLACE(head, elm, elm2, field) do { \ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ (elm2)->field.tqe_next->field.tqe_prev = \ &(elm2)->field.tqe_next; \ else \ (head)->tqh_last = &(elm2)->field.tqe_next; \ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ *(elm2)->field.tqe_prev = (elm2); \ _Q_INVALIDATE((elm)->field.tqe_prev); \ _Q_INVALIDATE((elm)->field.tqe_next); \ } while (0) #define TAILQ_CONCAT(head1, head2, field) do { \ if (!TAILQ_EMPTY(head2)) { \ *(head1)->tqh_last = (head2)->tqh_first; \ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ (head1)->tqh_last = (head2)->tqh_last; \ TAILQ_INIT((head2)); \ } \ } while (0) /* * Singly-linked Tail queue declarations. */ #define STAILQ_HEAD(name, type) \ struct name { \ struct type *stqh_first; /* first element */ \ struct type **stqh_last; /* addr of last next element */ \ } #define STAILQ_HEAD_INITIALIZER(head) \ { NULL, &(head).stqh_first } #define STAILQ_ENTRY(type) \ struct { \ struct type *stqe_next; /* next element */ \ } /* * Singly-linked Tail queue access methods. */ #define STAILQ_FIRST(head) ((head)->stqh_first) #define STAILQ_END(head) NULL #define STAILQ_EMPTY(head) (STAILQ_FIRST(head) == STAILQ_END(head)) #define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) #define STAILQ_FOREACH(var, head, field) \ for ((var) = STAILQ_FIRST(head); \ (var) != STAILQ_END(head); \ (var) = STAILQ_NEXT(var, field)) #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ for ((var) = STAILQ_FIRST(head); \ (var) && ((tvar) = STAILQ_NEXT(var, field), 1); \ (var) = (tvar)) /* * Singly-linked Tail queue functions. */ #define STAILQ_INIT(head) do { \ STAILQ_FIRST((head)) = NULL; \ (head)->stqh_last = &STAILQ_FIRST((head)); \ } while (0) #define STAILQ_INSERT_HEAD(head, elm, field) do { \ if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ STAILQ_FIRST((head)) = (elm); \ } while (0) #define STAILQ_INSERT_TAIL(head, elm, field) do { \ STAILQ_NEXT((elm), field) = NULL; \ *(head)->stqh_last = (elm); \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ } while (0) #define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((elm), field)) == NULL)\ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ STAILQ_NEXT((elm), field) = (elm); \ } while (0) #define STAILQ_REMOVE_HEAD(head, field) do { \ if ((STAILQ_FIRST((head)) = \ STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ (head)->stqh_last = &STAILQ_FIRST((head)); \ } while (0) #define STAILQ_REMOVE_AFTER(head, elm, field) do { \ if ((STAILQ_NEXT(elm, field) = \ STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ (head)->stqh_last = &STAILQ_NEXT((elm), field); \ } while (0) #define STAILQ_REMOVE(head, elm, type, field) do { \ if (STAILQ_FIRST((head)) == (elm)) { \ STAILQ_REMOVE_HEAD((head), field); \ } else { \ struct type *curelm = (head)->stqh_first; \ while (STAILQ_NEXT(curelm, field) != (elm)) \ curelm = STAILQ_NEXT(curelm, field); \ STAILQ_REMOVE_AFTER(head, curelm, field); \ } \ } while (0) #define STAILQ_CONCAT(head1, head2) do { \ if (!STAILQ_EMPTY((head2))) { \ *(head1)->stqh_last = (head2)->stqh_first; \ (head1)->stqh_last = (head2)->stqh_last; \ STAILQ_INIT((head2)); \ } \ } while (0) #define STAILQ_LAST(head, type, field) \ (STAILQ_EMPTY((head)) ? NULL : \ ((struct type *)(void *) \ ((char *)((head)->stqh_last) - offsetof(struct type, field)))) #endif /* !_SYS_QUEUE_H_ */ openbgpd-8.8/include/sys/socket.h100644 001750 001750 00000000307 13441160747 0012602/* * Public domain * sys/socket.h compatibility shim */ #include_next #ifndef HAVE_GETRTABLE int getrtable(void); #endif #ifndef RT_TABLEID_MAX #define RT_TABLEID_MAX 255 #endif openbgpd-8.8/include/sys/time.h100644 001750 001750 00000000614 13441160747 0012251/* * Public domain * sys/time.h compatibility shim */ #include_next #ifndef timespecsub #define timespecsub(tsp, usp, vsp) \ do { \ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ if ((vsp)->tv_nsec < 0) { \ (vsp)->tv_sec--; \ (vsp)->tv_nsec += 1000000000L; \ } \ } while (0) #endif openbgpd-8.8/include/sys/tree.h100644 001750 001750 00000102152 13421757372 0012256/* $OpenBSD: tree.h,v 1.29 2017/07/30 19:27:20 deraadt Exp $ */ /* * Copyright 2002 Niels Provos * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _SYS_TREE_H_ #define _SYS_TREE_H_ #include /* * This file defines data structures for different types of trees: * splay trees and red-black trees. * * A splay tree is a self-organizing data structure. Every operation * on the tree causes a splay to happen. The splay moves the requested * node to the root of the tree and partly rebalances it. * * This has the benefit that request locality causes faster lookups as * the requested nodes move to the top of the tree. On the other hand, * every lookup causes memory writes. * * The Balance Theorem bounds the total access time for m operations * and n inserts on an initially empty tree as O((m + n)lg n). The * amortized cost for a sequence of m accesses to a splay tree is O(lg n); * * A red-black tree is a binary search tree with the node color as an * extra attribute. It fulfills a set of conditions: * - every search path from the root to a leaf consists of the * same number of black nodes, * - each red node (except for the root) has a black parent, * - each leaf node is black. * * Every operation on a red-black tree is bounded as O(lg n). * The maximum height of a red-black tree is 2lg (n+1). */ #define SPLAY_HEAD(name, type) \ struct name { \ struct type *sph_root; /* root of the tree */ \ } #define SPLAY_INITIALIZER(root) \ { NULL } #define SPLAY_INIT(root) do { \ (root)->sph_root = NULL; \ } while (0) #define SPLAY_ENTRY(type) \ struct { \ struct type *spe_left; /* left element */ \ struct type *spe_right; /* right element */ \ } #define SPLAY_LEFT(elm, field) (elm)->field.spe_left #define SPLAY_RIGHT(elm, field) (elm)->field.spe_right #define SPLAY_ROOT(head) (head)->sph_root #define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) /* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ #define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ (head)->sph_root = tmp; \ } while (0) #define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ SPLAY_LEFT(tmp, field) = (head)->sph_root; \ (head)->sph_root = tmp; \ } while (0) #define SPLAY_LINKLEFT(head, tmp, field) do { \ SPLAY_LEFT(tmp, field) = (head)->sph_root; \ tmp = (head)->sph_root; \ (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ } while (0) #define SPLAY_LINKRIGHT(head, tmp, field) do { \ SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ tmp = (head)->sph_root; \ (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ } while (0) #define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ } while (0) /* Generates prototypes and inline functions */ #define SPLAY_PROTOTYPE(name, type, field, cmp) \ void name##_SPLAY(struct name *, struct type *); \ void name##_SPLAY_MINMAX(struct name *, int); \ struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ \ /* Finds the node with the same key as elm */ \ static __unused __inline struct type * \ name##_SPLAY_FIND(struct name *head, struct type *elm) \ { \ if (SPLAY_EMPTY(head)) \ return(NULL); \ name##_SPLAY(head, elm); \ if ((cmp)(elm, (head)->sph_root) == 0) \ return (head->sph_root); \ return (NULL); \ } \ \ static __unused __inline struct type * \ name##_SPLAY_NEXT(struct name *head, struct type *elm) \ { \ name##_SPLAY(head, elm); \ if (SPLAY_RIGHT(elm, field) != NULL) { \ elm = SPLAY_RIGHT(elm, field); \ while (SPLAY_LEFT(elm, field) != NULL) { \ elm = SPLAY_LEFT(elm, field); \ } \ } else \ elm = NULL; \ return (elm); \ } \ \ static __unused __inline struct type * \ name##_SPLAY_MIN_MAX(struct name *head, int val) \ { \ name##_SPLAY_MINMAX(head, val); \ return (SPLAY_ROOT(head)); \ } /* Main splay operation. * Moves node close to the key of elm to top */ #define SPLAY_GENERATE(name, type, field, cmp) \ struct type * \ name##_SPLAY_INSERT(struct name *head, struct type *elm) \ { \ if (SPLAY_EMPTY(head)) { \ SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ } else { \ int __comp; \ name##_SPLAY(head, elm); \ __comp = (cmp)(elm, (head)->sph_root); \ if(__comp < 0) { \ SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ SPLAY_RIGHT(elm, field) = (head)->sph_root; \ SPLAY_LEFT((head)->sph_root, field) = NULL; \ } else if (__comp > 0) { \ SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ SPLAY_LEFT(elm, field) = (head)->sph_root; \ SPLAY_RIGHT((head)->sph_root, field) = NULL; \ } else \ return ((head)->sph_root); \ } \ (head)->sph_root = (elm); \ return (NULL); \ } \ \ struct type * \ name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ { \ struct type *__tmp; \ if (SPLAY_EMPTY(head)) \ return (NULL); \ name##_SPLAY(head, elm); \ if ((cmp)(elm, (head)->sph_root) == 0) { \ if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ } else { \ __tmp = SPLAY_RIGHT((head)->sph_root, field); \ (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ name##_SPLAY(head, elm); \ SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ } \ return (elm); \ } \ return (NULL); \ } \ \ void \ name##_SPLAY(struct name *head, struct type *elm) \ { \ struct type __node, *__left, *__right, *__tmp; \ int __comp; \ \ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ __left = __right = &__node; \ \ while ((__comp = (cmp)(elm, (head)->sph_root))) { \ if (__comp < 0) { \ __tmp = SPLAY_LEFT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if ((cmp)(elm, __tmp) < 0){ \ SPLAY_ROTATE_RIGHT(head, __tmp, field); \ if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ break; \ } \ SPLAY_LINKLEFT(head, __right, field); \ } else if (__comp > 0) { \ __tmp = SPLAY_RIGHT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if ((cmp)(elm, __tmp) > 0){ \ SPLAY_ROTATE_LEFT(head, __tmp, field); \ if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ break; \ } \ SPLAY_LINKRIGHT(head, __left, field); \ } \ } \ SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ } \ \ /* Splay with either the minimum or the maximum element \ * Used to find minimum or maximum element in tree. \ */ \ void name##_SPLAY_MINMAX(struct name *head, int __comp) \ { \ struct type __node, *__left, *__right, *__tmp; \ \ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ __left = __right = &__node; \ \ while (1) { \ if (__comp < 0) { \ __tmp = SPLAY_LEFT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if (__comp < 0){ \ SPLAY_ROTATE_RIGHT(head, __tmp, field); \ if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ break; \ } \ SPLAY_LINKLEFT(head, __right, field); \ } else if (__comp > 0) { \ __tmp = SPLAY_RIGHT((head)->sph_root, field); \ if (__tmp == NULL) \ break; \ if (__comp > 0) { \ SPLAY_ROTATE_LEFT(head, __tmp, field); \ if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ break; \ } \ SPLAY_LINKRIGHT(head, __left, field); \ } \ } \ SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ } #define SPLAY_NEGINF -1 #define SPLAY_INF 1 #define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) #define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) #define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) #define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) #define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) #define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) #define SPLAY_FOREACH(x, name, head) \ for ((x) = SPLAY_MIN(name, head); \ (x) != NULL; \ (x) = SPLAY_NEXT(name, head, x)) /* Macros that define a red-black tree */ #define RB_HEAD(name, type) \ struct name { \ struct type *rbh_root; /* root of the tree */ \ } #define RB_INITIALIZER(root) \ { NULL } #define RB_INIT(root) do { \ (root)->rbh_root = NULL; \ } while (0) #define RB_BLACK 0 #define RB_RED 1 #define RB_ENTRY(type) \ struct { \ struct type *rbe_left; /* left element */ \ struct type *rbe_right; /* right element */ \ struct type *rbe_parent; /* parent element */ \ int rbe_color; /* node color */ \ } #define RB_LEFT(elm, field) (elm)->field.rbe_left #define RB_RIGHT(elm, field) (elm)->field.rbe_right #define RB_PARENT(elm, field) (elm)->field.rbe_parent #define RB_COLOR(elm, field) (elm)->field.rbe_color #define RB_ROOT(head) (head)->rbh_root #define RB_EMPTY(head) (RB_ROOT(head) == NULL) #define RB_SET(elm, parent, field) do { \ RB_PARENT(elm, field) = parent; \ RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ RB_COLOR(elm, field) = RB_RED; \ } while (0) #define RB_SET_BLACKRED(black, red, field) do { \ RB_COLOR(black, field) = RB_BLACK; \ RB_COLOR(red, field) = RB_RED; \ } while (0) #ifndef RB_AUGMENT #define RB_AUGMENT(x) do {} while (0) #endif #define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ (tmp) = RB_RIGHT(elm, field); \ if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) { \ RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ } \ RB_AUGMENT(elm); \ if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ else \ RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ } else \ (head)->rbh_root = (tmp); \ RB_LEFT(tmp, field) = (elm); \ RB_PARENT(elm, field) = (tmp); \ RB_AUGMENT(tmp); \ if ((RB_PARENT(tmp, field))) \ RB_AUGMENT(RB_PARENT(tmp, field)); \ } while (0) #define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ (tmp) = RB_LEFT(elm, field); \ if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) { \ RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ } \ RB_AUGMENT(elm); \ if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \ if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ else \ RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ } else \ (head)->rbh_root = (tmp); \ RB_RIGHT(tmp, field) = (elm); \ RB_PARENT(elm, field) = (tmp); \ RB_AUGMENT(tmp); \ if ((RB_PARENT(tmp, field))) \ RB_AUGMENT(RB_PARENT(tmp, field)); \ } while (0) /* Generates prototypes and inline functions */ #define RB_PROTOTYPE(name, type, field, cmp) \ RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) #define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) #define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ attr struct type *name##_RB_INSERT(struct name *, struct type *); \ attr struct type *name##_RB_FIND(struct name *, struct type *); \ attr struct type *name##_RB_NFIND(struct name *, struct type *); \ attr struct type *name##_RB_NEXT(struct type *); \ attr struct type *name##_RB_PREV(struct type *); \ attr struct type *name##_RB_MINMAX(struct name *, int); \ \ /* Main rb operation. * Moves node close to the key of elm to top */ #define RB_GENERATE(name, type, field, cmp) \ RB_GENERATE_INTERNAL(name, type, field, cmp,) #define RB_GENERATE_STATIC(name, type, field, cmp) \ RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static) #define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ attr void \ name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ { \ struct type *parent, *gparent, *tmp; \ while ((parent = RB_PARENT(elm, field)) && \ RB_COLOR(parent, field) == RB_RED) { \ gparent = RB_PARENT(parent, field); \ if (parent == RB_LEFT(gparent, field)) { \ tmp = RB_RIGHT(gparent, field); \ if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ RB_COLOR(tmp, field) = RB_BLACK; \ RB_SET_BLACKRED(parent, gparent, field);\ elm = gparent; \ continue; \ } \ if (RB_RIGHT(parent, field) == elm) { \ RB_ROTATE_LEFT(head, parent, tmp, field);\ tmp = parent; \ parent = elm; \ elm = tmp; \ } \ RB_SET_BLACKRED(parent, gparent, field); \ RB_ROTATE_RIGHT(head, gparent, tmp, field); \ } else { \ tmp = RB_LEFT(gparent, field); \ if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ RB_COLOR(tmp, field) = RB_BLACK; \ RB_SET_BLACKRED(parent, gparent, field);\ elm = gparent; \ continue; \ } \ if (RB_LEFT(parent, field) == elm) { \ RB_ROTATE_RIGHT(head, parent, tmp, field);\ tmp = parent; \ parent = elm; \ elm = tmp; \ } \ RB_SET_BLACKRED(parent, gparent, field); \ RB_ROTATE_LEFT(head, gparent, tmp, field); \ } \ } \ RB_COLOR(head->rbh_root, field) = RB_BLACK; \ } \ \ attr void \ name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ { \ struct type *tmp; \ while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ elm != RB_ROOT(head)) { \ if (RB_LEFT(parent, field) == elm) { \ tmp = RB_RIGHT(parent, field); \ if (RB_COLOR(tmp, field) == RB_RED) { \ RB_SET_BLACKRED(tmp, parent, field); \ RB_ROTATE_LEFT(head, parent, tmp, field);\ tmp = RB_RIGHT(parent, field); \ } \ if ((RB_LEFT(tmp, field) == NULL || \ RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ (RB_RIGHT(tmp, field) == NULL || \ RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ RB_COLOR(tmp, field) = RB_RED; \ elm = parent; \ parent = RB_PARENT(elm, field); \ } else { \ if (RB_RIGHT(tmp, field) == NULL || \ RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ struct type *oleft; \ if ((oleft = RB_LEFT(tmp, field)))\ RB_COLOR(oleft, field) = RB_BLACK;\ RB_COLOR(tmp, field) = RB_RED; \ RB_ROTATE_RIGHT(head, tmp, oleft, field);\ tmp = RB_RIGHT(parent, field); \ } \ RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ RB_COLOR(parent, field) = RB_BLACK; \ if (RB_RIGHT(tmp, field)) \ RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ RB_ROTATE_LEFT(head, parent, tmp, field);\ elm = RB_ROOT(head); \ break; \ } \ } else { \ tmp = RB_LEFT(parent, field); \ if (RB_COLOR(tmp, field) == RB_RED) { \ RB_SET_BLACKRED(tmp, parent, field); \ RB_ROTATE_RIGHT(head, parent, tmp, field);\ tmp = RB_LEFT(parent, field); \ } \ if ((RB_LEFT(tmp, field) == NULL || \ RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ (RB_RIGHT(tmp, field) == NULL || \ RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ RB_COLOR(tmp, field) = RB_RED; \ elm = parent; \ parent = RB_PARENT(elm, field); \ } else { \ if (RB_LEFT(tmp, field) == NULL || \ RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ struct type *oright; \ if ((oright = RB_RIGHT(tmp, field)))\ RB_COLOR(oright, field) = RB_BLACK;\ RB_COLOR(tmp, field) = RB_RED; \ RB_ROTATE_LEFT(head, tmp, oright, field);\ tmp = RB_LEFT(parent, field); \ } \ RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ RB_COLOR(parent, field) = RB_BLACK; \ if (RB_LEFT(tmp, field)) \ RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ RB_ROTATE_RIGHT(head, parent, tmp, field);\ elm = RB_ROOT(head); \ break; \ } \ } \ } \ if (elm) \ RB_COLOR(elm, field) = RB_BLACK; \ } \ \ attr struct type * \ name##_RB_REMOVE(struct name *head, struct type *elm) \ { \ struct type *child, *parent, *old = elm; \ int color; \ if (RB_LEFT(elm, field) == NULL) \ child = RB_RIGHT(elm, field); \ else if (RB_RIGHT(elm, field) == NULL) \ child = RB_LEFT(elm, field); \ else { \ struct type *left; \ elm = RB_RIGHT(elm, field); \ while ((left = RB_LEFT(elm, field))) \ elm = left; \ child = RB_RIGHT(elm, field); \ parent = RB_PARENT(elm, field); \ color = RB_COLOR(elm, field); \ if (child) \ RB_PARENT(child, field) = parent; \ if (parent) { \ if (RB_LEFT(parent, field) == elm) \ RB_LEFT(parent, field) = child; \ else \ RB_RIGHT(parent, field) = child; \ RB_AUGMENT(parent); \ } else \ RB_ROOT(head) = child; \ if (RB_PARENT(elm, field) == old) \ parent = elm; \ (elm)->field = (old)->field; \ if (RB_PARENT(old, field)) { \ if (RB_LEFT(RB_PARENT(old, field), field) == old)\ RB_LEFT(RB_PARENT(old, field), field) = elm;\ else \ RB_RIGHT(RB_PARENT(old, field), field) = elm;\ RB_AUGMENT(RB_PARENT(old, field)); \ } else \ RB_ROOT(head) = elm; \ RB_PARENT(RB_LEFT(old, field), field) = elm; \ if (RB_RIGHT(old, field)) \ RB_PARENT(RB_RIGHT(old, field), field) = elm; \ if (parent) { \ left = parent; \ do { \ RB_AUGMENT(left); \ } while ((left = RB_PARENT(left, field))); \ } \ goto color; \ } \ parent = RB_PARENT(elm, field); \ color = RB_COLOR(elm, field); \ if (child) \ RB_PARENT(child, field) = parent; \ if (parent) { \ if (RB_LEFT(parent, field) == elm) \ RB_LEFT(parent, field) = child; \ else \ RB_RIGHT(parent, field) = child; \ RB_AUGMENT(parent); \ } else \ RB_ROOT(head) = child; \ color: \ if (color == RB_BLACK) \ name##_RB_REMOVE_COLOR(head, parent, child); \ return (old); \ } \ \ /* Inserts a node into the RB tree */ \ attr struct type * \ name##_RB_INSERT(struct name *head, struct type *elm) \ { \ struct type *tmp; \ struct type *parent = NULL; \ int comp = 0; \ tmp = RB_ROOT(head); \ while (tmp) { \ parent = tmp; \ comp = (cmp)(elm, parent); \ if (comp < 0) \ tmp = RB_LEFT(tmp, field); \ else if (comp > 0) \ tmp = RB_RIGHT(tmp, field); \ else \ return (tmp); \ } \ RB_SET(elm, parent, field); \ if (parent != NULL) { \ if (comp < 0) \ RB_LEFT(parent, field) = elm; \ else \ RB_RIGHT(parent, field) = elm; \ RB_AUGMENT(parent); \ } else \ RB_ROOT(head) = elm; \ name##_RB_INSERT_COLOR(head, elm); \ return (NULL); \ } \ \ /* Finds the node with the same key as elm */ \ attr struct type * \ name##_RB_FIND(struct name *head, struct type *elm) \ { \ struct type *tmp = RB_ROOT(head); \ int comp; \ while (tmp) { \ comp = cmp(elm, tmp); \ if (comp < 0) \ tmp = RB_LEFT(tmp, field); \ else if (comp > 0) \ tmp = RB_RIGHT(tmp, field); \ else \ return (tmp); \ } \ return (NULL); \ } \ \ /* Finds the first node greater than or equal to the search key */ \ attr struct type * \ name##_RB_NFIND(struct name *head, struct type *elm) \ { \ struct type *tmp = RB_ROOT(head); \ struct type *res = NULL; \ int comp; \ while (tmp) { \ comp = cmp(elm, tmp); \ if (comp < 0) { \ res = tmp; \ tmp = RB_LEFT(tmp, field); \ } \ else if (comp > 0) \ tmp = RB_RIGHT(tmp, field); \ else \ return (tmp); \ } \ return (res); \ } \ \ /* ARGSUSED */ \ attr struct type * \ name##_RB_NEXT(struct type *elm) \ { \ if (RB_RIGHT(elm, field)) { \ elm = RB_RIGHT(elm, field); \ while (RB_LEFT(elm, field)) \ elm = RB_LEFT(elm, field); \ } else { \ if (RB_PARENT(elm, field) && \ (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ elm = RB_PARENT(elm, field); \ else { \ while (RB_PARENT(elm, field) && \ (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ elm = RB_PARENT(elm, field); \ elm = RB_PARENT(elm, field); \ } \ } \ return (elm); \ } \ \ /* ARGSUSED */ \ attr struct type * \ name##_RB_PREV(struct type *elm) \ { \ if (RB_LEFT(elm, field)) { \ elm = RB_LEFT(elm, field); \ while (RB_RIGHT(elm, field)) \ elm = RB_RIGHT(elm, field); \ } else { \ if (RB_PARENT(elm, field) && \ (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ elm = RB_PARENT(elm, field); \ else { \ while (RB_PARENT(elm, field) && \ (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ elm = RB_PARENT(elm, field); \ elm = RB_PARENT(elm, field); \ } \ } \ return (elm); \ } \ \ attr struct type * \ name##_RB_MINMAX(struct name *head, int val) \ { \ struct type *tmp = RB_ROOT(head); \ struct type *parent = NULL; \ while (tmp) { \ parent = tmp; \ if (val < 0) \ tmp = RB_LEFT(tmp, field); \ else \ tmp = RB_RIGHT(tmp, field); \ } \ return (parent); \ } #define RB_NEGINF -1 #define RB_INF 1 #define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) #define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) #define RB_FIND(name, x, y) name##_RB_FIND(x, y) #define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) #define RB_NEXT(name, x, y) name##_RB_NEXT(y) #define RB_PREV(name, x, y) name##_RB_PREV(y) #define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) #define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) #define RB_FOREACH(x, name, head) \ for ((x) = RB_MIN(name, head); \ (x) != NULL; \ (x) = name##_RB_NEXT(x)) #define RB_FOREACH_SAFE(x, name, head, y) \ for ((x) = RB_MIN(name, head); \ ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \ (x) = (y)) #define RB_FOREACH_REVERSE(x, name, head) \ for ((x) = RB_MAX(name, head); \ (x) != NULL; \ (x) = name##_RB_PREV(x)) #define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \ for ((x) = RB_MAX(name, head); \ ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \ (x) = (y)) /* * Copyright (c) 2016 David Gwynne * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ struct rb_type { int (*t_compare)(const void *, const void *); void (*t_augment)(void *); unsigned int t_offset; /* offset of rb_entry in type */ }; struct rb_tree { struct rb_entry *rbt_root; }; struct rb_entry { struct rb_entry *rbt_parent; struct rb_entry *rbt_left; struct rb_entry *rbt_right; unsigned int rbt_color; }; #define RBT_HEAD(_name, _type) \ struct _name { \ struct rb_tree rbh_root; \ } #define RBT_ENTRY(_type) struct rb_entry static inline void _rb_init(struct rb_tree *rbt) { rbt->rbt_root = NULL; } static inline int _rb_empty(struct rb_tree *rbt) { return (rbt->rbt_root == NULL); } void *_rb_insert(const struct rb_type *, struct rb_tree *, void *); void *_rb_remove(const struct rb_type *, struct rb_tree *, void *); void *_rb_find(const struct rb_type *, struct rb_tree *, const void *); void *_rb_nfind(const struct rb_type *, struct rb_tree *, const void *); void *_rb_root(const struct rb_type *, struct rb_tree *); void *_rb_min(const struct rb_type *, struct rb_tree *); void *_rb_max(const struct rb_type *, struct rb_tree *); void *_rb_next(const struct rb_type *, void *); void *_rb_prev(const struct rb_type *, void *); void *_rb_left(const struct rb_type *, void *); void *_rb_right(const struct rb_type *, void *); void *_rb_parent(const struct rb_type *, void *); void _rb_set_left(const struct rb_type *, void *, void *); void _rb_set_right(const struct rb_type *, void *, void *); void _rb_set_parent(const struct rb_type *, void *, void *); void _rb_poison(const struct rb_type *, void *, unsigned long); int _rb_check(const struct rb_type *, void *, unsigned long); #define RBT_INITIALIZER(_head) { { NULL } } #define RBT_PROTOTYPE(_name, _type, _field, _cmp) \ extern const struct rb_type *const _name##_RBT_TYPE; \ \ __unused static inline void \ _name##_RBT_INIT(struct _name *head) \ { \ _rb_init(&head->rbh_root); \ } \ \ __unused static inline struct _type * \ _name##_RBT_INSERT(struct _name *head, struct _type *elm) \ { \ return _rb_insert(_name##_RBT_TYPE, &head->rbh_root, elm); \ } \ \ __unused static inline struct _type * \ _name##_RBT_REMOVE(struct _name *head, struct _type *elm) \ { \ return _rb_remove(_name##_RBT_TYPE, &head->rbh_root, elm); \ } \ \ __unused static inline struct _type * \ _name##_RBT_FIND(struct _name *head, const struct _type *key) \ { \ return _rb_find(_name##_RBT_TYPE, &head->rbh_root, key); \ } \ \ __unused static inline struct _type * \ _name##_RBT_NFIND(struct _name *head, const struct _type *key) \ { \ return _rb_nfind(_name##_RBT_TYPE, &head->rbh_root, key); \ } \ \ __unused static inline struct _type * \ _name##_RBT_ROOT(struct _name *head) \ { \ return _rb_root(_name##_RBT_TYPE, &head->rbh_root); \ } \ \ __unused static inline int \ _name##_RBT_EMPTY(struct _name *head) \ { \ return _rb_empty(&head->rbh_root); \ } \ \ __unused static inline struct _type * \ _name##_RBT_MIN(struct _name *head) \ { \ return _rb_min(_name##_RBT_TYPE, &head->rbh_root); \ } \ \ __unused static inline struct _type * \ _name##_RBT_MAX(struct _name *head) \ { \ return _rb_max(_name##_RBT_TYPE, &head->rbh_root); \ } \ \ __unused static inline struct _type * \ _name##_RBT_NEXT(struct _type *elm) \ { \ return _rb_next(_name##_RBT_TYPE, elm); \ } \ \ __unused static inline struct _type * \ _name##_RBT_PREV(struct _type *elm) \ { \ return _rb_prev(_name##_RBT_TYPE, elm); \ } \ \ __unused static inline struct _type * \ _name##_RBT_LEFT(struct _type *elm) \ { \ return _rb_left(_name##_RBT_TYPE, elm); \ } \ \ __unused static inline struct _type * \ _name##_RBT_RIGHT(struct _type *elm) \ { \ return _rb_right(_name##_RBT_TYPE, elm); \ } \ \ __unused static inline struct _type * \ _name##_RBT_PARENT(struct _type *elm) \ { \ return _rb_parent(_name##_RBT_TYPE, elm); \ } \ \ __unused static inline void \ _name##_RBT_SET_LEFT(struct _type *elm, struct _type *left) \ { \ return _rb_set_left(_name##_RBT_TYPE, elm, left); \ } \ \ __unused static inline void \ _name##_RBT_SET_RIGHT(struct _type *elm, struct _type *right) \ { \ return _rb_set_right(_name##_RBT_TYPE, elm, right); \ } \ \ __unused static inline void \ _name##_RBT_SET_PARENT(struct _type *elm, struct _type *parent) \ { \ return _rb_set_parent(_name##_RBT_TYPE, elm, parent); \ } \ \ __unused static inline void \ _name##_RBT_POISON(struct _type *elm, unsigned long poison) \ { \ return _rb_poison(_name##_RBT_TYPE, elm, poison); \ } \ \ __unused static inline int \ _name##_RBT_CHECK(struct _type *elm, unsigned long poison) \ { \ return _rb_check(_name##_RBT_TYPE, elm, poison); \ } #define RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \ static int \ _name##_RBT_COMPARE(const void *lptr, const void *rptr) \ { \ const struct _type *l = lptr, *r = rptr; \ return _cmp(l, r); \ } \ static const struct rb_type _name##_RBT_INFO = { \ _name##_RBT_COMPARE, \ _aug, \ offsetof(struct _type, _field), \ }; \ const struct rb_type *const _name##_RBT_TYPE = &_name##_RBT_INFO #define RBT_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \ static void \ _name##_RBT_AUGMENT(void *ptr) \ { \ struct _type *p = ptr; \ return _aug(p); \ } \ RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RBT_AUGMENT) #define RBT_GENERATE(_name, _type, _field, _cmp) \ RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL) #define RBT_INIT(_name, _head) _name##_RBT_INIT(_head) #define RBT_INSERT(_name, _head, _elm) _name##_RBT_INSERT(_head, _elm) #define RBT_REMOVE(_name, _head, _elm) _name##_RBT_REMOVE(_head, _elm) #define RBT_FIND(_name, _head, _key) _name##_RBT_FIND(_head, _key) #define RBT_NFIND(_name, _head, _key) _name##_RBT_NFIND(_head, _key) #define RBT_ROOT(_name, _head) _name##_RBT_ROOT(_head) #define RBT_EMPTY(_name, _head) _name##_RBT_EMPTY(_head) #define RBT_MIN(_name, _head) _name##_RBT_MIN(_head) #define RBT_MAX(_name, _head) _name##_RBT_MAX(_head) #define RBT_NEXT(_name, _elm) _name##_RBT_NEXT(_elm) #define RBT_PREV(_name, _elm) _name##_RBT_PREV(_elm) #define RBT_LEFT(_name, _elm) _name##_RBT_LEFT(_elm) #define RBT_RIGHT(_name, _elm) _name##_RBT_RIGHT(_elm) #define RBT_PARENT(_name, _elm) _name##_RBT_PARENT(_elm) #define RBT_SET_LEFT(_name, _elm, _l) _name##_RBT_SET_LEFT(_elm, _l) #define RBT_SET_RIGHT(_name, _elm, _r) _name##_RBT_SET_RIGHT(_elm, _r) #define RBT_SET_PARENT(_name, _elm, _p) _name##_RBT_SET_PARENT(_elm, _p) #define RBT_POISON(_name, _elm, _p) _name##_RBT_POISON(_elm, _p) #define RBT_CHECK(_name, _elm, _p) _name##_RBT_CHECK(_elm, _p) #define RBT_FOREACH(_e, _name, _head) \ for ((_e) = RBT_MIN(_name, (_head)); \ (_e) != NULL; \ (_e) = RBT_NEXT(_name, (_e))) #define RBT_FOREACH_SAFE(_e, _name, _head, _n) \ for ((_e) = RBT_MIN(_name, (_head)); \ (_e) != NULL && ((_n) = RBT_NEXT(_name, (_e)), 1); \ (_e) = (_n)) #define RBT_FOREACH_REVERSE(_e, _name, _head) \ for ((_e) = RBT_MAX(_name, (_head)); \ (_e) != NULL; \ (_e) = RBT_PREV(_name, (_e))) #define RBT_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \ for ((_e) = RBT_MAX(_name, (_head)); \ (_e) != NULL && ((_n) = RBT_PREV(_name, (_e)), 1); \ (_e) = (_n)) #endif /* _SYS_TREE_H_ */ openbgpd-8.8/include/sys/types.h100644 001750 001750 00000001050 14264017544 0012452/* * Public domain * sys/types.h compatibility shim */ #include_next #ifndef LIBCOMPAT_SYS_TYPES_H #define LIBCOMPAT_SYS_TYPES_H #include #ifdef __MINGW32__ #include <_bsd_types.h> #endif #if !defined(HAVE_ATTRIBUTE__DEAD) && !defined(__dead) #define __dead __attribute__((__noreturn__)) #endif #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__bounded__) # define __bounded__(x, y, z) #endif #if !defined(HAVE_ATTRIBUTE__PACKED) && !defined(__packed) #define __packed __attribute__((__packed__)) #endif #endif openbgpd-8.8/include/sys/wait.h100644 001750 001750 00000000307 14264017544 0012256/* * Public domain * sys/wait.h compatibility shim */ #include_next #ifndef LIBCOMPAT_SYS_WAIT_H #define LIBCOMPAT_SYS_WAIT_H #ifndef WAIT_ANY #define WAIT_ANY (-1) #endif #endif openbgpd-8.8/include/Makefile.am100644 001750 001750 00000001235 14422740467 0012363noinst_HEADERS = noinst_HEADERS += linux/rtnetlink.h noinst_HEADERS += netinet/icmp6.h noinst_HEADERS += netinet/in.h noinst_HEADERS += netinet/ip.h noinst_HEADERS += netinet/ip_icmp.h noinst_HEADERS += netinet/ip_ipsp.h noinst_HEADERS += sys/_null.h noinst_HEADERS += sys/queue.h noinst_HEADERS += sys/socket.h noinst_HEADERS += sys/time.h noinst_HEADERS += sys/tree.h noinst_HEADERS += sys/types.h noinst_HEADERS += sys/wait.h noinst_HEADERS += endian.h noinst_HEADERS += imsg.h noinst_HEADERS += sha2.h noinst_HEADERS += sha2_openbsd.h noinst_HEADERS += stdlib.h noinst_HEADERS += string.h noinst_HEADERS += unistd.h noinst_HEADERS += util.h noinst_HEADERS += vis.h openbgpd-8.8/include/endian.h100644 001750 001750 00000000213 13421757372 0011732/* * endian.h compatibility shim * Public domain */ #ifdef HAVE_ENDIAN_H #include_next #else #include #endif openbgpd-8.8/include/imsg.h100644 001750 001750 00000012600 14751151130 0011421/* $OpenBSD: imsg.h,v 1.19 2024/11/26 13:57:31 claudio Exp $ */ /* * Copyright (c) 2023 Claudio Jeker * Copyright (c) 2006, 2007 Pierre-Yves Ritschard * Copyright (c) 2006, 2007, 2008 Reyk Floeter * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef _IMSG_H_ #define _IMSG_H_ #include #define IBUF_READ_SIZE 65535 #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define MAX_IMSGSIZE 16384 struct ibuf { TAILQ_ENTRY(ibuf) entry; unsigned char *buf; size_t size; size_t max; size_t wpos; size_t rpos; int fd; }; struct msgbuf; struct imsgbuf { struct msgbuf *w; pid_t pid; uint32_t maxsize; int fd; int flags; }; struct imsg_hdr { uint32_t type; uint32_t len; uint32_t peerid; uint32_t pid; }; struct imsg { struct imsg_hdr hdr; void *data; struct ibuf *buf; }; struct iovec; /* imsg-buffer.c */ struct ibuf *ibuf_open(size_t); struct ibuf *ibuf_dynamic(size_t, size_t); int ibuf_add(struct ibuf *, const void *, size_t); int ibuf_add_ibuf(struct ibuf *, const struct ibuf *); int ibuf_add_zero(struct ibuf *, size_t); int ibuf_add_n8(struct ibuf *, uint64_t); int ibuf_add_n16(struct ibuf *, uint64_t); int ibuf_add_n32(struct ibuf *, uint64_t); int ibuf_add_n64(struct ibuf *, uint64_t); int ibuf_add_h16(struct ibuf *, uint64_t); int ibuf_add_h32(struct ibuf *, uint64_t); int ibuf_add_h64(struct ibuf *, uint64_t); void *ibuf_reserve(struct ibuf *, size_t); void *ibuf_seek(struct ibuf *, size_t, size_t); int ibuf_set(struct ibuf *, size_t, const void *, size_t); int ibuf_set_n8(struct ibuf *, size_t, uint64_t); int ibuf_set_n16(struct ibuf *, size_t, uint64_t); int ibuf_set_n32(struct ibuf *, size_t, uint64_t); int ibuf_set_n64(struct ibuf *, size_t, uint64_t); int ibuf_set_h16(struct ibuf *, size_t, uint64_t); int ibuf_set_h32(struct ibuf *, size_t, uint64_t); int ibuf_set_h64(struct ibuf *, size_t, uint64_t); void *ibuf_data(const struct ibuf *); size_t ibuf_size(const struct ibuf *); size_t ibuf_left(const struct ibuf *); int ibuf_truncate(struct ibuf *, size_t); void ibuf_rewind(struct ibuf *); void ibuf_close(struct msgbuf *, struct ibuf *); void ibuf_from_buffer(struct ibuf *, void *, size_t); void ibuf_from_ibuf(struct ibuf *, const struct ibuf *); int ibuf_get(struct ibuf *, void *, size_t); int ibuf_get_ibuf(struct ibuf *, size_t, struct ibuf *); int ibuf_get_n8(struct ibuf *, uint8_t *); int ibuf_get_n16(struct ibuf *, uint16_t *); int ibuf_get_n32(struct ibuf *, uint32_t *); int ibuf_get_n64(struct ibuf *, uint64_t *); int ibuf_get_h16(struct ibuf *, uint16_t *); int ibuf_get_h32(struct ibuf *, uint32_t *); int ibuf_get_h64(struct ibuf *, uint64_t *); char *ibuf_get_string(struct ibuf *, size_t); int ibuf_skip(struct ibuf *, size_t); void ibuf_free(struct ibuf *); int ibuf_fd_avail(struct ibuf *); int ibuf_fd_get(struct ibuf *); void ibuf_fd_set(struct ibuf *, int); struct msgbuf *msgbuf_new(void); struct msgbuf *msgbuf_new_reader(size_t, struct ibuf *(*)(struct ibuf *, void *, int *), void *); void msgbuf_free(struct msgbuf *); void msgbuf_clear(struct msgbuf *); uint32_t msgbuf_queuelen(struct msgbuf *); int ibuf_write(int, struct msgbuf *); int msgbuf_write(int, struct msgbuf *); int ibuf_read(int, struct msgbuf *); int msgbuf_read(int, struct msgbuf *); struct ibuf *msgbuf_get(struct msgbuf *); /* imsg.c */ int imsgbuf_init(struct imsgbuf *, int); void imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf); int imsgbuf_set_maxsize(struct imsgbuf *, uint32_t); int imsgbuf_read(struct imsgbuf *); int imsgbuf_write(struct imsgbuf *); int imsgbuf_flush(struct imsgbuf *); void imsgbuf_clear(struct imsgbuf *); uint32_t imsgbuf_queuelen(struct imsgbuf *); ssize_t imsg_get(struct imsgbuf *, struct imsg *); int imsg_get_ibuf(struct imsg *, struct ibuf *); int imsg_get_data(struct imsg *, void *, size_t); int imsg_get_fd(struct imsg *); uint32_t imsg_get_id(struct imsg *); size_t imsg_get_len(struct imsg *); pid_t imsg_get_pid(struct imsg *); uint32_t imsg_get_type(struct imsg *); int imsg_forward(struct imsgbuf *, struct imsg *); int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const void *, size_t); int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const struct iovec *, int); int imsg_compose_ibuf(struct imsgbuf *, uint32_t, uint32_t, pid_t, struct ibuf *); struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, size_t); int imsg_add(struct ibuf *, const void *, size_t); void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); #endif openbgpd-8.8/include/sha2.h100644 001750 001750 00000000432 13431263542 0011324/* * Public domain * sha2.h compatibility shim */ #include "sha2_openbsd.h" #define SHA512_CTX SHA2_CTX #define SHA512_Init(ctx) SHA512Init(ctx) #define SHA512_Update(ctx, buf, len) SHA512Update(ctx, (void *)buf, len) #define SHA512_Final(digest, ctx) SHA512Final(digest, ctx) openbgpd-8.8/include/sha2_openbsd.h100644 001750 001750 00000016324 14751151130 0013040/* $OpenBSD: sha2.h,v 1.10 2016/09/03 17:00:29 tedu Exp $ */ /* * FILE: sha2.h * AUTHOR: Aaron D. Gifford * * Copyright (c) 2000-2001, Aaron D. Gifford * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holder nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ */ #ifndef _SHA2_H #define _SHA2_H /*** SHA-256/384/512 Various Length Definitions ***********************/ #define SHA224_BLOCK_LENGTH 64 #define SHA224_DIGEST_LENGTH 28 #define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1) #define SHA256_BLOCK_LENGTH 64 #define SHA256_DIGEST_LENGTH 32 #define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1) #define SHA384_BLOCK_LENGTH 128 #define SHA384_DIGEST_LENGTH 48 #define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1) #define SHA512_BLOCK_LENGTH 128 #define SHA512_DIGEST_LENGTH 64 #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) #define SHA512_256_BLOCK_LENGTH 128 #define SHA512_256_DIGEST_LENGTH 32 #define SHA512_256_DIGEST_STRING_LENGTH (SHA512_256_DIGEST_LENGTH * 2 + 1) /*** SHA-224/256/384/512 Context Structure *******************************/ typedef struct _SHA2_CTX { union { u_int32_t st32[8]; u_int64_t st64[8]; } state; u_int64_t bitcount[2]; u_int8_t buffer[SHA512_BLOCK_LENGTH]; } SHA2_CTX; void SHA224Init(SHA2_CTX *); void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]); void SHA224Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); void SHA224Pad(SHA2_CTX *); void SHA224Final(u_int8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA224_DIGEST_LENGTH))); char *SHA224End(SHA2_CTX *, char *) __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); char *SHA224File(const char *, char *) __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); char *SHA224FileChunk(const char *, char *, off_t, off_t) __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH))); char *SHA224Data(const u_int8_t *, size_t, char *) __attribute__((__bounded__(__string__,1,2))) __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH))); void SHA256Init(SHA2_CTX *); void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]); void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); void SHA256Pad(SHA2_CTX *); void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); char *SHA256End(SHA2_CTX *, char *) __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); char *SHA256File(const char *, char *) __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); char *SHA256FileChunk(const char *, char *, off_t, off_t) __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH))); char *SHA256Data(const u_int8_t *, size_t, char *) __attribute__((__bounded__(__string__,1,2))) __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH))); void SHA384Init(SHA2_CTX *); void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]); void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); void SHA384Pad(SHA2_CTX *); void SHA384Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); char *SHA384End(SHA2_CTX *, char *) __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); char *SHA384File(const char *, char *) __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); char *SHA384FileChunk(const char *, char *, off_t, off_t) __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH))); char *SHA384Data(const u_int8_t *, size_t, char *) __attribute__((__bounded__(__string__,1,2))) __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH))); void SHA512Init(SHA2_CTX *); void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]); void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); void SHA512Pad(SHA2_CTX *); void SHA512Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); char *SHA512End(SHA2_CTX *, char *) __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); char *SHA512File(const char *, char *) __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); char *SHA512FileChunk(const char *, char *, off_t, off_t) __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH))); char *SHA512Data(const u_int8_t *, size_t, char *) __attribute__((__bounded__(__string__,1,2))) __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH))); void SHA512_256Init(SHA2_CTX *); void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]); void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); void SHA512_256Pad(SHA2_CTX *); void SHA512_256Final(u_int8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA512_256_DIGEST_LENGTH))); char *SHA512_256End(SHA2_CTX *, char *) __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); char *SHA512_256File(const char *, char *) __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); char *SHA512_256FileChunk(const char *, char *, off_t, off_t) __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH))); char *SHA512_256Data(const u_int8_t *, size_t, char *) __attribute__((__bounded__(__string__,1,2))) __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH))); #endif /* _SHA2_H */ openbgpd-8.8/include/stdlib.h100644 001750 001750 00000001435 14505475621 0011762/* * stdlib.h compatibility shim * Public domain */ #include_next #ifndef LIBCOMPAT_STDLIB_H #define LIBCOMPAT_STDLIB_H #include #ifndef HAVE_ARC4RANDOM_ uint32_t arc4random(void); uint32_t arc4random_uniform(uint32_t); void arc4random_buf(void *, size_t); #endif #ifndef HAVE_DAEMON int daemon(int, int); #endif #ifndef HAVE_FREEZERO void freezero(void *, size_t); #endif #ifndef HAVE_REALLOCARRAY void *reallocarray(void *, size_t, size_t); #endif #ifndef HAVE_RECALLOCARRAY void *recallocarray(void *, size_t, size_t, size_t); #endif #ifndef HAVE_SETPROCTITLE void compat_init_setproctitle(int, char *[]); void setproctitle(const char *, ...); #endif #ifndef HAVE_STRTONUM long long strtonum(const char *, long long, long long, const char **); #endif #endif openbgpd-8.8/include/string.h100644 001750 001750 00000001163 14476044750 0012007/* * Public domain * string.h compatibility shim */ #include_next #ifndef LIBCOMPAT_STRING_H #define LIBCOMPAT_STRING_H #include #if defined(__sun) || defined(__hpux) /* Some functions historically defined in string.h were placed in strings.h by * SUS. Use the same hack as OS X and FreeBSD use to work around on Solaris and HPUX. */ #include #endif #ifndef HAVE_EXPLICIT_BZERO void explicit_bzero(void *, size_t); #endif #ifndef HAVE_STRLCAT size_t strlcat(char *, const char *, size_t); #endif #ifndef HAVE_STRLCPY size_t strlcpy(char *, const char *, size_t); #endif #endif openbgpd-8.8/include/unistd.h100644 001750 001750 00000001211 14476044750 0012001/* * Public domain * unistd.h compatibility shim */ #include_next #ifndef LIBCOMPAT_UNISTD_H #define LIBCOMPAT_UNISTD_H #ifndef HAVE_PLEDGE #define pledge(request, paths) 0 #endif #ifndef HAVE_UNVEIL #define unveil(path, permissions) 0 #endif #ifndef HAVE_GETENTROPY int getentropy(void *, size_t); #endif #include #ifndef HAVE_SETGROUPS int setgroups(int, const gid_t *); #endif #ifndef HAVE_SETRESGID int setresgid(gid_t, gid_t, gid_t); #endif #ifndef HAVE_SETRESUID int setresuid(uid_t, uid_t, uid_t); #endif #ifndef HAVE_HOST_NAME_MAX #include #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX #endif #endif openbgpd-8.8/include/util.h100644 001750 001750 00000010634 14751151130 0011444/* $OpenBSD: util.h,v 1.38 2022/05/11 17:23:56 millert Exp $ */ /* $NetBSD: util.h,v 1.2 1996/05/16 07:00:22 thorpej Exp $ */ /*- * Copyright (c) 1995 * The Regents of the University of California. All rights reserved. * Portions Copyright (c) 1996, Jason Downs. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef _UTIL_H_ #define _UTIL_H_ #include /* * fparseln() specific operation flags. */ #define FPARSELN_UNESCESC 0x01 #define FPARSELN_UNESCCONT 0x02 #define FPARSELN_UNESCCOMM 0x04 #define FPARSELN_UNESCREST 0x08 #define FPARSELN_UNESCALL 0x0f /* * opendev() specific operation flags. */ #define OPENDEV_PART 0x01 /* Try to open the raw partition. */ #define OPENDEV_BLCK 0x04 /* Open block, not character device. */ /* * uu_lock(3) specific flags. */ #define UU_LOCK_INUSE (1) #define UU_LOCK_OK (0) #define UU_LOCK_OPEN_ERR (-1) #define UU_LOCK_READ_ERR (-2) #define UU_LOCK_CREAT_ERR (-3) #define UU_LOCK_WRITE_ERR (-4) #define UU_LOCK_LINK_ERR (-5) #define UU_LOCK_TRY_ERR (-6) #define UU_LOCK_OWNER_ERR (-7) /* * fmt_scaled(3) specific flags. */ #define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */ /* * stub struct definitions. */ struct __sFILE; struct login_cap; struct passwd; struct termios; struct utmp; struct winsize; char *fparseln(struct __sFILE *, size_t *, size_t *, const char[3], int); void login(struct utmp *); int login_tty(int); int logout(const char *); void logwtmp(const char *, const char *, const char *); int opendev(const char *, int, int, char **); int pidfile(const char *); void pw_setdir(const char *); char *pw_file(const char *); int pw_lock(int); int pw_mkdb(char *, int); int pw_abort(void); void pw_init(void); void pw_edit(int, const char *); void pw_prompt(void); void pw_copy(int, int, const struct passwd *, const struct passwd *); int pw_scan(char *, struct passwd *, int *); __dead void pw_error(const char *, int, int); int getptmfd(void); int openpty(int *, int *, char *, const struct termios *, const struct winsize *); int fdopenpty(int, int *, int *, char *, const struct termios *, const struct winsize *); int opendisk(const char *, int, char *, size_t, int); pid_t forkpty(int *, char *, const struct termios *, const struct winsize *); pid_t fdforkpty(int, int *, char *, const struct termios *, const struct winsize *); int getmaxpartitions(void); int getrawpartition(void); void login_fbtab(const char *, uid_t, gid_t); int login_check_expire(struct __sFILE *, struct passwd *, char *, int); char *readlabelfs(char *, int); const char *uu_lockerr(int); int uu_lock(const char *); int uu_lock_txfr(const char *, pid_t); int uu_unlock(const char *); int fmt_scaled(long long, char *); int scan_scaled(char *, long long *); int isduid(const char *, int); int pkcs5_pbkdf2(const char *, size_t, const uint8_t *, size_t, uint8_t *, size_t, unsigned int); int bcrypt_pbkdf(const char *, size_t, const uint8_t *, size_t, uint8_t *, size_t, unsigned int); #endif /* !_UTIL_H_ */ openbgpd-8.8/include/vis.h100644 001750 001750 00000006577 14751151130 0011303/* $OpenBSD: vis.h,v 1.15 2015/07/20 01:52:27 millert Exp $ */ /* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)vis.h 5.9 (Berkeley) 4/3/91 */ #ifndef _VIS_H_ #define _VIS_H_ /* * to select alternate encoding format */ #define VIS_OCTAL 0x01 /* use octal \ddd format */ #define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ /* * to alter set of characters encoded (default is to encode all * non-graphic except space, tab, and newline). */ #define VIS_SP 0x04 /* also encode space */ #define VIS_TAB 0x08 /* also encode tab */ #define VIS_NL 0x10 /* also encode newline */ #define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) #define VIS_SAFE 0x20 /* only encode "unsafe" characters */ #define VIS_DQ 0x200 /* backslash-escape double quotes */ #define VIS_ALL 0x400 /* encode all characters */ /* * other */ #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ #define VIS_GLOB 0x100 /* encode glob(3) magics and '#' */ /* * unvis return codes */ #define UNVIS_VALID 1 /* character valid */ #define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ #define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ #define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ #define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ /* * unvis flags */ #define UNVIS_END 1 /* no more characters */ char *vis(char *, int, int, int); int strvis(char *, const char *, int); int stravis(char **, const char *, int); int strnvis(char *, const char *, size_t, int) __attribute__ ((__bounded__(__string__,1,3))); int strvisx(char *, const char *, size_t, int) __attribute__ ((__bounded__(__string__,1,3))); int strunvis(char *, const char *); int unvis(char *, char, int *, int); ssize_t strnunvis(char *, const char *, size_t) __attribute__ ((__bounded__(__string__,1,3))); #endif /* !_VIS_H_ */ openbgpd-8.8/include/Makefile.in100644 001750 001750 00000034265 14751151140 0012372# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ subdir = include ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = SOURCES = DIST_SOURCES = am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac HEADERS = $(noinst_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LDFLAGS = @AM_LDFLAGS@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BGPD_USER = @BGPD_USER@ BGPLGD_USER = @BGPLGD_USER@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ WWW_USER = @WWW_USER@ YACC = @YACC@ YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwrunstatedir = @wwwrunstatedir@ noinst_HEADERS = linux/rtnetlink.h netinet/icmp6.h netinet/in.h \ netinet/ip.h netinet/ip_icmp.h netinet/ip_ipsp.h sys/_null.h \ sys/queue.h sys/socket.h sys/time.h sys/tree.h sys/types.h \ sys/wait.h endian.h imsg.h sha2.h sha2_openbsd.h stdlib.h \ string.h unistd.h util.h vis.h all: all-am .SUFFIXES: $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign include/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(HEADERS) installdirs: install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile distclean-am: clean-am distclean-generic distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-generic mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ clean-libtool cscopelist-am ctags ctags-am distclean \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man install-pdf \ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-generic \ mostlyclean-libtool pdf pdf-am ps ps-am tags tags-am uninstall \ uninstall-am .PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: openbgpd-8.8/compat/Makefile.am100644 001750 001750 00000005655 14304730461 0012225# # Copyright (c) 2014 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -DSHA2_SMALL noinst_LTLIBRARIES = libcompat.la libcompatnoopt.la # compatibility functions that need to be built without optimizations libcompatnoopt_la_CFLAGS = -O0 libcompatnoopt_la_SOURCES = if !HAVE_EXPLICIT_BZERO libcompatnoopt_la_SOURCES += explicit_bzero.c endif # other compatibility functions libcompat_la_SOURCES = libcompat_la_LIBADD = $(PLATFORM_LDADD) if !HAVE_FREEZERO libcompat_la_SOURCES += freezero.c endif if !HAVE_IMSG libcompat_la_SOURCES += imsg.c libcompat_la_SOURCES += imsg-buffer.c endif if !HAVE_REALLOCARRAY libcompat_la_SOURCES += reallocarray.c endif if !HAVE_RECALLOCARRAY libcompat_la_SOURCES += recallocarray.c endif if !HAVE_SETPROCTITLE libcompat_la_SOURCES += setproctitle.c endif if !HAVE_STRLCAT libcompat_la_SOURCES += strlcat.c endif if !HAVE_STRLCPY libcompat_la_SOURCES += strlcpy.c endif if !HAVE_STRTONUM libcompat_la_SOURCES += strtonum.c endif if !HAVE_SETRESGID libcompat_la_SOURCES += bsd-setresgid.c endif if !HAVE_SETRESUID libcompat_la_SOURCES += bsd-setresuid.c endif if !HAVE_ARC4RANDOM libcompat_la_SOURCES += arc4random.c libcompat_la_SOURCES += arc4random_uniform.c if !HAVE_GETENTROPY if HOST_FREEBSD libcompat_la_SOURCES += getentropy_freebsd.c endif if HOST_LINUX libcompat_la_SOURCES += getentropy_linux.c libcompat_la_SOURCES += sha2.c endif if HOST_NETBSD libcompat_la_SOURCES += getentropy_netbsd.c endif if HOST_DARWIN libcompat_la_SOURCES += getentropy_osx.c libcompat_la_SOURCES += sha2.c endif if HOST_SOLARIS libcompat_la_SOURCES += getentropy_solaris.c libcompat_la_SOURCES += sha2.c endif endif endif if !HAVE_GETRTABLE libcompat_la_SOURCES += getrtable.c endif if !HAVE_INET_NET_PTON libcompat_la_SOURCES += inet_net_pton.c endif if !HAVE_FMT_SCALED libcompat_la_SOURCES += fmt_scaled.c endif if !HAVE_STRNVIS libcompat_la_SOURCES += vis.c endif if BROKEN_STRNVIS libcompat_la_SOURCES += vis.c endif noinst_HEADERS = arc4random.h noinst_HEADERS += arc4random_freebsd.h noinst_HEADERS += arc4random_linux.h noinst_HEADERS += arc4random_netbsd.h noinst_HEADERS += arc4random_osx.h noinst_HEADERS += arc4random_solaris.h noinst_HEADERS += arc4random_win.h noinst_HEADERS += chacha_private.h openbgpd-8.8/compat/arc4random.h100644 001750 001750 00000000774 13421757372 0012402#ifndef LIBCRYPTOCOMPAT_ARC4RANDOM_H #define LIBCRYPTOCOMPAT_ARC4RANDOM_H #include #if defined(__FreeBSD__) #include "arc4random_freebsd.h" #elif defined(__linux__) #include "arc4random_linux.h" #elif defined(__NetBSD__) #include "arc4random_netbsd.h" #elif defined(__APPLE__) #include "arc4random_osx.h" #elif defined(__sun) #include "arc4random_solaris.h" #elif defined(_WIN32) #include "arc4random_win.h" #else #error "No arc4random hooks defined for this platform." #endif #endif openbgpd-8.8/compat/arc4random_freebsd.h100644 001750 001750 00000004642 13430764165 0014070/* $OpenBSD: arc4random_freebsd.h,v 1.4 2016/06/30 12:19:51 bcook Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * Stub functions for portability. */ #include #include #include static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) /* * Unfortunately, pthread_atfork() is broken on FreeBSD (at least 9 and 10) if * a program does not link to -lthr. Callbacks registered with pthread_atfork() * appear to fail silently. So, it is not always possible to detect a PID * wraparound. */ #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) static inline void _getentropy_fail(void) { raise(SIGKILL); } static volatile sig_atomic_t _rs_forked; static inline void _rs_forkhandler(void) { _rs_forked = 1; } static inline void _rs_forkdetect(void) { static pid_t _rs_pid = 0; pid_t pid = getpid(); if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { _rs_pid = pid; _rs_forked = 0; if (rs) memset(rs, 0, sizeof(*rs)); } } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) return (-1); if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { munmap(*rsp, sizeof(**rsp)); *rsp = NULL; return (-1); } _ARC4_ATFORK(_rs_forkhandler); return (0); } openbgpd-8.8/compat/arc4random_linux.h100644 001750 001750 00000005007 13544334673 0013614/* $OpenBSD: arc4random_linux.h,v 1.12 2019/07/11 10:37:28 inoguchi Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * Stub functions for portability. */ #include #include #include static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) #if defined(__GLIBC__) && !(defined(__UCLIBC__) && !defined(__ARCH_USE_MMU__)) extern void *__dso_handle; extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *); #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle) #else #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) #endif static inline void _getentropy_fail(void) { raise(SIGKILL); } static volatile sig_atomic_t _rs_forked; static inline void _rs_forkhandler(void) { _rs_forked = 1; } static inline void _rs_forkdetect(void) { static pid_t _rs_pid = 0; pid_t pid = getpid(); /* XXX unusual calls to clone() can bypass checks */ if (_rs_pid == 0 || _rs_pid == 1 || _rs_pid != pid || _rs_forked) { _rs_pid = pid; _rs_forked = 0; if (rs) memset(rs, 0, sizeof(*rs)); } } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) return (-1); if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { munmap(*rsp, sizeof(**rsp)); *rsp = NULL; return (-1); } _ARC4_ATFORK(_rs_forkhandler); return (0); } openbgpd-8.8/compat/arc4random_netbsd.h100644 001750 001750 00000004641 13430764165 0013734/* $OpenBSD: arc4random_netbsd.h,v 1.3 2016/06/30 12:19:51 bcook Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * Stub functions for portability. */ #include #include #include static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) /* * Unfortunately, pthread_atfork() is broken on FreeBSD (at least 9 and 10) if * a program does not link to -lthr. Callbacks registered with pthread_atfork() * appear to fail silently. So, it is not always possible to detect a PID * wraparound. */ #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) static inline void _getentropy_fail(void) { raise(SIGKILL); } static volatile sig_atomic_t _rs_forked; static inline void _rs_forkhandler(void) { _rs_forked = 1; } static inline void _rs_forkdetect(void) { static pid_t _rs_pid = 0; pid_t pid = getpid(); if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { _rs_pid = pid; _rs_forked = 0; if (rs) memset(rs, 0, sizeof(*rs)); } } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) return (-1); if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { munmap(*rsp, sizeof(**rsp)); *rsp = NULL; return (-1); } _ARC4_ATFORK(_rs_forkhandler); return (0); } openbgpd-8.8/compat/arc4random_osx.h100644 001750 001750 00000004240 13430764165 0013261/* $OpenBSD: arc4random_osx.h,v 1.11 2016/06/30 12:19:51 bcook Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * Stub functions for portability. */ #include #include #include static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) static inline void _getentropy_fail(void) { raise(SIGKILL); } static volatile sig_atomic_t _rs_forked; static inline void _rs_forkhandler(void) { _rs_forked = 1; } static inline void _rs_forkdetect(void) { static pid_t _rs_pid = 0; pid_t pid = getpid(); if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { _rs_pid = pid; _rs_forked = 0; if (rs) memset(rs, 0, sizeof(*rs)); } } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) return (-1); if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { munmap(*rsp, sizeof(**rsp)); *rsp = NULL; return (-1); } _ARC4_ATFORK(_rs_forkhandler); return (0); } openbgpd-8.8/compat/arc4random_solaris.h100644 001750 001750 00000004244 13430764165 0014130/* $OpenBSD: arc4random_solaris.h,v 1.10 2016/06/30 12:19:51 bcook Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * Stub functions for portability. */ #include #include #include static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) static inline void _getentropy_fail(void) { raise(SIGKILL); } static volatile sig_atomic_t _rs_forked; static inline void _rs_forkhandler(void) { _rs_forked = 1; } static inline void _rs_forkdetect(void) { static pid_t _rs_pid = 0; pid_t pid = getpid(); if (_rs_pid == 0 || _rs_pid != pid || _rs_forked) { _rs_pid = pid; _rs_forked = 0; if (rs) memset(rs, 0, sizeof(*rs)); } } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) return (-1); if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) { munmap(*rsp, sizeof(**rsp)); *rsp = NULL; return (-1); } _ARC4_ATFORK(_rs_forkhandler); return (0); } openbgpd-8.8/compat/arc4random_win.h100644 001750 001750 00000004346 13430764165 0013254/* $OpenBSD: arc4random_win.h,v 1.6 2016/06/30 12:17:29 bcook Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * Stub functions for portability. */ #include static volatile HANDLE arc4random_mtx = NULL; /* * Initialize the mutex on the first lock attempt. On collision, each thread * will attempt to allocate a mutex and compare-and-swap it into place as the * global mutex. On failure to swap in the global mutex, the mutex is closed. */ #define _ARC4_LOCK() { \ if (!arc4random_mtx) { \ HANDLE p = CreateMutex(NULL, FALSE, NULL); \ if (InterlockedCompareExchangePointer((void **)&arc4random_mtx, (void *)p, NULL)) \ CloseHandle(p); \ } \ WaitForSingleObject(arc4random_mtx, INFINITE); \ } \ #define _ARC4_UNLOCK() ReleaseMutex(arc4random_mtx) static inline void _getentropy_fail(void) { TerminateProcess(GetCurrentProcess(), 0); } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { *rsp = VirtualAlloc(NULL, sizeof(**rsp), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (*rsp == NULL) return (-1); *rsxp = VirtualAlloc(NULL, sizeof(**rsxp), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); if (*rsxp == NULL) { VirtualFree(*rsp, 0, MEM_RELEASE); *rsp = NULL; return (-1); } return (0); } static inline void _rs_forkhandler(void) { } static inline void _rs_forkdetect(void) { } openbgpd-8.8/compat/chacha_private.h100644 001750 001750 00000012406 14751151130 0013267/* chacha-merged.c version 20080118 D. J. Bernstein Public domain. */ /* $OpenBSD: chacha_private.h,v 1.3 2022/02/28 21:56:29 dtucker Exp $ */ typedef unsigned char u8; typedef unsigned int u32; typedef struct { u32 input[16]; /* could be compressed */ } chacha_ctx; #define U8C(v) (v##U) #define U32C(v) (v##U) #define U8V(v) ((u8)(v) & U8C(0xFF)) #define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF)) #define ROTL32(v, n) \ (U32V((v) << (n)) | ((v) >> (32 - (n)))) #define U8TO32_LITTLE(p) \ (((u32)((p)[0]) ) | \ ((u32)((p)[1]) << 8) | \ ((u32)((p)[2]) << 16) | \ ((u32)((p)[3]) << 24)) #define U32TO8_LITTLE(p, v) \ do { \ (p)[0] = U8V((v) ); \ (p)[1] = U8V((v) >> 8); \ (p)[2] = U8V((v) >> 16); \ (p)[3] = U8V((v) >> 24); \ } while (0) #define ROTATE(v,c) (ROTL32(v,c)) #define XOR(v,w) ((v) ^ (w)) #define PLUS(v,w) (U32V((v) + (w))) #define PLUSONE(v) (PLUS((v),1)) #define QUARTERROUND(a,b,c,d) \ a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \ c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \ a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \ c = PLUS(c,d); b = ROTATE(XOR(b,c), 7); static const char sigma[16] = "expand 32-byte k"; static const char tau[16] = "expand 16-byte k"; static void chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits) { const char *constants; x->input[4] = U8TO32_LITTLE(k + 0); x->input[5] = U8TO32_LITTLE(k + 4); x->input[6] = U8TO32_LITTLE(k + 8); x->input[7] = U8TO32_LITTLE(k + 12); if (kbits == 256) { /* recommended */ k += 16; constants = sigma; } else { /* kbits == 128 */ constants = tau; } x->input[8] = U8TO32_LITTLE(k + 0); x->input[9] = U8TO32_LITTLE(k + 4); x->input[10] = U8TO32_LITTLE(k + 8); x->input[11] = U8TO32_LITTLE(k + 12); x->input[0] = U8TO32_LITTLE(constants + 0); x->input[1] = U8TO32_LITTLE(constants + 4); x->input[2] = U8TO32_LITTLE(constants + 8); x->input[3] = U8TO32_LITTLE(constants + 12); } static void chacha_ivsetup(chacha_ctx *x,const u8 *iv) { x->input[12] = 0; x->input[13] = 0; x->input[14] = U8TO32_LITTLE(iv + 0); x->input[15] = U8TO32_LITTLE(iv + 4); } static void chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes) { u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15; u8 *ctarget = NULL; u8 tmp[64]; u_int i; if (!bytes) return; j0 = x->input[0]; j1 = x->input[1]; j2 = x->input[2]; j3 = x->input[3]; j4 = x->input[4]; j5 = x->input[5]; j6 = x->input[6]; j7 = x->input[7]; j8 = x->input[8]; j9 = x->input[9]; j10 = x->input[10]; j11 = x->input[11]; j12 = x->input[12]; j13 = x->input[13]; j14 = x->input[14]; j15 = x->input[15]; for (;;) { if (bytes < 64) { for (i = 0;i < bytes;++i) tmp[i] = m[i]; m = tmp; ctarget = c; c = tmp; } x0 = j0; x1 = j1; x2 = j2; x3 = j3; x4 = j4; x5 = j5; x6 = j6; x7 = j7; x8 = j8; x9 = j9; x10 = j10; x11 = j11; x12 = j12; x13 = j13; x14 = j14; x15 = j15; for (i = 20;i > 0;i -= 2) { QUARTERROUND( x0, x4, x8,x12) QUARTERROUND( x1, x5, x9,x13) QUARTERROUND( x2, x6,x10,x14) QUARTERROUND( x3, x7,x11,x15) QUARTERROUND( x0, x5,x10,x15) QUARTERROUND( x1, x6,x11,x12) QUARTERROUND( x2, x7, x8,x13) QUARTERROUND( x3, x4, x9,x14) } x0 = PLUS(x0,j0); x1 = PLUS(x1,j1); x2 = PLUS(x2,j2); x3 = PLUS(x3,j3); x4 = PLUS(x4,j4); x5 = PLUS(x5,j5); x6 = PLUS(x6,j6); x7 = PLUS(x7,j7); x8 = PLUS(x8,j8); x9 = PLUS(x9,j9); x10 = PLUS(x10,j10); x11 = PLUS(x11,j11); x12 = PLUS(x12,j12); x13 = PLUS(x13,j13); x14 = PLUS(x14,j14); x15 = PLUS(x15,j15); #ifndef KEYSTREAM_ONLY x0 = XOR(x0,U8TO32_LITTLE(m + 0)); x1 = XOR(x1,U8TO32_LITTLE(m + 4)); x2 = XOR(x2,U8TO32_LITTLE(m + 8)); x3 = XOR(x3,U8TO32_LITTLE(m + 12)); x4 = XOR(x4,U8TO32_LITTLE(m + 16)); x5 = XOR(x5,U8TO32_LITTLE(m + 20)); x6 = XOR(x6,U8TO32_LITTLE(m + 24)); x7 = XOR(x7,U8TO32_LITTLE(m + 28)); x8 = XOR(x8,U8TO32_LITTLE(m + 32)); x9 = XOR(x9,U8TO32_LITTLE(m + 36)); x10 = XOR(x10,U8TO32_LITTLE(m + 40)); x11 = XOR(x11,U8TO32_LITTLE(m + 44)); x12 = XOR(x12,U8TO32_LITTLE(m + 48)); x13 = XOR(x13,U8TO32_LITTLE(m + 52)); x14 = XOR(x14,U8TO32_LITTLE(m + 56)); x15 = XOR(x15,U8TO32_LITTLE(m + 60)); #endif j12 = PLUSONE(j12); if (!j12) { j13 = PLUSONE(j13); /* stopping at 2^70 bytes per nonce is user's responsibility */ } U32TO8_LITTLE(c + 0,x0); U32TO8_LITTLE(c + 4,x1); U32TO8_LITTLE(c + 8,x2); U32TO8_LITTLE(c + 12,x3); U32TO8_LITTLE(c + 16,x4); U32TO8_LITTLE(c + 20,x5); U32TO8_LITTLE(c + 24,x6); U32TO8_LITTLE(c + 28,x7); U32TO8_LITTLE(c + 32,x8); U32TO8_LITTLE(c + 36,x9); U32TO8_LITTLE(c + 40,x10); U32TO8_LITTLE(c + 44,x11); U32TO8_LITTLE(c + 48,x12); U32TO8_LITTLE(c + 52,x13); U32TO8_LITTLE(c + 56,x14); U32TO8_LITTLE(c + 60,x15); if (bytes <= 64) { if (bytes < 64) { for (i = 0;i < bytes;++i) ctarget[i] = c[i]; } x->input[12] = j12; x->input[13] = j13; return; } bytes -= 64; c += 64; #ifndef KEYSTREAM_ONLY m += 64; #endif } } openbgpd-8.8/compat/Makefile.in100644 001750 001750 00000073235 14751151140 0012232# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # # Copyright (c) 2014 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @HAVE_EXPLICIT_BZERO_FALSE@am__append_1 = explicit_bzero.c @HAVE_FREEZERO_FALSE@am__append_2 = freezero.c @HAVE_IMSG_FALSE@am__append_3 = imsg.c imsg-buffer.c @HAVE_REALLOCARRAY_FALSE@am__append_4 = reallocarray.c @HAVE_RECALLOCARRAY_FALSE@am__append_5 = recallocarray.c @HAVE_SETPROCTITLE_FALSE@am__append_6 = setproctitle.c @HAVE_STRLCAT_FALSE@am__append_7 = strlcat.c @HAVE_STRLCPY_FALSE@am__append_8 = strlcpy.c @HAVE_STRTONUM_FALSE@am__append_9 = strtonum.c @HAVE_SETRESGID_FALSE@am__append_10 = bsd-setresgid.c @HAVE_SETRESUID_FALSE@am__append_11 = bsd-setresuid.c @HAVE_ARC4RANDOM_FALSE@am__append_12 = arc4random.c \ @HAVE_ARC4RANDOM_FALSE@ arc4random_uniform.c @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_FREEBSD_TRUE@am__append_13 = getentropy_freebsd.c @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_LINUX_TRUE@am__append_14 = getentropy_linux.c \ @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_LINUX_TRUE@ sha2.c @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_NETBSD_TRUE@am__append_15 = getentropy_netbsd.c @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_DARWIN_TRUE@am__append_16 = getentropy_osx.c \ @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_DARWIN_TRUE@ sha2.c @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_SOLARIS_TRUE@am__append_17 = getentropy_solaris.c \ @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_SOLARIS_TRUE@ sha2.c @HAVE_GETRTABLE_FALSE@am__append_18 = getrtable.c @HAVE_INET_NET_PTON_FALSE@am__append_19 = inet_net_pton.c @HAVE_FMT_SCALED_FALSE@am__append_20 = fmt_scaled.c @HAVE_STRNVIS_FALSE@am__append_21 = vis.c @BROKEN_STRNVIS_TRUE@am__append_22 = vis.c subdir = compat ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = LTLIBRARIES = $(noinst_LTLIBRARIES) libcompat_la_DEPENDENCIES = am__libcompat_la_SOURCES_DIST = freezero.c imsg.c imsg-buffer.c \ reallocarray.c recallocarray.c setproctitle.c strlcat.c \ strlcpy.c strtonum.c bsd-setresgid.c bsd-setresuid.c \ arc4random.c arc4random_uniform.c getentropy_freebsd.c \ getentropy_linux.c sha2.c getentropy_netbsd.c getentropy_osx.c \ getentropy_solaris.c getrtable.c inet_net_pton.c fmt_scaled.c \ vis.c @HAVE_FREEZERO_FALSE@am__objects_1 = freezero.lo @HAVE_IMSG_FALSE@am__objects_2 = imsg.lo imsg-buffer.lo @HAVE_REALLOCARRAY_FALSE@am__objects_3 = reallocarray.lo @HAVE_RECALLOCARRAY_FALSE@am__objects_4 = recallocarray.lo @HAVE_SETPROCTITLE_FALSE@am__objects_5 = setproctitle.lo @HAVE_STRLCAT_FALSE@am__objects_6 = strlcat.lo @HAVE_STRLCPY_FALSE@am__objects_7 = strlcpy.lo @HAVE_STRTONUM_FALSE@am__objects_8 = strtonum.lo @HAVE_SETRESGID_FALSE@am__objects_9 = bsd-setresgid.lo @HAVE_SETRESUID_FALSE@am__objects_10 = bsd-setresuid.lo @HAVE_ARC4RANDOM_FALSE@am__objects_11 = arc4random.lo \ @HAVE_ARC4RANDOM_FALSE@ arc4random_uniform.lo @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_FREEBSD_TRUE@am__objects_12 = getentropy_freebsd.lo @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_LINUX_TRUE@am__objects_13 = getentropy_linux.lo \ @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_LINUX_TRUE@ sha2.lo @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_NETBSD_TRUE@am__objects_14 = getentropy_netbsd.lo @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_DARWIN_TRUE@am__objects_15 = getentropy_osx.lo \ @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_DARWIN_TRUE@ sha2.lo @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_SOLARIS_TRUE@am__objects_16 = getentropy_solaris.lo \ @HAVE_ARC4RANDOM_FALSE@@HAVE_GETENTROPY_FALSE@@HOST_SOLARIS_TRUE@ sha2.lo @HAVE_GETRTABLE_FALSE@am__objects_17 = getrtable.lo @HAVE_INET_NET_PTON_FALSE@am__objects_18 = inet_net_pton.lo @HAVE_FMT_SCALED_FALSE@am__objects_19 = fmt_scaled.lo @HAVE_STRNVIS_FALSE@am__objects_20 = vis.lo @BROKEN_STRNVIS_TRUE@am__objects_21 = vis.lo am_libcompat_la_OBJECTS = $(am__objects_1) $(am__objects_2) \ $(am__objects_3) $(am__objects_4) $(am__objects_5) \ $(am__objects_6) $(am__objects_7) $(am__objects_8) \ $(am__objects_9) $(am__objects_10) $(am__objects_11) \ $(am__objects_12) $(am__objects_13) $(am__objects_14) \ $(am__objects_15) $(am__objects_16) $(am__objects_17) \ $(am__objects_18) $(am__objects_19) $(am__objects_20) \ $(am__objects_21) libcompat_la_OBJECTS = $(am_libcompat_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = libcompatnoopt_la_LIBADD = am__libcompatnoopt_la_SOURCES_DIST = explicit_bzero.c @HAVE_EXPLICIT_BZERO_FALSE@am__objects_22 = libcompatnoopt_la-explicit_bzero.lo am_libcompatnoopt_la_OBJECTS = $(am__objects_22) libcompatnoopt_la_OBJECTS = $(am_libcompatnoopt_la_OBJECTS) libcompatnoopt_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(libcompatnoopt_la_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \ -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/arc4random.Plo \ ./$(DEPDIR)/arc4random_uniform.Plo \ ./$(DEPDIR)/bsd-setresgid.Plo ./$(DEPDIR)/bsd-setresuid.Plo \ ./$(DEPDIR)/fmt_scaled.Plo ./$(DEPDIR)/freezero.Plo \ ./$(DEPDIR)/getentropy_freebsd.Plo \ ./$(DEPDIR)/getentropy_linux.Plo \ ./$(DEPDIR)/getentropy_netbsd.Plo \ ./$(DEPDIR)/getentropy_osx.Plo \ ./$(DEPDIR)/getentropy_solaris.Plo ./$(DEPDIR)/getrtable.Plo \ ./$(DEPDIR)/imsg-buffer.Plo ./$(DEPDIR)/imsg.Plo \ ./$(DEPDIR)/inet_net_pton.Plo \ ./$(DEPDIR)/libcompatnoopt_la-explicit_bzero.Plo \ ./$(DEPDIR)/reallocarray.Plo ./$(DEPDIR)/recallocarray.Plo \ ./$(DEPDIR)/setproctitle.Plo ./$(DEPDIR)/sha2.Plo \ ./$(DEPDIR)/strlcat.Plo ./$(DEPDIR)/strlcpy.Plo \ ./$(DEPDIR)/strtonum.Plo ./$(DEPDIR)/vis.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(libcompat_la_SOURCES) $(libcompatnoopt_la_SOURCES) DIST_SOURCES = $(am__libcompat_la_SOURCES_DIST) \ $(am__libcompatnoopt_la_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac HEADERS = $(noinst_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LDFLAGS = @AM_LDFLAGS@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BGPD_USER = @BGPD_USER@ BGPLGD_USER = @BGPLGD_USER@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ WWW_USER = @WWW_USER@ YACC = @YACC@ YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwrunstatedir = @wwwrunstatedir@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -DSHA2_SMALL noinst_LTLIBRARIES = libcompat.la libcompatnoopt.la # compatibility functions that need to be built without optimizations libcompatnoopt_la_CFLAGS = -O0 libcompatnoopt_la_SOURCES = $(am__append_1) # other compatibility functions libcompat_la_SOURCES = $(am__append_2) $(am__append_3) $(am__append_4) \ $(am__append_5) $(am__append_6) $(am__append_7) \ $(am__append_8) $(am__append_9) $(am__append_10) \ $(am__append_11) $(am__append_12) $(am__append_13) \ $(am__append_14) $(am__append_15) $(am__append_16) \ $(am__append_17) $(am__append_18) $(am__append_19) \ $(am__append_20) $(am__append_21) $(am__append_22) libcompat_la_LIBADD = $(PLATFORM_LDADD) noinst_HEADERS = arc4random.h arc4random_freebsd.h arc4random_linux.h \ arc4random_netbsd.h arc4random_osx.h arc4random_solaris.h \ arc4random_win.h chacha_private.h all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign compat/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign compat/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): clean-noinstLTLIBRARIES: -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) @list='$(noinst_LTLIBRARIES)'; \ locs=`for p in $$list; do echo $$p; done | \ sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ sort -u`; \ test -z "$$locs" || { \ echo rm -f $${locs}; \ rm -f $${locs}; \ } libcompat.la: $(libcompat_la_OBJECTS) $(libcompat_la_DEPENDENCIES) $(EXTRA_libcompat_la_DEPENDENCIES) $(AM_V_CCLD)$(LINK) $(libcompat_la_OBJECTS) $(libcompat_la_LIBADD) $(LIBS) libcompatnoopt.la: $(libcompatnoopt_la_OBJECTS) $(libcompatnoopt_la_DEPENDENCIES) $(EXTRA_libcompatnoopt_la_DEPENDENCIES) $(AM_V_CCLD)$(libcompatnoopt_la_LINK) $(libcompatnoopt_la_OBJECTS) $(libcompatnoopt_la_LIBADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/arc4random.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/arc4random_uniform.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bsd-setresgid.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bsd-setresuid.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fmt_scaled.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/freezero.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getentropy_freebsd.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getentropy_linux.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getentropy_netbsd.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getentropy_osx.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getentropy_solaris.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getrtable.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imsg-buffer.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/imsg.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_net_pton.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcompatnoopt_la-explicit_bzero.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reallocarray.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/recallocarray.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/setproctitle.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha2.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strlcat.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strlcpy.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strtonum.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vis.Plo@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @echo '# dummy' >$@-t && $(am__mv) $@-t $@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< libcompatnoopt_la-explicit_bzero.lo: explicit_bzero.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcompatnoopt_la_CFLAGS) $(CFLAGS) -MT libcompatnoopt_la-explicit_bzero.lo -MD -MP -MF $(DEPDIR)/libcompatnoopt_la-explicit_bzero.Tpo -c -o libcompatnoopt_la-explicit_bzero.lo `test -f 'explicit_bzero.c' || echo '$(srcdir)/'`explicit_bzero.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcompatnoopt_la-explicit_bzero.Tpo $(DEPDIR)/libcompatnoopt_la-explicit_bzero.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='explicit_bzero.c' object='libcompatnoopt_la-explicit_bzero.lo' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcompatnoopt_la_CFLAGS) $(CFLAGS) -c -o libcompatnoopt_la-explicit_bzero.lo `test -f 'explicit_bzero.c' || echo '$(srcdir)/'`explicit_bzero.c mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(LTLIBRARIES) $(HEADERS) installdirs: install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ mostlyclean-am distclean: distclean-am -rm -f ./$(DEPDIR)/arc4random.Plo -rm -f ./$(DEPDIR)/arc4random_uniform.Plo -rm -f ./$(DEPDIR)/bsd-setresgid.Plo -rm -f ./$(DEPDIR)/bsd-setresuid.Plo -rm -f ./$(DEPDIR)/fmt_scaled.Plo -rm -f ./$(DEPDIR)/freezero.Plo -rm -f ./$(DEPDIR)/getentropy_freebsd.Plo -rm -f ./$(DEPDIR)/getentropy_linux.Plo -rm -f ./$(DEPDIR)/getentropy_netbsd.Plo -rm -f ./$(DEPDIR)/getentropy_osx.Plo -rm -f ./$(DEPDIR)/getentropy_solaris.Plo -rm -f ./$(DEPDIR)/getrtable.Plo -rm -f ./$(DEPDIR)/imsg-buffer.Plo -rm -f ./$(DEPDIR)/imsg.Plo -rm -f ./$(DEPDIR)/inet_net_pton.Plo -rm -f ./$(DEPDIR)/libcompatnoopt_la-explicit_bzero.Plo -rm -f ./$(DEPDIR)/reallocarray.Plo -rm -f ./$(DEPDIR)/recallocarray.Plo -rm -f ./$(DEPDIR)/setproctitle.Plo -rm -f ./$(DEPDIR)/sha2.Plo -rm -f ./$(DEPDIR)/strlcat.Plo -rm -f ./$(DEPDIR)/strlcpy.Plo -rm -f ./$(DEPDIR)/strtonum.Plo -rm -f ./$(DEPDIR)/vis.Plo -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/arc4random.Plo -rm -f ./$(DEPDIR)/arc4random_uniform.Plo -rm -f ./$(DEPDIR)/bsd-setresgid.Plo -rm -f ./$(DEPDIR)/bsd-setresuid.Plo -rm -f ./$(DEPDIR)/fmt_scaled.Plo -rm -f ./$(DEPDIR)/freezero.Plo -rm -f ./$(DEPDIR)/getentropy_freebsd.Plo -rm -f ./$(DEPDIR)/getentropy_linux.Plo -rm -f ./$(DEPDIR)/getentropy_netbsd.Plo -rm -f ./$(DEPDIR)/getentropy_osx.Plo -rm -f ./$(DEPDIR)/getentropy_solaris.Plo -rm -f ./$(DEPDIR)/getrtable.Plo -rm -f ./$(DEPDIR)/imsg-buffer.Plo -rm -f ./$(DEPDIR)/imsg.Plo -rm -f ./$(DEPDIR)/inet_net_pton.Plo -rm -f ./$(DEPDIR)/libcompatnoopt_la-explicit_bzero.Plo -rm -f ./$(DEPDIR)/reallocarray.Plo -rm -f ./$(DEPDIR)/recallocarray.Plo -rm -f ./$(DEPDIR)/setproctitle.Plo -rm -f ./$(DEPDIR)/sha2.Plo -rm -f ./$(DEPDIR)/strlcat.Plo -rm -f ./$(DEPDIR)/strlcpy.Plo -rm -f ./$(DEPDIR)/strtonum.Plo -rm -f ./$(DEPDIR)/vis.Plo -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-generic clean-libtool clean-noinstLTLIBRARIES \ cscopelist-am ctags ctags-am distclean distclean-compile \ distclean-generic distclean-libtool distclean-tags distdir dvi \ dvi-am html html-am info info-am install install-am \ install-data install-data-am install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man install-pdf \ install-pdf-am install-ps install-ps-am install-strip \ installcheck installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am .PRECIOUS: Makefile # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: openbgpd-8.8/compat/freezero.c100644 001750 001750 00000002176 13421757372 0012162/* * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek * Copyright (c) 2012 Matthew Dempsky * Copyright (c) 2008 Damien Miller * Copyright (c) 2000 Poul-Henning Kamp * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include void freezero(void *ptr, size_t sz) { /* This is legal. */ if (ptr == NULL) return; explicit_bzero(ptr, sz); free(ptr); } openbgpd-8.8/compat/imsg.c100644 001750 001750 00000016472 14730105010 0011260/* $OpenBSD: imsg.c,v 1.38 2024/11/29 04:35:13 tb Exp $ */ /* * Copyright (c) 2023 Claudio Jeker * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include "imsg.h" #define IMSG_ALLOW_FDPASS 0x01 #define IMSG_FD_MARK 0x80000000U static struct ibuf *imsg_parse_hdr(struct ibuf *, void *, int *); int imsgbuf_init(struct imsgbuf *imsgbuf, int fd) { imsgbuf->w = msgbuf_new_reader(IMSG_HEADER_SIZE, imsg_parse_hdr, imsgbuf); if (imsgbuf->w == NULL) return (-1); imsgbuf->pid = getpid(); imsgbuf->maxsize = MAX_IMSGSIZE; imsgbuf->fd = fd; imsgbuf->flags = 0; return (0); } void imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf) { imsgbuf->flags |= IMSG_ALLOW_FDPASS; } int imsgbuf_set_maxsize(struct imsgbuf *imsgbuf, uint32_t maxsize) { if (maxsize < IMSG_HEADER_SIZE || maxsize & IMSG_FD_MARK) { errno = EINVAL; return (-1); } imsgbuf->maxsize = maxsize; return (0); } int imsgbuf_read(struct imsgbuf *imsgbuf) { if (imsgbuf->flags & IMSG_ALLOW_FDPASS) return msgbuf_read(imsgbuf->fd, imsgbuf->w); else return ibuf_read(imsgbuf->fd, imsgbuf->w); } int imsgbuf_write(struct imsgbuf *imsgbuf) { if (imsgbuf->flags & IMSG_ALLOW_FDPASS) return msgbuf_write(imsgbuf->fd, imsgbuf->w); else return ibuf_write(imsgbuf->fd, imsgbuf->w); } int imsgbuf_flush(struct imsgbuf *imsgbuf) { while (imsgbuf_queuelen(imsgbuf) > 0) { if (imsgbuf_write(imsgbuf) == -1) return (-1); } return (0); } void imsgbuf_clear(struct imsgbuf *imsgbuf) { msgbuf_free(imsgbuf->w); imsgbuf->w = NULL; } uint32_t imsgbuf_queuelen(struct imsgbuf *imsgbuf) { return msgbuf_queuelen(imsgbuf->w); } ssize_t imsg_get(struct imsgbuf *imsgbuf, struct imsg *imsg) { struct imsg m; struct ibuf *buf; if ((buf = msgbuf_get(imsgbuf->w)) == NULL) return (0); if (ibuf_get(buf, &m.hdr, sizeof(m.hdr)) == -1) return (-1); if (ibuf_size(buf)) m.data = ibuf_data(buf); else m.data = NULL; m.buf = buf; m.hdr.len &= ~IMSG_FD_MARK; *imsg = m; return (ibuf_size(buf) + IMSG_HEADER_SIZE); } int imsg_get_ibuf(struct imsg *imsg, struct ibuf *ibuf) { if (ibuf_size(imsg->buf) == 0) { errno = EBADMSG; return (-1); } return ibuf_get_ibuf(imsg->buf, ibuf_size(imsg->buf), ibuf); } int imsg_get_data(struct imsg *imsg, void *data, size_t len) { if (len == 0) { errno = EINVAL; return (-1); } if (ibuf_size(imsg->buf) != len) { errno = EBADMSG; return (-1); } return ibuf_get(imsg->buf, data, len); } int imsg_get_fd(struct imsg *imsg) { return ibuf_fd_get(imsg->buf); } uint32_t imsg_get_id(struct imsg *imsg) { return (imsg->hdr.peerid); } size_t imsg_get_len(struct imsg *imsg) { return ibuf_size(imsg->buf); } pid_t imsg_get_pid(struct imsg *imsg) { return (imsg->hdr.pid); } uint32_t imsg_get_type(struct imsg *imsg) { return (imsg->hdr.type); } int imsg_compose(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid, int fd, const void *data, size_t datalen) { struct ibuf *wbuf; if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL) return (-1); if (imsg_add(wbuf, data, datalen) == -1) return (-1); ibuf_fd_set(wbuf, fd); imsg_close(imsgbuf, wbuf); return (1); } int imsg_composev(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { struct ibuf *wbuf; int i; size_t datalen = 0; for (i = 0; i < iovcnt; i++) datalen += iov[i].iov_len; if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL) return (-1); for (i = 0; i < iovcnt; i++) if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1) return (-1); ibuf_fd_set(wbuf, fd); imsg_close(imsgbuf, wbuf); return (1); } /* * Enqueue imsg with payload from ibuf buf. fd passing is not possible * with this function. */ int imsg_compose_ibuf(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid, struct ibuf *buf) { struct ibuf *hdrbuf = NULL; struct imsg_hdr hdr; int save_errno; if (ibuf_size(buf) + IMSG_HEADER_SIZE > imsgbuf->maxsize) { errno = ERANGE; goto fail; } hdr.type = type; hdr.len = ibuf_size(buf) + IMSG_HEADER_SIZE; hdr.peerid = id; if ((hdr.pid = pid) == 0) hdr.pid = imsgbuf->pid; if ((hdrbuf = ibuf_open(IMSG_HEADER_SIZE)) == NULL) goto fail; if (imsg_add(hdrbuf, &hdr, sizeof(hdr)) == -1) goto fail; ibuf_close(imsgbuf->w, hdrbuf); ibuf_close(imsgbuf->w, buf); return (1); fail: save_errno = errno; ibuf_free(buf); ibuf_free(hdrbuf); errno = save_errno; return (-1); } /* * Forward imsg to another channel. Any attached fd is closed. */ int imsg_forward(struct imsgbuf *imsgbuf, struct imsg *msg) { struct ibuf *wbuf; size_t len; ibuf_rewind(msg->buf); ibuf_skip(msg->buf, sizeof(msg->hdr)); len = ibuf_size(msg->buf); if ((wbuf = imsg_create(imsgbuf, msg->hdr.type, msg->hdr.peerid, msg->hdr.pid, len)) == NULL) return (-1); if (len != 0) { if (ibuf_add_ibuf(wbuf, msg->buf) == -1) { ibuf_free(wbuf); return (-1); } } imsg_close(imsgbuf, wbuf); return (1); } struct ibuf * imsg_create(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid, size_t datalen) { struct ibuf *wbuf; struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; if (datalen > imsgbuf->maxsize) { errno = ERANGE; return (NULL); } hdr.type = type; hdr.peerid = id; if ((hdr.pid = pid) == 0) hdr.pid = imsgbuf->pid; if ((wbuf = ibuf_dynamic(datalen, imsgbuf->maxsize)) == NULL) { return (NULL); } if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) return (NULL); return (wbuf); } int imsg_add(struct ibuf *msg, const void *data, size_t datalen) { if (datalen) if (ibuf_add(msg, data, datalen) == -1) { ibuf_free(msg); return (-1); } return (datalen); } void imsg_close(struct imsgbuf *imsgbuf, struct ibuf *msg) { uint32_t len; len = ibuf_size(msg); if (ibuf_fd_avail(msg)) len |= IMSG_FD_MARK; (void)ibuf_set_h32(msg, offsetof(struct imsg_hdr, len), len); ibuf_close(imsgbuf->w, msg); } void imsg_free(struct imsg *imsg) { ibuf_free(imsg->buf); } static struct ibuf * imsg_parse_hdr(struct ibuf *buf, void *arg, int *fd) { struct imsgbuf *imsgbuf = arg; struct imsg_hdr hdr; struct ibuf *b; uint32_t len; if (ibuf_get(buf, &hdr, sizeof(hdr)) == -1) return (NULL); len = hdr.len & ~IMSG_FD_MARK; if (len < IMSG_HEADER_SIZE || len > imsgbuf->maxsize) { errno = ERANGE; return (NULL); } if ((b = ibuf_open(len)) == NULL) return (NULL); if (hdr.len & IMSG_FD_MARK) { ibuf_fd_set(b, *fd); *fd = -1; } return b; } openbgpd-8.8/compat/imsg-buffer.c100644 001750 001750 00000042710 14730105010 0012521/* $OpenBSD: imsg-buffer.c,v 1.31 2024/11/26 13:57:31 claudio Exp $ */ /* * Copyright (c) 2023 Claudio Jeker * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include "imsg.h" struct msgbuf { TAILQ_HEAD(, ibuf) bufs; TAILQ_HEAD(, ibuf) rbufs; uint32_t queued; char *rbuf; struct ibuf *rpmsg; struct ibuf *(*readhdr)(struct ibuf *, void *, int *); void *rarg; size_t roff; size_t hdrsize; }; static void msgbuf_read_enqueue(struct msgbuf *, struct ibuf *); static void msgbuf_enqueue(struct msgbuf *, struct ibuf *); static void msgbuf_dequeue(struct msgbuf *, struct ibuf *); static void msgbuf_drain(struct msgbuf *, size_t); #define IBUF_FD_MARK_ON_STACK -2 struct ibuf * ibuf_open(size_t len) { struct ibuf *buf; if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if (len > 0) { if ((buf->buf = calloc(len, 1)) == NULL) { free(buf); return (NULL); } } buf->size = buf->max = len; buf->fd = -1; return (buf); } struct ibuf * ibuf_dynamic(size_t len, size_t max) { struct ibuf *buf; if (max == 0 || max < len) { errno = EINVAL; return (NULL); } if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); if (len > 0) { if ((buf->buf = calloc(len, 1)) == NULL) { free(buf); return (NULL); } } buf->size = len; buf->max = max; buf->fd = -1; return (buf); } void * ibuf_reserve(struct ibuf *buf, size_t len) { void *b; if (len > SIZE_MAX - buf->wpos) { errno = ERANGE; return (NULL); } if (buf->fd == IBUF_FD_MARK_ON_STACK) { /* can not grow stack buffers */ errno = EINVAL; return (NULL); } if (buf->wpos + len > buf->size) { unsigned char *nb; /* check if buffer is allowed to grow */ if (buf->wpos + len > buf->max) { errno = ERANGE; return (NULL); } nb = realloc(buf->buf, buf->wpos + len); if (nb == NULL) return (NULL); memset(nb + buf->size, 0, buf->wpos + len - buf->size); buf->buf = nb; buf->size = buf->wpos + len; } b = buf->buf + buf->wpos; buf->wpos += len; return (b); } int ibuf_add(struct ibuf *buf, const void *data, size_t len) { void *b; if ((b = ibuf_reserve(buf, len)) == NULL) return (-1); memcpy(b, data, len); return (0); } int ibuf_add_ibuf(struct ibuf *buf, const struct ibuf *from) { return ibuf_add(buf, ibuf_data(from), ibuf_size(from)); } int ibuf_add_n8(struct ibuf *buf, uint64_t value) { uint8_t v; if (value > UINT8_MAX) { errno = EINVAL; return (-1); } v = value; return ibuf_add(buf, &v, sizeof(v)); } int ibuf_add_n16(struct ibuf *buf, uint64_t value) { uint16_t v; if (value > UINT16_MAX) { errno = EINVAL; return (-1); } v = htobe16(value); return ibuf_add(buf, &v, sizeof(v)); } int ibuf_add_n32(struct ibuf *buf, uint64_t value) { uint32_t v; if (value > UINT32_MAX) { errno = EINVAL; return (-1); } v = htobe32(value); return ibuf_add(buf, &v, sizeof(v)); } int ibuf_add_n64(struct ibuf *buf, uint64_t value) { value = htobe64(value); return ibuf_add(buf, &value, sizeof(value)); } int ibuf_add_h16(struct ibuf *buf, uint64_t value) { uint16_t v; if (value > UINT16_MAX) { errno = EINVAL; return (-1); } v = value; return ibuf_add(buf, &v, sizeof(v)); } int ibuf_add_h32(struct ibuf *buf, uint64_t value) { uint32_t v; if (value > UINT32_MAX) { errno = EINVAL; return (-1); } v = value; return ibuf_add(buf, &v, sizeof(v)); } int ibuf_add_h64(struct ibuf *buf, uint64_t value) { return ibuf_add(buf, &value, sizeof(value)); } int ibuf_add_zero(struct ibuf *buf, size_t len) { void *b; if ((b = ibuf_reserve(buf, len)) == NULL) return (-1); memset(b, 0, len); return (0); } void * ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allow seeking between rpos and wpos */ if (ibuf_size(buf) < pos || SIZE_MAX - pos < len || ibuf_size(buf) < pos + len) { errno = ERANGE; return (NULL); } return (buf->buf + buf->rpos + pos); } int ibuf_set(struct ibuf *buf, size_t pos, const void *data, size_t len) { void *b; if ((b = ibuf_seek(buf, pos, len)) == NULL) return (-1); memcpy(b, data, len); return (0); } int ibuf_set_n8(struct ibuf *buf, size_t pos, uint64_t value) { uint8_t v; if (value > UINT8_MAX) { errno = EINVAL; return (-1); } v = value; return (ibuf_set(buf, pos, &v, sizeof(v))); } int ibuf_set_n16(struct ibuf *buf, size_t pos, uint64_t value) { uint16_t v; if (value > UINT16_MAX) { errno = EINVAL; return (-1); } v = htobe16(value); return (ibuf_set(buf, pos, &v, sizeof(v))); } int ibuf_set_n32(struct ibuf *buf, size_t pos, uint64_t value) { uint32_t v; if (value > UINT32_MAX) { errno = EINVAL; return (-1); } v = htobe32(value); return (ibuf_set(buf, pos, &v, sizeof(v))); } int ibuf_set_n64(struct ibuf *buf, size_t pos, uint64_t value) { value = htobe64(value); return (ibuf_set(buf, pos, &value, sizeof(value))); } int ibuf_set_h16(struct ibuf *buf, size_t pos, uint64_t value) { uint16_t v; if (value > UINT16_MAX) { errno = EINVAL; return (-1); } v = value; return (ibuf_set(buf, pos, &v, sizeof(v))); } int ibuf_set_h32(struct ibuf *buf, size_t pos, uint64_t value) { uint32_t v; if (value > UINT32_MAX) { errno = EINVAL; return (-1); } v = value; return (ibuf_set(buf, pos, &v, sizeof(v))); } int ibuf_set_h64(struct ibuf *buf, size_t pos, uint64_t value) { return (ibuf_set(buf, pos, &value, sizeof(value))); } void * ibuf_data(const struct ibuf *buf) { return (buf->buf + buf->rpos); } size_t ibuf_size(const struct ibuf *buf) { return (buf->wpos - buf->rpos); } size_t ibuf_left(const struct ibuf *buf) { /* on stack buffers have no space left */ if (buf->fd == IBUF_FD_MARK_ON_STACK) return (0); return (buf->max - buf->wpos); } int ibuf_truncate(struct ibuf *buf, size_t len) { if (ibuf_size(buf) >= len) { buf->wpos = buf->rpos + len; return (0); } if (buf->fd == IBUF_FD_MARK_ON_STACK) { /* only allow to truncate down for stack buffers */ errno = ERANGE; return (-1); } return ibuf_add_zero(buf, len - ibuf_size(buf)); } void ibuf_rewind(struct ibuf *buf) { buf->rpos = 0; } void ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { msgbuf_enqueue(msgbuf, buf); } void ibuf_from_buffer(struct ibuf *buf, void *data, size_t len) { memset(buf, 0, sizeof(*buf)); buf->buf = data; buf->size = buf->wpos = len; buf->fd = IBUF_FD_MARK_ON_STACK; } void ibuf_from_ibuf(struct ibuf *buf, const struct ibuf *from) { ibuf_from_buffer(buf, ibuf_data(from), ibuf_size(from)); } int ibuf_get(struct ibuf *buf, void *data, size_t len) { if (ibuf_size(buf) < len) { errno = EBADMSG; return (-1); } memcpy(data, ibuf_data(buf), len); buf->rpos += len; return (0); } int ibuf_get_ibuf(struct ibuf *buf, size_t len, struct ibuf *new) { if (ibuf_size(buf) < len) { errno = EBADMSG; return (-1); } ibuf_from_buffer(new, ibuf_data(buf), len); buf->rpos += len; return (0); } int ibuf_get_h16(struct ibuf *buf, uint16_t *value) { return ibuf_get(buf, value, sizeof(*value)); } int ibuf_get_h32(struct ibuf *buf, uint32_t *value) { return ibuf_get(buf, value, sizeof(*value)); } int ibuf_get_h64(struct ibuf *buf, uint64_t *value) { return ibuf_get(buf, value, sizeof(*value)); } int ibuf_get_n8(struct ibuf *buf, uint8_t *value) { return ibuf_get(buf, value, sizeof(*value)); } int ibuf_get_n16(struct ibuf *buf, uint16_t *value) { int rv; rv = ibuf_get(buf, value, sizeof(*value)); *value = be16toh(*value); return (rv); } int ibuf_get_n32(struct ibuf *buf, uint32_t *value) { int rv; rv = ibuf_get(buf, value, sizeof(*value)); *value = be32toh(*value); return (rv); } int ibuf_get_n64(struct ibuf *buf, uint64_t *value) { int rv; rv = ibuf_get(buf, value, sizeof(*value)); *value = be64toh(*value); return (rv); } char * ibuf_get_string(struct ibuf *buf, size_t len) { char *str; if (ibuf_size(buf) < len) { errno = EBADMSG; return (NULL); } str = strndup(ibuf_data(buf), len); if (str == NULL) return (NULL); buf->rpos += len; return (str); } int ibuf_skip(struct ibuf *buf, size_t len) { if (ibuf_size(buf) < len) { errno = EBADMSG; return (-1); } buf->rpos += len; return (0); } void ibuf_free(struct ibuf *buf) { if (buf == NULL) return; /* if buf lives on the stack abort before causing more harm */ if (buf->fd == IBUF_FD_MARK_ON_STACK) abort(); if (buf->fd >= 0) close(buf->fd); freezero(buf->buf, buf->size); free(buf); } int ibuf_fd_avail(struct ibuf *buf) { return (buf->fd >= 0); } int ibuf_fd_get(struct ibuf *buf) { int fd; /* negative fds are internal use and equivalent to -1 */ if (buf->fd < 0) return (-1); fd = buf->fd; buf->fd = -1; return (fd); } void ibuf_fd_set(struct ibuf *buf, int fd) { /* if buf lives on the stack abort before causing more harm */ if (buf->fd == IBUF_FD_MARK_ON_STACK) abort(); if (buf->fd >= 0) close(buf->fd); buf->fd = -1; if (fd >= 0) buf->fd = fd; } struct msgbuf * msgbuf_new(void) { struct msgbuf *msgbuf; if ((msgbuf = calloc(1, sizeof(*msgbuf))) == NULL) return (NULL); msgbuf->queued = 0; TAILQ_INIT(&msgbuf->bufs); TAILQ_INIT(&msgbuf->rbufs); return msgbuf; } struct msgbuf * msgbuf_new_reader(size_t hdrsz, struct ibuf *(*readhdr)(struct ibuf *, void *, int *), void *arg) { struct msgbuf *msgbuf; char *buf; if (hdrsz == 0 || hdrsz > IBUF_READ_SIZE / 2) { errno = EINVAL; return (NULL); } if ((buf = malloc(IBUF_READ_SIZE)) == NULL) return (NULL); msgbuf = msgbuf_new(); if (msgbuf == NULL) { free(buf); return (NULL); } msgbuf->rbuf = buf; msgbuf->hdrsize = hdrsz; msgbuf->readhdr = readhdr; msgbuf->rarg = arg; return (msgbuf); } void msgbuf_free(struct msgbuf *msgbuf) { if (msgbuf == NULL) return; msgbuf_clear(msgbuf); free(msgbuf->rbuf); free(msgbuf); } uint32_t msgbuf_queuelen(struct msgbuf *msgbuf) { return (msgbuf->queued); } void msgbuf_clear(struct msgbuf *msgbuf) { struct ibuf *buf; /* write side */ while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) msgbuf_dequeue(msgbuf, buf); msgbuf->queued = 0; /* read side */ while ((buf = TAILQ_FIRST(&msgbuf->rbufs)) != NULL) { TAILQ_REMOVE(&msgbuf->rbufs, buf, entry); ibuf_free(buf); } msgbuf->roff = 0; ibuf_free(msgbuf->rpmsg); msgbuf->rpmsg = NULL; } struct ibuf * msgbuf_get(struct msgbuf *msgbuf) { struct ibuf *buf; if ((buf = TAILQ_FIRST(&msgbuf->rbufs)) != NULL) TAILQ_REMOVE(&msgbuf->rbufs, buf, entry); return buf; } int ibuf_write(int fd, struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; struct ibuf *buf; unsigned int i = 0; ssize_t n; memset(&iov, 0, sizeof(iov)); TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { if (i >= IOV_MAX) break; iov[i].iov_base = ibuf_data(buf); iov[i].iov_len = ibuf_size(buf); i++; } if (i == 0) return (0); /* nothing queued */ again: if ((n = writev(fd, iov, i)) == -1) { if (errno == EINTR) goto again; if (errno == EAGAIN || errno == ENOBUFS) /* lets retry later again */ return (0); return (-1); } msgbuf_drain(msgbuf, n); return (0); } int msgbuf_write(int fd, struct msgbuf *msgbuf) { struct iovec iov[IOV_MAX]; struct ibuf *buf, *buf0 = NULL; unsigned int i = 0; ssize_t n; struct msghdr msg; struct cmsghdr *cmsg; union { struct cmsghdr hdr; char buf[CMSG_SPACE(sizeof(int))]; } cmsgbuf; memset(&iov, 0, sizeof(iov)); memset(&msg, 0, sizeof(msg)); memset(&cmsgbuf, 0, sizeof(cmsgbuf)); TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { if (i >= IOV_MAX) break; if (i > 0 && buf->fd != -1) break; iov[i].iov_base = ibuf_data(buf); iov[i].iov_len = ibuf_size(buf); i++; if (buf->fd != -1) buf0 = buf; } if (i == 0) return (0); /* nothing queued */ msg.msg_iov = iov; msg.msg_iovlen = i; if (buf0 != NULL) { msg.msg_control = (caddr_t)&cmsgbuf.buf; msg.msg_controllen = sizeof(cmsgbuf.buf); cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_len = CMSG_LEN(sizeof(int)); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; *(int *)CMSG_DATA(cmsg) = buf0->fd; } again: if ((n = sendmsg(fd, &msg, 0)) == -1) { if (errno == EINTR) goto again; if (errno == EAGAIN || errno == ENOBUFS) /* lets retry later again */ return (0); return (-1); } /* * assumption: fd got sent if sendmsg sent anything * this works because fds are passed one at a time */ if (buf0 != NULL) { close(buf0->fd); buf0->fd = -1; } msgbuf_drain(msgbuf, n); return (0); } static int ibuf_read_process(struct msgbuf *msgbuf, int fd) { struct ibuf rbuf, msg; ssize_t sz; ibuf_from_buffer(&rbuf, msgbuf->rbuf, msgbuf->roff); do { if (msgbuf->rpmsg == NULL) { if (ibuf_size(&rbuf) < msgbuf->hdrsize) break; /* get size from header */ ibuf_from_buffer(&msg, ibuf_data(&rbuf), msgbuf->hdrsize); if ((msgbuf->rpmsg = msgbuf->readhdr(&msg, msgbuf->rarg, &fd)) == NULL) goto fail; } if (ibuf_left(msgbuf->rpmsg) <= ibuf_size(&rbuf)) sz = ibuf_left(msgbuf->rpmsg); else sz = ibuf_size(&rbuf); /* neither call below can fail */ if (ibuf_get_ibuf(&rbuf, sz, &msg) == -1 || ibuf_add_ibuf(msgbuf->rpmsg, &msg) == -1) goto fail; if (ibuf_left(msgbuf->rpmsg) == 0) { msgbuf_read_enqueue(msgbuf, msgbuf->rpmsg); msgbuf->rpmsg = NULL; } } while (ibuf_size(&rbuf) > 0); if (ibuf_size(&rbuf) > 0) memmove(msgbuf->rbuf, ibuf_data(&rbuf), ibuf_size(&rbuf)); msgbuf->roff = ibuf_size(&rbuf); if (fd != -1) close(fd); return (1); fail: /* XXX how to properly clean up is unclear */ if (fd != -1) close(fd); return (-1); } int ibuf_read(int fd, struct msgbuf *msgbuf) { struct iovec iov; ssize_t n; if (msgbuf->rbuf == NULL) { errno = EINVAL; return (-1); } iov.iov_base = msgbuf->rbuf + msgbuf->roff; iov.iov_len = IBUF_READ_SIZE - msgbuf->roff; again: if ((n = readv(fd, &iov, 1)) == -1) { if (errno == EINTR) goto again; if (errno == EAGAIN) /* lets retry later again */ return (1); return (-1); } if (n == 0) /* connection closed */ return (0); msgbuf->roff += n; /* new data arrived, try to process it */ return (ibuf_read_process(msgbuf, -1)); } int msgbuf_read(int fd, struct msgbuf *msgbuf) { struct msghdr msg; struct cmsghdr *cmsg; union { struct cmsghdr hdr; char buf[CMSG_SPACE(sizeof(int) * 1)]; } cmsgbuf; struct iovec iov; ssize_t n; int fdpass = -1; if (msgbuf->rbuf == NULL) { errno = EINVAL; return (-1); } memset(&msg, 0, sizeof(msg)); memset(&cmsgbuf, 0, sizeof(cmsgbuf)); iov.iov_base = msgbuf->rbuf + msgbuf->roff; iov.iov_len = IBUF_READ_SIZE - msgbuf->roff; msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = &cmsgbuf.buf; msg.msg_controllen = sizeof(cmsgbuf.buf); again: if ((n = recvmsg(fd, &msg, 0)) == -1) { if (errno == EINTR) goto again; if (errno == EMSGSIZE) /* * Not enough fd slots: fd passing failed, retry * to receive the message without fd. * imsg_get_fd() will return -1 in that case. */ goto again; if (errno == EAGAIN) /* lets retry later again */ return (1); return (-1); } if (n == 0) /* connection closed */ return (0); msgbuf->roff += n; for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = CMSG_NXTHDR(&msg, cmsg)) { if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { int i, j, f; /* * We only accept one file descriptor. Due to C * padding rules, our control buffer might contain * more than one fd, and we must close them. */ j = ((char *)cmsg + cmsg->cmsg_len - (char *)CMSG_DATA(cmsg)) / sizeof(int); for (i = 0; i < j; i++) { f = ((int *)CMSG_DATA(cmsg))[i]; if (i == 0) fdpass = f; else close(f); } } /* we do not handle other ctl data level */ } /* new data arrived, try to process it */ return (ibuf_read_process(msgbuf, fdpass)); } static void msgbuf_read_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { /* if buf lives on the stack abort before causing more harm */ if (buf->fd == IBUF_FD_MARK_ON_STACK) abort(); TAILQ_INSERT_TAIL(&msgbuf->rbufs, buf, entry); } static void msgbuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { /* if buf lives on the stack abort before causing more harm */ if (buf->fd == IBUF_FD_MARK_ON_STACK) abort(); TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } static void msgbuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); msgbuf->queued--; ibuf_free(buf); } static void msgbuf_drain(struct msgbuf *msgbuf, size_t n) { struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; buf = next) { next = TAILQ_NEXT(buf, entry); if (n >= ibuf_size(buf)) { n -= ibuf_size(buf); msgbuf_dequeue(msgbuf, buf); } else { buf->rpos += n; n = 0; } } } openbgpd-8.8/compat/reallocarray.c100644 001750 001750 00000002523 14751151130 0013000/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */ /* * Copyright (c) 2008 Otto Moerbeek * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include /* * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW */ #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) void * reallocarray(void *optr, size_t nmemb, size_t size) { if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && nmemb > 0 && SIZE_MAX / nmemb < size) { errno = ENOMEM; return NULL; } return realloc(optr, size * nmemb); } openbgpd-8.8/compat/recallocarray.c100644 001750 001750 00000004330 14751151130 0013141/* $OpenBSD: recallocarray.c,v 1.2 2021/03/18 11:16:58 claudio Exp $ */ /* * Copyright (c) 2008, 2017 Otto Moerbeek * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include /* * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW */ #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) void * recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) { size_t oldsize, newsize; void *newptr; if (ptr == NULL) return calloc(newnmemb, size); if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && newnmemb > 0 && SIZE_MAX / newnmemb < size) { errno = ENOMEM; return NULL; } newsize = newnmemb * size; if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && oldnmemb > 0 && SIZE_MAX / oldnmemb < size) { errno = EINVAL; return NULL; } oldsize = oldnmemb * size; /* * Don't bother too much if we're shrinking just a bit, * we do not shrink for series of small steps, oh well. */ if (newsize <= oldsize) { size_t d = oldsize - newsize; if (d < oldsize / 2 && d < (size_t)getpagesize()) { memset((char *)ptr + newsize, 0, d); return ptr; } } newptr = malloc(newsize); if (newptr == NULL) return NULL; if (newsize > oldsize) { memcpy(newptr, ptr, oldsize); memset((char *)newptr + oldsize, 0, newsize - oldsize); } else memcpy(newptr, ptr, newsize); explicit_bzero(ptr, oldsize); free(ptr); return newptr; } openbgpd-8.8/compat/setproctitle.c100644 001750 001750 00000010655 13421757372 0013063/* Based on conf.c from UCB sendmail 8.8.8 */ /* * Copyright 2003 Damien Miller * Copyright (c) 1983, 1995-1997 Eric P. Allman * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef HAVE_SETPROCTITLE #include #include #include #include #ifdef HAVE_SYS_PSTAT_H #include #endif #include #define SPT_NONE 0 /* don't use it at all */ #define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */ #define SPT_REUSEARGV 2 /* cover argv with title information */ #ifndef SPT_TYPE # define SPT_TYPE SPT_NONE #endif #ifndef SPT_PADCHAR # define SPT_PADCHAR '\0' #endif #if SPT_TYPE == SPT_REUSEARGV static char *argv_start = NULL; static size_t argv_env_len = 0; #endif #endif /* HAVE_SETPROCTITLE */ void compat_init_setproctitle(int argc, char *argv[]) { #if !defined(HAVE_SETPROCTITLE) && \ defined(SPT_TYPE) && SPT_TYPE == SPT_REUSEARGV extern char **environ; char *lastargv = NULL; char **envp = environ; int i; /* * NB: This assumes that argv has already been copied out of the * way. This is true for sshd, but may not be true for other * programs. Beware. */ if (argc == 0 || argv[0] == NULL) return; /* Fail if we can't allocate room for the new environment */ for (i = 0; envp[i] != NULL; i++) ; if ((environ = calloc(i + 1, sizeof(*environ))) == NULL) { environ = envp; /* put it back */ return; } /* * Find the last argv string or environment variable within * our process memory area. */ for (i = 0; i < argc; i++) { if (lastargv == NULL || lastargv + 1 == argv[i]) lastargv = argv[i] + strlen(argv[i]); } for (i = 0; envp[i] != NULL; i++) { if (lastargv + 1 == envp[i]) lastargv = envp[i] + strlen(envp[i]); } argv[1] = NULL; argv_start = argv[0]; argv_env_len = lastargv - argv[0] - 1; /* * Copy environment * XXX - will truncate env on strdup fail */ for (i = 0; envp[i] != NULL; i++) environ[i] = strdup(envp[i]); environ[i] = NULL; #endif /* SPT_REUSEARGV */ } #ifndef HAVE_SETPROCTITLE void setproctitle(const char *fmt, ...) { #if SPT_TYPE != SPT_NONE va_list ap; char buf[1024]; size_t len; int r; extern char *__progname; #if SPT_TYPE == SPT_PSTAT union pstun pst; #endif #if SPT_TYPE == SPT_REUSEARGV if (argv_env_len <= 0) return; #endif strlcpy(buf, __progname, sizeof(buf)); r = -1; va_start(ap, fmt); if (fmt != NULL) { len = strlcat(buf, ": ", sizeof(buf)); if (len < sizeof(buf)) r = vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); } va_end(ap); if (r == -1 || (size_t)r >= sizeof(buf) - len) return; #if SPT_TYPE == SPT_PSTAT pst.pst_command = buf; pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0); #elif SPT_TYPE == SPT_REUSEARGV /* debug("setproctitle: copy \"%s\" into len %d", buf, argv_env_len); */ len = strlcpy(argv_start, buf, argv_env_len); for(; len < argv_env_len; len++) argv_start[len] = SPT_PADCHAR; #endif #endif /* SPT_NONE */ } #endif /* HAVE_SETPROCTITLE */ openbgpd-8.8/compat/strlcat.c100644 001750 001750 00000003314 14751151130 0011773/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ /* * Copyright (c) 1998, 2015 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include /* * Appends src to string dst of size dsize (unlike strncat, dsize is the * full size of dst, not space left). At most dsize-1 characters * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). * Returns strlen(src) + MIN(dsize, strlen(initial dst)). * If retval >= dsize, truncation occurred. */ size_t strlcat(char *dst, const char *src, size_t dsize) { const char *odst = dst; const char *osrc = src; size_t n = dsize; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end. */ while (n-- != 0 && *dst != '\0') dst++; dlen = dst - odst; n = dsize - dlen; if (n-- == 0) return(dlen + strlen(src)); while (*src != '\0') { if (n != 0) { *dst++ = *src; n--; } src++; } *dst = '\0'; return(dlen + (src - osrc)); /* count does not include NUL */ } openbgpd-8.8/compat/strlcpy.c100644 001750 001750 00000003071 14751151130 0012017/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ /* * Copyright (c) 1998, 2015 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include /* * Copy string src to buffer dst of size dsize. At most dsize-1 * chars will be copied. Always NUL terminates (unless dsize == 0). * Returns strlen(src); if retval >= dsize, truncation occurred. */ size_t strlcpy(char *dst, const char *src, size_t dsize) { const char *osrc = src; size_t nleft = dsize; /* Copy as many bytes as will fit. */ if (nleft != 0) { while (--nleft != 0) { if ((*dst++ = *src++) == '\0') break; } } /* Not enough room in dst, add NUL and traverse rest of src. */ if (nleft == 0) { if (dsize != 0) *dst = '\0'; /* NUL-terminate dst */ while (*src++) ; } return(src - osrc - 1); /* count does not include NUL */ } openbgpd-8.8/compat/strtonum.c100644 001750 001750 00000003354 14751151130 0012216/* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */ /* * Copyright (c) 2004 Ted Unangst and Todd Miller * All rights reserved. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #define INVALID 1 #define TOOSMALL 2 #define TOOLARGE 3 long long strtonum(const char *numstr, long long minval, long long maxval, const char **errstrp) { long long ll = 0; int error = 0; char *ep; struct errval { const char *errstr; int err; } ev[4] = { { NULL, 0 }, { "invalid", EINVAL }, { "too small", ERANGE }, { "too large", ERANGE }, }; ev[0].err = errno; errno = 0; if (minval > maxval) { error = INVALID; } else { ll = strtoll(numstr, &ep, 10); if (numstr == ep || *ep != '\0') error = INVALID; else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval) error = TOOSMALL; else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval) error = TOOLARGE; } if (errstrp != NULL) *errstrp = ev[error].errstr; errno = ev[error].err; if (error) ll = 0; return (ll); } openbgpd-8.8/compat/bsd-setresgid.c100644 001750 001750 00000002266 13421757372 0013100/* * Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au). * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include int setresgid(gid_t rgid, gid_t egid, gid_t sgid) { /* this is the only configuration tested */ if (rgid != egid || egid != sgid) return -1; # if defined(HAVE_SETREGID) && !defined(BROKEN_SETREGID) if (setregid(rgid, egid) == -1) return -1; # else if (setegid(egid) == -1) return -1; if (setgid(rgid) == -1) return -1; # endif return 0; } openbgpd-8.8/compat/bsd-setresuid.c100644 001750 001750 00000003404 13421757372 0013111/* * Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au). * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include int setresuid(uid_t ruid, uid_t euid, uid_t suid) { uid_t ouid; int ret = -1; /* Allow only the tested configuration. */ if (ruid != euid || euid != suid) { errno = ENOSYS; return -1; } ouid = getuid(); # if defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID) if ((ret = setreuid(euid, euid)) == -1) return -1; # else # ifndef SETEUID_BREAKS_SETUID if (seteuid(euid) == -1) return -1; # endif if ((ret = setuid(ruid)) == -1) return -1; # endif /* * When real, effective and saved uids are the same and we have * changed uids, sanity check that we cannot restore the old uid. */ if (ruid == euid && euid == suid && ouid != ruid && setuid(ouid) != -1 && seteuid(ouid) != -1) { errno = EINVAL; return -1; } /* * Finally, check that the real and effective uids are what we * expect. */ if (getuid() != ruid || geteuid() != euid) { errno = EACCES; return -1; } return ret; } openbgpd-8.8/compat/arc4random.c100644 001750 001750 00000011503 14751151130 0012350/* $OpenBSD: arc4random.c,v 1.58 2022/07/31 13:41:45 tb Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* * ChaCha based random number generator for OpenBSD. */ #include #include #include #include #include #include #include #include #include #define KEYSTREAM_ONLY #include "chacha_private.h" #define minimum(a, b) ((a) < (b) ? (a) : (b)) #if defined(__GNUC__) || defined(_MSC_VER) #define inline __inline #else /* __GNUC__ || _MSC_VER */ #define inline #endif /* !__GNUC__ && !_MSC_VER */ #define KEYSZ 32 #define IVSZ 8 #define BLOCKSZ 64 #define RSBUFSZ (16*BLOCKSZ) #define REKEY_BASE (1024*1024) /* NB. should be a power of 2 */ /* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */ static struct _rs { size_t rs_have; /* valid bytes at end of rs_buf */ size_t rs_count; /* bytes till reseed */ } *rs; /* Maybe be preserved in fork children, if _rs_allocate() decides. */ static struct _rsx { chacha_ctx rs_chacha; /* chacha context for random keystream */ u_char rs_buf[RSBUFSZ]; /* keystream blocks */ } *rsx; static inline int _rs_allocate(struct _rs **, struct _rsx **); static inline void _rs_forkdetect(void); #include "arc4random.h" static inline void _rs_rekey(u_char *dat, size_t datlen); static inline void _rs_init(u_char *buf, size_t n) { if (n < KEYSZ + IVSZ) return; if (rs == NULL) { if (_rs_allocate(&rs, &rsx) == -1) _exit(1); } chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8); chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ); } static void _rs_stir(void) { u_char rnd[KEYSZ + IVSZ]; uint32_t rekey_fuzz = 0; if (getentropy(rnd, sizeof rnd) == -1) _getentropy_fail(); if (!rs) _rs_init(rnd, sizeof(rnd)); else _rs_rekey(rnd, sizeof(rnd)); explicit_bzero(rnd, sizeof(rnd)); /* discard source seed */ /* invalidate rs_buf */ rs->rs_have = 0; memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); /* rekey interval should not be predictable */ chacha_encrypt_bytes(&rsx->rs_chacha, (uint8_t *)&rekey_fuzz, (uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz)); rs->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE); } static inline void _rs_stir_if_needed(size_t len) { _rs_forkdetect(); if (!rs || rs->rs_count <= len) _rs_stir(); if (rs->rs_count <= len) rs->rs_count = 0; else rs->rs_count -= len; } static inline void _rs_rekey(u_char *dat, size_t datlen) { #ifndef KEYSTREAM_ONLY memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); #endif /* fill rs_buf with the keystream */ chacha_encrypt_bytes(&rsx->rs_chacha, rsx->rs_buf, rsx->rs_buf, sizeof(rsx->rs_buf)); /* mix in optional user provided data */ if (dat) { size_t i, m; m = minimum(datlen, KEYSZ + IVSZ); for (i = 0; i < m; i++) rsx->rs_buf[i] ^= dat[i]; } /* immediately reinit for backtracking resistance */ _rs_init(rsx->rs_buf, KEYSZ + IVSZ); memset(rsx->rs_buf, 0, KEYSZ + IVSZ); rs->rs_have = sizeof(rsx->rs_buf) - KEYSZ - IVSZ; } static inline void _rs_random_buf(void *_buf, size_t n) { u_char *buf = (u_char *)_buf; u_char *keystream; size_t m; _rs_stir_if_needed(n); while (n > 0) { if (rs->rs_have > 0) { m = minimum(n, rs->rs_have); keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have; memcpy(buf, keystream, m); memset(keystream, 0, m); buf += m; n -= m; rs->rs_have -= m; } if (rs->rs_have == 0) _rs_rekey(NULL, 0); } } static inline void _rs_random_u32(uint32_t *val) { u_char *keystream; _rs_stir_if_needed(sizeof(*val)); if (rs->rs_have < sizeof(*val)) _rs_rekey(NULL, 0); keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have; memcpy(val, keystream, sizeof(*val)); memset(keystream, 0, sizeof(*val)); rs->rs_have -= sizeof(*val); } uint32_t arc4random(void) { uint32_t val; _ARC4_LOCK(); _rs_random_u32(&val); _ARC4_UNLOCK(); return val; } void arc4random_buf(void *buf, size_t n) { _ARC4_LOCK(); _rs_random_buf(buf, n); _ARC4_UNLOCK(); } openbgpd-8.8/compat/arc4random_uniform.c100644 001750 001750 00000003403 14751151130 0014107/* $OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $ */ /* * Copyright (c) 2008, Damien Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include /* * Calculate a uniformly distributed random number less than upper_bound * avoiding "modulo bias". * * Uniformity is achieved by generating new random numbers until the one * returned is outside the range [0, 2**32 % upper_bound). This * guarantees the selected random number will be inside * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) * after reduction modulo upper_bound. */ uint32_t arc4random_uniform(uint32_t upper_bound) { uint32_t r, min; if (upper_bound < 2) return 0; /* 2**32 % x == (2**32 - x) % x */ min = -upper_bound % upper_bound; /* * This could theoretically loop forever but each retry has * p > 0.5 (worst case, usually far better) of selecting a * number inside the range we need, so it should rarely need * to re-roll. */ for (;;) { r = arc4random(); if (r >= min) break; } return r % upper_bound; } openbgpd-8.8/compat/getentropy_freebsd.c100644 001750 001750 00000003121 14751151130 0014205/* $OpenBSD: getentropy_freebsd.c,v 1.4 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 2014 Pawel Jakub Dawidek * Copyright (c) 2014 Brent Cook * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Emulation of getentropy(2) as documented at: * http://man.openbsd.org/getentropy.2 */ #include #include #include #include /* * Derived from lib/libc/gen/arc4random.c from FreeBSD. */ static size_t getentropy_sysctl(u_char *buf, size_t size) { const int mib[2] = { CTL_KERN, KERN_ARND }; size_t len, done; done = 0; do { len = size; if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) return (done); done += len; buf += len; size -= len; } while (size > 0); return (done); } int getentropy(void *buf, size_t len) { if (len <= 256 && getentropy_sysctl(buf, len) == len) return (0); errno = EIO; return (-1); } openbgpd-8.8/compat/getentropy_linux.c100644 001750 001750 00000031033 14751151130 0013735/* $OpenBSD: getentropy_linux.c,v 1.48 2021/10/24 21:24:20 deraadt Exp $ */ /* * Copyright (c) 2014 Theo de Raadt * Copyright (c) 2014 Bob Beck * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Emulation of getentropy(2) as documented at: * http://man.openbsd.org/getentropy.2 */ #define _POSIX_C_SOURCE 199309L #define _GNU_SOURCE 1 #include #include #include #include #include #ifdef SYS__sysctl #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_GETAUXVAL #include #endif #include #define REPEAT 5 #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) #define HX(a, b) \ do { \ if ((a)) \ HD(errno); \ else \ HD(b); \ } while (0) #define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) #define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) #define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*))) int getentropy(void *buf, size_t len); #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) static int getentropy_getrandom(void *buf, size_t len); #endif static int getentropy_urandom(void *buf, size_t len); #ifdef SYS__sysctl static int getentropy_sysctl(void *buf, size_t len); #endif static int getentropy_fallback(void *buf, size_t len); static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); int getentropy(void *buf, size_t len) { int ret = -1; if (len > 256) { errno = EIO; return (-1); } #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) /* * Try descriptor-less getrandom(), in non-blocking mode. * * The design of Linux getrandom is broken. It has an * uninitialized phase coupled with blocking behaviour, which * is unacceptable from within a library at boot time without * possible recovery. See http://bugs.python.org/issue26839#msg267745 */ ret = getentropy_getrandom(buf, len); if (ret != -1) return (ret); #endif /* * Try to get entropy with /dev/urandom * * This can fail if the process is inside a chroot or if file * descriptors are exhausted. */ ret = getentropy_urandom(buf, len); if (ret != -1) return (ret); #ifdef SYS__sysctl /* * Try to use sysctl CTL_KERN, KERN_RANDOM, RANDOM_UUID. * sysctl is a failsafe API, so it guarantees a result. This * should work inside a chroot, or when file descriptors are * exhausted. * * However this can fail if the Linux kernel removes support * for sysctl. Starting in 2007, there have been efforts to * deprecate the sysctl API/ABI, and push callers towards use * of the chroot-unavailable fd-using /proc mechanism -- * essentially the same problems as /dev/urandom. * * Numerous setbacks have been encountered in their deprecation * schedule, so as of June 2014 the kernel ABI still exists on * most Linux architectures. The sysctl() stub in libc is missing * on some systems. There are also reports that some kernels * spew messages to the console. */ ret = getentropy_sysctl(buf, len); if (ret != -1) return (ret); #endif /* SYS__sysctl */ /* * Entropy collection via /dev/urandom and sysctl have failed. * * No other API exists for collecting entropy. See the large * comment block above. * * We have very few options: * - Even syslog_r is unsafe to call at this low level, so * there is no way to alert the user or program. * - Cannot call abort() because some systems have unsafe * corefiles. * - Could raise(SIGKILL) resulting in silent program termination. * - Return EIO, to hint that arc4random's stir function * should raise(SIGKILL) * - Do the best under the circumstances.... * * This code path exists to bring light to the issue that Linux * still does not provide a failsafe API for entropy collection. * * We hope this demonstrates that Linux should either retain their * sysctl ABI, or consider providing a new failsafe API which * works in a chroot or when file descriptors are exhausted. */ #undef FAIL_INSTEAD_OF_TRYING_FALLBACK #ifdef FAIL_INSTEAD_OF_TRYING_FALLBACK raise(SIGKILL); #endif ret = getentropy_fallback(buf, len); if (ret != -1) return (ret); errno = EIO; return (ret); } #if defined(SYS_getrandom) && defined(GRND_NONBLOCK) static int getentropy_getrandom(void *buf, size_t len) { int pre_errno = errno; int ret; if (len > 256) return (-1); do { ret = syscall(SYS_getrandom, buf, len, GRND_NONBLOCK); } while (ret == -1 && errno == EINTR); if (ret != len) return (-1); errno = pre_errno; return (0); } #endif static int getentropy_urandom(void *buf, size_t len) { struct stat st; size_t i; int fd, cnt, flags; int save_errno = errno; start: flags = O_RDONLY; #ifdef O_NOFOLLOW flags |= O_NOFOLLOW; #endif #ifdef O_CLOEXEC flags |= O_CLOEXEC; #endif fd = open("/dev/urandom", flags); if (fd == -1) { if (errno == EINTR) goto start; goto nodevrandom; } #ifndef O_CLOEXEC fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); #endif /* Lightly verify that the device node looks sane */ if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode)) { close(fd); goto nodevrandom; } if (ioctl(fd, RNDGETENTCNT, &cnt) == -1) { close(fd); goto nodevrandom; } for (i = 0; i < len; ) { size_t wanted = len - i; ssize_t ret = read(fd, (char *)buf + i, wanted); if (ret == -1) { if (errno == EAGAIN || errno == EINTR) continue; close(fd); goto nodevrandom; } i += ret; } close(fd); errno = save_errno; return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); } #ifdef SYS__sysctl static int getentropy_sysctl(void *buf, size_t len) { static int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID }; size_t i; int save_errno = errno; for (i = 0; i < len; ) { size_t chunk = MINIMUM(len - i, 16); /* SYS__sysctl because some systems already removed sysctl() */ struct __sysctl_args args = { .name = mib, .nlen = 3, .oldval = (char *)buf + i, .oldlenp = &chunk, }; if (syscall(SYS__sysctl, &args) != 0) goto sysctlfailed; i += chunk; } errno = save_errno; return (0); /* satisfied */ sysctlfailed: errno = EIO; return (-1); } #endif /* SYS__sysctl */ static const int cl[] = { CLOCK_REALTIME, #ifdef CLOCK_MONOTONIC CLOCK_MONOTONIC, #endif #ifdef CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC_RAW, #endif #ifdef CLOCK_TAI CLOCK_TAI, #endif #ifdef CLOCK_VIRTUAL CLOCK_VIRTUAL, #endif #ifdef CLOCK_UPTIME CLOCK_UPTIME, #endif #ifdef CLOCK_PROCESS_CPUTIME_ID CLOCK_PROCESS_CPUTIME_ID, #endif #ifdef CLOCK_THREAD_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID, #endif }; static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) { SHA512_CTX *ctx = data; SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); return (0); } static int getentropy_fallback(void *buf, size_t len) { uint8_t results[SHA512_DIGEST_LENGTH]; int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat; static int cnt; struct timespec ts; struct timeval tv; struct rusage ru; sigset_t sigset; struct stat st; SHA512_CTX ctx; static pid_t lastpid; pid_t pid; size_t i, ii, m; char *p; pid = getpid(); if (lastpid == pid) { faster = 1; repeat = 2; } else { faster = 0; lastpid = pid; repeat = REPEAT; } for (i = 0; i < len; ) { int j; SHA512_Init(&ctx); for (j = 0; j < repeat; j++) { HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } dl_iterate_phdr(getentropy_phdr, &ctx); for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); HX((pid = getpid()) == -1, pid); HX((pid = getsid(pid)) == -1, pid); HX((pid = getppid()) == -1, pid); HX((pid = getpgid(0)) == -1, pid); HX((e = getpriority(0, 0)) == -1, e); if (!faster) { ts.tv_sec = 0; ts.tv_nsec = 1; (void) nanosleep(&ts, NULL); } HX(sigpending(&sigset) == -1, sigset); HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; HD(p); /* the addr of errno */ if (i == 0) { struct sockaddr_storage ss; struct statvfs stvfs; struct termios tios; struct statfs stfs; socklen_t ssl; off_t off; /* * Prime-sized mappings encourage fragmentation; * thus exposing some address entropy. */ struct mm { size_t npg; void *p; } mm[] = { { 17, MAP_FAILED }, { 3, MAP_FAILED }, { 11, MAP_FAILED }, { 2, MAP_FAILED }, { 5, MAP_FAILED }, { 3, MAP_FAILED }, { 7, MAP_FAILED }, { 1, MAP_FAILED }, { 57, MAP_FAILED }, { 3, MAP_FAILED }, { 131, MAP_FAILED }, { 1, MAP_FAILED }, }; for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { HX(mm[m].p = mmap(NULL, mm[m].npg * pgs, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, (off_t)0), mm[m].p); if (mm[m].p != MAP_FAILED) { size_t mo; /* Touch some memory... */ p = mm[m].p; mo = cnt % (mm[m].npg * pgs - 1); p[mo] = 1; cnt += (int)((long)(mm[m].p) / pgs); } /* Check cnts and times... */ for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) { HX((e = clock_gettime(cl[ii], &ts)) == -1, ts); if (e != -1) cnt += (int)ts.tv_nsec; } HX((e = getrusage(RUSAGE_SELF, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { if (mm[m].p != MAP_FAILED) munmap(mm[m].p, mm[m].npg * pgs); mm[m].p = MAP_FAILED; } HX(stat(".", &st) == -1, st); HX(statvfs(".", &stvfs) == -1, stvfs); HX(statfs(".", &stfs) == -1, stfs); HX(stat("/", &st) == -1, st); HX(statvfs("/", &stvfs) == -1, stvfs); HX(statfs("/", &stfs) == -1, stfs); HX((e = fstat(0, &st)) == -1, st); if (e == -1) { if (S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { HX(fstatvfs(0, &stvfs) == -1, stvfs); HX(fstatfs(0, &stfs) == -1, stfs); HX((off = lseek(0, (off_t)0, SEEK_CUR)) < 0, off); } if (S_ISCHR(st.st_mode)) { HX(tcgetattr(0, &tios) == -1, tios); } else if (S_ISSOCK(st.st_mode)) { memset(&ss, 0, sizeof ss); ssl = sizeof(ss); HX(getpeername(0, (void *)&ss, &ssl) == -1, ss); } } HX((e = getrusage(RUSAGE_CHILDREN, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } else { /* Subsequent hashes absorb previous result */ HD(results); } HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HD(cnt); } #ifdef HAVE_GETAUXVAL #ifdef AT_RANDOM /* Not as random as you think but we take what we are given */ p = (char *) getauxval(AT_RANDOM); if (p) HR(p, 16); #endif #ifdef AT_SYSINFO_EHDR p = (char *) getauxval(AT_SYSINFO_EHDR); if (p) HR(p, pgs); #endif #ifdef AT_BASE p = (char *) getauxval(AT_BASE); if (p) HD(p); #endif #endif SHA512_Final(results, &ctx); memcpy((char *)buf + i, results, MINIMUM(sizeof(results), len - i)); i += MINIMUM(sizeof(results), len - i); } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); errno = save_errno; return (0); /* satisfied */ } openbgpd-8.8/compat/sha2.c100644 001750 001750 00000064633 14751151130 0011167/* $OpenBSD: sha2.c,v 1.28 2019/07/23 12:35:22 dtucker Exp $ */ /* * FILE: sha2.c * AUTHOR: Aaron D. Gifford * * Copyright (c) 2000-2001, Aaron D. Gifford * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holder nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $ */ #include #include #include /* * UNROLLED TRANSFORM LOOP NOTE: * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform * loop version for the hash transform rounds (defined using macros * later in this file). Either define on the command line, for example: * * cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c * * or define below: * * #define SHA2_UNROLL_TRANSFORM * */ #ifndef SHA2_SMALL #if defined(__amd64__) || defined(__i386__) #define SHA2_UNROLL_TRANSFORM #endif #endif /*** SHA-224/256/384/512 Machine Architecture Definitions *****************/ /* * BYTE_ORDER NOTE: * * Please make sure that your system defines BYTE_ORDER. If your * architecture is little-endian, make sure it also defines * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are * equivalent. * * If your system does not define the above, then you can do so by * hand like this: * * #define LITTLE_ENDIAN 1234 * #define BIG_ENDIAN 4321 * * And for little-endian machines, add: * * #define BYTE_ORDER LITTLE_ENDIAN * * Or for big-endian machines: * * #define BYTE_ORDER BIG_ENDIAN * * The FreeBSD machine this was written on defines BYTE_ORDER * appropriately by including (which in turn includes * where the appropriate definitions are actually * made). */ #if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN) #error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN #endif /*** SHA-224/256/384/512 Various Length Definitions ***********************/ /* NOTE: Most of these are in sha2.h */ #define SHA224_SHORT_BLOCK_LENGTH (SHA224_BLOCK_LENGTH - 8) #define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8) #define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16) #define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16) /*** ENDIAN SPECIFIC COPY MACROS **************************************/ #define BE_8_TO_32(dst, cp) do { \ (dst) = (u_int32_t)(cp)[3] | ((u_int32_t)(cp)[2] << 8) | \ ((u_int32_t)(cp)[1] << 16) | ((u_int32_t)(cp)[0] << 24); \ } while(0) #define BE_8_TO_64(dst, cp) do { \ (dst) = (u_int64_t)(cp)[7] | ((u_int64_t)(cp)[6] << 8) | \ ((u_int64_t)(cp)[5] << 16) | ((u_int64_t)(cp)[4] << 24) | \ ((u_int64_t)(cp)[3] << 32) | ((u_int64_t)(cp)[2] << 40) | \ ((u_int64_t)(cp)[1] << 48) | ((u_int64_t)(cp)[0] << 56); \ } while (0) #define BE_64_TO_8(cp, src) do { \ (cp)[0] = (src) >> 56; \ (cp)[1] = (src) >> 48; \ (cp)[2] = (src) >> 40; \ (cp)[3] = (src) >> 32; \ (cp)[4] = (src) >> 24; \ (cp)[5] = (src) >> 16; \ (cp)[6] = (src) >> 8; \ (cp)[7] = (src); \ } while (0) #define BE_32_TO_8(cp, src) do { \ (cp)[0] = (src) >> 24; \ (cp)[1] = (src) >> 16; \ (cp)[2] = (src) >> 8; \ (cp)[3] = (src); \ } while (0) /* * Macro for incrementally adding the unsigned 64-bit integer n to the * unsigned 128-bit integer (represented using a two-element array of * 64-bit words): */ #define ADDINC128(w,n) do { \ (w)[0] += (u_int64_t)(n); \ if ((w)[0] < (n)) { \ (w)[1]++; \ } \ } while (0) /*** THE SIX LOGICAL FUNCTIONS ****************************************/ /* * Bit shifting and rotation (used by the six SHA-XYZ logical functions: * * NOTE: The naming of R and S appears backwards here (R is a SHIFT and * S is a ROTATION) because the SHA-224/256/384/512 description document * (see http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf) uses this * same "backwards" definition. */ /* Shift-right (used in SHA-224, SHA-256, SHA-384, and SHA-512): */ #define R(b,x) ((x) >> (b)) /* 32-bit Rotate-right (used in SHA-224 and SHA-256): */ #define S32(b,x) (((x) >> (b)) | ((x) << (32 - (b)))) /* 64-bit Rotate-right (used in SHA-384 and SHA-512): */ #define S64(b,x) (((x) >> (b)) | ((x) << (64 - (b)))) /* Two of six logical functions used in SHA-224, SHA-256, SHA-384, and SHA-512: */ #define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) #define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) /* Four of six logical functions used in SHA-224 and SHA-256: */ #define Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x))) #define Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x))) #define sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x))) #define sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x))) /* Four of six logical functions used in SHA-384 and SHA-512: */ #define Sigma0_512(x) (S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x))) #define Sigma1_512(x) (S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x))) #define sigma0_512(x) (S64( 1, (x)) ^ S64( 8, (x)) ^ R( 7, (x))) #define sigma1_512(x) (S64(19, (x)) ^ S64(61, (x)) ^ R( 6, (x))) /*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/ /* Hash constant words K for SHA-224 and SHA-256: */ static const u_int32_t K256[64] = { 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL, 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL, 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL }; /* Initial hash value H for SHA-256: */ static const u_int32_t sha256_initial_hash_value[8] = { 0x6a09e667UL, 0xbb67ae85UL, 0x3c6ef372UL, 0xa54ff53aUL, 0x510e527fUL, 0x9b05688cUL, 0x1f83d9abUL, 0x5be0cd19UL }; /* Hash constant words K for SHA-384 and SHA-512: */ static const u_int64_t K512[80] = { 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL }; /* Initial hash value H for SHA-512 */ static const u_int64_t sha512_initial_hash_value[8] = { 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL }; #if !defined(SHA2_SMALL) /* Initial hash value H for SHA-224: */ static const u_int32_t sha224_initial_hash_value[8] = { 0xc1059ed8UL, 0x367cd507UL, 0x3070dd17UL, 0xf70e5939UL, 0xffc00b31UL, 0x68581511UL, 0x64f98fa7UL, 0xbefa4fa4UL }; /* Initial hash value H for SHA-384 */ static const u_int64_t sha384_initial_hash_value[8] = { 0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL, 0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL, 0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL, 0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL }; /* Initial hash value H for SHA-512-256 */ static const u_int64_t sha512_256_initial_hash_value[8] = { 0x22312194fc2bf72cULL, 0x9f555fa3c84c64c2ULL, 0x2393b86b6f53b151ULL, 0x963877195940eabdULL, 0x96283ee2a88effe3ULL, 0xbe5e1e2553863992ULL, 0x2b0199fc2c85b8aaULL, 0x0eb72ddc81c52ca2ULL }; /*** SHA-224: *********************************************************/ void SHA224Init(SHA2_CTX *context) { memcpy(context->state.st32, sha224_initial_hash_value, sizeof(sha224_initial_hash_value)); memset(context->buffer, 0, sizeof(context->buffer)); context->bitcount[0] = 0; } MAKE_CLONE(SHA224Transform, SHA256Transform); MAKE_CLONE(SHA224Update, SHA256Update); MAKE_CLONE(SHA224Pad, SHA256Pad); void SHA224Final(u_int8_t digest[SHA224_DIGEST_LENGTH], SHA2_CTX *context) { SHA224Pad(context); #if BYTE_ORDER == LITTLE_ENDIAN int i; /* Convert TO host byte order */ for (i = 0; i < 7; i++) BE_32_TO_8(digest + i * 4, context->state.st32[i]); #else memcpy(digest, context->state.st32, SHA224_DIGEST_LENGTH); #endif explicit_bzero(context, sizeof(*context)); } #endif /* !defined(SHA2_SMALL) */ /*** SHA-256: *********************************************************/ void SHA256Init(SHA2_CTX *context) { memcpy(context->state.st32, sha256_initial_hash_value, sizeof(sha256_initial_hash_value)); memset(context->buffer, 0, sizeof(context->buffer)); context->bitcount[0] = 0; } #ifdef SHA2_UNROLL_TRANSFORM /* Unrolled SHA-256 round macros: */ #define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) do { \ BE_8_TO_32(W256[j], data); \ data += 4; \ T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + W256[j]; \ (d) += T1; \ (h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \ j++; \ } while(0) #define ROUND256(a,b,c,d,e,f,g,h) do { \ s0 = W256[(j+1)&0x0f]; \ s0 = sigma0_256(s0); \ s1 = W256[(j+14)&0x0f]; \ s1 = sigma1_256(s1); \ T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + \ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \ (d) += T1; \ (h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \ j++; \ } while(0) void SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH]) { u_int32_t a, b, c, d, e, f, g, h, s0, s1; u_int32_t T1, W256[16]; int j; /* Initialize registers with the prev. intermediate value */ a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; f = state[5]; g = state[6]; h = state[7]; j = 0; do { /* Rounds 0 to 15 (unrolled): */ ROUND256_0_TO_15(a,b,c,d,e,f,g,h); ROUND256_0_TO_15(h,a,b,c,d,e,f,g); ROUND256_0_TO_15(g,h,a,b,c,d,e,f); ROUND256_0_TO_15(f,g,h,a,b,c,d,e); ROUND256_0_TO_15(e,f,g,h,a,b,c,d); ROUND256_0_TO_15(d,e,f,g,h,a,b,c); ROUND256_0_TO_15(c,d,e,f,g,h,a,b); ROUND256_0_TO_15(b,c,d,e,f,g,h,a); } while (j < 16); /* Now for the remaining rounds up to 63: */ do { ROUND256(a,b,c,d,e,f,g,h); ROUND256(h,a,b,c,d,e,f,g); ROUND256(g,h,a,b,c,d,e,f); ROUND256(f,g,h,a,b,c,d,e); ROUND256(e,f,g,h,a,b,c,d); ROUND256(d,e,f,g,h,a,b,c); ROUND256(c,d,e,f,g,h,a,b); ROUND256(b,c,d,e,f,g,h,a); } while (j < 64); /* Compute the current intermediate hash value */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; state[5] += f; state[6] += g; state[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = 0; } #else /* SHA2_UNROLL_TRANSFORM */ void SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH]) { u_int32_t a, b, c, d, e, f, g, h, s0, s1; u_int32_t T1, T2, W256[16]; int j; /* Initialize registers with the prev. intermediate value */ a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; f = state[5]; g = state[6]; h = state[7]; j = 0; do { BE_8_TO_32(W256[j], data); data += 4; /* Apply the SHA-256 compression function to update a..h */ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j]; T2 = Sigma0_256(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; j++; } while (j < 16); do { /* Part of the message block expansion: */ s0 = W256[(j+1)&0x0f]; s0 = sigma0_256(s0); s1 = W256[(j+14)&0x0f]; s1 = sigma1_256(s1); /* Apply the SHA-256 compression function to update a..h */ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); T2 = Sigma0_256(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; j++; } while (j < 64); /* Compute the current intermediate hash value */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; state[5] += f; state[6] += g; state[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = T2 = 0; } #endif /* SHA2_UNROLL_TRANSFORM */ void SHA256Update(SHA2_CTX *context, const u_int8_t *data, size_t len) { u_int64_t freespace, usedspace; /* Calling with no data is valid (we do nothing) */ if (len == 0) return; usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH; if (usedspace > 0) { /* Calculate how much free space is available in the buffer */ freespace = SHA256_BLOCK_LENGTH - usedspace; if (len >= freespace) { /* Fill the buffer completely and process it */ memcpy(&context->buffer[usedspace], data, freespace); context->bitcount[0] += freespace << 3; len -= freespace; data += freespace; SHA256Transform(context->state.st32, context->buffer); } else { /* The buffer is not yet full */ memcpy(&context->buffer[usedspace], data, len); context->bitcount[0] += (u_int64_t)len << 3; /* Clean up: */ usedspace = freespace = 0; return; } } while (len >= SHA256_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ SHA256Transform(context->state.st32, data); context->bitcount[0] += SHA256_BLOCK_LENGTH << 3; len -= SHA256_BLOCK_LENGTH; data += SHA256_BLOCK_LENGTH; } if (len > 0) { /* There's left-overs, so save 'em */ memcpy(context->buffer, data, len); context->bitcount[0] += len << 3; } /* Clean up: */ usedspace = freespace = 0; } void SHA256Pad(SHA2_CTX *context) { unsigned int usedspace; usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH; if (usedspace > 0) { /* Begin padding with a 1 bit: */ context->buffer[usedspace++] = 0x80; if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ memset(&context->buffer[usedspace], 0, SHA256_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA256_BLOCK_LENGTH) { memset(&context->buffer[usedspace], 0, SHA256_BLOCK_LENGTH - usedspace); } /* Do second-to-last transform: */ SHA256Transform(context->state.st32, context->buffer); /* Prepare for last transform: */ memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); } } else { /* Set-up for the last transform: */ memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *context->buffer = 0x80; } /* Store the length of input data (in bits) in big endian format: */ BE_64_TO_8(&context->buffer[SHA256_SHORT_BLOCK_LENGTH], context->bitcount[0]); /* Final transform: */ SHA256Transform(context->state.st32, context->buffer); /* Clean up: */ usedspace = 0; } void SHA256Final(u_int8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *context) { SHA256Pad(context); #if BYTE_ORDER == LITTLE_ENDIAN int i; /* Convert TO host byte order */ for (i = 0; i < 8; i++) BE_32_TO_8(digest + i * 4, context->state.st32[i]); #else memcpy(digest, context->state.st32, SHA256_DIGEST_LENGTH); #endif explicit_bzero(context, sizeof(*context)); } /*** SHA-512: *********************************************************/ void SHA512Init(SHA2_CTX *context) { memcpy(context->state.st64, sha512_initial_hash_value, sizeof(sha512_initial_hash_value)); memset(context->buffer, 0, sizeof(context->buffer)); context->bitcount[0] = context->bitcount[1] = 0; } #ifdef SHA2_UNROLL_TRANSFORM /* Unrolled SHA-512 round macros: */ #define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) do { \ BE_8_TO_64(W512[j], data); \ data += 8; \ T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + W512[j]; \ (d) += T1; \ (h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \ j++; \ } while(0) #define ROUND512(a,b,c,d,e,f,g,h) do { \ s0 = W512[(j+1)&0x0f]; \ s0 = sigma0_512(s0); \ s1 = W512[(j+14)&0x0f]; \ s1 = sigma1_512(s1); \ T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + \ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \ (d) += T1; \ (h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \ j++; \ } while(0) void SHA512Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH]) { u_int64_t a, b, c, d, e, f, g, h, s0, s1; u_int64_t T1, W512[16]; int j; /* Initialize registers with the prev. intermediate value */ a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; f = state[5]; g = state[6]; h = state[7]; j = 0; do { /* Rounds 0 to 15 (unrolled): */ ROUND512_0_TO_15(a,b,c,d,e,f,g,h); ROUND512_0_TO_15(h,a,b,c,d,e,f,g); ROUND512_0_TO_15(g,h,a,b,c,d,e,f); ROUND512_0_TO_15(f,g,h,a,b,c,d,e); ROUND512_0_TO_15(e,f,g,h,a,b,c,d); ROUND512_0_TO_15(d,e,f,g,h,a,b,c); ROUND512_0_TO_15(c,d,e,f,g,h,a,b); ROUND512_0_TO_15(b,c,d,e,f,g,h,a); } while (j < 16); /* Now for the remaining rounds up to 79: */ do { ROUND512(a,b,c,d,e,f,g,h); ROUND512(h,a,b,c,d,e,f,g); ROUND512(g,h,a,b,c,d,e,f); ROUND512(f,g,h,a,b,c,d,e); ROUND512(e,f,g,h,a,b,c,d); ROUND512(d,e,f,g,h,a,b,c); ROUND512(c,d,e,f,g,h,a,b); ROUND512(b,c,d,e,f,g,h,a); } while (j < 80); /* Compute the current intermediate hash value */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; state[5] += f; state[6] += g; state[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = 0; } #else /* SHA2_UNROLL_TRANSFORM */ void SHA512Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH]) { u_int64_t a, b, c, d, e, f, g, h, s0, s1; u_int64_t T1, T2, W512[16]; int j; /* Initialize registers with the prev. intermediate value */ a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; f = state[5]; g = state[6]; h = state[7]; j = 0; do { BE_8_TO_64(W512[j], data); data += 8; /* Apply the SHA-512 compression function to update a..h */ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j]; T2 = Sigma0_512(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; j++; } while (j < 16); do { /* Part of the message block expansion: */ s0 = W512[(j+1)&0x0f]; s0 = sigma0_512(s0); s1 = W512[(j+14)&0x0f]; s1 = sigma1_512(s1); /* Apply the SHA-512 compression function to update a..h */ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); T2 = Sigma0_512(a) + Maj(a, b, c); h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; j++; } while (j < 80); /* Compute the current intermediate hash value */ state[0] += a; state[1] += b; state[2] += c; state[3] += d; state[4] += e; state[5] += f; state[6] += g; state[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = T2 = 0; } #endif /* SHA2_UNROLL_TRANSFORM */ void SHA512Update(SHA2_CTX *context, const u_int8_t *data, size_t len) { size_t freespace, usedspace; /* Calling with no data is valid (we do nothing) */ if (len == 0) return; usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH; if (usedspace > 0) { /* Calculate how much free space is available in the buffer */ freespace = SHA512_BLOCK_LENGTH - usedspace; if (len >= freespace) { /* Fill the buffer completely and process it */ memcpy(&context->buffer[usedspace], data, freespace); ADDINC128(context->bitcount, freespace << 3); len -= freespace; data += freespace; SHA512Transform(context->state.st64, context->buffer); } else { /* The buffer is not yet full */ memcpy(&context->buffer[usedspace], data, len); ADDINC128(context->bitcount, len << 3); /* Clean up: */ usedspace = freespace = 0; return; } } while (len >= SHA512_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ SHA512Transform(context->state.st64, data); ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3); len -= SHA512_BLOCK_LENGTH; data += SHA512_BLOCK_LENGTH; } if (len > 0) { /* There's left-overs, so save 'em */ memcpy(context->buffer, data, len); ADDINC128(context->bitcount, len << 3); } /* Clean up: */ usedspace = freespace = 0; } void SHA512Pad(SHA2_CTX *context) { unsigned int usedspace; usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH; if (usedspace > 0) { /* Begin padding with a 1 bit: */ context->buffer[usedspace++] = 0x80; if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) { /* Set-up for the last transform: */ memset(&context->buffer[usedspace], 0, SHA512_SHORT_BLOCK_LENGTH - usedspace); } else { if (usedspace < SHA512_BLOCK_LENGTH) { memset(&context->buffer[usedspace], 0, SHA512_BLOCK_LENGTH - usedspace); } /* Do second-to-last transform: */ SHA512Transform(context->state.st64, context->buffer); /* And set-up for the last transform: */ memset(context->buffer, 0, SHA512_BLOCK_LENGTH - 2); } } else { /* Prepare for final transform: */ memset(context->buffer, 0, SHA512_SHORT_BLOCK_LENGTH); /* Begin padding with a 1 bit: */ *context->buffer = 0x80; } /* Store the length of input data (in bits) in big endian format: */ BE_64_TO_8(&context->buffer[SHA512_SHORT_BLOCK_LENGTH], context->bitcount[1]); BE_64_TO_8(&context->buffer[SHA512_SHORT_BLOCK_LENGTH + 8], context->bitcount[0]); /* Final transform: */ SHA512Transform(context->state.st64, context->buffer); /* Clean up: */ usedspace = 0; } void SHA512Final(u_int8_t digest[SHA512_DIGEST_LENGTH], SHA2_CTX *context) { SHA512Pad(context); #if BYTE_ORDER == LITTLE_ENDIAN int i; /* Convert TO host byte order */ for (i = 0; i < 8; i++) BE_64_TO_8(digest + i * 8, context->state.st64[i]); #else memcpy(digest, context->state.st64, SHA512_DIGEST_LENGTH); #endif explicit_bzero(context, sizeof(*context)); } #if !defined(SHA2_SMALL) /*** SHA-384: *********************************************************/ void SHA384Init(SHA2_CTX *context) { memcpy(context->state.st64, sha384_initial_hash_value, sizeof(sha384_initial_hash_value)); memset(context->buffer, 0, sizeof(context->buffer)); context->bitcount[0] = context->bitcount[1] = 0; } MAKE_CLONE(SHA384Transform, SHA512Transform); MAKE_CLONE(SHA384Update, SHA512Update); MAKE_CLONE(SHA384Pad, SHA512Pad); void SHA384Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context) { SHA384Pad(context); #if BYTE_ORDER == LITTLE_ENDIAN int i; /* Convert TO host byte order */ for (i = 0; i < 6; i++) BE_64_TO_8(digest + i * 8, context->state.st64[i]); #else memcpy(digest, context->state.st64, SHA384_DIGEST_LENGTH); #endif /* Zero out state data */ explicit_bzero(context, sizeof(*context)); } /*** SHA-512/256: *********************************************************/ void SHA512_256Init(SHA2_CTX *context) { memcpy(context->state.st64, sha512_256_initial_hash_value, sizeof(sha512_256_initial_hash_value)); memset(context->buffer, 0, sizeof(context->buffer)); context->bitcount[0] = context->bitcount[1] = 0; } MAKE_CLONE(SHA512_256Transform, SHA512Transform); MAKE_CLONE(SHA512_256Update, SHA512Update); MAKE_CLONE(SHA512_256Pad, SHA512Pad); void SHA512_256Final(u_int8_t digest[SHA512_256_DIGEST_LENGTH], SHA2_CTX *context) { SHA512_256Pad(context); #if BYTE_ORDER == LITTLE_ENDIAN int i; /* Convert TO host byte order */ for (i = 0; i < 4; i++) BE_64_TO_8(digest + i * 8, context->state.st64[i]); #else memcpy(digest, context->state.st64, SHA512_256_DIGEST_LENGTH); #endif /* Zero out state data */ explicit_bzero(context, sizeof(*context)); } #endif /* !defined(SHA2_SMALL) */ openbgpd-8.8/compat/getentropy_netbsd.c100644 001750 001750 00000003132 14751151130 0014054/* $OpenBSD: getentropy_netbsd.c,v 1.4 2020/10/12 22:08:33 deraadt Exp $ */ /* * Copyright (c) 2014 Pawel Jakub Dawidek * Copyright (c) 2014 Brent Cook * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Emulation of getentropy(2) as documented at: * http://man.openbsd.org/getentropy.2 */ #include #include #include #include /* * Derived from lib/libc/gen/arc4random.c from FreeBSD. */ static size_t getentropy_sysctl(u_char *buf, size_t size) { const int mib[2] = { CTL_KERN, KERN_ARND }; size_t len, done; done = 0; do { len = size; if (sysctl(mib, 2, buf, &len, NULL, 0) == -1) return (done); done += len; buf += len; size -= len; } while (size > 0); return (done); } int getentropy(void *buf, size_t len) { if (len <= 256 && getentropy_sysctl(buf, len) == len) { return (0); } errno = EIO; return (-1); } openbgpd-8.8/compat/getentropy_osx.c100644 001750 001750 00000024513 14751151130 0013414/* $OpenBSD: getentropy_osx.c,v 1.14 2021/10/24 21:24:20 deraadt Exp $ */ /* * Copyright (c) 2014 Theo de Raadt * Copyright (c) 2014 Bob Beck * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Emulation of getentropy(2) as documented at: * http://man.openbsd.org/getentropy.2 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if TARGET_OS_OSX #include #include #endif #include #include #if TARGET_OS_OSX #include #include #include #include #endif #include #define SHA512_Update(a, b, c) (CC_SHA512_Update((a), (b), (c))) #define SHA512_Init(xxx) (CC_SHA512_Init((xxx))) #define SHA512_Final(xxx, yyy) (CC_SHA512_Final((xxx), (yyy))) #define SHA512_CTX CC_SHA512_CTX #define SHA512_DIGEST_LENGTH CC_SHA512_DIGEST_LENGTH #define REPEAT 5 #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) #define HX(a, b) \ do { \ if ((a)) \ HD(errno); \ else \ HD(b); \ } while (0) #define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) #define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) #define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*))) int getentropy(void *buf, size_t len); static int getentropy_urandom(void *buf, size_t len); static int getentropy_fallback(void *buf, size_t len); int getentropy(void *buf, size_t len) { int ret = -1; if (len > 256) { errno = EIO; return (-1); } /* * Try to get entropy with /dev/urandom * * This can fail if the process is inside a chroot or if file * descriptors are exhausted. */ ret = getentropy_urandom(buf, len); if (ret != -1) return (ret); /* * Entropy collection via /dev/urandom and sysctl have failed. * * No other API exists for collecting entropy, and we have * no failsafe way to get it on OSX that is not sensitive * to resource exhaustion. * * We have very few options: * - Even syslog_r is unsafe to call at this low level, so * there is no way to alert the user or program. * - Cannot call abort() because some systems have unsafe * corefiles. * - Could raise(SIGKILL) resulting in silent program termination. * - Return EIO, to hint that arc4random's stir function * should raise(SIGKILL) * - Do the best under the circumstances.... * * This code path exists to bring light to the issue that OSX * does not provide a failsafe API for entropy collection. * * We hope this demonstrates that OSX should consider * providing a new failsafe API which works in a chroot or * when file descriptors are exhausted. */ #undef FAIL_INSTEAD_OF_TRYING_FALLBACK #ifdef FAIL_INSTEAD_OF_TRYING_FALLBACK raise(SIGKILL); #endif ret = getentropy_fallback(buf, len); if (ret != -1) return (ret); errno = EIO; return (ret); } static int getentropy_urandom(void *buf, size_t len) { struct stat st; size_t i; int fd, flags; int save_errno = errno; start: flags = O_RDONLY; #ifdef O_NOFOLLOW flags |= O_NOFOLLOW; #endif #ifdef O_CLOEXEC flags |= O_CLOEXEC; #endif fd = open("/dev/urandom", flags); if (fd == -1) { if (errno == EINTR) goto start; goto nodevrandom; } #ifndef O_CLOEXEC fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); #endif /* Lightly verify that the device node looks sane */ if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode)) { close(fd); goto nodevrandom; } for (i = 0; i < len; ) { size_t wanted = len - i; ssize_t ret = read(fd, (char *)buf + i, wanted); if (ret == -1) { if (errno == EAGAIN || errno == EINTR) continue; close(fd); goto nodevrandom; } i += ret; } close(fd); errno = save_errno; return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); } #if TARGET_OS_OSX static int tcpmib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS }; static int udpmib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS }; static int ipmib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS }; #endif static int kmib[] = { CTL_KERN, KERN_USRSTACK }; static int hwmib[] = { CTL_HW, HW_USERMEM }; static int getentropy_fallback(void *buf, size_t len) { uint8_t results[SHA512_DIGEST_LENGTH]; int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat; static int cnt; struct timespec ts; struct timeval tv; struct rusage ru; sigset_t sigset; struct stat st; SHA512_CTX ctx; static pid_t lastpid; pid_t pid; size_t i, ii, m; char *p; #if TARGET_OS_OSX struct tcpstat tcpstat; struct udpstat udpstat; struct ipstat ipstat; #endif u_int64_t mach_time; unsigned int idata; void *addr; pid = getpid(); if (lastpid == pid) { faster = 1; repeat = 2; } else { faster = 0; lastpid = pid; repeat = REPEAT; } for (i = 0; i < len; ) { int j; SHA512_Init(&ctx); for (j = 0; j < repeat; j++) { HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } mach_time = mach_absolute_time(); HD(mach_time); ii = sizeof(addr); HX(sysctl(kmib, sizeof(kmib) / sizeof(kmib[0]), &addr, &ii, NULL, 0) == -1, addr); ii = sizeof(idata); HX(sysctl(hwmib, sizeof(hwmib) / sizeof(hwmib[0]), &idata, &ii, NULL, 0) == -1, idata); #if TARGET_OS_OSX ii = sizeof(tcpstat); HX(sysctl(tcpmib, sizeof(tcpmib) / sizeof(tcpmib[0]), &tcpstat, &ii, NULL, 0) == -1, tcpstat); ii = sizeof(udpstat); HX(sysctl(udpmib, sizeof(udpmib) / sizeof(udpmib[0]), &udpstat, &ii, NULL, 0) == -1, udpstat); ii = sizeof(ipstat); HX(sysctl(ipmib, sizeof(ipmib) / sizeof(ipmib[0]), &ipstat, &ii, NULL, 0) == -1, ipstat); #endif HX((pid = getpid()) == -1, pid); HX((pid = getsid(pid)) == -1, pid); HX((pid = getppid()) == -1, pid); HX((pid = getpgid(0)) == -1, pid); HX((e = getpriority(0, 0)) == -1, e); if (!faster) { ts.tv_sec = 0; ts.tv_nsec = 1; (void) nanosleep(&ts, NULL); } HX(sigpending(&sigset) == -1, sigset); HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; HD(p); /* the addr of errno */ if (i == 0) { struct sockaddr_storage ss; struct statvfs stvfs; struct termios tios; struct statfs stfs; socklen_t ssl; off_t off; /* * Prime-sized mappings encourage fragmentation; * thus exposing some address entropy. */ struct mm { size_t npg; void *p; } mm[] = { { 17, MAP_FAILED }, { 3, MAP_FAILED }, { 11, MAP_FAILED }, { 2, MAP_FAILED }, { 5, MAP_FAILED }, { 3, MAP_FAILED }, { 7, MAP_FAILED }, { 1, MAP_FAILED }, { 57, MAP_FAILED }, { 3, MAP_FAILED }, { 131, MAP_FAILED }, { 1, MAP_FAILED }, }; for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { HX(mm[m].p = mmap(NULL, mm[m].npg * pgs, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, (off_t)0), mm[m].p); if (mm[m].p != MAP_FAILED) { size_t mo; /* Touch some memory... */ p = mm[m].p; mo = cnt % (mm[m].npg * pgs - 1); p[mo] = 1; cnt += (int)((long)(mm[m].p) / pgs); } /* Check cnts and times... */ mach_time = mach_absolute_time(); HD(mach_time); cnt += (int)mach_time; HX((e = getrusage(RUSAGE_SELF, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { if (mm[m].p != MAP_FAILED) munmap(mm[m].p, mm[m].npg * pgs); mm[m].p = MAP_FAILED; } HX(stat(".", &st) == -1, st); HX(statvfs(".", &stvfs) == -1, stvfs); HX(statfs(".", &stfs) == -1, stfs); HX(stat("/", &st) == -1, st); HX(statvfs("/", &stvfs) == -1, stvfs); HX(statfs("/", &stfs) == -1, stfs); HX((e = fstat(0, &st)) == -1, st); if (e == -1) { if (S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { HX(fstatvfs(0, &stvfs) == -1, stvfs); HX(fstatfs(0, &stfs) == -1, stfs); HX((off = lseek(0, (off_t)0, SEEK_CUR)) < 0, off); } if (S_ISCHR(st.st_mode)) { HX(tcgetattr(0, &tios) == -1, tios); } else if (S_ISSOCK(st.st_mode)) { memset(&ss, 0, sizeof ss); ssl = sizeof(ss); HX(getpeername(0, (void *)&ss, &ssl) == -1, ss); } } HX((e = getrusage(RUSAGE_CHILDREN, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } else { /* Subsequent hashes absorb previous result */ HD(results); } HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HD(cnt); } SHA512_Final(results, &ctx); memcpy((char *)buf + i, results, MINIMUM(sizeof(results), len - i)); i += MINIMUM(sizeof(results), len - i); } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); errno = save_errno; return (0); /* satisfied */ } openbgpd-8.8/compat/getentropy_solaris.c100644 001750 001750 00000024440 14751151130 0014256/* $OpenBSD: getentropy_solaris.c,v 1.15 2021/10/24 21:24:20 deraadt Exp $ */ /* * Copyright (c) 2014 Theo de Raadt * Copyright (c) 2014 Bob Beck * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Emulation of getentropy(2) as documented at: * http://man.openbsd.org/getentropy.2 */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define SHA512_Init SHA512Init #define SHA512_Update SHA512Update #define SHA512_Final SHA512Final #include #include #include #define REPEAT 5 #define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) #define HX(a, b) \ do { \ if ((a)) \ HD(errno); \ else \ HD(b); \ } while (0) #define HR(x, l) (SHA512_Update(&ctx, (char *)(x), (l))) #define HD(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (x))) #define HF(x) (SHA512_Update(&ctx, (char *)&(x), sizeof (void*))) int getentropy(void *buf, size_t len); static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck); static int getentropy_fallback(void *buf, size_t len); static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data); int getentropy(void *buf, size_t len) { int ret = -1; if (len > 256) { errno = EIO; return (-1); } /* * Try to get entropy with /dev/urandom * * Solaris provides /dev/urandom as a symbolic link to * /devices/pseudo/random@0:urandom which is provided by * a devfs filesystem. Best practice is to use O_NOFOLLOW, * so we must try the unpublished name directly. * * This can fail if the process is inside a chroot which lacks * the devfs mount, or if file descriptors are exhausted. */ ret = getentropy_urandom(buf, len, "/devices/pseudo/random@0:urandom", 1); if (ret != -1) return (ret); /* * Unfortunately, chroot spaces on Solaris are sometimes setup * with direct device node of the well-known /dev/urandom name * (perhaps to avoid dragging all of devfs into the space). * * This can fail if the process is inside a chroot or if file * descriptors are exhausted. */ ret = getentropy_urandom(buf, len, "/dev/urandom", 0); if (ret != -1) return (ret); /* * Entropy collection via /dev/urandom has failed. * * No other API exists for collecting entropy, and we have * no failsafe way to get it on Solaris that is not sensitive * to resource exhaustion. * * We have very few options: * - Even syslog_r is unsafe to call at this low level, so * there is no way to alert the user or program. * - Cannot call abort() because some systems have unsafe * corefiles. * - Could raise(SIGKILL) resulting in silent program termination. * - Return EIO, to hint that arc4random's stir function * should raise(SIGKILL) * - Do the best under the circumstances.... * * This code path exists to bring light to the issue that Solaris * does not provide a failsafe API for entropy collection. * * We hope this demonstrates that Solaris should consider * providing a new failsafe API which works in a chroot or * when file descriptors are exhausted. */ #undef FAIL_INSTEAD_OF_TRYING_FALLBACK #ifdef FAIL_INSTEAD_OF_TRYING_FALLBACK raise(SIGKILL); #endif ret = getentropy_fallback(buf, len); if (ret != -1) return (ret); errno = EIO; return (ret); } static int getentropy_urandom(void *buf, size_t len, const char *path, int devfscheck) { struct stat st; size_t i; int fd, flags; int save_errno = errno; start: flags = O_RDONLY; #ifdef O_NOFOLLOW flags |= O_NOFOLLOW; #endif #ifdef O_CLOEXEC flags |= O_CLOEXEC; #endif fd = open(path, flags); if (fd == -1) { if (errno == EINTR) goto start; goto nodevrandom; } #ifndef O_CLOEXEC fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC); #endif /* Lightly verify that the device node looks sane */ if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode) || (devfscheck && (strcmp(st.st_fstype, "devfs") != 0))) { close(fd); goto nodevrandom; } for (i = 0; i < len; ) { size_t wanted = len - i; ssize_t ret = read(fd, (char *)buf + i, wanted); if (ret == -1) { if (errno == EAGAIN || errno == EINTR) continue; close(fd); goto nodevrandom; } i += ret; } close(fd); errno = save_errno; return (0); /* satisfied */ nodevrandom: errno = EIO; return (-1); } static const int cl[] = { CLOCK_REALTIME, #ifdef CLOCK_MONOTONIC CLOCK_MONOTONIC, #endif #ifdef CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC_RAW, #endif #ifdef CLOCK_TAI CLOCK_TAI, #endif #ifdef CLOCK_VIRTUAL CLOCK_VIRTUAL, #endif #ifdef CLOCK_UPTIME CLOCK_UPTIME, #endif #ifdef CLOCK_PROCESS_CPUTIME_ID CLOCK_PROCESS_CPUTIME_ID, #endif #ifdef CLOCK_THREAD_CPUTIME_ID CLOCK_THREAD_CPUTIME_ID, #endif }; static int getentropy_phdr(struct dl_phdr_info *info, size_t size, void *data) { SHA512_CTX *ctx = data; SHA512_Update(ctx, &info->dlpi_addr, sizeof (info->dlpi_addr)); return (0); } static int getentropy_fallback(void *buf, size_t len) { uint8_t results[SHA512_DIGEST_LENGTH]; int save_errno = errno, e, pgs = getpagesize(), faster = 0, repeat; static int cnt; struct timespec ts; struct timeval tv; double loadavg[3]; struct rusage ru; sigset_t sigset; struct stat st; SHA512_CTX ctx; static pid_t lastpid; pid_t pid; size_t i, ii, m; char *p; pid = getpid(); if (lastpid == pid) { faster = 1; repeat = 2; } else { faster = 0; lastpid = pid; repeat = REPEAT; } for (i = 0; i < len; ) { int j; SHA512_Init(&ctx); for (j = 0; j < repeat; j++) { HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } dl_iterate_phdr(getentropy_phdr, &ctx); for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) HX(clock_gettime(cl[ii], &ts) == -1, ts); HX((pid = getpid()) == -1, pid); HX((pid = getsid(pid)) == -1, pid); HX((pid = getppid()) == -1, pid); HX((pid = getpgid(0)) == -1, pid); HX((e = getpriority(0, 0)) == -1, e); HX((getloadavg(loadavg, 3) == -1), loadavg); if (!faster) { ts.tv_sec = 0; ts.tv_nsec = 1; (void) nanosleep(&ts, NULL); } HX(sigpending(&sigset) == -1, sigset); HX(sigprocmask(SIG_BLOCK, NULL, &sigset) == -1, sigset); HF(getentropy); /* an addr in this library */ HF(printf); /* an addr in libc */ p = (char *)&p; HD(p); /* an addr on stack */ p = (char *)&errno; HD(p); /* the addr of errno */ if (i == 0) { struct sockaddr_storage ss; struct statvfs stvfs; struct termios tios; socklen_t ssl; off_t off; /* * Prime-sized mappings encourage fragmentation; * thus exposing some address entropy. */ struct mm { size_t npg; void *p; } mm[] = { { 17, MAP_FAILED }, { 3, MAP_FAILED }, { 11, MAP_FAILED }, { 2, MAP_FAILED }, { 5, MAP_FAILED }, { 3, MAP_FAILED }, { 7, MAP_FAILED }, { 1, MAP_FAILED }, { 57, MAP_FAILED }, { 3, MAP_FAILED }, { 131, MAP_FAILED }, { 1, MAP_FAILED }, }; for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { HX(mm[m].p = mmap(NULL, mm[m].npg * pgs, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, (off_t)0), mm[m].p); if (mm[m].p != MAP_FAILED) { size_t mo; /* Touch some memory... */ p = mm[m].p; mo = cnt % (mm[m].npg * pgs - 1); p[mo] = 1; cnt += (int)((long)(mm[m].p) / pgs); } /* Check cnts and times... */ for (ii = 0; ii < sizeof(cl)/sizeof(cl[0]); ii++) { HX((e = clock_gettime(cl[ii], &ts)) == -1, ts); if (e != -1) cnt += (int)ts.tv_nsec; } HX((e = getrusage(RUSAGE_SELF, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } for (m = 0; m < sizeof mm/sizeof(mm[0]); m++) { if (mm[m].p != MAP_FAILED) munmap(mm[m].p, mm[m].npg * pgs); mm[m].p = MAP_FAILED; } HX(stat(".", &st) == -1, st); HX(statvfs(".", &stvfs) == -1, stvfs); HX(stat("/", &st) == -1, st); HX(statvfs("/", &stvfs) == -1, stvfs); HX((e = fstat(0, &st)) == -1, st); if (e == -1) { if (S_ISREG(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { HX(fstatvfs(0, &stvfs) == -1, stvfs); HX((off = lseek(0, (off_t)0, SEEK_CUR)) < 0, off); } if (S_ISCHR(st.st_mode)) { HX(tcgetattr(0, &tios) == -1, tios); } else if (S_ISSOCK(st.st_mode)) { memset(&ss, 0, sizeof ss); ssl = sizeof(ss); HX(getpeername(0, (void *)&ss, &ssl) == -1, ss); } } HX((e = getrusage(RUSAGE_CHILDREN, &ru)) == -1, ru); if (e != -1) { cnt += (int)ru.ru_utime.tv_sec; cnt += (int)ru.ru_utime.tv_usec; } } else { /* Subsequent hashes absorb previous result */ HD(results); } HX((e = gettimeofday(&tv, NULL)) == -1, tv); if (e != -1) { cnt += (int)tv.tv_sec; cnt += (int)tv.tv_usec; } HD(cnt); } SHA512_Final(results, &ctx); memcpy((char *)buf + i, results, MINIMUM(sizeof(results), len - i)); i += MINIMUM(sizeof(results), len - i); } explicit_bzero(&ctx, sizeof ctx); explicit_bzero(results, sizeof results); errno = save_errno; return (0); /* satisfied */ } openbgpd-8.8/compat/getrtable.c100644 001750 001750 00000000677 14264017544 0012312/* * Public domain * getrtable.c compatibility shim */ #include #ifdef HAVE_SETFIB #include #include #include #include #endif int getrtable(void) { #ifdef HAVE_SETFIB int fib; size_t len = sizeof(fib); if (sysctlbyname("net.my_fibnum", &fib, &len, NULL, 0) == -1) { if (errno == ENOENT) /* no fib support */ return 0; return -1; } return fib; #endif return 0; } openbgpd-8.8/compat/inet_net_pton.c100644 001750 001750 00000014233 14751151130 0013166/* $OpenBSD: inet_net_pton.c,v 1.14 2022/12/27 17:10:06 jmc Exp $ */ /* * Copyright (c) 2012 by Gilles Chehade * Copyright (c) 1996,1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include static int inet_net_pton_ipv4(const char *, u_char *, size_t); static int inet_net_pton_ipv6(const char *, u_char *, size_t); /* * static int * inet_net_pton(af, src, dst, size) * convert network number from presentation to network format. * accepts hex octets, hex strings, decimal octets, and /CIDR. * "size" is in bytes and describes "dst". * return: * number of bits, either imputed classfully or specified with /CIDR, * or -1 if some failure occurred (check errno). ENOENT means it was * not a valid network specification. * author: * Paul Vixie (ISC), June 1996 */ int inet_net_pton(int af, const char *src, void *dst, size_t size) { switch (af) { case AF_INET: return (inet_net_pton_ipv4(src, dst, size)); case AF_INET6: return (inet_net_pton_ipv6(src, dst, size)); default: errno = EAFNOSUPPORT; return (-1); } } /* * static int * inet_net_pton_ipv4(src, dst, size) * convert IPv4 network number from presentation to network format. * accepts hex octets, hex strings, decimal octets, and /CIDR. * "size" is in bytes and describes "dst". * return: * number of bits, either imputed classfully or specified with /CIDR, * or -1 if some failure occurred (check errno). ENOENT means it was * not an IPv4 network specification. * note: * network byte order assumed. this means 192.5.5.240/28 has * 0x11110000 in its fourth octet. * author: * Paul Vixie (ISC), June 1996 */ static int inet_net_pton_ipv4(const char *src, u_char *dst, size_t size) { static const char xdigits[] = "0123456789abcdef", digits[] = "0123456789"; int n, ch, tmp, dirty, bits; const u_char *odst = dst; ch = (unsigned char)*src++; if (ch == '0' && (src[0] == 'x' || src[0] == 'X') && isascii((unsigned char)src[1]) && isxdigit((unsigned char)src[1])) { /* Hexadecimal: Eat nybble string. */ if (size == 0) goto emsgsize; tmp = 0, dirty = 0; src++; /* skip x or X. */ while ((ch = (unsigned char)*src++) != '\0' && isascii(ch) && isxdigit(ch)) { if (isupper(ch)) ch = tolower(ch); n = strchr(xdigits, ch) - xdigits; assert(n >= 0 && n <= 15); if (dirty == 0) tmp = n; else tmp = (tmp << 4) | n; if (++dirty == 2) { if (size-- == 0) goto emsgsize; *dst++ = (u_char) tmp; dirty = 0; } } if (dirty) { /* Odd trailing nybble? */ if (size-- == 0) goto emsgsize; *dst++ = (u_char) (tmp << 4); } } else if (isascii(ch) && isdigit(ch)) { /* Decimal: eat dotted digit string. */ for (;;) { tmp = 0; do { n = strchr(digits, ch) - digits; assert(n >= 0 && n <= 9); tmp *= 10; tmp += n; if (tmp > 255) goto enoent; } while ((ch = (unsigned char)*src++) != '\0' && isascii(ch) && isdigit(ch)); if (size-- == 0) goto emsgsize; *dst++ = (u_char) tmp; if (ch == '\0' || ch == '/') break; if (ch != '.') goto enoent; ch = (unsigned char)*src++; if (!isascii(ch) || !isdigit(ch)) goto enoent; } } else goto enoent; bits = -1; if (ch == '/' && isascii((unsigned char)src[0]) && isdigit((unsigned char)src[0]) && dst > odst) { /* CIDR width specifier. Nothing can follow it. */ ch = (unsigned char)*src++; /* Skip over the /. */ bits = 0; do { n = strchr(digits, ch) - digits; assert(n >= 0 && n <= 9); bits *= 10; bits += n; if (bits > 32) goto emsgsize; } while ((ch = (unsigned char)*src++) != '\0' && isascii(ch) && isdigit(ch)); if (ch != '\0') goto enoent; } /* Fiery death and destruction unless we prefetched EOS. */ if (ch != '\0') goto enoent; /* If nothing was written to the destination, we found no address. */ if (dst == odst) goto enoent; /* If no CIDR spec was given, infer width from net class. */ if (bits == -1) { if (*odst >= 240) /* Class E */ bits = 32; else if (*odst >= 224) /* Class D */ bits = 4; else if (*odst >= 192) /* Class C */ bits = 24; else if (*odst >= 128) /* Class B */ bits = 16; else /* Class A */ bits = 8; /* If imputed mask is narrower than specified octets, widen. */ if (bits < ((dst - odst) * 8)) bits = (dst - odst) * 8; } /* Extend network to cover the actual mask. */ while (bits > ((dst - odst) * 8)) { if (size-- == 0) goto emsgsize; *dst++ = '\0'; } return (bits); enoent: errno = ENOENT; return (-1); emsgsize: errno = EMSGSIZE; return (-1); } static int inet_net_pton_ipv6(const char *src, u_char *dst, size_t size) { struct in6_addr in6; int ret; int bits; size_t bytes; char buf[INET6_ADDRSTRLEN + sizeof("/128")]; char *sep; const char *errstr; if (strlcpy(buf, src, sizeof buf) >= sizeof buf) { errno = EMSGSIZE; return (-1); } sep = strchr(buf, '/'); if (sep != NULL) *sep++ = '\0'; ret = inet_pton(AF_INET6, buf, &in6); if (ret != 1) return (-1); if (sep == NULL) bits = 128; else { bits = strtonum(sep, 0, 128, &errstr); if (errstr) { errno = EINVAL; return (-1); } } bytes = (bits + 7) / 8; if (bytes > size) { errno = EMSGSIZE; return (-1); } memcpy(dst, &in6.s6_addr, bytes); return (bits); } openbgpd-8.8/compat/fmt_scaled.c100644 001750 001750 00000017267 14403051271 0012433/* $OpenBSD: fmt_scaled.c,v 1.23 2022/12/27 17:10:08 jmc Exp $ */ /* * Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * fmt_scaled: Format numbers scaled for human comprehension * scan_scaled: Scan numbers in this format. * * "Human-readable" output uses 4 digits max, and puts a unit suffix at * the end. Makes output compact and easy-to-read esp. on huge disks. * Formatting code was originally in OpenBSD "df", converted to library routine. * Scanning code written for OpenBSD libutil. */ #include #include #include #include #include #include #include "util.h" typedef enum { NONE = 0, KILO = 1, MEGA = 2, GIGA = 3, TERA = 4, PETA = 5, EXA = 6 } unit_type; /* These three arrays MUST be in sync! XXX make a struct */ static const unit_type units[] = { NONE, KILO, MEGA, GIGA, TERA, PETA, EXA }; static const char scale_chars[] = "BKMGTPE"; static const long long scale_factors[] = { 1LL, 1024LL, 1024LL*1024, 1024LL*1024*1024, 1024LL*1024*1024*1024, 1024LL*1024*1024*1024*1024, 1024LL*1024*1024*1024*1024*1024, }; #define SCALE_LENGTH (sizeof(units)/sizeof(units[0])) #define MAX_DIGITS (SCALE_LENGTH * 3) /* XXX strlen(sprintf("%lld", -1)? */ /* Convert the given input string "scaled" into numeric in "result". * Return 0 on success, -1 and errno set on error. */ int scan_scaled(char *scaled, long long *result) { char *p = scaled; int sign = 0; unsigned int i, ndigits = 0, fract_digits = 0; long long scale_fact = 1, whole = 0, fpart = 0; /* Skip leading whitespace */ while (isascii((unsigned char)*p) && isspace((unsigned char)*p)) ++p; /* Then at most one leading + or - */ while (*p == '-' || *p == '+') { if (*p == '-') { if (sign) { errno = EINVAL; return -1; } sign = -1; ++p; } else if (*p == '+') { if (sign) { errno = EINVAL; return -1; } sign = +1; ++p; } } /* Main loop: Scan digits, find decimal point, if present. * We don't allow exponentials, so no scientific notation * (but note that E for Exa might look like e to some!). * Advance 'p' to end, to get scale factor. */ for (; isascii((unsigned char)*p) && (isdigit((unsigned char)*p) || *p=='.'); ++p) { if (*p == '.') { if (fract_digits > 0) { /* oops, more than one '.' */ errno = EINVAL; return -1; } fract_digits = 1; continue; } i = (*p) - '0'; /* whew! finally a digit we can use */ if (fract_digits > 0) { if (fract_digits >= MAX_DIGITS-1) /* ignore extra fractional digits */ continue; fract_digits++; /* for later scaling */ if (fpart > LLONG_MAX / 10) { errno = ERANGE; return -1; } fpart *= 10; if (i > LLONG_MAX - fpart) { errno = ERANGE; return -1; } fpart += i; } else { /* normal digit */ if (++ndigits >= MAX_DIGITS) { errno = ERANGE; return -1; } if (whole > LLONG_MAX / 10) { errno = ERANGE; return -1; } whole *= 10; if (i > LLONG_MAX - whole) { errno = ERANGE; return -1; } whole += i; } } if (sign) whole *= sign; /* If no scale factor given, we're done. fraction is discarded. */ if (!*p) { *result = whole; return 0; } /* Validate scale factor, and scale whole and fraction by it. */ for (i = 0; i < SCALE_LENGTH; i++) { /* Are we there yet? */ if (*p == scale_chars[i] || *p == tolower((unsigned char)scale_chars[i])) { /* If it ends with alphanumerics after the scale char, bad. */ if (isalnum((unsigned char)*(p+1))) { errno = EINVAL; return -1; } scale_fact = scale_factors[i]; /* check for overflow and underflow after scaling */ if (whole > LLONG_MAX / scale_fact || whole < LLONG_MIN / scale_fact) { errno = ERANGE; return -1; } /* scale whole part */ whole *= scale_fact; /* truncate fpart so it doesn't overflow. * then scale fractional part. */ while (fpart >= LLONG_MAX / scale_fact) { fpart /= 10; fract_digits--; } fpart *= scale_fact; if (fract_digits > 0) { for (i = 0; i < fract_digits -1; i++) fpart /= 10; } if (sign == -1) whole -= fpart; else whole += fpart; *result = whole; return 0; } } /* Invalid unit or character */ errno = EINVAL; return -1; } /* Format the given "number" into human-readable form in "result". * Result must point to an allocated buffer of length FMT_SCALED_STRSIZE. * Return 0 on success, -1 and errno set if error. */ int fmt_scaled(long long number, char *result) { long long abval, fract = 0; unsigned int i; unit_type unit = NONE; /* Not every negative long long has a positive representation. */ if (number == LLONG_MIN) { errno = ERANGE; return -1; } abval = llabs(number); /* Also check for numbers that are just too darned big to format. */ if (abval / 1024 >= scale_factors[SCALE_LENGTH-1]) { errno = ERANGE; return -1; } /* scale whole part; get unscaled fraction */ for (i = 0; i < SCALE_LENGTH; i++) { if (abval/1024 < scale_factors[i]) { unit = units[i]; fract = (i == 0) ? 0 : abval % scale_factors[i]; number /= scale_factors[i]; if (i > 0) fract /= scale_factors[i - 1]; break; } } fract = (10 * fract + 512) / 1024; /* if the result would be >= 10, round main number */ if (fract >= 10) { if (number >= 0) number++; else number--; fract = 0; } else if (fract < 0) { /* shouldn't happen */ fract = 0; } if (number == 0) strlcpy(result, "0B", FMT_SCALED_STRSIZE); else if (unit == NONE || number >= 100 || number <= -100) { if (fract >= 5) { if (number >= 0) number++; else number--; } (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c", number, scale_chars[unit]); } else (void)snprintf(result, FMT_SCALED_STRSIZE, "%lld.%1lld%c", number, fract, scale_chars[unit]); return 0; } #ifdef MAIN /* * This is the original version of the program in the man page. * Copy-and-paste whatever you need from it. */ int main(int argc, char **argv) { char *cinput = "1.5K", buf[FMT_SCALED_STRSIZE]; long long ninput = 10483892, result; if (scan_scaled(cinput, &result) == 0) printf("\"%s\" -> %lld\n", cinput, result); else perror(cinput); if (fmt_scaled(ninput, buf) == 0) printf("%lld -> \"%s\"\n", ninput, buf); else fprintf(stderr, "%lld invalid (%s)\n", ninput, strerror(errno)); return 0; } #endif openbgpd-8.8/compat/vis.c100644 001750 001750 00000014163 14751151130 0011124/* $OpenBSD: vis.c,v 1.26 2022/05/04 18:57:50 deraadt Exp $ */ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include static int isoctal(int c) { u_char uc = c; return uc >= '0' && uc <= '7'; } static int isvisible(int c, int flag) { int vis_sp = flag & VIS_SP; int vis_tab = flag & VIS_TAB; int vis_nl = flag & VIS_NL; int vis_safe = flag & VIS_SAFE; int vis_glob = flag & VIS_GLOB; int vis_all = flag & VIS_ALL; u_char uc = c; if (c == '\\' || !vis_all) { if ((u_int)c <= UCHAR_MAX && isascii(uc) && ((c != '*' && c != '?' && c != '[' && c != '#') || !vis_glob) && isgraph(uc)) return 1; if (!vis_sp && c == ' ') return 1; if (!vis_tab && c == '\t') return 1; if (!vis_nl && c == '\n') return 1; if (vis_safe && (c == '\b' || c == '\007' || c == '\r' || isgraph(uc))) return 1; } return 0; } /* * vis - visually encode characters */ char * vis(char *dst, int c, int flag, int nextc) { int vis_dq = flag & VIS_DQ; int vis_noslash = flag & VIS_NOSLASH; int vis_cstyle = flag & VIS_CSTYLE; int vis_octal = flag & VIS_OCTAL; int vis_glob = flag & VIS_GLOB; if (isvisible(c, flag)) { if ((c == '"' && vis_dq) || (c == '\\' && !vis_noslash)) *dst++ = '\\'; *dst++ = c; *dst = '\0'; return (dst); } if (vis_cstyle) { switch (c) { case '\n': *dst++ = '\\'; *dst++ = 'n'; goto done; case '\r': *dst++ = '\\'; *dst++ = 'r'; goto done; case '\b': *dst++ = '\\'; *dst++ = 'b'; goto done; case '\a': *dst++ = '\\'; *dst++ = 'a'; goto done; case '\v': *dst++ = '\\'; *dst++ = 'v'; goto done; case '\t': *dst++ = '\\'; *dst++ = 't'; goto done; case '\f': *dst++ = '\\'; *dst++ = 'f'; goto done; case ' ': *dst++ = '\\'; *dst++ = 's'; goto done; case '\0': *dst++ = '\\'; *dst++ = '0'; if (isoctal(nextc)) { *dst++ = '0'; *dst++ = '0'; } goto done; } } if (((c & 0177) == ' ') || vis_octal || (vis_glob && (c == '*' || c == '?' || c == '[' || c == '#'))) { *dst++ = '\\'; *dst++ = ((u_char)c >> 6 & 07) + '0'; *dst++ = ((u_char)c >> 3 & 07) + '0'; *dst++ = ((u_char)c & 07) + '0'; goto done; } if (!vis_noslash) *dst++ = '\\'; if (c & 0200) { c &= 0177; *dst++ = 'M'; } if (iscntrl((u_char)c)) { *dst++ = '^'; if (c == 0177) *dst++ = '?'; else *dst++ = c + '@'; } else { *dst++ = '-'; *dst++ = c; } done: *dst = '\0'; return (dst); } /* * strvis, strnvis, strvisx - visually encode characters from src into dst * * Dst must be 4 times the size of src to account for possible * expansion. The length of dst, not including the trailing NULL, * is returned. * * Strnvis will write no more than siz-1 bytes (and will NULL terminate). * The number of bytes needed to fully encode the string is returned. * * Strvisx encodes exactly len bytes from src into dst. * This is useful for encoding a block of data. */ int strvis(char *dst, const char *src, int flag) { char c; char *start; for (start = dst; (c = *src);) dst = vis(dst, c, flag, *++src); *dst = '\0'; return (dst - start); } int strnvis(char *dst, const char *src, size_t siz, int flag) { int vis_dq = flag & VIS_DQ; int vis_noslash = flag & VIS_NOSLASH; char *start, *end; char tbuf[5]; int c, i; i = 0; for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) { if (isvisible(c, flag)) { if ((c == '"' && vis_dq) || (c == '\\' && !vis_noslash)) { /* need space for the extra '\\' */ if (dst + 1 >= end) { i = 2; break; } *dst++ = '\\'; } i = 1; *dst++ = c; src++; } else { i = vis(tbuf, c, flag, *++src) - tbuf; if (dst + i <= end) { memcpy(dst, tbuf, i); dst += i; } else { src--; break; } } } if (siz > 0) *dst = '\0'; if (dst + i > end) { /* adjust return value for truncation */ while ((c = *src)) dst += vis(tbuf, c, flag, *++src) - tbuf; } return (dst - start); } int stravis(char **outp, const char *src, int flag) { char *buf; int len, serrno; buf = reallocarray(NULL, 4, strlen(src) + 1); if (buf == NULL) return -1; len = strvis(buf, src, flag); serrno = errno; *outp = realloc(buf, len + 1); if (*outp == NULL) { *outp = buf; errno = serrno; } return (len); } int strvisx(char *dst, const char *src, size_t len, int flag) { char c; char *start; for (start = dst; len > 1; len--) { c = *src; dst = vis(dst, c, flag, *++src); } if (len) dst = vis(dst, *src, flag, '\0'); *dst = '\0'; return (dst - start); } openbgpd-8.8/compat/explicit_bzero.c100644 001750 001750 00000000514 14751151130 0013340/* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */ /* * Public domain. * Written by Matthew Dempsky. */ #include __attribute__((weak)) void __explicit_bzero_hook(void *buf, size_t len) { } void explicit_bzero(void *buf, size_t len) { memset(buf, 0, len); __explicit_bzero_hook(buf, len); } openbgpd-8.8/src/bgpd/Makefile.am100644 001750 001750 00000006164 14576036603 0012451# # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS += -I$(top_srcdir)/src/bgpd ACLOCAL_AMFLAGS = -Im4 CLEANFILES = $(man_MANS) CLEANFILES += parse.c sbin_PROGRAMS = bgpd man_MANS = bgpd.8 man_MANS += bgpd.conf.5 EXTRA_DIST = bgpd.8.in bgpd.conf.5.in bgpd_CFLAGS = $(AM_CFLAGS) bgpd_CFLAGS += -DSYSCONFDIR=\"$(sysconfdir)\" bgpd_CFLAGS += -DRUNSTATEDIR=\"$(runstatedir)\" bgpd_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) -lutil bgpd_LDADD += $(top_builddir)/compat/libcompat.la bgpd_LDADD += $(top_builddir)/compat/libcompatnoopt.la bgpd_SOURCES = bgpd.c bgpd_SOURCES += session.c bgpd_SOURCES += log.c bgpd_SOURCES += logmsg.c bgpd_SOURCES += parse.y bgpd_SOURCES += config.c bgpd_SOURCES += rde.c bgpd_SOURCES += rde_rib.c bgpd_SOURCES += rde_decide.c bgpd_SOURCES += rde_prefix.c bgpd_SOURCES += mrt.c if DISABLE_FIB bgpd_SOURCES += kroute-disabled.c else if HOST_OPENBSD bgpd_SOURCES += kroute.c else if HOST_FREEBSD bgpd_SOURCES += kroute-freebsd.c else if HAVE_MNL bgpd_SOURCES += kroute-linux.c else bgpd_SOURCES += kroute-disabled.c endif endif endif endif bgpd_SOURCES += control.c if HOST_OPENBSD bgpd_SOURCES += pfkey.c else if HOST_FREEBSD bgpd_SOURCES += pfkey-freebsd.c else if HAVE_LINUX_TCPMD5 bgpd_SOURCES += pfkey-linux.c else bgpd_SOURCES += pfkey-disabled.c endif endif endif bgpd_SOURCES += rde_update.c bgpd_SOURCES += rde_attr.c bgpd_SOURCES += rde_community.c bgpd_SOURCES += printconf.c bgpd_SOURCES += rde_filter.c bgpd_SOURCES += rde_sets.c bgpd_SOURCES += rde_trie.c bgpd_SOURCES += rde_aspa.c if HAVE_PFTABLE bgpd_SOURCES += pftable.c else bgpd_SOURCES += pftable-disabled.c endif bgpd_SOURCES += name2id.c bgpd_SOURCES += util.c if HOST_OPENBSD bgpd_SOURCES += carp.c else bgpd_SOURCES += carp-disabled.c endif bgpd_SOURCES += timer.c bgpd_SOURCES += rde_peer.c bgpd_SOURCES += rtr.c bgpd_SOURCES += rtr_proto.c bgpd_SOURCES += flowspec.c bgpd_DEPENDENCIES = $(man_MANS) noinst_HEADERS = bgpd.h noinst_HEADERS += log.h noinst_HEADERS += mrt.h noinst_HEADERS += rde.h noinst_HEADERS += session.h noinst_HEADERS += version.h bgpd.conf.5: bgpd.conf.5.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ '$(srcdir)/bgpd.conf.5.in' >$@ bgpd.8: bgpd.8.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ '$(srcdir)/bgpd.8.in' >$@ openbgpd-8.8/src/bgpd/bgpd.h100644 001750 001750 00000131346 14751151130 0011467/* $OpenBSD: bgpd.h,v 1.512 2025/02/04 18:16:56 denis Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __BGPD_H__ #define __BGPD_H__ #include #include #include #include #include #include #include #include #include #include #include #include #define BGP_VERSION 4 #define RTR_MAX_VERSION 2 #define RTR_DEFAULT_VERSION 1 #define BGP_PORT 179 #define RTR_PORT 323 #define PEER_DESCR_LEN 64 #define REASON_LEN 256 /* includes NUL terminator */ #define PFTABLE_LEN 32 #define ROUTELABEL_LEN 32 #define TCP_MD5_KEY_LEN 80 #define IPSEC_ENC_KEY_LEN 32 #define IPSEC_AUTH_KEY_LEN 20 #define SET_NAME_LEN 128 #define MAX_PKTSIZE 4096 #define MAX_EXT_PKTSIZE 65535 #define MAX_BGPD_IMSGSIZE (128 * 1024) #define MAX_SOCK_BUF (4 * IBUF_READ_SIZE) #define RT_BUF_SIZE 16384 #define MAX_RTSOCK_BUF (2 * 1024 * 1024) #define MAX_COMM_MATCH 3 #define MAX_ASPA_SPAS_COUNT 10000 #define MIN_HOLDTIME 3 #define BGPD_OPT_VERBOSE 0x0001 #define BGPD_OPT_VERBOSE2 0x0002 #define BGPD_OPT_NOACTION 0x0004 #define BGPD_OPT_FORCE_DEMOTE 0x0008 #define BGPD_FLAG_REFLECTOR 0x0004 #define BGPD_FLAG_NEXTHOP_BGP 0x0010 #define BGPD_FLAG_NEXTHOP_DEFAULT 0x0020 #define BGPD_FLAG_DECISION_MASK 0x0f00 #define BGPD_FLAG_DECISION_ROUTEAGE 0x0100 #define BGPD_FLAG_DECISION_TRANS_AS 0x0200 #define BGPD_FLAG_DECISION_MED_ALWAYS 0x0400 #define BGPD_FLAG_DECISION_ALL_PATHS 0x0800 #define BGPD_FLAG_PERMIT_AS_SET 0x1000 #define BGPD_LOG_UPDATES 0x0001 #ifndef BGPD_USER #define BGPD_USER "_bgpd" #endif #ifndef SYSCONFDIR #define SYSCONFDIR "/etc" #endif #define CONFFILE SYSCONFDIR "/bgpd.conf" #ifndef RUNSTATEDIR #define RUNSTATEDIR "/var/run" #endif #define SOCKET_NAME RUNSTATEDIR "/bgpd.sock" #define F_BGPD 0x0001 #define F_BGPD_INSERTED 0x0002 #define F_CONNECTED 0x0004 #define F_STATIC 0x0008 #define F_NEXTHOP 0x0010 #define F_REJECT 0x0020 #define F_BLACKHOLE 0x0040 #define F_MPLS 0x0080 #define F_LONGER 0x0200 #define F_SHORTER 0x0400 #define F_CTL_DETAIL 0x1000 /* only set on requests */ #define F_CTL_ADJ_IN 0x2000 /* only set on requests */ #define F_CTL_ADJ_OUT 0x4000 /* only set on requests */ #define F_CTL_BEST 0x8000 #define F_CTL_INELIGIBLE 0x10000 /* only set on requests */ #define F_CTL_LEAKED 0x20000 /* only set on requests */ #define F_CTL_INVALID 0x40000 /* only set on requests */ #define F_CTL_OVS_VALID 0x80000 #define F_CTL_OVS_INVALID 0x100000 #define F_CTL_OVS_NOTFOUND 0x200000 #define F_CTL_NEIGHBORS 0x400000 /* only used by bgpctl */ #define F_CTL_HAS_PATHID 0x800000 /* only set on requests */ #define F_CTL_AVS_VALID 0x1000000 #define F_CTL_AVS_INVALID 0x2000000 #define F_CTL_AVS_UNKNOWN 0x4000000 #define F_CTL_FILTERED 0x8000000 /* only set on requests */ #define F_CTL_SSV 0x80000000 /* only used by bgpctl */ #define CTASSERT(x) extern char _ctassert[(x) ? 1 : -1 ] \ __attribute__((__unused__)) /* * Note that these numeric assignments differ from the numbers commonly * used in route origin validation context. */ #define ROA_NOTFOUND 0x0 /* default */ #define ROA_INVALID 0x1 #define ROA_VALID 0x2 #define ROA_MASK 0x3 #define ASPA_UNKNOWN 0x00 /* default */ #define ASPA_INVALID 0x01 #define ASPA_VALID 0x02 #define ASPA_MASK 0x03 #define ASPA_NEVER_KNOWN 0x08 /* unknown and check never needed */ /* * Limit the number of messages queued in the session engine. * The SE will send an IMSG_XOFF messages to the RDE if the high water mark * is reached. The RDE should then throttle this peer or control connection. * Once the message queue in the SE drops below the low water mark an * IMSG_XON message will be sent and the RDE will produce more messages again. */ #define RDE_RUNNER_ROUNDS 100 #define RDE_REAPER_ROUNDS 5000 #define SESS_MSG_HIGH_MARK 2000 #define SESS_MSG_LOW_MARK 500 #define CTL_MSG_HIGH_MARK 500 #define CTL_MSG_LOW_MARK 100 enum bgpd_process { PROC_MAIN, PROC_SE, PROC_RDE, PROC_RTR, }; enum reconf_action { RECONF_NONE, RECONF_KEEP, RECONF_REINIT, RECONF_RELOAD, RECONF_DELETE }; /* Address Family Numbers as per RFC 1700 */ #define AFI_UNSPEC 0 #define AFI_IPv4 1 #define AFI_IPv6 2 #define AFI_L2VPN 25 /* Subsequent Address Family Identifier as per RFC 4760 */ #define SAFI_NONE 0 #define SAFI_UNICAST 1 #define SAFI_MULTICAST 2 #define SAFI_MPLS 4 #define SAFI_EVPN 70 /* RFC 7432 */ #define SAFI_MPLSVPN 128 #define SAFI_FLOWSPEC 133 #define SAFI_VPNFLOWSPEC 134 struct aid { uint16_t afi; sa_family_t af; uint8_t safi; const char *name; }; extern const struct aid aid_vals[]; #define AID_UNSPEC 0 #define AID_INET 1 #define AID_INET6 2 #define AID_VPN_IPv4 3 #define AID_VPN_IPv6 4 #define AID_FLOWSPECv4 5 #define AID_FLOWSPECv6 6 #define AID_EVPN 7 #define AID_MAX 8 #define AID_MIN 1 /* skip AID_UNSPEC since that is a dummy */ #define AID_VALS { \ /* afi, af, safii, name */ \ { AFI_UNSPEC, AF_UNSPEC, SAFI_NONE, "unspec"}, \ { AFI_IPv4, AF_INET, SAFI_UNICAST, "IPv4 unicast" }, \ { AFI_IPv6, AF_INET6, SAFI_UNICAST, "IPv6 unicast" }, \ { AFI_IPv4, AF_INET, SAFI_MPLSVPN, "IPv4 vpn" }, \ { AFI_IPv6, AF_INET6, SAFI_MPLSVPN, "IPv6 vpn" }, \ { AFI_IPv4, AF_INET, SAFI_FLOWSPEC, "IPv4 flowspec" }, \ { AFI_IPv6, AF_INET6, SAFI_FLOWSPEC, "IPv6 flowspec" }, \ { AFI_L2VPN, AF_UNSPEC, SAFI_EVPN, "EVPN" }, \ } #define BGP_MPLS_BOS 0x01 #define ESI_ADDR_LEN 10 #define EVPN_ROUTE_TYPE_2 0x02 #define EVPN_ROUTE_TYPE_3 0x03 #define EVPN_ROUTE_TYPE_5 0x05 struct evpn_addr { union { struct in_addr v4; struct in6_addr v6; }; uint32_t ethtag; uint8_t mac[ETHER_ADDR_LEN]; uint8_t esi[ESI_ADDR_LEN]; uint8_t aid; uint8_t type; }; struct bgpd_addr { union { struct in_addr v4; struct in6_addr v6; struct evpn_addr evpn; /* maximum size for a prefix is 256 bits */ }; /* 128-bit address */ uint64_t rd; /* route distinguisher for VPN addrs */ uint32_t scope_id; /* iface scope id for v6 */ uint8_t aid; uint8_t labellen; /* size of the labelstack */ uint8_t labelstack[18]; /* max that makes sense */ }; #define DEFAULT_LISTENER 0x01 #define LISTENER_LISTENING 0x02 struct listen_addr { TAILQ_ENTRY(listen_addr) entry; struct sockaddr_storage sa; int fd; enum reconf_action reconf; socklen_t sa_len; uint8_t flags; }; TAILQ_HEAD(listen_addrs, listen_addr); TAILQ_HEAD(filter_set_head, filter_set); struct peer; RB_HEAD(peer_head, peer); struct l3vpn; SIMPLEQ_HEAD(l3vpn_head, l3vpn); struct network; TAILQ_HEAD(network_head, network); struct flowspec_config; RB_HEAD(flowspec_tree, flowspec_config); struct prefixset; SIMPLEQ_HEAD(prefixset_head, prefixset); struct prefixset_item; RB_HEAD(prefixset_tree, prefixset_item); struct tentry_v4; struct tentry_v6; struct trie_head { struct tentry_v4 *root_v4; struct tentry_v6 *root_v6; int match_default_v4; int match_default_v6; size_t v4_cnt; size_t v6_cnt; }; struct rde_prefixset { char name[SET_NAME_LEN]; struct trie_head th; SIMPLEQ_ENTRY(rde_prefixset) entry; time_t lastchange; int dirty; }; SIMPLEQ_HEAD(rde_prefixset_head, rde_prefixset); struct roa { RB_ENTRY(roa) entry; uint8_t aid; uint8_t prefixlen; uint8_t maxlen; uint8_t pad; uint32_t asnum; time_t expires; union { struct in_addr inet; struct in6_addr inet6; } prefix; }; RB_HEAD(roa_tree, roa); struct aspa_set; RB_HEAD(aspa_tree, aspa_set); struct set_table; struct as_set; SIMPLEQ_HEAD(as_set_head, as_set); struct filter_rule; TAILQ_HEAD(filter_head, filter_rule); struct rtr_config; SIMPLEQ_HEAD(rtr_config_head, rtr_config); struct bgpd_config { struct peer_head peers; struct l3vpn_head l3vpns; struct network_head networks; struct flowspec_tree flowspecs; struct filter_head *filters; struct listen_addrs *listen_addrs; struct mrt_head *mrt; struct prefixset_head prefixsets; struct prefixset_head originsets; struct roa_tree roa; struct aspa_tree aspa; struct rde_prefixset_head rde_prefixsets; struct rde_prefixset_head rde_originsets; struct as_set_head as_sets; struct rtr_config_head rtrs; char *csock; char *rcsock; int flags; int log; u_int default_tableid; uint32_t bgpid; uint32_t clusterid; uint32_t as; uint16_t short_as; uint16_t holdtime; uint16_t min_holdtime; uint16_t connectretry; uint16_t staletime; uint8_t fib_priority; uint8_t filtered_in_locrib; }; extern int cmd_opts; enum addpath_mode { ADDPATH_EVAL_NONE, ADDPATH_EVAL_BEST, ADDPATH_EVAL_ECMP, ADDPATH_EVAL_AS_WIDE, ADDPATH_EVAL_ALL, }; struct addpath_eval { enum addpath_mode mode; int extrapaths; int maxpaths; }; enum export_type { EXPORT_UNSET, EXPORT_NONE, EXPORT_DEFAULT_ROUTE }; enum enforce_as { ENFORCE_AS_UNDEF, ENFORCE_AS_OFF, ENFORCE_AS_ON }; enum role { ROLE_NONE, ROLE_CUSTOMER, ROLE_PROVIDER, ROLE_RS, ROLE_RS_CLIENT, ROLE_PEER, }; enum auth_method { AUTH_NONE, AUTH_MD5SIG, AUTH_IPSEC_MANUAL_ESP, AUTH_IPSEC_MANUAL_AH, AUTH_IPSEC_IKE_ESP, AUTH_IPSEC_IKE_AH }; enum auth_alg { AUTH_AALG_NONE, AUTH_AALG_SHA1HMAC, AUTH_AALG_MD5HMAC, }; enum auth_enc_alg { AUTH_EALG_NONE, AUTH_EALG_3DESCBC, AUTH_EALG_AES, }; struct auth_config { char md5key[TCP_MD5_KEY_LEN]; char auth_key_in[IPSEC_AUTH_KEY_LEN]; char auth_key_out[IPSEC_AUTH_KEY_LEN]; char enc_key_in[IPSEC_ENC_KEY_LEN]; char enc_key_out[IPSEC_ENC_KEY_LEN]; uint32_t spi_in; uint32_t spi_out; enum auth_method method; enum auth_alg auth_alg_in; enum auth_alg auth_alg_out; enum auth_enc_alg enc_alg_in; enum auth_enc_alg enc_alg_out; uint8_t md5key_len; uint8_t auth_keylen_in; uint8_t auth_keylen_out; uint8_t enc_keylen_in; uint8_t enc_keylen_out; }; struct capabilities { struct { int16_t timeout; /* graceful restart timeout */ int8_t flags[AID_MAX]; /* graceful restart per AID flags */ int8_t restart; /* graceful restart, RFC 4724 */ int8_t grnotification; /* graceful notification, RFC 8538 */ } grestart; int8_t mp[AID_MAX]; /* multiprotocol extensions, RFC 4760 */ int8_t add_path[AID_MAX]; /* ADD_PATH, RFC 7911 */ int8_t ext_nh[AID_MAX]; /* Ext Nexthop Encoding, RFC 8950 */ int8_t refresh; /* route refresh, RFC 2918 */ int8_t as4byte; /* 4-byte ASnum, RFC 4893 */ int8_t enhanced_rr; /* enhanced route refresh, RFC 7313 */ int8_t policy; /* Open Policy, RFC 9234, 2 = enforce */ int8_t ext_msg; /* Extended Msg, RFC 8654 */ }; enum capa_codes { CAPA_NONE = 0, CAPA_MP = 1, CAPA_REFRESH = 2, CAPA_EXT_NEXTHOP = 5, CAPA_EXT_MSG = 6, CAPA_ROLE = 9, CAPA_RESTART = 64, CAPA_AS4BYTE = 65, CAPA_ADD_PATH = 69, CAPA_ENHANCED_RR = 70, }; /* flags for RFC 4724 - graceful restart */ #define CAPA_GR_PRESENT 0x01 #define CAPA_GR_RESTART 0x02 #define CAPA_GR_FORWARD 0x04 #define CAPA_GR_RESTARTING 0x08 #define CAPA_GR_TIMEMASK 0x0fff #define CAPA_GR_R_FLAG 0x8000 #define CAPA_GR_N_FLAG 0x4000 #define CAPA_GR_F_FLAG 0x80 /* flags for RFC 7911 - enhanced router refresh */ #define CAPA_AP_RECV 0x01 #define CAPA_AP_SEND 0x02 #define CAPA_AP_BIDIR 0x03 #define CAPA_AP_MASK 0x0f #define CAPA_AP_RECV_ENFORCE 0x10 /* internal only */ #define CAPA_AP_SEND_ENFORCE 0x20 /* internal only */ /* values for RFC 9234 - BGP Open Policy */ #define CAPA_ROLE_PROVIDER 0x00 #define CAPA_ROLE_RS 0x01 #define CAPA_ROLE_RS_CLIENT 0x02 #define CAPA_ROLE_CUSTOMER 0x03 #define CAPA_ROLE_PEER 0x04 struct peer_config { struct bgpd_addr remote_addr; struct bgpd_addr local_addr_v4; struct bgpd_addr local_addr_v6; struct capabilities capabilities; struct addpath_eval eval; char group[PEER_DESCR_LEN]; char descr[PEER_DESCR_LEN]; char reason[REASON_LEN]; char rib[PEER_DESCR_LEN]; char if_depend[IFNAMSIZ]; char demote_group[IFNAMSIZ]; uint32_t id; uint32_t groupid; uint32_t remote_as; uint32_t local_as; uint32_t max_prefix; uint32_t max_out_prefix; enum export_type export_type; enum enforce_as enforce_as; enum enforce_as enforce_local_as; enum role role; uint16_t max_prefix_restart; uint16_t max_out_prefix_restart; uint16_t holdtime; uint16_t min_holdtime; uint16_t staletime; uint16_t local_short_as; uint16_t remote_port; uint8_t template; uint8_t remote_masklen; uint8_t ebgp; /* 0 = ibgp else ebgp */ uint8_t distance; /* 1 = direct, >1 = multihop */ uint8_t passive; uint8_t down; uint8_t reflector_client; uint8_t ttlsec; /* TTL security hack */ uint8_t flags; }; #define PEER_ID_NONE 0 #define PEER_ID_SELF 1 #define PEER_ID_STATIC_MIN 2 /* exclude self */ #define PEER_ID_STATIC_MAX (UINT_MAX / 2) #define PEER_ID_DYN_MAX UINT_MAX #define PEERFLAG_TRANS_AS 0x01 #define PEERFLAG_LOG_UPDATES 0x02 #define PEERFLAG_EVALUATE_ALL 0x04 #define PEERFLAG_PERMIT_AS_SET 0x08 struct rde_peer_stats { uint64_t prefix_rcvd_update; uint64_t prefix_rcvd_withdraw; uint64_t prefix_rcvd_eor; uint64_t prefix_sent_update; uint64_t prefix_sent_withdraw; uint64_t prefix_sent_eor; uint32_t prefix_cnt; uint32_t prefix_out_cnt; uint32_t pending_update; uint32_t pending_withdraw; }; enum network_type { NETWORK_DEFAULT, /* from network statements */ NETWORK_STATIC, NETWORK_CONNECTED, NETWORK_RTLABEL, NETWORK_MRTCLONE, NETWORK_PRIORITY, NETWORK_PREFIXSET, }; struct network_config { struct bgpd_addr prefix; struct filter_set_head attrset; char psname[SET_NAME_LEN]; uint64_t rd; enum network_type type; uint16_t rtlabel; uint8_t prefixlen; uint8_t priority; uint8_t old; /* used for reloading */ }; struct network { struct network_config net; TAILQ_ENTRY(network) entry; }; struct flowspec { uint16_t len; uint8_t aid; uint8_t flags; uint8_t data[1]; }; #define FLOWSPEC_SIZE (offsetof(struct flowspec, data)) struct flowspec_config { RB_ENTRY(flowspec_config) entry; struct filter_set_head attrset; struct flowspec *flow; enum reconf_action reconf_action; }; enum rtr_error { NO_ERROR = -1, CORRUPT_DATA = 0, INTERNAL_ERROR, NO_DATA_AVAILABLE, INVALID_REQUEST, UNSUPP_PROTOCOL_VERS, UNSUPP_PDU_TYPE, UNK_REC_WDRAWL, DUP_REC_RECV, UNEXP_PROTOCOL_VERS, }; struct rtr_config { SIMPLEQ_ENTRY(rtr_config) entry; char descr[PEER_DESCR_LEN]; struct auth_config auth; struct bgpd_addr remote_addr; struct bgpd_addr local_addr; uint32_t id; uint16_t remote_port; uint8_t min_version; }; struct rtr_config_msg { char descr[PEER_DESCR_LEN]; uint8_t min_version; }; struct ctl_show_rtr { char descr[PEER_DESCR_LEN]; char state[PEER_DESCR_LEN]; char last_sent_msg[REASON_LEN]; char last_recv_msg[REASON_LEN]; struct bgpd_addr remote_addr; struct bgpd_addr local_addr; uint32_t serial; uint32_t refresh; uint32_t retry; uint32_t expire; int session_id; enum rtr_error last_sent_error; enum rtr_error last_recv_error; uint16_t remote_port; uint8_t version; uint8_t min_version; }; enum imsg_type { IMSG_NONE, IMSG_CTL_END, IMSG_CTL_RELOAD, IMSG_CTL_FIB_COUPLE, IMSG_CTL_FIB_DECOUPLE, IMSG_CTL_NEIGHBOR_UP, IMSG_CTL_NEIGHBOR_DOWN, IMSG_CTL_NEIGHBOR_CLEAR, IMSG_CTL_NEIGHBOR_RREFRESH, IMSG_CTL_NEIGHBOR_DESTROY, IMSG_CTL_KROUTE, IMSG_CTL_KROUTE_ADDR, IMSG_CTL_RESULT, IMSG_CTL_SHOW_NEIGHBOR, IMSG_CTL_SHOW_NEXTHOP, IMSG_CTL_SHOW_INTERFACE, IMSG_CTL_SHOW_RIB, IMSG_CTL_SHOW_RIB_PREFIX, IMSG_CTL_SHOW_RIB_COMMUNITIES, IMSG_CTL_SHOW_RIB_ATTR, IMSG_CTL_SHOW_NETWORK, IMSG_CTL_SHOW_FLOWSPEC, IMSG_CTL_SHOW_RIB_MEM, IMSG_CTL_SHOW_TERSE, IMSG_CTL_SHOW_TIMER, IMSG_CTL_LOG_VERBOSE, IMSG_CTL_SHOW_FIB_TABLES, IMSG_CTL_SHOW_SET, IMSG_CTL_SHOW_RTR, IMSG_CTL_TERMINATE, IMSG_NETWORK_ADD, IMSG_NETWORK_ASPATH, IMSG_NETWORK_ATTR, IMSG_NETWORK_REMOVE, IMSG_NETWORK_FLUSH, IMSG_NETWORK_DONE, IMSG_FLOWSPEC_ADD, IMSG_FLOWSPEC_DONE, IMSG_FLOWSPEC_REMOVE, IMSG_FLOWSPEC_FLUSH, IMSG_FILTER_SET, IMSG_SOCKET_CONN, IMSG_SOCKET_CONN_CTL, IMSG_SOCKET_CONN_RTR, IMSG_SOCKET_SETUP, IMSG_SOCKET_TEARDOWN, IMSG_RECONF_CONF, IMSG_RECONF_RIB, IMSG_RECONF_PEER, IMSG_RECONF_PEER_AUTH, IMSG_RECONF_FILTER, IMSG_RECONF_LISTENER, IMSG_RECONF_CTRL, IMSG_RECONF_VPN, IMSG_RECONF_VPN_EXPORT, IMSG_RECONF_VPN_IMPORT, IMSG_RECONF_VPN_DONE, IMSG_RECONF_PREFIX_SET, IMSG_RECONF_PREFIX_SET_ITEM, IMSG_RECONF_AS_SET, IMSG_RECONF_AS_SET_ITEMS, IMSG_RECONF_AS_SET_DONE, IMSG_RECONF_ORIGIN_SET, IMSG_RECONF_ROA_SET, IMSG_RECONF_ROA_ITEM, IMSG_RECONF_ASPA, IMSG_RECONF_ASPA_TAS, IMSG_RECONF_ASPA_DONE, IMSG_RECONF_ASPA_PREP, IMSG_RECONF_RTR_CONFIG, IMSG_RECONF_DRAIN, IMSG_RECONF_DONE, IMSG_UPDATE, IMSG_UPDATE_ERR, IMSG_SESSION_ADD, IMSG_SESSION_UP, IMSG_SESSION_DOWN, IMSG_SESSION_DELETE, IMSG_SESSION_STALE, IMSG_SESSION_NOGRACE, IMSG_SESSION_FLUSH, IMSG_SESSION_RESTARTED, IMSG_SESSION_DEPENDON, IMSG_PFKEY_RELOAD, IMSG_MRT_OPEN, IMSG_MRT_REOPEN, IMSG_MRT_CLOSE, IMSG_KROUTE_CHANGE, IMSG_KROUTE_DELETE, IMSG_KROUTE_FLUSH, IMSG_NEXTHOP_ADD, IMSG_NEXTHOP_REMOVE, IMSG_NEXTHOP_UPDATE, IMSG_PFTABLE_ADD, IMSG_PFTABLE_REMOVE, IMSG_PFTABLE_COMMIT, IMSG_REFRESH, IMSG_DEMOTE, IMSG_XON, IMSG_XOFF }; struct demote_msg { char demote_group[IFNAMSIZ]; int level; }; enum ctl_results { CTL_RES_OK, CTL_RES_NOSUCHPEER, CTL_RES_DENIED, CTL_RES_NOCAP, CTL_RES_PARSE_ERROR, CTL_RES_PENDING, CTL_RES_NOMEM, CTL_RES_BADPEER, CTL_RES_BADSTATE, CTL_RES_NOSUCHRIB, CTL_RES_OPNOTSUPP, }; /* needed for session.h parse prototype */ LIST_HEAD(mrt_head, mrt); /* error codes and subcodes needed in SE and RDE */ enum err_codes { ERR_HEADER = 1, ERR_OPEN, ERR_UPDATE, ERR_HOLDTIMEREXPIRED, ERR_FSM, ERR_CEASE, ERR_RREFRESH, ERR_SENDHOLDTIMEREXPIRED, }; enum suberr_update { ERR_UPD_UNSPECIFIC, ERR_UPD_ATTRLIST, ERR_UPD_UNKNWN_WK_ATTR, ERR_UPD_MISSNG_WK_ATTR, ERR_UPD_ATTRFLAGS, ERR_UPD_ATTRLEN, ERR_UPD_ORIGIN, ERR_UPD_LOOP, ERR_UPD_NEXTHOP, ERR_UPD_OPTATTR, ERR_UPD_NETWORK, ERR_UPD_ASPATH }; enum suberr_cease { ERR_CEASE_MAX_PREFIX = 1, ERR_CEASE_ADMIN_DOWN, ERR_CEASE_PEER_UNCONF, ERR_CEASE_ADMIN_RESET, ERR_CEASE_CONN_REJECT, ERR_CEASE_OTHER_CHANGE, ERR_CEASE_COLLISION, ERR_CEASE_RSRC_EXHAUST, ERR_CEASE_HARD_RESET, ERR_CEASE_MAX_SENT_PREFIX }; enum suberr_rrefresh { ERR_RR_INV_LEN = 1 }; struct kroute; struct kroute6; struct knexthop; struct kredist_node; RB_HEAD(kroute_tree, kroute); RB_HEAD(kroute6_tree, kroute6); RB_HEAD(knexthop_tree, knexthop); RB_HEAD(kredist_tree, kredist_node); struct ktable { char descr[PEER_DESCR_LEN]; struct kroute_tree krt; struct kroute6_tree krt6; struct knexthop_tree knt; struct kredist_tree kredist; struct network_head krn; u_int rtableid; u_int nhtableid; /* rdomain id for nexthop lookup */ int nhrefcnt; /* refcnt for nexthop table */ enum reconf_action state; uint8_t fib_conf; /* configured FIB sync flag */ uint8_t fib_sync; /* is FIB synced with kernel? */ }; struct kroute_full { struct bgpd_addr prefix; struct bgpd_addr nexthop; char label[ROUTELABEL_LEN]; uint32_t mplslabel; uint16_t flags; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct kroute_nexthop { struct bgpd_addr nexthop; struct bgpd_addr gateway; struct bgpd_addr net; uint8_t netlen; uint8_t valid; uint8_t connected; }; struct session_dependon { char ifname[IFNAMSIZ]; uint8_t depend_state; /* for session depend on */ }; struct session_up { struct bgpd_addr local_v4_addr; struct bgpd_addr local_v6_addr; struct bgpd_addr remote_addr; struct capabilities capa; uint32_t remote_bgpid; unsigned int if_scope; uint16_t short_as; }; struct route_refresh { uint8_t aid; uint8_t subtype; }; #define ROUTE_REFRESH_REQUEST 0 #define ROUTE_REFRESH_BEGIN_RR 1 #define ROUTE_REFRESH_END_RR 2 struct pftable_msg { struct bgpd_addr addr; char pftable[PFTABLE_LEN]; uint8_t len; }; struct ctl_show_interface { char ifname[IFNAMSIZ]; char linkstate[32]; char media[32]; uint64_t baudrate; u_int rdomain; uint8_t nh_reachable; uint8_t is_up; }; struct ctl_show_nexthop { struct bgpd_addr addr; struct ctl_show_interface iface; struct kroute_full kr; uint8_t valid; uint8_t krvalid; }; struct ctl_show_set { char name[SET_NAME_LEN]; time_t lastchange; size_t v4_cnt; size_t v6_cnt; size_t as_cnt; enum { ASNUM_SET, PREFIX_SET, ORIGIN_SET, ROA_SET, ASPA_SET, } type; }; struct ctl_neighbor { struct bgpd_addr addr; char descr[PEER_DESCR_LEN]; char reason[REASON_LEN]; int show_timers; int is_group; }; #define F_PREF_ELIGIBLE 0x001 #define F_PREF_BEST 0x002 #define F_PREF_INTERNAL 0x004 #define F_PREF_ANNOUNCE 0x008 #define F_PREF_STALE 0x010 #define F_PREF_INVALID 0x020 #define F_PREF_PATH_ID 0x040 #define F_PREF_OTC_LEAK 0x080 #define F_PREF_ECMP 0x100 #define F_PREF_AS_WIDE 0x200 #define F_PREF_FILTERED 0x400 struct ctl_show_rib { struct bgpd_addr true_nexthop; struct bgpd_addr exit_nexthop; struct bgpd_addr prefix; struct bgpd_addr remote_addr; char descr[PEER_DESCR_LEN]; time_t age; uint32_t remote_id; uint32_t path_id; uint32_t local_pref; uint32_t med; uint32_t weight; uint32_t flags; uint8_t prefixlen; uint8_t origin; uint8_t roa_validation_state; uint8_t aspa_validation_state; int8_t dmetric; /* plus an aspath */ }; enum as_spec { AS_UNDEF, AS_ALL, AS_SOURCE, AS_TRANSIT, AS_PEER, AS_EMPTY }; enum aslen_spec { ASLEN_NONE, ASLEN_MAX, ASLEN_SEQ }; #define AS_FLAG_NEIGHBORAS 0x01 #define AS_FLAG_AS_SET_NAME 0x02 #define AS_FLAG_AS_SET 0x04 struct filter_as { char name[SET_NAME_LEN]; struct as_set *aset; uint32_t as_min; uint32_t as_max; enum as_spec type; uint8_t flags; uint8_t op; }; struct filter_aslen { u_int aslen; enum aslen_spec type; }; #define PREFIXSET_FLAG_FILTER 0x01 #define PREFIXSET_FLAG_DIRTY 0x02 /* prefix-set changed at reload */ #define PREFIXSET_FLAG_OPS 0x04 /* indiv. prefixes have prefixlenops */ #define PREFIXSET_FLAG_LONGER 0x08 /* filter all prefixes with or-longer */ struct filter_prefixset { int flags; char name[SET_NAME_LEN]; struct rde_prefixset *ps; }; struct filter_originset { char name[SET_NAME_LEN]; struct rde_prefixset *ps; }; struct filter_vs { uint8_t validity; uint8_t is_set; }; /* * Communities are encoded depending on their type. The low byte of flags * is the COMMUNITY_TYPE (BASIC, LARGE, EXT). BASIC encoding is just using * data1 and data2, LARGE uses all data fields and EXT is also using all * data fields. The 4-byte flags fields consists of up to 3 data flags * for e.g. COMMUNITY_ANY and the low byte is the community type. * If flags is 0 the community struct is unused. If the upper 24bit of * flags is 0 a fast compare can be used. * The code uses a type cast to uint8_t to access the type. */ struct community { uint32_t flags; uint32_t data1; uint32_t data2; uint32_t data3; }; struct ctl_show_rib_request { char rib[PEER_DESCR_LEN]; struct ctl_neighbor neighbor; struct bgpd_addr prefix; struct filter_as as; struct community community; uint32_t flags; uint32_t path_id; pid_t pid; enum imsg_type type; uint8_t validation_state; uint8_t prefixlen; uint8_t aid; }; struct ctl_kroute_req { int flags; sa_family_t af; }; enum filter_actions { ACTION_NONE, ACTION_ALLOW, ACTION_DENY }; enum directions { DIR_IN = 1, DIR_OUT }; enum from_spec { FROM_ALL, FROM_ADDRESS, FROM_DESCR, FROM_GROUP }; enum comp_ops { OP_NONE, OP_RANGE, OP_XRANGE, OP_EQ, OP_NE, OP_LE, OP_LT, OP_GE, OP_GT }; struct filter_peers { uint32_t peerid; uint32_t groupid; uint32_t remote_as; uint16_t ribid; uint8_t ebgp; uint8_t ibgp; }; /* special community type, keep in sync with the attribute type */ #define COMMUNITY_TYPE_NONE 0 #define COMMUNITY_TYPE_BASIC 8 #define COMMUNITY_TYPE_EXT 16 #define COMMUNITY_TYPE_LARGE 32 #define COMMUNITY_ANY 1 #define COMMUNITY_NEIGHBOR_AS 2 #define COMMUNITY_LOCAL_AS 3 /* wellknown community definitions */ #define COMMUNITY_WELLKNOWN 0xffff #define COMMUNITY_GRACEFUL_SHUTDOWN 0x0000 /* RFC 8326 */ #define COMMUNITY_BLACKHOLE 0x029A /* RFC 7999 */ #define COMMUNITY_NO_EXPORT 0xff01 #define COMMUNITY_NO_ADVERTISE 0xff02 #define COMMUNITY_NO_EXPSUBCONFED 0xff03 #define COMMUNITY_NO_PEER 0xff04 /* RFC 3765 */ /* extended community definitions */ #define EXT_COMMUNITY_IANA 0x80 #define EXT_COMMUNITY_NON_TRANSITIVE 0x40 #define EXT_COMMUNITY_VALUE 0x3f /* extended transitive types */ #define EXT_COMMUNITY_TRANS_TWO_AS 0x00 /* 2 octet AS specific */ #define EXT_COMMUNITY_TRANS_IPV4 0x01 /* IPv4 specific */ #define EXT_COMMUNITY_TRANS_FOUR_AS 0x02 /* 4 octet AS specific */ #define EXT_COMMUNITY_TRANS_OPAQUE 0x03 /* opaque ext community */ #define EXT_COMMUNITY_TRANS_EVPN 0x06 /* EVPN RFC 7432 */ /* extended non-transitive types */ #define EXT_COMMUNITY_NON_TRANS_TWO_AS 0x40 /* 2 octet AS specific */ #define EXT_COMMUNITY_NON_TRANS_IPV4 0x41 /* IPv4 specific */ #define EXT_COMMUNITY_NON_TRANS_FOUR_AS 0x42 /* 4 octet AS specific */ #define EXT_COMMUNITY_NON_TRANS_OPAQUE 0x43 /* opaque ext community */ #define EXT_COMMUNITY_UNKNOWN -1 /* generic transitive types */ #define EXT_COMMUNITY_GEN_TWO_AS 0x80 /* 2 octet AS specific */ #define EXT_COMMUNITY_GEN_IPV4 0x81 /* IPv4 specific */ #define EXT_COMMUNITY_GEN_FOUR_AS 0x82 /* 4 octet AS specific */ /* BGP Origin Validation State Extended Community RFC 8097 */ #define EXT_COMMUNITY_SUBTYPE_OVS 0 #define EXT_COMMUNITY_OVS_VALID 0 #define EXT_COMMUNITY_OVS_NOTFOUND 1 #define EXT_COMMUNITY_OVS_INVALID 2 /* other handy defines */ #define EXT_COMMUNITY_OPAQUE_MAX 0xffffffffffffULL #define EXT_COMMUNITY_FLAG_VALID 0x01 struct ext_comm_pairs { uint8_t type; uint8_t subtype; const char *subname; }; #define IANA_EXT_COMMUNITIES { \ { EXT_COMMUNITY_TRANS_TWO_AS, 0x02, "rt" }, \ { EXT_COMMUNITY_TRANS_TWO_AS, 0x03, "soo" }, \ { EXT_COMMUNITY_TRANS_TWO_AS, 0x05, "odi" }, \ { EXT_COMMUNITY_TRANS_TWO_AS, 0x08, "bdc" }, \ { EXT_COMMUNITY_TRANS_TWO_AS, 0x09, "srcas" }, \ { EXT_COMMUNITY_TRANS_TWO_AS, 0x0a, "l2vid" }, \ \ { EXT_COMMUNITY_TRANS_FOUR_AS, 0x02, "rt" }, \ { EXT_COMMUNITY_TRANS_FOUR_AS, 0x03, "soo" }, \ { EXT_COMMUNITY_TRANS_FOUR_AS, 0x05, "odi" }, \ { EXT_COMMUNITY_TRANS_FOUR_AS, 0x08, "bdc" }, \ { EXT_COMMUNITY_TRANS_FOUR_AS, 0x09, "srcas" }, \ \ { EXT_COMMUNITY_TRANS_IPV4, 0x02, "rt" }, \ { EXT_COMMUNITY_TRANS_IPV4, 0x03, "soo" }, \ { EXT_COMMUNITY_TRANS_IPV4, 0x05, "odi" }, \ { EXT_COMMUNITY_TRANS_IPV4, 0x07, "ori" }, \ { EXT_COMMUNITY_TRANS_IPV4, 0x0a, "l2vid" }, \ { EXT_COMMUNITY_TRANS_IPV4, 0x0b, "vrfri" }, \ \ { EXT_COMMUNITY_TRANS_OPAQUE, 0x06, "ort" }, \ { EXT_COMMUNITY_TRANS_OPAQUE, 0x0c, "encap" }, \ { EXT_COMMUNITY_TRANS_OPAQUE, 0x0d, "defgw" }, \ \ { EXT_COMMUNITY_NON_TRANS_OPAQUE, EXT_COMMUNITY_SUBTYPE_OVS, "ovs" }, \ \ { EXT_COMMUNITY_TRANS_EVPN, 0x00, "mac-mob" }, \ { EXT_COMMUNITY_TRANS_EVPN, 0x01, "esi-lab" }, \ { EXT_COMMUNITY_TRANS_EVPN, 0x02, "esi-rt" }, \ \ { EXT_COMMUNITY_GEN_TWO_AS, 0x06, "flow-rate" }, \ { EXT_COMMUNITY_GEN_TWO_AS, 0x0c, "flow-pps" }, \ { EXT_COMMUNITY_GEN_TWO_AS, 0x07, "flow-action" }, \ { EXT_COMMUNITY_GEN_TWO_AS, 0x08, "flow-rt-redir" }, \ { EXT_COMMUNITY_GEN_IPV4, 0x08, "flow-rt-redir" }, \ { EXT_COMMUNITY_GEN_FOUR_AS, 0x08, "flow-rt-redir" }, \ { EXT_COMMUNITY_GEN_TWO_AS, 0x09, "flow-dscp" }, \ \ { 0 } \ } extern const struct ext_comm_pairs iana_ext_comms[]; /* BGP flowspec defines RFC 8955 and 8956 */ #define FLOWSPEC_LEN_LIMIT 0xf0 #define FLOWSPEC_OP_EOL 0x80 #define FLOWSPEC_OP_AND 0x40 #define FLOWSPEC_OP_LEN_MASK 0x30 #define FLOWSPEC_OP_LEN_SHIFT 4 #define FLOWSPEC_OP_LEN(op) \ (1 << (((op) & FLOWSPEC_OP_LEN_MASK) >> FLOWSPEC_OP_LEN_SHIFT)) #define FLOWSPEC_OP_NUM_LT 0x04 #define FLOWSPEC_OP_NUM_GT 0x02 #define FLOWSPEC_OP_NUM_EQ 0x01 #define FLOWSPEC_OP_NUM_LE (FLOWSPEC_OP_NUM_LT | FLOWSPEC_OP_NUM_EQ) #define FLOWSPEC_OP_NUM_GE (FLOWSPEC_OP_NUM_GT | FLOWSPEC_OP_NUM_EQ) #define FLOWSPEC_OP_NUM_NOT (FLOWSPEC_OP_NUM_GT | FLOWSPEC_OP_NUM_LT) #define FLOWSPEC_OP_NUM_MASK 0x07 #define FLOWSPEC_OP_BIT_NOT 0x02 #define FLOWSPEC_OP_BIT_MATCH 0x01 #define FLOWSPEC_OP_BIT_MASK 0x03 #define FLOWSPEC_TYPE_MIN 1 #define FLOWSPEC_TYPE_DEST 1 #define FLOWSPEC_TYPE_SOURCE 2 #define FLOWSPEC_TYPE_PROTO 3 #define FLOWSPEC_TYPE_PORT 4 #define FLOWSPEC_TYPE_DST_PORT 5 #define FLOWSPEC_TYPE_SRC_PORT 6 #define FLOWSPEC_TYPE_ICMP_TYPE 7 #define FLOWSPEC_TYPE_ICMP_CODE 8 #define FLOWSPEC_TYPE_TCP_FLAGS 9 #define FLOWSPEC_TYPE_PKT_LEN 10 #define FLOWSPEC_TYPE_DSCP 11 #define FLOWSPEC_TYPE_FRAG 12 #define FLOWSPEC_TYPE_FLOW 13 #define FLOWSPEC_TYPE_MAX 14 #define FLOWSPEC_TCP_FLAG_STRING "FSRPAUEW" #define FLOWSPEC_FRAG_STRING4 "DIFL" #define FLOWSPEC_FRAG_STRING6 " IFL" struct filter_prefix { struct bgpd_addr addr; uint8_t op; uint8_t len; uint8_t len_min; uint8_t len_max; }; struct filter_nexthop { struct bgpd_addr addr; uint8_t flags; #define FILTER_NEXTHOP_ADDR 1 #define FILTER_NEXTHOP_NEIGHBOR 2 }; struct filter_match { struct filter_prefix prefix; struct filter_nexthop nexthop; struct filter_as as; struct filter_aslen aslen; struct community community[MAX_COMM_MATCH]; struct filter_prefixset prefixset; struct filter_originset originset; struct filter_vs ovs; struct filter_vs avs; int maxcomm; int maxextcomm; int maxlargecomm; }; struct filter_rule { TAILQ_ENTRY(filter_rule) entry; char rib[PEER_DESCR_LEN]; struct filter_peers peer; struct filter_match match; struct filter_set_head set; #define RDE_FILTER_SKIP_PEERID 0 #define RDE_FILTER_SKIP_GROUPID 1 #define RDE_FILTER_SKIP_REMOTE_AS 2 #define RDE_FILTER_SKIP_COUNT 3 struct filter_rule *skip[RDE_FILTER_SKIP_COUNT]; enum filter_actions action; enum directions dir; uint8_t quick; }; enum action_types { ACTION_SET_LOCALPREF, ACTION_SET_RELATIVE_LOCALPREF, ACTION_SET_MED, ACTION_SET_RELATIVE_MED, ACTION_SET_WEIGHT, ACTION_SET_RELATIVE_WEIGHT, ACTION_SET_PREPEND_SELF, ACTION_SET_PREPEND_PEER, ACTION_SET_AS_OVERRIDE, ACTION_SET_NEXTHOP, ACTION_SET_NEXTHOP_REF, ACTION_SET_NEXTHOP_REJECT, ACTION_SET_NEXTHOP_BLACKHOLE, ACTION_SET_NEXTHOP_NOMODIFY, ACTION_SET_NEXTHOP_SELF, ACTION_DEL_COMMUNITY, ACTION_SET_COMMUNITY, ACTION_PFTABLE, ACTION_PFTABLE_ID, ACTION_RTLABEL, ACTION_RTLABEL_ID, ACTION_SET_ORIGIN }; struct nexthop; struct filter_set { TAILQ_ENTRY(filter_set) entry; union { uint8_t prepend; uint16_t id; uint32_t metric; int32_t relative; struct bgpd_addr nexthop; struct nexthop *nh_ref; struct community community; char pftable[PFTABLE_LEN]; char rtlabel[ROUTELABEL_LEN]; uint8_t origin; } action; enum action_types type; }; struct roa_set { uint32_t as; /* must be first */ uint32_t maxlen; /* change type for better struct layout */ }; struct prefixset_item { struct filter_prefix p; RB_ENTRY(prefixset_item) entry; }; struct prefixset { int sflags; char name[SET_NAME_LEN]; struct prefixset_tree psitems; struct roa_tree roaitems; SIMPLEQ_ENTRY(prefixset) entry; }; struct as_set { char name[SET_NAME_LEN]; SIMPLEQ_ENTRY(as_set) entry; struct set_table *set; time_t lastchange; int dirty; }; struct aspa_set { time_t expires; uint32_t as; uint32_t num; uint32_t *tas; RB_ENTRY(aspa_set) entry; }; struct aspa_prep { size_t datasize; uint32_t entries; }; struct l3vpn { SIMPLEQ_ENTRY(l3vpn) entry; char descr[PEER_DESCR_LEN]; char ifmpe[IFNAMSIZ]; struct filter_set_head import; struct filter_set_head export; struct network_head net_l; uint64_t rd; u_int rtableid; u_int label; int flags; }; struct rde_rib { SIMPLEQ_ENTRY(rde_rib) entry; char name[PEER_DESCR_LEN]; u_int rtableid; uint16_t id; uint16_t flags; }; SIMPLEQ_HEAD(rib_names, rde_rib); extern struct rib_names ribnames; /* rde_rib flags */ #define F_RIB_LOCAL 0x0001 #define F_RIB_NOEVALUATE 0x0002 #define F_RIB_NOFIB 0x0004 #define F_RIB_NOFIBSYNC 0x0008 /* 4-byte magic AS number */ #define AS_TRANS 23456 /* AS_NONE for origin validation */ #define AS_NONE 0 struct rde_memstats { long long path_cnt; long long path_refs; long long prefix_cnt; long long rib_cnt; long long pt_cnt[AID_MAX]; long long pt_size[AID_MAX]; long long nexthop_cnt; long long aspath_cnt; long long aspath_size; long long comm_cnt; long long comm_nmemb; long long comm_size; long long comm_refs; long long attr_cnt; long long attr_refs; long long attr_data; long long attr_dcnt; long long aset_cnt; long long aset_size; long long aset_nmemb; long long pset_cnt; long long pset_size; }; #define MRT_FILE_LEN 512 #define MRT2MC(x) ((struct mrt_config *)(x)) enum mrt_type { MRT_NONE, MRT_TABLE_DUMP, MRT_TABLE_DUMP_MP, MRT_TABLE_DUMP_V2, MRT_ALL_IN, MRT_ALL_OUT, MRT_UPDATE_IN, MRT_UPDATE_OUT }; enum mrt_state { MRT_STATE_RUNNING, MRT_STATE_OPEN, MRT_STATE_REOPEN, MRT_STATE_REMOVE }; struct mrt { char rib[PEER_DESCR_LEN]; LIST_ENTRY(mrt) entry; struct msgbuf *wbuf; uint32_t peer_id; uint32_t group_id; int fd; enum mrt_type type; enum mrt_state state; uint16_t seqnum; }; struct mrt_config { struct mrt conf; char name[MRT_FILE_LEN]; /* base file name */ char file[MRT_FILE_LEN]; /* actual file name */ time_t ReopenTimer; int ReopenTimerInterval; }; /* prototypes */ /* bgpd.c */ void send_nexthop_update(struct kroute_nexthop *); void send_imsg_session(int, pid_t, void *, uint16_t); int send_network(int, struct network_config *, struct filter_set_head *); int bgpd_oknexthop(struct kroute_full *); int bgpd_has_bgpnh(void); void set_pollfd(struct pollfd *, struct imsgbuf *); int handle_pollfd(struct pollfd *, struct imsgbuf *); /* control.c */ int control_imsg_relay(struct imsg *, struct peer *); /* config.c */ struct bgpd_config *new_config(void); void copy_config(struct bgpd_config *, struct bgpd_config *); void network_free(struct network *); struct flowspec_config *flowspec_alloc(uint8_t, int); void flowspec_free(struct flowspec_config *); void free_l3vpns(struct l3vpn_head *); void free_config(struct bgpd_config *); void free_prefixsets(struct prefixset_head *); void free_rde_prefixsets(struct rde_prefixset_head *); void free_prefixtree(struct prefixset_tree *); void free_roatree(struct roa_tree *); void free_aspa(struct aspa_set *); void free_aspatree(struct aspa_tree *); void free_rtrs(struct rtr_config_head *); void filterlist_free(struct filter_head *); int host(const char *, struct bgpd_addr *, uint8_t *); uint32_t get_bgpid(void); void expand_networks(struct bgpd_config *, struct network_head *); RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp); RB_PROTOTYPE(roa_tree, roa, entry, roa_cmp); RB_PROTOTYPE(aspa_tree, aspa_set, entry, aspa_cmp); RB_PROTOTYPE(flowspec_tree, flowspec_config, entry, flowspec_config_cmp); /* kroute.c */ int kr_init(int *, uint8_t); int kr_default_prio(void); int kr_check_prio(long long); int ktable_update(u_int, char *, int); void ktable_preload(void); void ktable_postload(void); int ktable_exists(u_int, u_int *); int kr_change(u_int, struct kroute_full *); int kr_delete(u_int, struct kroute_full *); int kr_flush(u_int); void kr_shutdown(void); void kr_fib_couple(u_int); void kr_fib_couple_all(void); void kr_fib_decouple(u_int); void kr_fib_decouple_all(void); void kr_fib_prio_set(uint8_t); int kr_dispatch_msg(void); int kr_nexthop_add(uint32_t, struct bgpd_addr *); void kr_nexthop_delete(uint32_t, struct bgpd_addr *); void kr_show_route(struct imsg *); void kr_ifinfo(char *); void kr_net_reload(u_int, uint64_t, struct network_head *); int kr_reload(void); int get_mpe_config(const char *, u_int *, u_int *); uint8_t mask2prefixlen(sa_family_t, struct sockaddr *); /* log.c */ void log_peer_info(const struct peer_config *, const char *, ...) __attribute__((__format__ (printf, 2, 3))); void log_peer_warn(const struct peer_config *, const char *, ...) __attribute__((__format__ (printf, 2, 3))); void log_peer_warnx(const struct peer_config *, const char *, ...) __attribute__((__format__ (printf, 2, 3))); /* mrt.c */ void mrt_write(struct mrt *); void mrt_clean(struct mrt *); void mrt_init(struct imsgbuf *, struct imsgbuf *); time_t mrt_timeout(struct mrt_head *); void mrt_reconfigure(struct mrt_head *); void mrt_handler(struct mrt_head *); struct mrt *mrt_get(struct mrt_head *, struct mrt *); void mrt_mergeconfig(struct mrt_head *, struct mrt_head *); /* name2id.c */ uint16_t rtlabel_name2id(const char *); const char *rtlabel_id2name(uint16_t); void rtlabel_unref(uint16_t); uint16_t rtlabel_ref(uint16_t); uint16_t pftable_name2id(const char *); const char *pftable_id2name(uint16_t); void pftable_unref(uint16_t); uint16_t pftable_ref(uint16_t); /* parse.y */ int cmdline_symset(char *); struct prefixset *find_prefixset(char *, struct prefixset_head *); struct bgpd_config *parse_config(char *, struct peer_head *, struct rtr_config_head *); /* pftable.c */ int pftable_exists(const char *); int pftable_add(const char *); int pftable_clear_all(void); int pftable_addr_add(struct pftable_msg *); int pftable_addr_remove(struct pftable_msg *); int pftable_commit(void); /* rde_filter.c */ void filterset_free(struct filter_set_head *); int filterset_cmp(struct filter_set *, struct filter_set *); void filterset_move(struct filter_set_head *, struct filter_set_head *); void filterset_copy(struct filter_set_head *, struct filter_set_head *); const char *filterset_name(enum action_types); /* rde_sets.c */ struct as_set *as_sets_lookup(struct as_set_head *, const char *); struct as_set *as_sets_new(struct as_set_head *, const char *, size_t, size_t); void as_sets_free(struct as_set_head *); void as_sets_mark_dirty(struct as_set_head *, struct as_set_head *); int as_set_match(const struct as_set *, uint32_t); struct set_table *set_new(size_t, size_t); void set_free(struct set_table *); int set_add(struct set_table *, void *, size_t); void *set_get(struct set_table *, size_t *); void set_prep(struct set_table *); void *set_match(const struct set_table *, uint32_t); int set_equal(const struct set_table *, const struct set_table *); size_t set_nmemb(const struct set_table *); /* rde_trie.c */ int trie_add(struct trie_head *, struct bgpd_addr *, uint8_t, uint8_t, uint8_t); int trie_roa_add(struct trie_head *, struct roa *); void trie_free(struct trie_head *); int trie_match(struct trie_head *, struct bgpd_addr *, uint8_t, int); int trie_roa_check(struct trie_head *, struct bgpd_addr *, uint8_t, uint32_t); void trie_dump(struct trie_head *); int trie_equal(struct trie_head *, struct trie_head *); /* timer.c */ time_t getmonotime(void); /* util.c */ char *ibuf_get_string(struct ibuf *, size_t); const char *log_addr(const struct bgpd_addr *); const char *log_evpnaddr(const struct bgpd_addr *, struct sockaddr *, socklen_t); const char *log_in6addr(const struct in6_addr *); const char *log_sockaddr(struct sockaddr *, socklen_t); const char *log_as(uint32_t); const char *log_rd(uint64_t); const char *log_ext_subtype(int, uint8_t); const char *log_reason(const char *); const char *log_aspath_error(int); const char *log_roa(struct roa *); const char *log_aspa(struct aspa_set *); const char *log_rtr_error(enum rtr_error); const char *log_policy(enum role); const char *log_capability(uint8_t); int aspath_asprint(char **, struct ibuf *); uint32_t aspath_extract(const void *, int); int aspath_verify(struct ibuf *, int, int); #define AS_ERR_LEN -1 #define AS_ERR_TYPE -2 #define AS_ERR_BAD -3 #define AS_ERR_SOFT -4 struct ibuf *aspath_inflate(struct ibuf *); int extract_prefix(const u_char *, int, void *, uint8_t, uint8_t); int nlri_get_prefix(struct ibuf *, struct bgpd_addr *, uint8_t *); int nlri_get_prefix6(struct ibuf *, struct bgpd_addr *, uint8_t *); int nlri_get_vpn4(struct ibuf *, struct bgpd_addr *, uint8_t *, int); int nlri_get_vpn6(struct ibuf *, struct bgpd_addr *, uint8_t *, int); int nlri_get_evpn(struct ibuf *, struct bgpd_addr *, uint8_t *); int prefix_compare(const struct bgpd_addr *, const struct bgpd_addr *, int); void inet4applymask(struct in_addr *, const struct in_addr *, int); void inet6applymask(struct in6_addr *, const struct in6_addr *, int); void applymask(struct bgpd_addr *, const struct bgpd_addr *, int); const char *aid2str(uint8_t); int aid2afi(uint8_t, uint16_t *, uint8_t *); int afi2aid(uint16_t, uint8_t, uint8_t *); sa_family_t aid2af(uint8_t); int af2aid(sa_family_t, uint8_t, uint8_t *); struct sockaddr *addr2sa(const struct bgpd_addr *, uint16_t, socklen_t *); void sa2addr(struct sockaddr *, struct bgpd_addr *, uint16_t *); const char * get_baudrate(unsigned long long, char *); /* flowspec.c */ int flowspec_valid(const uint8_t *, int, int); int flowspec_cmp(const uint8_t *, int, const uint8_t *, int, int); int flowspec_get_component(const uint8_t *, int, int, int, const uint8_t **, int *); int flowspec_get_addr(const uint8_t *, int, int, int, struct bgpd_addr *, uint8_t *, uint8_t *); const char *flowspec_fmt_label(int); const char *flowspec_fmt_num_op(const uint8_t *, int, int *); const char *flowspec_fmt_bin_op(const uint8_t *, int, int *, const char *); static const char * const log_procnames[] = { "parent", "SE", "RDE", "RTR" }; /* logmsg.c and needed by bgpctl */ static const char * const statenames[] = { "None", "Idle", "Connect", "Active", "OpenSent", "OpenConfirm", "Established" }; static const char * const msgtypenames[] = { "NONE", "OPEN", "UPDATE", "NOTIFICATION", "KEEPALIVE", "RREFRESH" }; static const char * const eventnames[] = { "None", "Start", "Stop", "Connection opened", "Connection closed", "Connection open failed", "Fatal error", "ConnectRetryTimer expired", "HoldTimer expired", "KeepaliveTimer expired", "SendHoldTimer expired", "OPEN message received", "KEEPALIVE message received", "UPDATE message received", "NOTIFICATION received", "graceful NOTIFICATION received", }; static const char * const errnames[] = { "none", "Header error", "error in OPEN message", "error in UPDATE message", "HoldTimer expired", "Finite State Machine error", "Cease", "error in ROUTE-REFRESH message" }; static const char * const suberr_header_names[] = { "none", "synchronization error", "wrong length", "unknown message type" }; static const char * const suberr_open_names[] = { "none", "version mismatch", "AS unacceptable", "BGPID invalid", "optional parameter error", "authentication error", "unacceptable holdtime", "unsupported capability", NULL, NULL, NULL, "role mismatch", }; static const char * const suberr_fsm_names[] = { "unspecified error", "received unexpected message in OpenSent", "received unexpected message in OpenConfirm", "received unexpected message in Established" }; static const char * const suberr_update_names[] = { "none", "attribute list error", "unknown well-known attribute", "well-known attribute missing", "attribute flags error", "attribute length wrong", "origin unacceptable", "loop detected", "nexthop unacceptable", "optional attribute error", "network unacceptable", "AS-Path unacceptable" }; static const char * const suberr_cease_names[] = { "none", "received max-prefix exceeded", "administratively down", "peer unconfigured", "administrative reset", "connection rejected", "other config change", "collision", "resource exhaustion", "hard reset", "sent max-prefix exceeded" }; static const char * const suberr_rrefresh_names[] = { "none", "invalid message length" }; static const char * const ctl_res_strerror[] = { "no error", "no such neighbor", "permission denied", "neighbor does not have this capability", "config file has errors, reload failed", "previous reload still running", "out of memory", "not a cloned peer", "peer still active, down peer first", "no such RIB", "operation not supported", }; static const char * const timernames[] = { "None", "ConnectRetryTimer", "KeepaliveTimer", "HoldTimer", "SendHoldTimer", "IdleHoldTimer", "IdleHoldResetTimer", "CarpUndemoteTimer", "RestartTimer", "SessionDownTimer", "RTR RefreshTimer", "RTR RetryTimer", "RTR ExpireTimer", "RTR ActiveTimer", "" }; #endif /* __BGPD_H__ */ openbgpd-8.8/src/bgpd/log.h100644 001750 001750 00000003317 13751203036 0011332/* $OpenBSD: log.h,v 1.20 2020/10/21 06:48:33 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef LOG_H #define LOG_H #include #include void log_init(int, int); void log_procinit(const char *); void log_setverbose(int); int log_getverbose(void); void log_warn(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_warnx(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_info(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void log_debug(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void logit(int, const char *, ...) __attribute__((__format__ (printf, 2, 3))); void vlog(int, const char *, va_list) __attribute__((__format__ (printf, 2, 0))); __dead void fatal(const char *, ...) __attribute__((__format__ (printf, 1, 2))); __dead void fatalx(const char *, ...) __attribute__((__format__ (printf, 1, 2))); #endif /* LOG_H */ openbgpd-8.8/src/bgpd/mrt.h100644 001750 001750 00000032241 14403051271 0011346/* $OpenBSD: mrt.h,v 1.38 2022/12/28 21:30:16 jmc Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __MRT_H__ #define __MRT_H__ /* * MRT binary packet format * For more info see: * RFC6396 , "MRT Routing Information Export Format" * http://www.quagga.net/docs/docs-multi/Packet-Binary-Dump-Format.html */ /* * MRT header: * +--------+--------+--------+--------+ * | timestamp | * +--------+--------+--------+--------+ * | type | subtype | * +--------+--------+--------+--------+ * | length | length of packet excluding this header * +--------+--------+--------+--------+ * * ET types include an additional 32bit microsecond field coming after the * length field. Which is accounted in the length field. */ #define MRT_HEADER_SIZE 12 #define MRT_ET_HEADER_SIZE 16 struct mrt_hdr { uint32_t timestamp; uint16_t type; uint16_t subtype; uint32_t length; } __packed; enum MRT_MSG_TYPES { MSG_NULL, /* 0 empty msg (deprecated) */ MSG_START, /* 1 sender is starting up */ MSG_DIE, /* 2 receiver should shut down (deprecated) */ MSG_I_AM_DEAD, /* 3 sender is shutting down */ MSG_PEER_DOWN, /* 4 sender's peer is down (deprecated) */ MSG_PROTOCOL_BGP, /* 5 msg is a BGP packet (deprecated) */ MSG_PROTOCOL_RIP, /* 6 msg is a RIP packet */ MSG_PROTOCOL_IDRP, /* 7 msg is an IDRP packet (deprecated) */ MSG_PROTOCOL_RIPNG, /* 8 msg is a RIPNG packet */ MSG_PROTOCOL_BGP4PLUS, /* 9 msg is a BGP4+ packet (deprecated) */ MSG_PROTOCOL_BGP4PLUS1, /* 10 msg is a BGP4+ (draft 01) (deprecated) */ MSG_PROTOCOL_OSPF, /* 11 msg is an OSPF packet */ MSG_TABLE_DUMP, /* 12 routing table dump */ MSG_TABLE_DUMP_V2, /* 13 routing table dump */ MSG_PROTOCOL_BGP4MP=16, /* 16 zebras own packet format */ MSG_PROTOCOL_BGP4MP_ET=17, MSG_PROTOCOL_ISIS=32, /* 32 msg is a ISIS package */ MSG_PROTOCOL_ISIS_ET=33, MSG_PROTOCOL_OSPFV3=48, /* 48 msg is a OSPFv3 package */ MSG_PROTOCOL_OSPFV3_ET=49 }; /* * Main zebra dump format is in MSG_PROTOCOL_BGP4MP exceptions are table dumps * that are normally saved as MSG_TABLE_DUMP. * In most cases this is the format to choose to dump updates et al. */ enum MRT_BGP4MP_SUBTYPES { BGP4MP_STATE_CHANGE, /* state change */ BGP4MP_MESSAGE, /* bgp message */ BGP4MP_ENTRY, /* table dumps (deprecated) */ BGP4MP_SNAPSHOT, /* file name for dump (deprecated) */ BGP4MP_MESSAGE_AS4, /* same as BGP4MP_MESSAGE with 4byte AS */ BGP4MP_STATE_CHANGE_AS4, BGP4MP_MESSAGE_LOCAL, /* same as BGP4MP_MESSAGE but for self */ BGP4MP_MESSAGE_AS4_LOCAL, /* originated updates. Not implemented */ BGP4MP_MESSAGE_ADDPATH, /* same as above but for add-path peers */ BGP4MP_MESSAGE_AS4_ADDPATH, BGP4MP_MESSAGE_LOCAL_ADDPATH, BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH, }; /* size of the BGP4MP headers without payload */ #define MRT_BGP4MP_IPv4_HEADER_SIZE 16 #define MRT_BGP4MP_IPv6_HEADER_SIZE 40 #define MRT_BGP4MP_ET_IPv4_HEADER_SIZE 20 #define MRT_BGP4MP_ET_IPv6_HEADER_SIZE 44 /* 4-byte AS variants of the previous */ #define MRT_BGP4MP_AS4_IPv4_HEADER_SIZE 20 #define MRT_BGP4MP_AS4_IPv6_HEADER_SIZE 44 #define MRT_BGP4MP_ET_AS4_IPv4_HEADER_SIZE 24 #define MRT_BGP4MP_ET_AS4_IPv6_HEADER_SIZE 48 /* If the type is PROTOCOL_BGP4MP and the subtype is either BGP4MP_STATE_CHANGE * or BGP4MP_MESSAGE the message consists of a common header plus the payload. * Header format: * * +--------+--------+--------+--------+ * | source_as | dest_as | * +--------+--------+--------+--------+ * | if_index | afi | * +--------+--------+--------+--------+ * | source_ip | * +--------+--------+--------+--------+ * | dest_ip | * +--------+--------+--------+--------+ * | message specific payload ... * +--------+--------+--------+--------+ * * The source_ip and dest_ip are dependant of the afi type. For IPv6 source_ip * and dest_ip are both 16 bytes long. * For the AS4 types the source_as and dest_as numbers are both 4 bytes long. * * Payload of a BGP4MP_STATE_CHANGE packet: * * +--------+--------+--------+--------+ * | old_state | new_state | * +--------+--------+--------+--------+ * * The state values are the same as in RFC 1771. * * The payload of a BGP4MP_MESSAGE is the full bgp message with header. */ /* * size of the BGP4MP entries without variable stuff. * All until nexthop plus attr_len, not included plen, prefix and bgp attrs. */ #define MRT_BGP4MP_IPv4_ENTRY_SIZE 18 #define MRT_BGP4MP_IPv6_ENTRY_SIZE 30 #define MRT_BGP4MP_MAX_PREFIXLEN 256 /* * The "new" table dump format consists of messages of type PROTOCOL_BGP4MP * and subtype BGP4MP_ENTRY. * * +--------+--------+--------+--------+ * | view | status | * +--------+--------+--------+--------+ * | originated | * +--------+--------+--------+--------+ * | afi | safi | nhlen | * +--------+--------+--------+--------+ * | nexthop | * +--------+--------+--------+--------+ * | plen | prefix variable ... | * +--------+--------+--------+--------+ * | attr_len | bgp attributes * +--------+--------+--------+--------+ * bgp attributes, attr_len bytes long * +--------+--------+--------+--------+ * ... | * +--------+--------+--------+ * * View is normally 0 and originated the time of last change. * The status seems to be 1 by default but probably something to indicate * the status of a prefix would be more useful. * The format of the nexthop address is defined via the afi value. For IPv6 * the nexthop field is 16 bytes long. * The prefix field is as in the bgp update message variable length. It is * plen bits long but rounded to the next octet. */ /* * New MRT dump format MSG_TABLE_DUMP_V2, the dump is implemented with * sub-tables for peers and NLRI entries just use the index into the peer * table. */ enum MRT_DUMP_V2_SUBTYPES { MRT_DUMP_V2_PEER_INDEX_TABLE=1, MRT_DUMP_V2_RIB_IPV4_UNICAST=2, MRT_DUMP_V2_RIB_IPV4_MULTICAST=3, MRT_DUMP_V2_RIB_IPV6_UNICAST=4, MRT_DUMP_V2_RIB_IPV6_MULTICAST=5, MRT_DUMP_V2_RIB_GENERIC=6, MRT_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH=8, MRT_DUMP_V2_RIB_IPV4_MULTICAST_ADDPATH=9, MRT_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH=10, MRT_DUMP_V2_RIB_IPV6_MULTICAST_ADDPATH=11, MRT_DUMP_V2_RIB_GENERIC_ADDPATH=12, }; /* * Format of the MRT_DUMP_V2_PEER_INDEX_TABLE: * If there is no view_name, view_name_len must be set to 0 * * +--------+--------+--------+--------+ * | collector_bgp_id | * +--------+--------+--------+--------+ * | view_name_len | view_name * +--------+--------+--------+--------+ * view_name (variable) ... | * +--------+--------+--------+--------+ * | peer_count | peer_entries * +--------+--------+--------+--------+ * peer_entries (variable) ... * +--------+--------+--------+--------+ * * The format of a peer_entry is the following: * * +--------+ * | type | * +--------+--------+--------+--------+ * | peer_bgp_id | * +--------+--------+--------+--------+ * | peer_ip_addr (variable) | * +--------+--------+--------+--------+ * | peer_as (variable) | * +--------+--------+--------+--------+ * * The message is packed a bit strangely. The type byte defines what size * the peer addr and peer AS have. * The position of a peer in the PEER_INDEX_TABLE is used as the index for * the other messages. */ #define MRT_DUMP_V2_PEER_BIT_I 0x1 /* set for IPv6 addrs */ #define MRT_DUMP_V2_PEER_BIT_A 0x2 /* set for 32 bits AS number */ /* * AFI/SAFI specific RIB Subtypes are special to save a few bytes. * * +--------+--------+--------+--------+ * | seq_num | * +--------+--------+--------+--------+ * | plen | prefix (variable) * +--------+--------+--------+--------+ * | #entry | rib entries (variable) * +--------+--------+--------+--------+ * * The RIB_GENERIC subtype is needed for the less common AFI/SAFI pairs. * * +--------+--------+--------+--------+ * | seq_num | * +--------+--------+--------+--------+ * | AFI | SAFI | NLRI * +--------+--------+--------+--------+ * NLRI (variable) ... * +--------+--------+--------+--------+ * | #entry | rib entries (variable) * +--------+--------+--------+--------+ */ /* * The RIB entries have the following form. * * +--------+--------+ * | peer index | * +--------+--------+--------+--------+ * | originated_time | * +--------+--------+--------+--------+ * [ path_id in _ADDPATH variants ] * +--------+--------+--------+--------+ * | attr_len | bgp_attrs * +--------+--------+--------+--------+ * bgp_attrs (variable) ... * +--------+--------+--------+--------+ * * Some BGP path attributes need special encoding: * - the AS_PATH attribute MUST be encoded as 4-Byte AS * - the MP_REACH_NLRI only consists of the nexthop len and nexthop address * * The non generic ADDPATH variants add the path-identifier between * originated_time and attr_len. For RIB_GENERIC_ADDPATH the path_id should * be part of the NLRI. */ /* * Format for routing table dumps in "old" mrt format. * Type MSG_TABLE_DUMP and subtype is AFI_IPv4 (1) for IPv4 and AFI_IPv6 (2) * for IPv6. In the IPv6 case prefix and peer_ip are both 16 bytes long. * * +--------+--------+--------+--------+ * | view | seqnum | * +--------+--------+--------+--------+ * | prefix | * +--------+--------+--------+--------+ * | plen | status | originated time * +--------+--------+--------+--------+ * originated time | peer_ip * +--------+--------+--------+--------+ * peer_ip | peer_as | * +--------+--------+--------+--------+ * | attr_len | bgp attributes * +--------+--------+--------+--------+ * bgp attributes, attr_len bytes long * +--------+--------+--------+--------+ * ... | * +--------+--------+--------+ * * * View is normally 0 and seqnum just a simple counter for this dump. * The status field is unused and should be set to 1. */ enum MRT_DUMP_SUBTYPES { MRT_DUMP_AFI_IP=1, MRT_DUMP_AFI_IPv6=2 }; /* size of the dump header until attr_len */ #define MRT_DUMP_HEADER_SIZE 22 #define MRT_DUMP_HEADER_SIZE_V6 46 /* * OLD MRT message headers. These structs are here for completion but * will not be used to generate dumps. It seems that nobody uses those. * * Only for bgp messages (type 5, 9 and 10) * Nota bene for bgp dumps MSG_PROTOCOL_BGP4MP should be used. */ enum MRT_BGP_SUBTYPES { MSG_BGP_NULL, MSG_BGP_UPDATE, /* raw update packet (contains both withdraws and announcements) */ MSG_BGP_PREF_UPDATE, /* tlv preferences followed by raw update */ MSG_BGP_STATE_CHANGE, /* state change */ MSG_BGP_SYNC, /* file name for a table dump */ MSG_BGP_OPEN, /* BGP open messages */ MSG_BGP_NOTIFY, /* BGP notify messages */ MSG_BGP_KEEPALIVE /* BGP keepalives */ }; /* if type MSG_PROTOCOL_BGP and subtype MSG_BGP_UPDATE, MSG_BGP_OPEN, * MSG_BGP_NOTIFY or MSG_BGP_KEEPALIVE * * +--------+--------+--------+--------+ * | source_as | source_ip * +--------+--------+--------+--------+ * source_ip | dest_as | * +--------+--------+--------+--------+ * | dest_ip | * +--------+--------+--------+--------+ * | bgp update packet with header et * +--------+--------+--------+--------+ * al. (variable length) ... * +--------+--------+--------+--------+ * * For IPv6 the type is MSG_PROTOCOL_BGP4PLUS and the subtype remains * MSG_BGP_UPDATE. The source_ip and dest_ip are again extended to 16 bytes. * * For subtype MSG_BGP_STATE_CHANGE (for all BGP types or just for the * MSG_PROTOCOL_BGP4PLUS case? Unclear.) * * +--------+--------+--------+--------+ * | source_as | source_ip * +--------+--------+--------+--------+ * source_ip | old_state | * +--------+--------+--------+--------+ * | new_state | * +--------+--------+ * * States are defined in RFC 1771/4271. */ /* * if type MSG_PROTOCOL_BGP and subtype MSG_BGP_SYNC OR * if type MSG_PROTOCOL_BGP4MP and subtype BGP4MP_SNAPSHOT * *DEPRECATED* * * +--------+--------+--------+--------+ * | view | filename * +--------+--------+--------+--------+ * filename variable length zero * +--------+--------+--------+--------+ * terminated ... | 0 | * +--------+--------+--------+ */ #endif openbgpd-8.8/src/bgpd/rde.h100644 001750 001750 00000053352 14751151130 0011325/* $OpenBSD: rde.h,v 1.313 2025/01/27 15:22:11 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker and * Andre Oppermann * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #ifndef __RDE_H__ #define __RDE_H__ #include #include #include #include #include #include "bgpd.h" #include "log.h" /* rde internal structures */ enum peer_state { PEER_NONE, PEER_DOWN, PEER_UP, PEER_ERR /* error occurred going to PEER_DOWN state */ }; LIST_HEAD(prefix_list, prefix); TAILQ_HEAD(prefix_queue, prefix); RB_HEAD(rib_tree, rib_entry); struct rib_entry { RB_ENTRY(rib_entry) rib_e; struct prefix_queue prefix_h; struct pt_entry *prefix; uint16_t rib_id; uint16_t lock; }; struct rib { struct rib_tree tree; char name[PEER_DESCR_LEN]; struct filter_head *in_rules; struct filter_head *in_rules_tmp; u_int rtableid; u_int rtableid_tmp; enum reconf_action state, fibstate; uint16_t id; uint16_t flags; uint16_t flags_tmp; }; #define RIB_ADJ_IN 0 #define RIB_LOC_START 1 #define RIB_NOTFOUND 0xffff /* * How do we identify peers between the session handler and the rde? * Currently I assume that we can do that with the neighbor_ip... */ RB_HEAD(peer_tree, rde_peer); RB_HEAD(prefix_tree, prefix); RB_HEAD(prefix_index, prefix); struct iq; struct rde_peer { RB_ENTRY(rde_peer) entry; SIMPLEQ_HEAD(, iq) imsg_queue; struct peer_config conf; struct rde_peer_stats stats; struct bgpd_addr remote_addr; struct bgpd_addr local_v4_addr; struct bgpd_addr local_v6_addr; struct capabilities capa; struct addpath_eval eval; struct prefix_index adj_rib_out; struct prefix_tree updates[AID_MAX]; struct prefix_tree withdraws[AID_MAX]; struct filter_head *out_rules; time_t staletime[AID_MAX]; uint32_t remote_bgpid; uint32_t path_id_tx; unsigned int local_if_scope; enum peer_state state; enum export_type export_type; enum role role; uint16_t loc_rib_id; uint16_t short_as; uint16_t mrt_idx; uint8_t recv_eor; /* bitfield per AID */ uint8_t sent_eor; /* bitfield per AID */ uint8_t reconf_out; /* out filter changed */ uint8_t reconf_rib; /* rib changed */ uint8_t throttled; uint8_t flags; }; struct rde_aspa; struct rde_aspa_state { uint8_t onlyup; uint8_t downup; }; #define AS_SET 1 #define AS_SEQUENCE 2 #define AS_CONFED_SEQUENCE 3 #define AS_CONFED_SET 4 #define ASPATH_HEADER_SIZE (offsetof(struct aspath, data)) struct aspath { uint32_t source_as; /* cached source_as */ uint16_t len; /* total length of aspath in octets */ uint16_t ascnt; /* number of AS hops in data */ u_char data[1]; /* placeholder for actual data */ }; enum attrtypes { ATTR_UNDEF, ATTR_ORIGIN, ATTR_ASPATH, ATTR_NEXTHOP, ATTR_MED, ATTR_LOCALPREF, ATTR_ATOMIC_AGGREGATE, ATTR_AGGREGATOR, ATTR_COMMUNITIES, ATTR_ORIGINATOR_ID, ATTR_CLUSTER_LIST, ATTR_MP_REACH_NLRI=14, ATTR_MP_UNREACH_NLRI=15, ATTR_EXT_COMMUNITIES=16, ATTR_AS4_PATH=17, ATTR_AS4_AGGREGATOR=18, ATTR_PMSI_TUNNEL=22, ATTR_LARGE_COMMUNITIES=32, ATTR_OTC=35, ATTR_FIRST_UNKNOWN, /* after this all attributes are unknown */ }; /* attribute flags. 4 low order bits reserved */ #define ATTR_EXTLEN 0x10 #define ATTR_PARTIAL 0x20 #define ATTR_TRANSITIVE 0x40 #define ATTR_OPTIONAL 0x80 #define ATTR_RESERVED 0x0f /* by default mask the reserved bits and the ext len bit */ #define ATTR_DEFMASK (ATTR_RESERVED | ATTR_EXTLEN) /* default attribute flags for well-known attributes */ #define ATTR_WELL_KNOWN ATTR_TRANSITIVE struct attr { RB_ENTRY(attr) entry; u_char *data; int refcnt; uint16_t len; uint8_t flags; uint8_t type; }; struct rde_community { RB_ENTRY(rde_community) entry; int size; int nentries; int flags; int refcnt; struct community *communities; }; #define PARTIAL_COMMUNITIES 0x01 #define PARTIAL_LARGE_COMMUNITIES 0x02 #define PARTIAL_EXT_COMMUNITIES 0x04 #define F_ATTR_ORIGIN 0x00001 #define F_ATTR_ASPATH 0x00002 #define F_ATTR_NEXTHOP 0x00004 #define F_ATTR_LOCALPREF 0x00008 #define F_ATTR_MED 0x00010 #define F_ATTR_MED_ANNOUNCE 0x00020 #define F_ATTR_MP_REACH 0x00040 #define F_ATTR_MP_UNREACH 0x00080 #define F_ATTR_AS4BYTE_NEW 0x00100 /* AS4_PATH or AS4_AGGREGATOR */ #define F_ATTR_LOOP 0x00200 /* path would cause a route loop */ #define F_PREFIX_ANNOUNCED 0x00400 #define F_ANN_DYNAMIC 0x00800 #define F_ATTR_OTC 0x01000 /* OTC present */ #define F_ATTR_OTC_LEAK 0x02000 /* otc leak, not eligible */ #define F_ATTR_PARSE_ERR 0x10000 /* parse error, not eligible */ #define F_ATTR_LINKED 0x20000 /* if set path is on various lists */ #define ORIGIN_IGP 0 #define ORIGIN_EGP 1 #define ORIGIN_INCOMPLETE 2 #define DEFAULT_LPREF 100 struct rde_aspath { RB_ENTRY(rde_aspath) entry; struct attr **others; struct aspath *aspath; struct rde_aspa_state aspa_state; int refcnt; uint32_t flags; /* internally used */ uint32_t med; /* multi exit disc */ uint32_t lpref; /* local pref */ uint32_t weight; /* low prio lpref */ uint16_t rtlabelid; /* route label id */ uint16_t pftableid; /* pf table id */ uint8_t origin; uint8_t others_len; uint8_t aspa_generation; }; enum nexthop_state { NEXTHOP_LOOKUP, NEXTHOP_UNREACH, NEXTHOP_REACH, NEXTHOP_FLAPPED /* only used by oldstate */ }; struct nexthop { RB_ENTRY(nexthop) entry; TAILQ_ENTRY(nexthop) runner_l; struct prefix_list prefix_h; struct prefix *next_prefix; struct bgpd_addr exit_nexthop; struct bgpd_addr true_nexthop; struct bgpd_addr nexthop_net; #if 0 /* * currently we use the boolean nexthop state, this could be exchanged * with a variable cost with a max for unreachable. */ uint32_t costs; #endif int refcnt; enum nexthop_state state; enum nexthop_state oldstate; uint8_t nexthop_netlen; uint8_t flags; #define NEXTHOP_CONNECTED 0x01 }; /* generic entry without address specific part */ struct pt_entry { RB_ENTRY(pt_entry) pt_e; uint8_t aid; uint8_t prefixlen; uint16_t len; uint32_t refcnt; uint8_t data[4]; /* data depending on aid */ }; struct prefix { union { struct { TAILQ_ENTRY(prefix) rib; LIST_ENTRY(prefix) nexthop; struct rib_entry *re; } list; struct { RB_ENTRY(prefix) index, update; } tree; } entry; struct pt_entry *pt; struct rde_aspath *aspath; struct rde_community *communities; struct rde_peer *peer; struct nexthop *nexthop; /* may be NULL */ time_t lastchange; uint32_t path_id; uint32_t path_id_tx; uint16_t flags; uint8_t validation_state; uint8_t nhflags; int8_t dmetric; /* decision metric */ }; #define PREFIX_FLAG_WITHDRAW 0x0001 /* enqueued on withdraw queue */ #define PREFIX_FLAG_UPDATE 0x0002 /* enqueued on update queue */ #define PREFIX_FLAG_DEAD 0x0004 /* locked but removed */ #define PREFIX_FLAG_STALE 0x0008 /* stale entry (for addpath) */ #define PREFIX_FLAG_MASK 0x000f /* mask for the prefix types */ #define PREFIX_FLAG_ADJOUT 0x0010 /* prefix is in the adj-out rib */ #define PREFIX_FLAG_EOR 0x0020 /* prefix is EoR */ #define PREFIX_NEXTHOP_LINKED 0x0040 /* prefix is linked onto nexthop list */ #define PREFIX_FLAG_LOCKED 0x0080 /* locked by rib walker */ #define PREFIX_FLAG_FILTERED 0x0100 /* prefix is filtered (ineligible) */ #define PREFIX_DMETRIC_NONE 0 #define PREFIX_DMETRIC_INVALID 1 #define PREFIX_DMETRIC_VALID 2 #define PREFIX_DMETRIC_AS_WIDE 3 #define PREFIX_DMETRIC_ECMP 4 #define PREFIX_DMETRIC_BEST 5 /* possible states for nhflags */ #define NEXTHOP_SELF 0x01 #define NEXTHOP_REJECT 0x02 #define NEXTHOP_BLACKHOLE 0x04 #define NEXTHOP_NOMODIFY 0x08 #define NEXTHOP_MASK 0x0f #define NEXTHOP_VALID 0x80 struct filterstate { struct rde_aspath aspath; struct rde_community communities; struct nexthop *nexthop; uint8_t nhflags; uint8_t vstate; }; enum eval_mode { EVAL_DEFAULT, EVAL_ALL, EVAL_RECONF, }; extern struct rde_memstats rdemem; /* prototypes */ /* mrt.c */ int mrt_dump_v2_hdr(struct mrt *, struct bgpd_config *); void mrt_dump_upcall(struct rib_entry *, void *); /* rde.c */ void rde_update_err(struct rde_peer *, uint8_t , uint8_t, struct ibuf *); void rde_update_log(const char *, uint16_t, const struct rde_peer *, const struct bgpd_addr *, const struct bgpd_addr *, uint8_t); void rde_send_kroute_flush(struct rib *); void rde_send_kroute(struct rib *, struct prefix *, struct prefix *); void rde_send_nexthop(struct bgpd_addr *, int); void rde_pftable_add(uint16_t, struct prefix *); void rde_pftable_del(uint16_t, struct prefix *); int rde_evaluate_all(void); uint32_t rde_local_as(void); int rde_decisionflags(void); void rde_peer_send_rrefresh(struct rde_peer *, uint8_t, uint8_t); int rde_match_peer(struct rde_peer *, struct ctl_neighbor *); /* rde_peer.c */ int peer_has_as4byte(struct rde_peer *); int peer_has_add_path(struct rde_peer *, uint8_t, int); int peer_has_ext_msg(struct rde_peer *); int peer_has_ext_nexthop(struct rde_peer *, uint8_t); int peer_permit_as_set(struct rde_peer *); void peer_init(struct filter_head *); void peer_shutdown(void); void peer_foreach(void (*)(struct rde_peer *, void *), void *); struct rde_peer *peer_get(uint32_t); struct rde_peer *peer_match(struct ctl_neighbor *, uint32_t); struct rde_peer *peer_add(uint32_t, struct peer_config *, struct filter_head *); struct filter_head *peer_apply_out_filter(struct rde_peer *, struct filter_head *); void rde_generate_updates(struct rib_entry *, struct prefix *, struct prefix *, enum eval_mode); void peer_up(struct rde_peer *, struct session_up *); void peer_down(struct rde_peer *); void peer_delete(struct rde_peer *); void peer_flush(struct rde_peer *, uint8_t, time_t); void peer_stale(struct rde_peer *, uint8_t, int); void peer_blast(struct rde_peer *, uint8_t); void peer_dump(struct rde_peer *, uint8_t); void peer_begin_rrefresh(struct rde_peer *, uint8_t); int peer_work_pending(void); void peer_reaper(struct rde_peer *); void peer_imsg_push(struct rde_peer *, struct imsg *); int peer_imsg_pop(struct rde_peer *, struct imsg *); void peer_imsg_flush(struct rde_peer *); static inline int peer_is_up(struct rde_peer *peer) { return (peer->state == PEER_UP); } RB_PROTOTYPE(peer_tree, rde_peer, entry, peer_cmp); /* rde_attr.c */ int attr_writebuf(struct ibuf *, uint8_t, uint8_t, void *, uint16_t); void attr_shutdown(void); int attr_optadd(struct rde_aspath *, uint8_t, uint8_t, void *, uint16_t); struct attr *attr_optget(const struct rde_aspath *, uint8_t); void attr_copy(struct rde_aspath *, const struct rde_aspath *); int attr_compare(struct rde_aspath *, struct rde_aspath *); void attr_freeall(struct rde_aspath *); void attr_free(struct rde_aspath *, struct attr *); struct aspath *aspath_get(void *, uint16_t); struct aspath *aspath_copy(struct aspath *); void aspath_put(struct aspath *); u_char *aspath_deflate(u_char *, uint16_t *, int *); void aspath_merge(struct rde_aspath *, struct attr *); uint32_t aspath_neighbor(struct aspath *); int aspath_loopfree(struct aspath *, uint32_t); int aspath_compare(struct aspath *, struct aspath *); int aspath_match(struct aspath *, struct filter_as *, uint32_t); u_char *aspath_prepend(struct aspath *, uint32_t, int, uint16_t *); u_char *aspath_override(struct aspath *, uint32_t, uint32_t, uint16_t *); int aspath_lenmatch(struct aspath *, enum aslen_spec, u_int); static inline u_char * aspath_dump(struct aspath *aspath) { return (aspath->data); } static inline uint16_t aspath_length(struct aspath *aspath) { return (aspath->len); } static inline uint32_t aspath_origin(struct aspath *aspath) { return (aspath->source_as); } /* rde_community.c */ int community_match(struct rde_community *, struct community *, struct rde_peer *); int community_count(struct rde_community *, uint8_t type); int community_set(struct rde_community *, struct community *, struct rde_peer *); void community_delete(struct rde_community *, struct community *, struct rde_peer *); int community_add(struct rde_community *, int, struct ibuf *); int community_large_add(struct rde_community *, int, struct ibuf *); int community_ext_add(struct rde_community *, int, int, struct ibuf *); int community_writebuf(struct rde_community *, uint8_t, int, struct ibuf *); void communities_shutdown(void); struct rde_community *communities_lookup(struct rde_community *); struct rde_community *communities_link(struct rde_community *); void communities_unlink(struct rde_community *); int communities_equal(struct rde_community *, struct rde_community *); void communities_copy(struct rde_community *, struct rde_community *); void communities_clean(struct rde_community *); static inline struct rde_community * communities_ref(struct rde_community *comm) { if (comm->refcnt == 0) fatalx("%s: not-referenced community", __func__); comm->refcnt++; rdemem.comm_refs++; return comm; } static inline void communities_unref(struct rde_community *comm) { if (comm == NULL) return; rdemem.comm_refs--; if (--comm->refcnt == 1) /* last ref is hold internally */ communities_unlink(comm); } int community_to_rd(struct community *, uint64_t *); /* rde_decide.c */ int prefix_eligible(struct prefix *); struct prefix *prefix_best(struct rib_entry *); void prefix_evaluate(struct rib_entry *, struct prefix *, struct prefix *); void prefix_evaluate_nexthop(struct prefix *, enum nexthop_state, enum nexthop_state); /* rde_filter.c */ void rde_apply_set(struct filter_set_head *, struct rde_peer *, struct rde_peer *, struct filterstate *, u_int8_t); void rde_filterstate_init(struct filterstate *); void rde_filterstate_prep(struct filterstate *, struct prefix *); void rde_filterstate_copy(struct filterstate *, struct filterstate *); void rde_filterstate_set_vstate(struct filterstate *, uint8_t, uint8_t); void rde_filterstate_clean(struct filterstate *); int rde_filter_skip_rule(struct rde_peer *, struct filter_rule *); int rde_filter_equal(struct filter_head *, struct filter_head *); void rde_filter_calc_skip_steps(struct filter_head *); enum filter_actions rde_filter(struct filter_head *, struct rde_peer *, struct rde_peer *, struct bgpd_addr *, uint8_t, struct filterstate *); /* rde_prefix.c */ void pt_init(void); void pt_shutdown(void); void pt_getaddr(struct pt_entry *, struct bgpd_addr *); int pt_getflowspec(struct pt_entry *, uint8_t **); struct pt_entry *pt_fill(struct bgpd_addr *, int); struct pt_entry *pt_get(struct bgpd_addr *, int); struct pt_entry *pt_add(struct bgpd_addr *, int); struct pt_entry *pt_get_flow(struct flowspec *); struct pt_entry *pt_add_flow(struct flowspec *); void pt_remove(struct pt_entry *); struct pt_entry *pt_lookup(struct bgpd_addr *); int pt_prefix_cmp(const struct pt_entry *, const struct pt_entry *); int pt_writebuf(struct ibuf *, struct pt_entry *, int, int, uint32_t); static inline struct pt_entry * pt_ref(struct pt_entry *pt) { ++pt->refcnt; if (pt->refcnt == 0) fatalx("pt_ref: overflow"); return pt; } static inline void pt_unref(struct pt_entry *pt) { if (pt->refcnt == 0) fatalx("pt_unref: underflow"); if (--pt->refcnt == 0) pt_remove(pt); } /* rde_rib.c */ extern uint16_t rib_size; struct rib *rib_new(char *, u_int, uint16_t); int rib_update(struct rib *); struct rib *rib_byid(uint16_t); uint16_t rib_find(char *); void rib_free(struct rib *); void rib_shutdown(void); struct rib_entry *rib_get(struct rib *, struct pt_entry *); struct rib_entry *rib_get_addr(struct rib *, struct bgpd_addr *, int); struct rib_entry *rib_match(struct rib *, struct bgpd_addr *); int rib_dump_pending(void); void rib_dump_runner(void); int rib_dump_new(uint16_t, uint8_t, unsigned int, void *, void (*)(struct rib_entry *, void *), void (*)(void *, uint8_t), int (*)(void *)); int rib_dump_subtree(uint16_t, struct bgpd_addr *, uint8_t, unsigned int count, void *arg, void (*)(struct rib_entry *, void *), void (*)(void *, uint8_t), int (*)(void *)); void rib_dump_terminate(void *); extern struct rib flowrib; static inline struct rib * re_rib(struct rib_entry *re) { if (re->prefix->aid == AID_FLOWSPECv4 || re->prefix->aid == AID_FLOWSPECv6) return &flowrib; return rib_byid(re->rib_id); } void path_shutdown(void); struct rde_aspath *path_copy(struct rde_aspath *, const struct rde_aspath *); struct rde_aspath *path_prep(struct rde_aspath *); struct rde_aspath *path_get(void); void path_clean(struct rde_aspath *); void path_put(struct rde_aspath *); #define PREFIX_SIZE(x) (((x) + 7) / 8 + 1) struct prefix *prefix_get(struct rib *, struct rde_peer *, uint32_t, struct bgpd_addr *, int); struct prefix *prefix_adjout_get(struct rde_peer *, uint32_t, struct pt_entry *); struct prefix *prefix_adjout_first(struct rde_peer *, struct pt_entry *); struct prefix *prefix_adjout_next(struct rde_peer *, struct prefix *); struct prefix *prefix_adjout_lookup(struct rde_peer *, struct bgpd_addr *, int); struct prefix *prefix_adjout_match(struct rde_peer *, struct bgpd_addr *); int prefix_update(struct rib *, struct rde_peer *, uint32_t, uint32_t, struct filterstate *, int, struct bgpd_addr *, int); int prefix_withdraw(struct rib *, struct rde_peer *, uint32_t, struct bgpd_addr *, int); int prefix_flowspec_update(struct rde_peer *, struct filterstate *, struct pt_entry *, uint32_t); int prefix_flowspec_withdraw(struct rde_peer *, struct pt_entry *); void prefix_flowspec_dump(uint8_t, void *, void (*)(struct rib_entry *, void *), void (*)(void *, uint8_t)); void prefix_add_eor(struct rde_peer *, uint8_t); void prefix_adjout_update(struct prefix *, struct rde_peer *, struct filterstate *, struct pt_entry *, uint32_t); void prefix_adjout_withdraw(struct prefix *); void prefix_adjout_destroy(struct prefix *); void prefix_adjout_flush_pending(struct rde_peer *); int prefix_adjout_reaper(struct rde_peer *); int prefix_dump_new(struct rde_peer *, uint8_t, unsigned int, void *, void (*)(struct prefix *, void *), void (*)(void *, uint8_t), int (*)(void *)); int prefix_dump_subtree(struct rde_peer *, struct bgpd_addr *, uint8_t, unsigned int, void *, void (*)(struct prefix *, void *), void (*)(void *, uint8_t), int (*)(void *)); struct prefix *prefix_bypeer(struct rib_entry *, struct rde_peer *, uint32_t); void prefix_destroy(struct prefix *); RB_PROTOTYPE(prefix_tree, prefix, entry, prefix_cmp) static inline struct rde_peer * prefix_peer(struct prefix *p) { return (p->peer); } static inline struct rde_aspath * prefix_aspath(struct prefix *p) { return (p->aspath); } static inline struct rde_community * prefix_communities(struct prefix *p) { return (p->communities); } static inline struct nexthop * prefix_nexthop(struct prefix *p) { return (p->nexthop); } static inline uint8_t prefix_nhflags(struct prefix *p) { return (p->nhflags & NEXTHOP_MASK); } static inline int prefix_nhvalid(struct prefix *p) { return ((p->nhflags & NEXTHOP_VALID) != 0); } static inline uint8_t prefix_roa_vstate(struct prefix *p) { return (p->validation_state & ROA_MASK); } static inline uint8_t prefix_aspa_vstate(struct prefix *p) { return (p->validation_state >> 4); } static inline void prefix_set_vstate(struct prefix *p, uint8_t roa_vstate, uint8_t aspa_vstate) { p->validation_state = roa_vstate & ROA_MASK; p->validation_state |= aspa_vstate << 4; } static inline struct rib_entry * prefix_re(struct prefix *p) { if (p->flags & PREFIX_FLAG_ADJOUT) return NULL; return (p->entry.list.re); } static inline int prefix_filtered(struct prefix *p) { return ((p->flags & PREFIX_FLAG_FILTERED) != 0); } void nexthop_shutdown(void); int nexthop_pending(void); void nexthop_runner(void); void nexthop_modify(struct nexthop *, enum action_types, uint8_t, struct nexthop **, uint8_t *); void nexthop_link(struct prefix *); void nexthop_unlink(struct prefix *); void nexthop_update(struct kroute_nexthop *); struct nexthop *nexthop_get(struct bgpd_addr *); struct nexthop *nexthop_ref(struct nexthop *); int nexthop_unref(struct nexthop *); /* rde_update.c */ void up_generate_updates(struct rde_peer *, struct rib_entry *); void up_generate_addpath(struct rde_peer *, struct rib_entry *); void up_generate_addpath_all(struct rde_peer *, struct rib_entry *, struct prefix *, struct prefix *); void up_generate_default(struct rde_peer *, uint8_t); int up_is_eor(struct rde_peer *, uint8_t); struct ibuf *up_dump_withdraws(struct rde_peer *, uint8_t); struct ibuf *up_dump_update(struct rde_peer *, uint8_t); /* rde_aspa.c */ void aspa_validation(struct rde_aspa *, struct aspath *, struct rde_aspa_state *); struct rde_aspa *aspa_table_prep(uint32_t, size_t); void aspa_add_set(struct rde_aspa *, uint32_t, const uint32_t *, uint32_t); void aspa_table_free(struct rde_aspa *); void aspa_table_stats(const struct rde_aspa *, struct ctl_show_set *); int aspa_table_equal(const struct rde_aspa *, const struct rde_aspa *); void aspa_table_unchanged(struct rde_aspa *, const struct rde_aspa *); #endif /* __RDE_H__ */ openbgpd-8.8/src/bgpd/session.h100644 001750 001750 00000023064 14751151130 0012233/* $OpenBSD: session.h,v 1.185 2025/01/31 20:07:18 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #define MAX_BACKLOG 5 #define INTERVAL_CONNECTRETRY 120 #define INTERVAL_HOLD_INITIAL 240 #define INTERVAL_HOLD 90 #define INTERVAL_IDLE_HOLD_INITIAL 30 #define INTERVAL_HOLD_DEMOTED 60 #define INTERVAL_STALE 180 #define INTERVAL_SESSION_DOWN 3600 #define MAX_IDLE_HOLD 3600 #define MSGSIZE_HEADER 19 #define MSGSIZE_HEADER_MARKER 16 #define MSGSIZE_NOTIFICATION_MIN 21 /* 19 hdr + 1 code + 1 sub */ #define MSGSIZE_OPEN_MIN 29 #define MSGSIZE_UPDATE_MIN 23 #define MSGSIZE_KEEPALIVE MSGSIZE_HEADER #define MSGSIZE_RREFRESH (MSGSIZE_HEADER + 4) #define MSGSIZE_RREFRESH_MIN MSGSIZE_RREFRESH #define MSG_PROCESS_LIMIT 25 #define SESSION_CLEAR_DELAY 5 enum session_state { STATE_NONE, STATE_IDLE, STATE_CONNECT, STATE_ACTIVE, STATE_OPENSENT, STATE_OPENCONFIRM, STATE_ESTABLISHED }; enum session_events { EVNT_NONE, EVNT_START, EVNT_STOP, EVNT_CON_OPEN, EVNT_CON_CLOSED, EVNT_CON_OPENFAIL, EVNT_CON_FATAL, EVNT_TIMER_CONNRETRY, EVNT_TIMER_HOLDTIME, EVNT_TIMER_KEEPALIVE, EVNT_TIMER_SENDHOLD, EVNT_RCVD_OPEN, EVNT_RCVD_KEEPALIVE, EVNT_RCVD_UPDATE, EVNT_RCVD_NOTIFICATION, EVNT_RCVD_GRACE_NOTIFICATION, }; enum msg_type { BGP_OPEN = 1, BGP_UPDATE, BGP_NOTIFICATION, BGP_KEEPALIVE, BGP_RREFRESH }; enum suberr_header { ERR_HDR_SYNC = 1, ERR_HDR_LEN, ERR_HDR_TYPE }; enum suberr_open { ERR_OPEN_VERSION = 1, ERR_OPEN_AS, ERR_OPEN_BGPID, ERR_OPEN_OPT, ERR_OPEN_AUTH, /* deprecated */ ERR_OPEN_HOLDTIME, ERR_OPEN_CAPA, ERR_OPEN_ROLE = 11, }; enum suberr_fsm { ERR_FSM_UNSPECIFIC = 0, ERR_FSM_UNEX_OPENSENT, ERR_FSM_UNEX_OPENCONFIRM, ERR_FSM_UNEX_ESTABLISHED }; enum opt_params { OPT_PARAM_NONE, OPT_PARAM_AUTH, OPT_PARAM_CAPABILITIES, OPT_PARAM_EXT_LEN=255, }; struct bgpd_sysdep { uint8_t no_pfkey; uint8_t no_md5sig; }; struct ctl_conn { TAILQ_ENTRY(ctl_conn) entry; struct imsgbuf imsgbuf; int restricted; int throttled; int terminate; }; struct peer_stats { unsigned long long msg_rcvd_open; unsigned long long msg_rcvd_update; unsigned long long msg_rcvd_notification; unsigned long long msg_rcvd_keepalive; unsigned long long msg_rcvd_rrefresh; unsigned long long msg_sent_open; unsigned long long msg_sent_update; unsigned long long msg_sent_notification; unsigned long long msg_sent_keepalive; unsigned long long msg_sent_rrefresh; unsigned long long refresh_rcvd_req; unsigned long long refresh_rcvd_borr; unsigned long long refresh_rcvd_eorr; unsigned long long refresh_sent_req; unsigned long long refresh_sent_borr; unsigned long long refresh_sent_eorr; unsigned long long prefix_rcvd_update; unsigned long long prefix_rcvd_withdraw; unsigned long long prefix_rcvd_eor; unsigned long long prefix_sent_update; unsigned long long prefix_sent_withdraw; unsigned long long prefix_sent_eor; time_t last_updown; time_t last_read; time_t last_write; uint32_t msg_queue_len; uint32_t prefix_cnt; uint32_t prefix_out_cnt; uint32_t pending_update; uint32_t pending_withdraw; uint8_t last_sent_errcode; uint8_t last_sent_suberr; uint8_t last_rcvd_errcode; uint8_t last_rcvd_suberr; char last_reason[REASON_LEN]; }; struct auth_state { struct bgpd_addr local_addr; struct bgpd_addr remote_addr; uint32_t spi_in; uint32_t spi_out; enum auth_method method; uint8_t established; }; enum Timer { Timer_None, Timer_ConnectRetry, Timer_Keepalive, Timer_Hold, Timer_SendHold, Timer_IdleHold, Timer_IdleHoldReset, Timer_CarpUndemote, Timer_RestartTimeout, Timer_SessionDown, Timer_Rtr_Refresh, Timer_Rtr_Retry, Timer_Rtr_Expire, Timer_Rtr_Active, Timer_Max }; struct timer { TAILQ_ENTRY(timer) entry; enum Timer type; time_t val; }; TAILQ_HEAD(timer_head, timer); struct peer { struct peer_config conf; struct peer_stats stats; RB_ENTRY(peer) entry; struct { struct capabilities ann; struct capabilities peer; struct capabilities neg; } capa; struct auth_state auth_state; struct auth_config auth_conf; struct bgpd_addr local; struct bgpd_addr local_alt; struct bgpd_addr remote; struct timer_head timers; struct msgbuf *wbuf; struct peer *template; int fd; int lasterr; u_int errcnt; u_int IdleHoldTime; unsigned int if_scope; /* interface scope for IPv6 */ uint32_t remote_bgpid; enum session_state state; enum session_state prev_state; enum reconf_action reconf_action; enum role remote_role; uint16_t short_as; uint16_t holdtime; uint16_t local_port; uint16_t remote_port; uint8_t depend_ok; uint8_t demoted; uint8_t passive; uint8_t throttled; uint8_t rpending; uint8_t rdesession; }; extern time_t pauseaccept; struct ctl_timer { enum Timer type; time_t val; }; /* carp.c */ int carp_demote_init(char *, int); void carp_demote_shutdown(void); int carp_demote_get(char *); int carp_demote_set(char *, int); /* config.c */ void merge_config(struct bgpd_config *, struct bgpd_config *); void free_deleted_peers(struct bgpd_config *); int prepare_listeners(struct bgpd_config *); /* control.c */ int control_check(char *); int control_init(int, char *); int control_listen(int); size_t control_fill_pfds(struct pollfd *, size_t); void control_shutdown(int); int control_dispatch_msg(struct pollfd *, struct peer_head *); unsigned int control_accept(int, int); /* log.c */ char *log_fmt_peer(const struct peer_config *); void log_statechange(struct peer *, enum session_state, enum session_events); void log_notification(const struct peer *, uint8_t, uint8_t, const struct ibuf *, const char *); void log_conn_attempt(const struct peer *, struct sockaddr *, socklen_t); /* mrt.c */ void mrt_dump_bgp_msg(struct mrt *, struct ibuf *, struct peer *, enum msg_type); void mrt_dump_state(struct mrt *, uint16_t, uint16_t, struct peer *); void mrt_done(struct mrt *); /* pfkey.c */ struct sadb_msg; int pfkey_read(int, struct sadb_msg *); int pfkey_establish(struct auth_state *, struct auth_config *, const struct bgpd_addr *, const struct bgpd_addr *); int pfkey_remove(struct auth_state *); int pfkey_init(void); int pfkey_send_conf(struct imsgbuf *, uint32_t, struct auth_config *); int pfkey_recv_conf(struct peer *, struct imsg *); int tcp_md5_check(int, struct auth_config *); int tcp_md5_set(int, struct auth_config *, struct bgpd_addr *); int tcp_md5_prep_listener(struct listen_addr *, struct peer_head *); void tcp_md5_add_listener(struct bgpd_config *, struct peer *); void tcp_md5_del_listener(struct bgpd_config *, struct peer *); /* printconf.c */ void print_config(struct bgpd_config *, struct rib_names *); /* rde.c */ void rde_main(int, int); /* rtr_proto.c */ struct rtr_session; size_t rtr_count(void); void rtr_check_events(struct pollfd *, size_t); size_t rtr_poll_events(struct pollfd *, size_t, time_t *); struct rtr_session *rtr_new(uint32_t, struct rtr_config_msg *); struct rtr_session *rtr_get(uint32_t); void rtr_free(struct rtr_session *); void rtr_open(struct rtr_session *, int); void rtr_config_prep(void); void rtr_config_merge(void); void rtr_config_keep(struct rtr_session *, struct rtr_config_msg *); void rtr_roa_merge(struct roa_tree *); void rtr_aspa_merge(struct aspa_tree *); void rtr_shutdown(void); void rtr_show(struct rtr_session *, pid_t); /* rtr.c */ void rtr_sem_acquire(int); void rtr_sem_release(int); void rtr_roa_insert(struct roa_tree *, struct roa *); void rtr_aspa_insert(struct aspa_tree *, struct aspa_set *); void rtr_main(int, int); void rtr_imsg_compose(int, uint32_t, pid_t, void *, size_t); void rtr_recalc(void); /* session.c */ RB_PROTOTYPE(peer_head, peer, entry, peer_compare); void session_main(int, int); void bgp_fsm(struct peer *, enum session_events, struct ibuf *); int session_neighbor_rrefresh(struct peer *p); struct peer *getpeerbydesc(struct bgpd_config *, const char *); struct peer *getpeerbyip(struct bgpd_config *, struct sockaddr *); struct peer *getpeerbyid(struct bgpd_config *, uint32_t); int peer_matched(struct peer *, struct ctl_neighbor *); int imsg_ctl_parent(struct imsg *); int imsg_ctl_rde(struct imsg *); int imsg_ctl_rde_msg(int, uint32_t, pid_t); void session_stop(struct peer *, uint8_t, const char *); struct bgpd_addr *session_localaddr(struct peer *); /* timer.c */ struct timer *timer_get(struct timer_head *, enum Timer); struct timer *timer_nextisdue(struct timer_head *, time_t); time_t timer_nextduein(struct timer_head *, time_t); int timer_running(struct timer_head *, enum Timer, time_t *); void timer_set(struct timer_head *, enum Timer, u_int); void timer_stop(struct timer_head *, enum Timer); void timer_remove(struct timer_head *, enum Timer); void timer_remove_all(struct timer_head *); openbgpd-8.8/src/bgpd/version.h100644 001750 001750 00000000137 14751151130 0012231/* $OpenBSD: version.h,v 1.19 2025/02/05 12:11:25 claudio Exp $ */ #define BGPD_VERSION "8.8" openbgpd-8.8/src/bgpd/Makefile.in100644 001750 001750 00000320630 14751151141 0012445# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ sbin_PROGRAMS = bgpd$(EXEEXT) @DISABLE_FIB_TRUE@am__append_1 = kroute-disabled.c @DISABLE_FIB_FALSE@@HOST_OPENBSD_TRUE@am__append_2 = kroute.c @DISABLE_FIB_FALSE@@HOST_FREEBSD_TRUE@@HOST_OPENBSD_FALSE@am__append_3 = kroute-freebsd.c @DISABLE_FIB_FALSE@@HAVE_MNL_TRUE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__append_4 = kroute-linux.c @DISABLE_FIB_FALSE@@HAVE_MNL_FALSE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__append_5 = kroute-disabled.c @HOST_OPENBSD_TRUE@am__append_6 = pfkey.c @HOST_FREEBSD_TRUE@@HOST_OPENBSD_FALSE@am__append_7 = pfkey-freebsd.c @HAVE_LINUX_TCPMD5_TRUE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__append_8 = pfkey-linux.c @HAVE_LINUX_TCPMD5_FALSE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__append_9 = pfkey-disabled.c @HAVE_PFTABLE_TRUE@am__append_10 = pftable.c @HAVE_PFTABLE_FALSE@am__append_11 = pftable-disabled.c @HOST_OPENBSD_TRUE@am__append_12 = carp.c @HOST_OPENBSD_FALSE@am__append_13 = carp-disabled.c subdir = src/bgpd ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man5dir)" \ "$(DESTDIR)$(man8dir)" PROGRAMS = $(sbin_PROGRAMS) am__bgpd_SOURCES_DIST = bgpd.c session.c log.c logmsg.c parse.y \ config.c rde.c rde_rib.c rde_decide.c rde_prefix.c mrt.c \ kroute-disabled.c kroute.c kroute-freebsd.c kroute-linux.c \ control.c pfkey.c pfkey-freebsd.c pfkey-linux.c \ pfkey-disabled.c rde_update.c rde_attr.c rde_community.c \ printconf.c rde_filter.c rde_sets.c rde_trie.c rde_aspa.c \ pftable.c pftable-disabled.c name2id.c util.c carp.c \ carp-disabled.c timer.c rde_peer.c rtr.c rtr_proto.c \ flowspec.c @DISABLE_FIB_TRUE@am__objects_1 = bgpd-kroute-disabled.$(OBJEXT) @DISABLE_FIB_FALSE@@HOST_OPENBSD_TRUE@am__objects_2 = \ @DISABLE_FIB_FALSE@@HOST_OPENBSD_TRUE@ bgpd-kroute.$(OBJEXT) @DISABLE_FIB_FALSE@@HOST_FREEBSD_TRUE@@HOST_OPENBSD_FALSE@am__objects_3 = bgpd-kroute-freebsd.$(OBJEXT) @DISABLE_FIB_FALSE@@HAVE_MNL_TRUE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__objects_4 = bgpd-kroute-linux.$(OBJEXT) @DISABLE_FIB_FALSE@@HAVE_MNL_FALSE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__objects_5 = bgpd-kroute-disabled.$(OBJEXT) @HOST_OPENBSD_TRUE@am__objects_6 = bgpd-pfkey.$(OBJEXT) @HOST_FREEBSD_TRUE@@HOST_OPENBSD_FALSE@am__objects_7 = bgpd-pfkey-freebsd.$(OBJEXT) @HAVE_LINUX_TCPMD5_TRUE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__objects_8 = bgpd-pfkey-linux.$(OBJEXT) @HAVE_LINUX_TCPMD5_FALSE@@HOST_FREEBSD_FALSE@@HOST_OPENBSD_FALSE@am__objects_9 = bgpd-pfkey-disabled.$(OBJEXT) @HAVE_PFTABLE_TRUE@am__objects_10 = bgpd-pftable.$(OBJEXT) @HAVE_PFTABLE_FALSE@am__objects_11 = bgpd-pftable-disabled.$(OBJEXT) @HOST_OPENBSD_TRUE@am__objects_12 = bgpd-carp.$(OBJEXT) @HOST_OPENBSD_FALSE@am__objects_13 = bgpd-carp-disabled.$(OBJEXT) am_bgpd_OBJECTS = bgpd-bgpd.$(OBJEXT) bgpd-session.$(OBJEXT) \ bgpd-log.$(OBJEXT) bgpd-logmsg.$(OBJEXT) bgpd-parse.$(OBJEXT) \ bgpd-config.$(OBJEXT) bgpd-rde.$(OBJEXT) \ bgpd-rde_rib.$(OBJEXT) bgpd-rde_decide.$(OBJEXT) \ bgpd-rde_prefix.$(OBJEXT) bgpd-mrt.$(OBJEXT) $(am__objects_1) \ $(am__objects_2) $(am__objects_3) $(am__objects_4) \ $(am__objects_5) bgpd-control.$(OBJEXT) $(am__objects_6) \ $(am__objects_7) $(am__objects_8) $(am__objects_9) \ bgpd-rde_update.$(OBJEXT) bgpd-rde_attr.$(OBJEXT) \ bgpd-rde_community.$(OBJEXT) bgpd-printconf.$(OBJEXT) \ bgpd-rde_filter.$(OBJEXT) bgpd-rde_sets.$(OBJEXT) \ bgpd-rde_trie.$(OBJEXT) bgpd-rde_aspa.$(OBJEXT) \ $(am__objects_10) $(am__objects_11) bgpd-name2id.$(OBJEXT) \ bgpd-util.$(OBJEXT) $(am__objects_12) $(am__objects_13) \ bgpd-timer.$(OBJEXT) bgpd-rde_peer.$(OBJEXT) \ bgpd-rtr.$(OBJEXT) bgpd-rtr_proto.$(OBJEXT) \ bgpd-flowspec.$(OBJEXT) bgpd_OBJECTS = $(am_bgpd_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = bgpd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(bgpd_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/bgpd-bgpd.Po \ ./$(DEPDIR)/bgpd-carp-disabled.Po ./$(DEPDIR)/bgpd-carp.Po \ ./$(DEPDIR)/bgpd-config.Po ./$(DEPDIR)/bgpd-control.Po \ ./$(DEPDIR)/bgpd-flowspec.Po \ ./$(DEPDIR)/bgpd-kroute-disabled.Po \ ./$(DEPDIR)/bgpd-kroute-freebsd.Po \ ./$(DEPDIR)/bgpd-kroute-linux.Po ./$(DEPDIR)/bgpd-kroute.Po \ ./$(DEPDIR)/bgpd-log.Po ./$(DEPDIR)/bgpd-logmsg.Po \ ./$(DEPDIR)/bgpd-mrt.Po ./$(DEPDIR)/bgpd-name2id.Po \ ./$(DEPDIR)/bgpd-parse.Po ./$(DEPDIR)/bgpd-pfkey-disabled.Po \ ./$(DEPDIR)/bgpd-pfkey-freebsd.Po \ ./$(DEPDIR)/bgpd-pfkey-linux.Po ./$(DEPDIR)/bgpd-pfkey.Po \ ./$(DEPDIR)/bgpd-pftable-disabled.Po \ ./$(DEPDIR)/bgpd-pftable.Po ./$(DEPDIR)/bgpd-printconf.Po \ ./$(DEPDIR)/bgpd-rde.Po ./$(DEPDIR)/bgpd-rde_aspa.Po \ ./$(DEPDIR)/bgpd-rde_attr.Po ./$(DEPDIR)/bgpd-rde_community.Po \ ./$(DEPDIR)/bgpd-rde_decide.Po ./$(DEPDIR)/bgpd-rde_filter.Po \ ./$(DEPDIR)/bgpd-rde_peer.Po ./$(DEPDIR)/bgpd-rde_prefix.Po \ ./$(DEPDIR)/bgpd-rde_rib.Po ./$(DEPDIR)/bgpd-rde_sets.Po \ ./$(DEPDIR)/bgpd-rde_trie.Po ./$(DEPDIR)/bgpd-rde_update.Po \ ./$(DEPDIR)/bgpd-rtr.Po ./$(DEPDIR)/bgpd-rtr_proto.Po \ ./$(DEPDIR)/bgpd-session.Po ./$(DEPDIR)/bgpd-timer.Po \ ./$(DEPDIR)/bgpd-util.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = am__yacc_c2h = sed -e s/cc$$/hh/ -e s/cpp$$/hpp/ -e s/cxx$$/hxx/ \ -e s/c++$$/h++/ -e s/c$$/h/ YACCCOMPILE = $(YACC) $(AM_YFLAGS) $(YFLAGS) LTYACCCOMPILE = $(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(YACC) $(AM_YFLAGS) $(YFLAGS) AM_V_YACC = $(am__v_YACC_@AM_V@) am__v_YACC_ = $(am__v_YACC_@AM_DEFAULT_V@) am__v_YACC_0 = @echo " YACC " $@; am__v_YACC_1 = YLWRAP = $(top_srcdir)/ylwrap SOURCES = $(bgpd_SOURCES) DIST_SOURCES = $(am__bgpd_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } man5dir = $(mandir)/man5 man8dir = $(mandir)/man8 NROFF = nroff MANS = $(man_MANS) HEADERS = $(noinst_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ $(top_srcdir)/ylwrap parse.c DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LDFLAGS = @AM_LDFLAGS@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BGPD_USER = @BGPD_USER@ BGPLGD_USER = @BGPLGD_USER@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ WWW_USER = @WWW_USER@ YACC = @YACC@ YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwrunstatedir = @wwwrunstatedir@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/bgpd ACLOCAL_AMFLAGS = -Im4 CLEANFILES = $(man_MANS) parse.c man_MANS = bgpd.8 bgpd.conf.5 EXTRA_DIST = bgpd.8.in bgpd.conf.5.in bgpd_CFLAGS = $(AM_CFLAGS) -DSYSCONFDIR=\"$(sysconfdir)\" \ -DRUNSTATEDIR=\"$(runstatedir)\" bgpd_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) -lutil \ $(top_builddir)/compat/libcompat.la \ $(top_builddir)/compat/libcompatnoopt.la bgpd_SOURCES = bgpd.c session.c log.c logmsg.c parse.y config.c rde.c \ rde_rib.c rde_decide.c rde_prefix.c mrt.c $(am__append_1) \ $(am__append_2) $(am__append_3) $(am__append_4) \ $(am__append_5) control.c $(am__append_6) $(am__append_7) \ $(am__append_8) $(am__append_9) rde_update.c rde_attr.c \ rde_community.c printconf.c rde_filter.c rde_sets.c rde_trie.c \ rde_aspa.c $(am__append_10) $(am__append_11) name2id.c util.c \ $(am__append_12) $(am__append_13) timer.c rde_peer.c rtr.c \ rtr_proto.c flowspec.c bgpd_DEPENDENCIES = $(man_MANS) noinst_HEADERS = bgpd.h log.h mrt.h rde.h session.h version.h all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj .y $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/bgpd/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign src/bgpd/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): install-sbinPROGRAMS: $(sbin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ || test -f $$p1 \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \ } \ ; done uninstall-sbinPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(sbindir)" && rm -f $$files clean-sbinPROGRAMS: @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list bgpd$(EXEEXT): $(bgpd_OBJECTS) $(bgpd_DEPENDENCIES) $(EXTRA_bgpd_DEPENDENCIES) @rm -f bgpd$(EXEEXT) $(AM_V_CCLD)$(bgpd_LINK) $(bgpd_OBJECTS) $(bgpd_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-bgpd.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-carp-disabled.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-carp.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-config.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-control.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-flowspec.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-kroute-disabled.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-kroute-freebsd.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-kroute-linux.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-kroute.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-log.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-logmsg.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-mrt.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-name2id.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-parse.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-pfkey-disabled.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-pfkey-freebsd.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-pfkey-linux.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-pfkey.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-pftable-disabled.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-pftable.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-printconf.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_aspa.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_attr.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_community.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_decide.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_filter.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_peer.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_prefix.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_rib.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_sets.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_trie.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rde_update.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rtr.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-rtr_proto.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-session.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-timer.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpd-util.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @echo '# dummy' >$@-t && $(am__mv) $@-t $@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< bgpd-bgpd.o: bgpd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-bgpd.o -MD -MP -MF $(DEPDIR)/bgpd-bgpd.Tpo -c -o bgpd-bgpd.o `test -f 'bgpd.c' || echo '$(srcdir)/'`bgpd.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-bgpd.Tpo $(DEPDIR)/bgpd-bgpd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bgpd.c' object='bgpd-bgpd.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-bgpd.o `test -f 'bgpd.c' || echo '$(srcdir)/'`bgpd.c bgpd-bgpd.obj: bgpd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-bgpd.obj -MD -MP -MF $(DEPDIR)/bgpd-bgpd.Tpo -c -o bgpd-bgpd.obj `if test -f 'bgpd.c'; then $(CYGPATH_W) 'bgpd.c'; else $(CYGPATH_W) '$(srcdir)/bgpd.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-bgpd.Tpo $(DEPDIR)/bgpd-bgpd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bgpd.c' object='bgpd-bgpd.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-bgpd.obj `if test -f 'bgpd.c'; then $(CYGPATH_W) 'bgpd.c'; else $(CYGPATH_W) '$(srcdir)/bgpd.c'; fi` bgpd-session.o: session.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-session.o -MD -MP -MF $(DEPDIR)/bgpd-session.Tpo -c -o bgpd-session.o `test -f 'session.c' || echo '$(srcdir)/'`session.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-session.Tpo $(DEPDIR)/bgpd-session.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='session.c' object='bgpd-session.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-session.o `test -f 'session.c' || echo '$(srcdir)/'`session.c bgpd-session.obj: session.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-session.obj -MD -MP -MF $(DEPDIR)/bgpd-session.Tpo -c -o bgpd-session.obj `if test -f 'session.c'; then $(CYGPATH_W) 'session.c'; else $(CYGPATH_W) '$(srcdir)/session.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-session.Tpo $(DEPDIR)/bgpd-session.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='session.c' object='bgpd-session.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-session.obj `if test -f 'session.c'; then $(CYGPATH_W) 'session.c'; else $(CYGPATH_W) '$(srcdir)/session.c'; fi` bgpd-log.o: log.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-log.o -MD -MP -MF $(DEPDIR)/bgpd-log.Tpo -c -o bgpd-log.o `test -f 'log.c' || echo '$(srcdir)/'`log.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-log.Tpo $(DEPDIR)/bgpd-log.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='log.c' object='bgpd-log.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-log.o `test -f 'log.c' || echo '$(srcdir)/'`log.c bgpd-log.obj: log.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-log.obj -MD -MP -MF $(DEPDIR)/bgpd-log.Tpo -c -o bgpd-log.obj `if test -f 'log.c'; then $(CYGPATH_W) 'log.c'; else $(CYGPATH_W) '$(srcdir)/log.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-log.Tpo $(DEPDIR)/bgpd-log.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='log.c' object='bgpd-log.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-log.obj `if test -f 'log.c'; then $(CYGPATH_W) 'log.c'; else $(CYGPATH_W) '$(srcdir)/log.c'; fi` bgpd-logmsg.o: logmsg.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-logmsg.o -MD -MP -MF $(DEPDIR)/bgpd-logmsg.Tpo -c -o bgpd-logmsg.o `test -f 'logmsg.c' || echo '$(srcdir)/'`logmsg.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-logmsg.Tpo $(DEPDIR)/bgpd-logmsg.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='logmsg.c' object='bgpd-logmsg.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-logmsg.o `test -f 'logmsg.c' || echo '$(srcdir)/'`logmsg.c bgpd-logmsg.obj: logmsg.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-logmsg.obj -MD -MP -MF $(DEPDIR)/bgpd-logmsg.Tpo -c -o bgpd-logmsg.obj `if test -f 'logmsg.c'; then $(CYGPATH_W) 'logmsg.c'; else $(CYGPATH_W) '$(srcdir)/logmsg.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-logmsg.Tpo $(DEPDIR)/bgpd-logmsg.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='logmsg.c' object='bgpd-logmsg.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-logmsg.obj `if test -f 'logmsg.c'; then $(CYGPATH_W) 'logmsg.c'; else $(CYGPATH_W) '$(srcdir)/logmsg.c'; fi` bgpd-parse.o: parse.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-parse.o -MD -MP -MF $(DEPDIR)/bgpd-parse.Tpo -c -o bgpd-parse.o `test -f 'parse.c' || echo '$(srcdir)/'`parse.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-parse.Tpo $(DEPDIR)/bgpd-parse.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='parse.c' object='bgpd-parse.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-parse.o `test -f 'parse.c' || echo '$(srcdir)/'`parse.c bgpd-parse.obj: parse.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-parse.obj -MD -MP -MF $(DEPDIR)/bgpd-parse.Tpo -c -o bgpd-parse.obj `if test -f 'parse.c'; then $(CYGPATH_W) 'parse.c'; else $(CYGPATH_W) '$(srcdir)/parse.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-parse.Tpo $(DEPDIR)/bgpd-parse.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='parse.c' object='bgpd-parse.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-parse.obj `if test -f 'parse.c'; then $(CYGPATH_W) 'parse.c'; else $(CYGPATH_W) '$(srcdir)/parse.c'; fi` bgpd-config.o: config.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-config.o -MD -MP -MF $(DEPDIR)/bgpd-config.Tpo -c -o bgpd-config.o `test -f 'config.c' || echo '$(srcdir)/'`config.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-config.Tpo $(DEPDIR)/bgpd-config.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='config.c' object='bgpd-config.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-config.o `test -f 'config.c' || echo '$(srcdir)/'`config.c bgpd-config.obj: config.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-config.obj -MD -MP -MF $(DEPDIR)/bgpd-config.Tpo -c -o bgpd-config.obj `if test -f 'config.c'; then $(CYGPATH_W) 'config.c'; else $(CYGPATH_W) '$(srcdir)/config.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-config.Tpo $(DEPDIR)/bgpd-config.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='config.c' object='bgpd-config.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-config.obj `if test -f 'config.c'; then $(CYGPATH_W) 'config.c'; else $(CYGPATH_W) '$(srcdir)/config.c'; fi` bgpd-rde.o: rde.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde.o -MD -MP -MF $(DEPDIR)/bgpd-rde.Tpo -c -o bgpd-rde.o `test -f 'rde.c' || echo '$(srcdir)/'`rde.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde.Tpo $(DEPDIR)/bgpd-rde.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde.c' object='bgpd-rde.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde.o `test -f 'rde.c' || echo '$(srcdir)/'`rde.c bgpd-rde.obj: rde.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde.obj -MD -MP -MF $(DEPDIR)/bgpd-rde.Tpo -c -o bgpd-rde.obj `if test -f 'rde.c'; then $(CYGPATH_W) 'rde.c'; else $(CYGPATH_W) '$(srcdir)/rde.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde.Tpo $(DEPDIR)/bgpd-rde.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde.c' object='bgpd-rde.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde.obj `if test -f 'rde.c'; then $(CYGPATH_W) 'rde.c'; else $(CYGPATH_W) '$(srcdir)/rde.c'; fi` bgpd-rde_rib.o: rde_rib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_rib.o -MD -MP -MF $(DEPDIR)/bgpd-rde_rib.Tpo -c -o bgpd-rde_rib.o `test -f 'rde_rib.c' || echo '$(srcdir)/'`rde_rib.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_rib.Tpo $(DEPDIR)/bgpd-rde_rib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_rib.c' object='bgpd-rde_rib.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_rib.o `test -f 'rde_rib.c' || echo '$(srcdir)/'`rde_rib.c bgpd-rde_rib.obj: rde_rib.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_rib.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_rib.Tpo -c -o bgpd-rde_rib.obj `if test -f 'rde_rib.c'; then $(CYGPATH_W) 'rde_rib.c'; else $(CYGPATH_W) '$(srcdir)/rde_rib.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_rib.Tpo $(DEPDIR)/bgpd-rde_rib.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_rib.c' object='bgpd-rde_rib.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_rib.obj `if test -f 'rde_rib.c'; then $(CYGPATH_W) 'rde_rib.c'; else $(CYGPATH_W) '$(srcdir)/rde_rib.c'; fi` bgpd-rde_decide.o: rde_decide.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_decide.o -MD -MP -MF $(DEPDIR)/bgpd-rde_decide.Tpo -c -o bgpd-rde_decide.o `test -f 'rde_decide.c' || echo '$(srcdir)/'`rde_decide.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_decide.Tpo $(DEPDIR)/bgpd-rde_decide.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_decide.c' object='bgpd-rde_decide.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_decide.o `test -f 'rde_decide.c' || echo '$(srcdir)/'`rde_decide.c bgpd-rde_decide.obj: rde_decide.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_decide.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_decide.Tpo -c -o bgpd-rde_decide.obj `if test -f 'rde_decide.c'; then $(CYGPATH_W) 'rde_decide.c'; else $(CYGPATH_W) '$(srcdir)/rde_decide.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_decide.Tpo $(DEPDIR)/bgpd-rde_decide.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_decide.c' object='bgpd-rde_decide.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_decide.obj `if test -f 'rde_decide.c'; then $(CYGPATH_W) 'rde_decide.c'; else $(CYGPATH_W) '$(srcdir)/rde_decide.c'; fi` bgpd-rde_prefix.o: rde_prefix.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_prefix.o -MD -MP -MF $(DEPDIR)/bgpd-rde_prefix.Tpo -c -o bgpd-rde_prefix.o `test -f 'rde_prefix.c' || echo '$(srcdir)/'`rde_prefix.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_prefix.Tpo $(DEPDIR)/bgpd-rde_prefix.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_prefix.c' object='bgpd-rde_prefix.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_prefix.o `test -f 'rde_prefix.c' || echo '$(srcdir)/'`rde_prefix.c bgpd-rde_prefix.obj: rde_prefix.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_prefix.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_prefix.Tpo -c -o bgpd-rde_prefix.obj `if test -f 'rde_prefix.c'; then $(CYGPATH_W) 'rde_prefix.c'; else $(CYGPATH_W) '$(srcdir)/rde_prefix.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_prefix.Tpo $(DEPDIR)/bgpd-rde_prefix.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_prefix.c' object='bgpd-rde_prefix.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_prefix.obj `if test -f 'rde_prefix.c'; then $(CYGPATH_W) 'rde_prefix.c'; else $(CYGPATH_W) '$(srcdir)/rde_prefix.c'; fi` bgpd-mrt.o: mrt.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-mrt.o -MD -MP -MF $(DEPDIR)/bgpd-mrt.Tpo -c -o bgpd-mrt.o `test -f 'mrt.c' || echo '$(srcdir)/'`mrt.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-mrt.Tpo $(DEPDIR)/bgpd-mrt.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mrt.c' object='bgpd-mrt.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-mrt.o `test -f 'mrt.c' || echo '$(srcdir)/'`mrt.c bgpd-mrt.obj: mrt.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-mrt.obj -MD -MP -MF $(DEPDIR)/bgpd-mrt.Tpo -c -o bgpd-mrt.obj `if test -f 'mrt.c'; then $(CYGPATH_W) 'mrt.c'; else $(CYGPATH_W) '$(srcdir)/mrt.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-mrt.Tpo $(DEPDIR)/bgpd-mrt.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mrt.c' object='bgpd-mrt.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-mrt.obj `if test -f 'mrt.c'; then $(CYGPATH_W) 'mrt.c'; else $(CYGPATH_W) '$(srcdir)/mrt.c'; fi` bgpd-kroute-disabled.o: kroute-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute-disabled.o -MD -MP -MF $(DEPDIR)/bgpd-kroute-disabled.Tpo -c -o bgpd-kroute-disabled.o `test -f 'kroute-disabled.c' || echo '$(srcdir)/'`kroute-disabled.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute-disabled.Tpo $(DEPDIR)/bgpd-kroute-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute-disabled.c' object='bgpd-kroute-disabled.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute-disabled.o `test -f 'kroute-disabled.c' || echo '$(srcdir)/'`kroute-disabled.c bgpd-kroute-disabled.obj: kroute-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute-disabled.obj -MD -MP -MF $(DEPDIR)/bgpd-kroute-disabled.Tpo -c -o bgpd-kroute-disabled.obj `if test -f 'kroute-disabled.c'; then $(CYGPATH_W) 'kroute-disabled.c'; else $(CYGPATH_W) '$(srcdir)/kroute-disabled.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute-disabled.Tpo $(DEPDIR)/bgpd-kroute-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute-disabled.c' object='bgpd-kroute-disabled.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute-disabled.obj `if test -f 'kroute-disabled.c'; then $(CYGPATH_W) 'kroute-disabled.c'; else $(CYGPATH_W) '$(srcdir)/kroute-disabled.c'; fi` bgpd-kroute.o: kroute.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute.o -MD -MP -MF $(DEPDIR)/bgpd-kroute.Tpo -c -o bgpd-kroute.o `test -f 'kroute.c' || echo '$(srcdir)/'`kroute.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute.Tpo $(DEPDIR)/bgpd-kroute.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute.c' object='bgpd-kroute.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute.o `test -f 'kroute.c' || echo '$(srcdir)/'`kroute.c bgpd-kroute.obj: kroute.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute.obj -MD -MP -MF $(DEPDIR)/bgpd-kroute.Tpo -c -o bgpd-kroute.obj `if test -f 'kroute.c'; then $(CYGPATH_W) 'kroute.c'; else $(CYGPATH_W) '$(srcdir)/kroute.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute.Tpo $(DEPDIR)/bgpd-kroute.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute.c' object='bgpd-kroute.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute.obj `if test -f 'kroute.c'; then $(CYGPATH_W) 'kroute.c'; else $(CYGPATH_W) '$(srcdir)/kroute.c'; fi` bgpd-kroute-freebsd.o: kroute-freebsd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute-freebsd.o -MD -MP -MF $(DEPDIR)/bgpd-kroute-freebsd.Tpo -c -o bgpd-kroute-freebsd.o `test -f 'kroute-freebsd.c' || echo '$(srcdir)/'`kroute-freebsd.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute-freebsd.Tpo $(DEPDIR)/bgpd-kroute-freebsd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute-freebsd.c' object='bgpd-kroute-freebsd.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute-freebsd.o `test -f 'kroute-freebsd.c' || echo '$(srcdir)/'`kroute-freebsd.c bgpd-kroute-freebsd.obj: kroute-freebsd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute-freebsd.obj -MD -MP -MF $(DEPDIR)/bgpd-kroute-freebsd.Tpo -c -o bgpd-kroute-freebsd.obj `if test -f 'kroute-freebsd.c'; then $(CYGPATH_W) 'kroute-freebsd.c'; else $(CYGPATH_W) '$(srcdir)/kroute-freebsd.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute-freebsd.Tpo $(DEPDIR)/bgpd-kroute-freebsd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute-freebsd.c' object='bgpd-kroute-freebsd.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute-freebsd.obj `if test -f 'kroute-freebsd.c'; then $(CYGPATH_W) 'kroute-freebsd.c'; else $(CYGPATH_W) '$(srcdir)/kroute-freebsd.c'; fi` bgpd-kroute-linux.o: kroute-linux.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute-linux.o -MD -MP -MF $(DEPDIR)/bgpd-kroute-linux.Tpo -c -o bgpd-kroute-linux.o `test -f 'kroute-linux.c' || echo '$(srcdir)/'`kroute-linux.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute-linux.Tpo $(DEPDIR)/bgpd-kroute-linux.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute-linux.c' object='bgpd-kroute-linux.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute-linux.o `test -f 'kroute-linux.c' || echo '$(srcdir)/'`kroute-linux.c bgpd-kroute-linux.obj: kroute-linux.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-kroute-linux.obj -MD -MP -MF $(DEPDIR)/bgpd-kroute-linux.Tpo -c -o bgpd-kroute-linux.obj `if test -f 'kroute-linux.c'; then $(CYGPATH_W) 'kroute-linux.c'; else $(CYGPATH_W) '$(srcdir)/kroute-linux.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-kroute-linux.Tpo $(DEPDIR)/bgpd-kroute-linux.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='kroute-linux.c' object='bgpd-kroute-linux.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-kroute-linux.obj `if test -f 'kroute-linux.c'; then $(CYGPATH_W) 'kroute-linux.c'; else $(CYGPATH_W) '$(srcdir)/kroute-linux.c'; fi` bgpd-control.o: control.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-control.o -MD -MP -MF $(DEPDIR)/bgpd-control.Tpo -c -o bgpd-control.o `test -f 'control.c' || echo '$(srcdir)/'`control.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-control.Tpo $(DEPDIR)/bgpd-control.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='control.c' object='bgpd-control.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-control.o `test -f 'control.c' || echo '$(srcdir)/'`control.c bgpd-control.obj: control.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-control.obj -MD -MP -MF $(DEPDIR)/bgpd-control.Tpo -c -o bgpd-control.obj `if test -f 'control.c'; then $(CYGPATH_W) 'control.c'; else $(CYGPATH_W) '$(srcdir)/control.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-control.Tpo $(DEPDIR)/bgpd-control.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='control.c' object='bgpd-control.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-control.obj `if test -f 'control.c'; then $(CYGPATH_W) 'control.c'; else $(CYGPATH_W) '$(srcdir)/control.c'; fi` bgpd-pfkey.o: pfkey.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey.o -MD -MP -MF $(DEPDIR)/bgpd-pfkey.Tpo -c -o bgpd-pfkey.o `test -f 'pfkey.c' || echo '$(srcdir)/'`pfkey.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey.Tpo $(DEPDIR)/bgpd-pfkey.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey.c' object='bgpd-pfkey.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey.o `test -f 'pfkey.c' || echo '$(srcdir)/'`pfkey.c bgpd-pfkey.obj: pfkey.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey.obj -MD -MP -MF $(DEPDIR)/bgpd-pfkey.Tpo -c -o bgpd-pfkey.obj `if test -f 'pfkey.c'; then $(CYGPATH_W) 'pfkey.c'; else $(CYGPATH_W) '$(srcdir)/pfkey.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey.Tpo $(DEPDIR)/bgpd-pfkey.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey.c' object='bgpd-pfkey.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey.obj `if test -f 'pfkey.c'; then $(CYGPATH_W) 'pfkey.c'; else $(CYGPATH_W) '$(srcdir)/pfkey.c'; fi` bgpd-pfkey-freebsd.o: pfkey-freebsd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey-freebsd.o -MD -MP -MF $(DEPDIR)/bgpd-pfkey-freebsd.Tpo -c -o bgpd-pfkey-freebsd.o `test -f 'pfkey-freebsd.c' || echo '$(srcdir)/'`pfkey-freebsd.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey-freebsd.Tpo $(DEPDIR)/bgpd-pfkey-freebsd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey-freebsd.c' object='bgpd-pfkey-freebsd.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey-freebsd.o `test -f 'pfkey-freebsd.c' || echo '$(srcdir)/'`pfkey-freebsd.c bgpd-pfkey-freebsd.obj: pfkey-freebsd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey-freebsd.obj -MD -MP -MF $(DEPDIR)/bgpd-pfkey-freebsd.Tpo -c -o bgpd-pfkey-freebsd.obj `if test -f 'pfkey-freebsd.c'; then $(CYGPATH_W) 'pfkey-freebsd.c'; else $(CYGPATH_W) '$(srcdir)/pfkey-freebsd.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey-freebsd.Tpo $(DEPDIR)/bgpd-pfkey-freebsd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey-freebsd.c' object='bgpd-pfkey-freebsd.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey-freebsd.obj `if test -f 'pfkey-freebsd.c'; then $(CYGPATH_W) 'pfkey-freebsd.c'; else $(CYGPATH_W) '$(srcdir)/pfkey-freebsd.c'; fi` bgpd-pfkey-linux.o: pfkey-linux.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey-linux.o -MD -MP -MF $(DEPDIR)/bgpd-pfkey-linux.Tpo -c -o bgpd-pfkey-linux.o `test -f 'pfkey-linux.c' || echo '$(srcdir)/'`pfkey-linux.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey-linux.Tpo $(DEPDIR)/bgpd-pfkey-linux.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey-linux.c' object='bgpd-pfkey-linux.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey-linux.o `test -f 'pfkey-linux.c' || echo '$(srcdir)/'`pfkey-linux.c bgpd-pfkey-linux.obj: pfkey-linux.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey-linux.obj -MD -MP -MF $(DEPDIR)/bgpd-pfkey-linux.Tpo -c -o bgpd-pfkey-linux.obj `if test -f 'pfkey-linux.c'; then $(CYGPATH_W) 'pfkey-linux.c'; else $(CYGPATH_W) '$(srcdir)/pfkey-linux.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey-linux.Tpo $(DEPDIR)/bgpd-pfkey-linux.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey-linux.c' object='bgpd-pfkey-linux.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey-linux.obj `if test -f 'pfkey-linux.c'; then $(CYGPATH_W) 'pfkey-linux.c'; else $(CYGPATH_W) '$(srcdir)/pfkey-linux.c'; fi` bgpd-pfkey-disabled.o: pfkey-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey-disabled.o -MD -MP -MF $(DEPDIR)/bgpd-pfkey-disabled.Tpo -c -o bgpd-pfkey-disabled.o `test -f 'pfkey-disabled.c' || echo '$(srcdir)/'`pfkey-disabled.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey-disabled.Tpo $(DEPDIR)/bgpd-pfkey-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey-disabled.c' object='bgpd-pfkey-disabled.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey-disabled.o `test -f 'pfkey-disabled.c' || echo '$(srcdir)/'`pfkey-disabled.c bgpd-pfkey-disabled.obj: pfkey-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pfkey-disabled.obj -MD -MP -MF $(DEPDIR)/bgpd-pfkey-disabled.Tpo -c -o bgpd-pfkey-disabled.obj `if test -f 'pfkey-disabled.c'; then $(CYGPATH_W) 'pfkey-disabled.c'; else $(CYGPATH_W) '$(srcdir)/pfkey-disabled.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pfkey-disabled.Tpo $(DEPDIR)/bgpd-pfkey-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pfkey-disabled.c' object='bgpd-pfkey-disabled.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pfkey-disabled.obj `if test -f 'pfkey-disabled.c'; then $(CYGPATH_W) 'pfkey-disabled.c'; else $(CYGPATH_W) '$(srcdir)/pfkey-disabled.c'; fi` bgpd-rde_update.o: rde_update.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_update.o -MD -MP -MF $(DEPDIR)/bgpd-rde_update.Tpo -c -o bgpd-rde_update.o `test -f 'rde_update.c' || echo '$(srcdir)/'`rde_update.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_update.Tpo $(DEPDIR)/bgpd-rde_update.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_update.c' object='bgpd-rde_update.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_update.o `test -f 'rde_update.c' || echo '$(srcdir)/'`rde_update.c bgpd-rde_update.obj: rde_update.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_update.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_update.Tpo -c -o bgpd-rde_update.obj `if test -f 'rde_update.c'; then $(CYGPATH_W) 'rde_update.c'; else $(CYGPATH_W) '$(srcdir)/rde_update.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_update.Tpo $(DEPDIR)/bgpd-rde_update.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_update.c' object='bgpd-rde_update.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_update.obj `if test -f 'rde_update.c'; then $(CYGPATH_W) 'rde_update.c'; else $(CYGPATH_W) '$(srcdir)/rde_update.c'; fi` bgpd-rde_attr.o: rde_attr.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_attr.o -MD -MP -MF $(DEPDIR)/bgpd-rde_attr.Tpo -c -o bgpd-rde_attr.o `test -f 'rde_attr.c' || echo '$(srcdir)/'`rde_attr.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_attr.Tpo $(DEPDIR)/bgpd-rde_attr.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_attr.c' object='bgpd-rde_attr.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_attr.o `test -f 'rde_attr.c' || echo '$(srcdir)/'`rde_attr.c bgpd-rde_attr.obj: rde_attr.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_attr.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_attr.Tpo -c -o bgpd-rde_attr.obj `if test -f 'rde_attr.c'; then $(CYGPATH_W) 'rde_attr.c'; else $(CYGPATH_W) '$(srcdir)/rde_attr.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_attr.Tpo $(DEPDIR)/bgpd-rde_attr.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_attr.c' object='bgpd-rde_attr.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_attr.obj `if test -f 'rde_attr.c'; then $(CYGPATH_W) 'rde_attr.c'; else $(CYGPATH_W) '$(srcdir)/rde_attr.c'; fi` bgpd-rde_community.o: rde_community.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_community.o -MD -MP -MF $(DEPDIR)/bgpd-rde_community.Tpo -c -o bgpd-rde_community.o `test -f 'rde_community.c' || echo '$(srcdir)/'`rde_community.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_community.Tpo $(DEPDIR)/bgpd-rde_community.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_community.c' object='bgpd-rde_community.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_community.o `test -f 'rde_community.c' || echo '$(srcdir)/'`rde_community.c bgpd-rde_community.obj: rde_community.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_community.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_community.Tpo -c -o bgpd-rde_community.obj `if test -f 'rde_community.c'; then $(CYGPATH_W) 'rde_community.c'; else $(CYGPATH_W) '$(srcdir)/rde_community.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_community.Tpo $(DEPDIR)/bgpd-rde_community.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_community.c' object='bgpd-rde_community.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_community.obj `if test -f 'rde_community.c'; then $(CYGPATH_W) 'rde_community.c'; else $(CYGPATH_W) '$(srcdir)/rde_community.c'; fi` bgpd-printconf.o: printconf.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-printconf.o -MD -MP -MF $(DEPDIR)/bgpd-printconf.Tpo -c -o bgpd-printconf.o `test -f 'printconf.c' || echo '$(srcdir)/'`printconf.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-printconf.Tpo $(DEPDIR)/bgpd-printconf.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='printconf.c' object='bgpd-printconf.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-printconf.o `test -f 'printconf.c' || echo '$(srcdir)/'`printconf.c bgpd-printconf.obj: printconf.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-printconf.obj -MD -MP -MF $(DEPDIR)/bgpd-printconf.Tpo -c -o bgpd-printconf.obj `if test -f 'printconf.c'; then $(CYGPATH_W) 'printconf.c'; else $(CYGPATH_W) '$(srcdir)/printconf.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-printconf.Tpo $(DEPDIR)/bgpd-printconf.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='printconf.c' object='bgpd-printconf.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-printconf.obj `if test -f 'printconf.c'; then $(CYGPATH_W) 'printconf.c'; else $(CYGPATH_W) '$(srcdir)/printconf.c'; fi` bgpd-rde_filter.o: rde_filter.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_filter.o -MD -MP -MF $(DEPDIR)/bgpd-rde_filter.Tpo -c -o bgpd-rde_filter.o `test -f 'rde_filter.c' || echo '$(srcdir)/'`rde_filter.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_filter.Tpo $(DEPDIR)/bgpd-rde_filter.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_filter.c' object='bgpd-rde_filter.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_filter.o `test -f 'rde_filter.c' || echo '$(srcdir)/'`rde_filter.c bgpd-rde_filter.obj: rde_filter.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_filter.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_filter.Tpo -c -o bgpd-rde_filter.obj `if test -f 'rde_filter.c'; then $(CYGPATH_W) 'rde_filter.c'; else $(CYGPATH_W) '$(srcdir)/rde_filter.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_filter.Tpo $(DEPDIR)/bgpd-rde_filter.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_filter.c' object='bgpd-rde_filter.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_filter.obj `if test -f 'rde_filter.c'; then $(CYGPATH_W) 'rde_filter.c'; else $(CYGPATH_W) '$(srcdir)/rde_filter.c'; fi` bgpd-rde_sets.o: rde_sets.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_sets.o -MD -MP -MF $(DEPDIR)/bgpd-rde_sets.Tpo -c -o bgpd-rde_sets.o `test -f 'rde_sets.c' || echo '$(srcdir)/'`rde_sets.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_sets.Tpo $(DEPDIR)/bgpd-rde_sets.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_sets.c' object='bgpd-rde_sets.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_sets.o `test -f 'rde_sets.c' || echo '$(srcdir)/'`rde_sets.c bgpd-rde_sets.obj: rde_sets.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_sets.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_sets.Tpo -c -o bgpd-rde_sets.obj `if test -f 'rde_sets.c'; then $(CYGPATH_W) 'rde_sets.c'; else $(CYGPATH_W) '$(srcdir)/rde_sets.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_sets.Tpo $(DEPDIR)/bgpd-rde_sets.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_sets.c' object='bgpd-rde_sets.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_sets.obj `if test -f 'rde_sets.c'; then $(CYGPATH_W) 'rde_sets.c'; else $(CYGPATH_W) '$(srcdir)/rde_sets.c'; fi` bgpd-rde_trie.o: rde_trie.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_trie.o -MD -MP -MF $(DEPDIR)/bgpd-rde_trie.Tpo -c -o bgpd-rde_trie.o `test -f 'rde_trie.c' || echo '$(srcdir)/'`rde_trie.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_trie.Tpo $(DEPDIR)/bgpd-rde_trie.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_trie.c' object='bgpd-rde_trie.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_trie.o `test -f 'rde_trie.c' || echo '$(srcdir)/'`rde_trie.c bgpd-rde_trie.obj: rde_trie.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_trie.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_trie.Tpo -c -o bgpd-rde_trie.obj `if test -f 'rde_trie.c'; then $(CYGPATH_W) 'rde_trie.c'; else $(CYGPATH_W) '$(srcdir)/rde_trie.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_trie.Tpo $(DEPDIR)/bgpd-rde_trie.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_trie.c' object='bgpd-rde_trie.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_trie.obj `if test -f 'rde_trie.c'; then $(CYGPATH_W) 'rde_trie.c'; else $(CYGPATH_W) '$(srcdir)/rde_trie.c'; fi` bgpd-rde_aspa.o: rde_aspa.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_aspa.o -MD -MP -MF $(DEPDIR)/bgpd-rde_aspa.Tpo -c -o bgpd-rde_aspa.o `test -f 'rde_aspa.c' || echo '$(srcdir)/'`rde_aspa.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_aspa.Tpo $(DEPDIR)/bgpd-rde_aspa.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_aspa.c' object='bgpd-rde_aspa.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_aspa.o `test -f 'rde_aspa.c' || echo '$(srcdir)/'`rde_aspa.c bgpd-rde_aspa.obj: rde_aspa.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_aspa.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_aspa.Tpo -c -o bgpd-rde_aspa.obj `if test -f 'rde_aspa.c'; then $(CYGPATH_W) 'rde_aspa.c'; else $(CYGPATH_W) '$(srcdir)/rde_aspa.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_aspa.Tpo $(DEPDIR)/bgpd-rde_aspa.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_aspa.c' object='bgpd-rde_aspa.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_aspa.obj `if test -f 'rde_aspa.c'; then $(CYGPATH_W) 'rde_aspa.c'; else $(CYGPATH_W) '$(srcdir)/rde_aspa.c'; fi` bgpd-pftable.o: pftable.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pftable.o -MD -MP -MF $(DEPDIR)/bgpd-pftable.Tpo -c -o bgpd-pftable.o `test -f 'pftable.c' || echo '$(srcdir)/'`pftable.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pftable.Tpo $(DEPDIR)/bgpd-pftable.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pftable.c' object='bgpd-pftable.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pftable.o `test -f 'pftable.c' || echo '$(srcdir)/'`pftable.c bgpd-pftable.obj: pftable.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pftable.obj -MD -MP -MF $(DEPDIR)/bgpd-pftable.Tpo -c -o bgpd-pftable.obj `if test -f 'pftable.c'; then $(CYGPATH_W) 'pftable.c'; else $(CYGPATH_W) '$(srcdir)/pftable.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pftable.Tpo $(DEPDIR)/bgpd-pftable.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pftable.c' object='bgpd-pftable.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pftable.obj `if test -f 'pftable.c'; then $(CYGPATH_W) 'pftable.c'; else $(CYGPATH_W) '$(srcdir)/pftable.c'; fi` bgpd-pftable-disabled.o: pftable-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pftable-disabled.o -MD -MP -MF $(DEPDIR)/bgpd-pftable-disabled.Tpo -c -o bgpd-pftable-disabled.o `test -f 'pftable-disabled.c' || echo '$(srcdir)/'`pftable-disabled.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pftable-disabled.Tpo $(DEPDIR)/bgpd-pftable-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pftable-disabled.c' object='bgpd-pftable-disabled.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pftable-disabled.o `test -f 'pftable-disabled.c' || echo '$(srcdir)/'`pftable-disabled.c bgpd-pftable-disabled.obj: pftable-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-pftable-disabled.obj -MD -MP -MF $(DEPDIR)/bgpd-pftable-disabled.Tpo -c -o bgpd-pftable-disabled.obj `if test -f 'pftable-disabled.c'; then $(CYGPATH_W) 'pftable-disabled.c'; else $(CYGPATH_W) '$(srcdir)/pftable-disabled.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-pftable-disabled.Tpo $(DEPDIR)/bgpd-pftable-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='pftable-disabled.c' object='bgpd-pftable-disabled.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-pftable-disabled.obj `if test -f 'pftable-disabled.c'; then $(CYGPATH_W) 'pftable-disabled.c'; else $(CYGPATH_W) '$(srcdir)/pftable-disabled.c'; fi` bgpd-name2id.o: name2id.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-name2id.o -MD -MP -MF $(DEPDIR)/bgpd-name2id.Tpo -c -o bgpd-name2id.o `test -f 'name2id.c' || echo '$(srcdir)/'`name2id.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-name2id.Tpo $(DEPDIR)/bgpd-name2id.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='name2id.c' object='bgpd-name2id.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-name2id.o `test -f 'name2id.c' || echo '$(srcdir)/'`name2id.c bgpd-name2id.obj: name2id.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-name2id.obj -MD -MP -MF $(DEPDIR)/bgpd-name2id.Tpo -c -o bgpd-name2id.obj `if test -f 'name2id.c'; then $(CYGPATH_W) 'name2id.c'; else $(CYGPATH_W) '$(srcdir)/name2id.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-name2id.Tpo $(DEPDIR)/bgpd-name2id.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='name2id.c' object='bgpd-name2id.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-name2id.obj `if test -f 'name2id.c'; then $(CYGPATH_W) 'name2id.c'; else $(CYGPATH_W) '$(srcdir)/name2id.c'; fi` bgpd-util.o: util.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-util.o -MD -MP -MF $(DEPDIR)/bgpd-util.Tpo -c -o bgpd-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-util.Tpo $(DEPDIR)/bgpd-util.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='util.c' object='bgpd-util.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c bgpd-util.obj: util.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-util.obj -MD -MP -MF $(DEPDIR)/bgpd-util.Tpo -c -o bgpd-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-util.Tpo $(DEPDIR)/bgpd-util.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='util.c' object='bgpd-util.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi` bgpd-carp.o: carp.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-carp.o -MD -MP -MF $(DEPDIR)/bgpd-carp.Tpo -c -o bgpd-carp.o `test -f 'carp.c' || echo '$(srcdir)/'`carp.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-carp.Tpo $(DEPDIR)/bgpd-carp.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='carp.c' object='bgpd-carp.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-carp.o `test -f 'carp.c' || echo '$(srcdir)/'`carp.c bgpd-carp.obj: carp.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-carp.obj -MD -MP -MF $(DEPDIR)/bgpd-carp.Tpo -c -o bgpd-carp.obj `if test -f 'carp.c'; then $(CYGPATH_W) 'carp.c'; else $(CYGPATH_W) '$(srcdir)/carp.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-carp.Tpo $(DEPDIR)/bgpd-carp.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='carp.c' object='bgpd-carp.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-carp.obj `if test -f 'carp.c'; then $(CYGPATH_W) 'carp.c'; else $(CYGPATH_W) '$(srcdir)/carp.c'; fi` bgpd-carp-disabled.o: carp-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-carp-disabled.o -MD -MP -MF $(DEPDIR)/bgpd-carp-disabled.Tpo -c -o bgpd-carp-disabled.o `test -f 'carp-disabled.c' || echo '$(srcdir)/'`carp-disabled.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-carp-disabled.Tpo $(DEPDIR)/bgpd-carp-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='carp-disabled.c' object='bgpd-carp-disabled.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-carp-disabled.o `test -f 'carp-disabled.c' || echo '$(srcdir)/'`carp-disabled.c bgpd-carp-disabled.obj: carp-disabled.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-carp-disabled.obj -MD -MP -MF $(DEPDIR)/bgpd-carp-disabled.Tpo -c -o bgpd-carp-disabled.obj `if test -f 'carp-disabled.c'; then $(CYGPATH_W) 'carp-disabled.c'; else $(CYGPATH_W) '$(srcdir)/carp-disabled.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-carp-disabled.Tpo $(DEPDIR)/bgpd-carp-disabled.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='carp-disabled.c' object='bgpd-carp-disabled.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-carp-disabled.obj `if test -f 'carp-disabled.c'; then $(CYGPATH_W) 'carp-disabled.c'; else $(CYGPATH_W) '$(srcdir)/carp-disabled.c'; fi` bgpd-timer.o: timer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-timer.o -MD -MP -MF $(DEPDIR)/bgpd-timer.Tpo -c -o bgpd-timer.o `test -f 'timer.c' || echo '$(srcdir)/'`timer.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-timer.Tpo $(DEPDIR)/bgpd-timer.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='timer.c' object='bgpd-timer.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-timer.o `test -f 'timer.c' || echo '$(srcdir)/'`timer.c bgpd-timer.obj: timer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-timer.obj -MD -MP -MF $(DEPDIR)/bgpd-timer.Tpo -c -o bgpd-timer.obj `if test -f 'timer.c'; then $(CYGPATH_W) 'timer.c'; else $(CYGPATH_W) '$(srcdir)/timer.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-timer.Tpo $(DEPDIR)/bgpd-timer.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='timer.c' object='bgpd-timer.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-timer.obj `if test -f 'timer.c'; then $(CYGPATH_W) 'timer.c'; else $(CYGPATH_W) '$(srcdir)/timer.c'; fi` bgpd-rde_peer.o: rde_peer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_peer.o -MD -MP -MF $(DEPDIR)/bgpd-rde_peer.Tpo -c -o bgpd-rde_peer.o `test -f 'rde_peer.c' || echo '$(srcdir)/'`rde_peer.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_peer.Tpo $(DEPDIR)/bgpd-rde_peer.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_peer.c' object='bgpd-rde_peer.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_peer.o `test -f 'rde_peer.c' || echo '$(srcdir)/'`rde_peer.c bgpd-rde_peer.obj: rde_peer.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rde_peer.obj -MD -MP -MF $(DEPDIR)/bgpd-rde_peer.Tpo -c -o bgpd-rde_peer.obj `if test -f 'rde_peer.c'; then $(CYGPATH_W) 'rde_peer.c'; else $(CYGPATH_W) '$(srcdir)/rde_peer.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rde_peer.Tpo $(DEPDIR)/bgpd-rde_peer.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rde_peer.c' object='bgpd-rde_peer.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rde_peer.obj `if test -f 'rde_peer.c'; then $(CYGPATH_W) 'rde_peer.c'; else $(CYGPATH_W) '$(srcdir)/rde_peer.c'; fi` bgpd-rtr.o: rtr.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rtr.o -MD -MP -MF $(DEPDIR)/bgpd-rtr.Tpo -c -o bgpd-rtr.o `test -f 'rtr.c' || echo '$(srcdir)/'`rtr.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rtr.Tpo $(DEPDIR)/bgpd-rtr.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rtr.c' object='bgpd-rtr.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rtr.o `test -f 'rtr.c' || echo '$(srcdir)/'`rtr.c bgpd-rtr.obj: rtr.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rtr.obj -MD -MP -MF $(DEPDIR)/bgpd-rtr.Tpo -c -o bgpd-rtr.obj `if test -f 'rtr.c'; then $(CYGPATH_W) 'rtr.c'; else $(CYGPATH_W) '$(srcdir)/rtr.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rtr.Tpo $(DEPDIR)/bgpd-rtr.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rtr.c' object='bgpd-rtr.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rtr.obj `if test -f 'rtr.c'; then $(CYGPATH_W) 'rtr.c'; else $(CYGPATH_W) '$(srcdir)/rtr.c'; fi` bgpd-rtr_proto.o: rtr_proto.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rtr_proto.o -MD -MP -MF $(DEPDIR)/bgpd-rtr_proto.Tpo -c -o bgpd-rtr_proto.o `test -f 'rtr_proto.c' || echo '$(srcdir)/'`rtr_proto.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rtr_proto.Tpo $(DEPDIR)/bgpd-rtr_proto.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rtr_proto.c' object='bgpd-rtr_proto.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rtr_proto.o `test -f 'rtr_proto.c' || echo '$(srcdir)/'`rtr_proto.c bgpd-rtr_proto.obj: rtr_proto.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-rtr_proto.obj -MD -MP -MF $(DEPDIR)/bgpd-rtr_proto.Tpo -c -o bgpd-rtr_proto.obj `if test -f 'rtr_proto.c'; then $(CYGPATH_W) 'rtr_proto.c'; else $(CYGPATH_W) '$(srcdir)/rtr_proto.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-rtr_proto.Tpo $(DEPDIR)/bgpd-rtr_proto.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='rtr_proto.c' object='bgpd-rtr_proto.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-rtr_proto.obj `if test -f 'rtr_proto.c'; then $(CYGPATH_W) 'rtr_proto.c'; else $(CYGPATH_W) '$(srcdir)/rtr_proto.c'; fi` bgpd-flowspec.o: flowspec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-flowspec.o -MD -MP -MF $(DEPDIR)/bgpd-flowspec.Tpo -c -o bgpd-flowspec.o `test -f 'flowspec.c' || echo '$(srcdir)/'`flowspec.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-flowspec.Tpo $(DEPDIR)/bgpd-flowspec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='flowspec.c' object='bgpd-flowspec.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-flowspec.o `test -f 'flowspec.c' || echo '$(srcdir)/'`flowspec.c bgpd-flowspec.obj: flowspec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -MT bgpd-flowspec.obj -MD -MP -MF $(DEPDIR)/bgpd-flowspec.Tpo -c -o bgpd-flowspec.obj `if test -f 'flowspec.c'; then $(CYGPATH_W) 'flowspec.c'; else $(CYGPATH_W) '$(srcdir)/flowspec.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpd-flowspec.Tpo $(DEPDIR)/bgpd-flowspec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='flowspec.c' object='bgpd-flowspec.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpd_CFLAGS) $(CFLAGS) -c -o bgpd-flowspec.obj `if test -f 'flowspec.c'; then $(CYGPATH_W) 'flowspec.c'; else $(CYGPATH_W) '$(srcdir)/flowspec.c'; fi` .y.c: $(AM_V_YACC)$(am__skipyacc) $(SHELL) $(YLWRAP) $< y.tab.c $@ y.tab.h `echo $@ | $(am__yacc_c2h)` y.output $*.output -- $(YACCCOMPILE) mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-man5: $(man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(man_MANS)'; \ test -n "$(man5dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man5dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man5dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.5[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man5dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man5dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man5dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man5dir)" || exit $$?; }; \ done; } uninstall-man5: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man5dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.5[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man5dir)'; $(am__uninstall_files_from_dir) install-man8: $(man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(man_MANS)'; \ test -n "$(man8dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.8[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \ done; } uninstall-man8: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man8dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.8[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(PROGRAMS) $(MANS) $(HEADERS) installdirs: for dir in "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man5dir)" "$(DESTDIR)$(man8dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." -rm -f parse.c clean: clean-am clean-am: clean-generic clean-libtool clean-sbinPROGRAMS \ mostlyclean-am distclean: distclean-am -rm -f ./$(DEPDIR)/bgpd-bgpd.Po -rm -f ./$(DEPDIR)/bgpd-carp-disabled.Po -rm -f ./$(DEPDIR)/bgpd-carp.Po -rm -f ./$(DEPDIR)/bgpd-config.Po -rm -f ./$(DEPDIR)/bgpd-control.Po -rm -f ./$(DEPDIR)/bgpd-flowspec.Po -rm -f ./$(DEPDIR)/bgpd-kroute-disabled.Po -rm -f ./$(DEPDIR)/bgpd-kroute-freebsd.Po -rm -f ./$(DEPDIR)/bgpd-kroute-linux.Po -rm -f ./$(DEPDIR)/bgpd-kroute.Po -rm -f ./$(DEPDIR)/bgpd-log.Po -rm -f ./$(DEPDIR)/bgpd-logmsg.Po -rm -f ./$(DEPDIR)/bgpd-mrt.Po -rm -f ./$(DEPDIR)/bgpd-name2id.Po -rm -f ./$(DEPDIR)/bgpd-parse.Po -rm -f ./$(DEPDIR)/bgpd-pfkey-disabled.Po -rm -f ./$(DEPDIR)/bgpd-pfkey-freebsd.Po -rm -f ./$(DEPDIR)/bgpd-pfkey-linux.Po -rm -f ./$(DEPDIR)/bgpd-pfkey.Po -rm -f ./$(DEPDIR)/bgpd-pftable-disabled.Po -rm -f ./$(DEPDIR)/bgpd-pftable.Po -rm -f ./$(DEPDIR)/bgpd-printconf.Po -rm -f ./$(DEPDIR)/bgpd-rde.Po -rm -f ./$(DEPDIR)/bgpd-rde_aspa.Po -rm -f ./$(DEPDIR)/bgpd-rde_attr.Po -rm -f ./$(DEPDIR)/bgpd-rde_community.Po -rm -f ./$(DEPDIR)/bgpd-rde_decide.Po -rm -f ./$(DEPDIR)/bgpd-rde_filter.Po -rm -f ./$(DEPDIR)/bgpd-rde_peer.Po -rm -f ./$(DEPDIR)/bgpd-rde_prefix.Po -rm -f ./$(DEPDIR)/bgpd-rde_rib.Po -rm -f ./$(DEPDIR)/bgpd-rde_sets.Po -rm -f ./$(DEPDIR)/bgpd-rde_trie.Po -rm -f ./$(DEPDIR)/bgpd-rde_update.Po -rm -f ./$(DEPDIR)/bgpd-rtr.Po -rm -f ./$(DEPDIR)/bgpd-rtr_proto.Po -rm -f ./$(DEPDIR)/bgpd-session.Po -rm -f ./$(DEPDIR)/bgpd-timer.Po -rm -f ./$(DEPDIR)/bgpd-util.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-man install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-sbinPROGRAMS install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-man5 install-man8 install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/bgpd-bgpd.Po -rm -f ./$(DEPDIR)/bgpd-carp-disabled.Po -rm -f ./$(DEPDIR)/bgpd-carp.Po -rm -f ./$(DEPDIR)/bgpd-config.Po -rm -f ./$(DEPDIR)/bgpd-control.Po -rm -f ./$(DEPDIR)/bgpd-flowspec.Po -rm -f ./$(DEPDIR)/bgpd-kroute-disabled.Po -rm -f ./$(DEPDIR)/bgpd-kroute-freebsd.Po -rm -f ./$(DEPDIR)/bgpd-kroute-linux.Po -rm -f ./$(DEPDIR)/bgpd-kroute.Po -rm -f ./$(DEPDIR)/bgpd-log.Po -rm -f ./$(DEPDIR)/bgpd-logmsg.Po -rm -f ./$(DEPDIR)/bgpd-mrt.Po -rm -f ./$(DEPDIR)/bgpd-name2id.Po -rm -f ./$(DEPDIR)/bgpd-parse.Po -rm -f ./$(DEPDIR)/bgpd-pfkey-disabled.Po -rm -f ./$(DEPDIR)/bgpd-pfkey-freebsd.Po -rm -f ./$(DEPDIR)/bgpd-pfkey-linux.Po -rm -f ./$(DEPDIR)/bgpd-pfkey.Po -rm -f ./$(DEPDIR)/bgpd-pftable-disabled.Po -rm -f ./$(DEPDIR)/bgpd-pftable.Po -rm -f ./$(DEPDIR)/bgpd-printconf.Po -rm -f ./$(DEPDIR)/bgpd-rde.Po -rm -f ./$(DEPDIR)/bgpd-rde_aspa.Po -rm -f ./$(DEPDIR)/bgpd-rde_attr.Po -rm -f ./$(DEPDIR)/bgpd-rde_community.Po -rm -f ./$(DEPDIR)/bgpd-rde_decide.Po -rm -f ./$(DEPDIR)/bgpd-rde_filter.Po -rm -f ./$(DEPDIR)/bgpd-rde_peer.Po -rm -f ./$(DEPDIR)/bgpd-rde_prefix.Po -rm -f ./$(DEPDIR)/bgpd-rde_rib.Po -rm -f ./$(DEPDIR)/bgpd-rde_sets.Po -rm -f ./$(DEPDIR)/bgpd-rde_trie.Po -rm -f ./$(DEPDIR)/bgpd-rde_update.Po -rm -f ./$(DEPDIR)/bgpd-rtr.Po -rm -f ./$(DEPDIR)/bgpd-rtr_proto.Po -rm -f ./$(DEPDIR)/bgpd-session.Po -rm -f ./$(DEPDIR)/bgpd-timer.Po -rm -f ./$(DEPDIR)/bgpd-util.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-man uninstall-sbinPROGRAMS uninstall-man: uninstall-man5 uninstall-man8 .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-generic clean-libtool clean-sbinPROGRAMS cscopelist-am \ ctags ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-dvi install-dvi-am install-exec \ install-exec-am install-html install-html-am install-info \ install-info-am install-man install-man5 install-man8 \ install-pdf install-pdf-am install-ps install-ps-am \ install-sbinPROGRAMS install-strip installcheck \ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am uninstall-man \ uninstall-man5 uninstall-man8 uninstall-sbinPROGRAMS .PRECIOUS: Makefile bgpd.conf.5: bgpd.conf.5.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ '$(srcdir)/bgpd.conf.5.in' >$@ bgpd.8: bgpd.8.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ '$(srcdir)/bgpd.8.in' >$@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: openbgpd-8.8/src/bgpd/parse.c100644 001750 001750 00001157162 14751151305 0011671/* A Bison parser, made by GNU Bison 3.8.2. */ /* Bison implementation for Yacc-like parsers in C Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, Inc. This program 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 3 of the License, or (at your option) any later version. This program 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. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ /* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, especially those whose name start with YY_ or yy_. They are private implementation details that can be changed or removed. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ /* Identify Bison output, and Bison version. */ #define YYBISON 30802 /* Bison version string. */ #define YYBISON_VERSION "3.8.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" /* Pure parsers. */ #define YYPURE 0 /* Push parsers. */ #define YYPUSH 0 /* Pull parsers. */ #define YYPULL 1 /* First part of user prologue. */ #line 25 "../../../openbgpd-portable/src/bgpd/parse.y" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "log.h" #ifndef nitems #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif #define MACRO_NAME_LEN 128 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files); static struct file { TAILQ_ENTRY(file) entry; FILE *stream; char *name; size_t ungetpos; size_t ungetsize; u_char *ungetbuf; int eof_reached; int lineno; int errors; } *file, *topfile; struct file *pushfile(const char *, int); int popfile(void); int check_file_secrecy(int, const char *); int yyparse(void); int yylex(void); int yyerror(const char *, ...) __attribute__((__format__ (printf, 1, 2))) __attribute__((__nonnull__ (1))); int kw_cmp(const void *, const void *); int lookup(char *); int igetc(void); int lgetc(int); void lungetc(int); int findeol(void); int expand_macro(void); TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); struct sym { TAILQ_ENTRY(sym) entry; int used; int persist; char *nam; char *val; }; int symset(const char *, const char *, int); char *symget(const char *); struct filter_rib_l { struct filter_rib_l *next; char name[PEER_DESCR_LEN]; }; struct filter_peers_l { struct filter_peers_l *next; struct filter_peers p; }; struct filter_prefix_l { struct filter_prefix_l *next; struct filter_prefix p; }; struct filter_prefixlen { enum comp_ops op; int len_min; int len_max; }; struct filter_as_l { struct filter_as_l *next; struct filter_as a; }; struct filter_match_l { struct filter_match m; struct filter_prefix_l *prefix_l; struct filter_as_l *as_l; struct filter_prefixset *prefixset; } fmopts; struct aspa_tas_l { struct aspa_tas_l *next; uint32_t as; uint32_t num; }; struct flowspec_context { uint8_t *components[FLOWSPEC_TYPE_MAX]; uint16_t complen[FLOWSPEC_TYPE_MAX]; uint8_t aid; uint8_t type; uint8_t addr_type; }; struct peer *alloc_peer(void); struct peer *new_peer(void); struct peer *new_group(void); int add_mrtconfig(enum mrt_type, char *, int, struct peer *, char *); struct rde_rib *add_rib(char *); struct rde_rib *find_rib(char *); int rib_add_fib(struct rde_rib *, u_int); int get_id(struct peer *); int merge_prefixspec(struct filter_prefix *, struct filter_prefixlen *); int expand_rule(struct filter_rule *, struct filter_rib_l *, struct filter_peers_l *, struct filter_match_l *, struct filter_set_head *); int str2key(char *, char *, size_t); int neighbor_consistent(struct peer *); int merge_filterset(struct filter_set_head *, struct filter_set *); void optimize_filters(struct filter_head *); struct filter_rule *get_rule(enum action_types); int parsecommunity(struct community *, int, char *); int parseextcommunity(struct community *, char *, char *); static int new_as_set(char *); static void add_as_set(uint32_t); static void done_as_set(void); static struct prefixset *new_prefix_set(char *, int); static void add_roa_set(struct prefixset_item *, uint32_t, uint8_t, time_t); static struct rtr_config *get_rtr(struct bgpd_addr *); static int insert_rtr(struct rtr_config *); static int merge_aspa_set(uint32_t, struct aspa_tas_l *, time_t); static int map_tos(char *, int *); static int getservice(char *); static int parse_flags(char *); static struct flowspec_config *flow_to_flowspec(struct flowspec_context *); static void flow_free(struct flowspec_context *); static int push_prefix(struct bgpd_addr *, uint8_t); static int push_binop(uint8_t, long long); static int push_unary_numop(enum comp_ops, long long); static int push_binary_numop(enum comp_ops, long long, long long); static int geticmptypebyname(char *, uint8_t); static int geticmpcodebyname(u_long, char *, uint8_t); static int merge_auth_conf(struct auth_config *, struct auth_config *); static struct bgpd_config *conf; static struct network_head *netconf; static struct peer_head *new_peers, *cur_peers; static struct rtr_config_head *cur_rtrs; static struct peer *curpeer; static struct peer *curgroup; static struct rde_rib *currib; static struct l3vpn *curvpn; static struct prefixset *curpset, *curoset; static struct roa_tree *curroatree; static struct rtr_config *currtr; static struct filter_head *filter_l; static struct filter_head *peerfilter_l; static struct filter_head *groupfilter_l; static struct filter_rule *curpeer_filter[2]; static struct filter_rule *curgroup_filter[2]; static struct flowspec_context *curflow; static int noexpires; typedef struct { union { long long number; char *string; struct bgpd_addr addr; uint8_t u8; struct filter_rib_l *filter_rib; struct filter_peers_l *filter_peers; struct filter_match_l filter_match; struct filter_prefixset *filter_prefixset; struct filter_prefix_l *filter_prefix; struct filter_as_l *filter_as; struct filter_set *filter_set; struct filter_set_head *filter_set_head; struct aspa_tas_l *aspa_elm; struct { struct bgpd_addr prefix; uint8_t len; } prefix; struct filter_prefixlen prefixlen; struct prefixset_item *prefixset_item; struct auth_config authconf; struct { enum auth_enc_alg enc_alg; uint8_t enc_key_len; char enc_key[IPSEC_ENC_KEY_LEN]; } encspec; } v; int lineno; } YYSTYPE; #line 290 "parse.c" # ifndef YY_CAST # ifdef __cplusplus # define YY_CAST(Type, Val) static_cast (Val) # define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) # else # define YY_CAST(Type, Val) ((Type) (Val)) # define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) # endif # endif # ifndef YY_NULLPTR # if defined __cplusplus # if 201103L <= __cplusplus # define YY_NULLPTR nullptr # else # define YY_NULLPTR 0 # endif # else # define YY_NULLPTR ((void*)0) # endif # endif /* Debug traces. */ #ifndef YYDEBUG # define YYDEBUG 0 #endif #if YYDEBUG extern int yydebug; #endif /* Token kinds. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { YYEMPTY = -2, YYEOF = 0, /* "end of file" */ YYerror = 256, /* error */ YYUNDEF = 257, /* "invalid token" */ AS = 258, /* AS */ ROUTERID = 259, /* ROUTERID */ HOLDTIME = 260, /* HOLDTIME */ YMIN = 261, /* YMIN */ LISTEN = 262, /* LISTEN */ ON = 263, /* ON */ FIBUPDATE = 264, /* FIBUPDATE */ FIBPRIORITY = 265, /* FIBPRIORITY */ RTABLE = 266, /* RTABLE */ NONE = 267, /* NONE */ UNICAST = 268, /* UNICAST */ VPN = 269, /* VPN */ RD = 270, /* RD */ EXPORT = 271, /* EXPORT */ EXPORTTRGT = 272, /* EXPORTTRGT */ IMPORTTRGT = 273, /* IMPORTTRGT */ DEFAULTROUTE = 274, /* DEFAULTROUTE */ RDE = 275, /* RDE */ RIB = 276, /* RIB */ EVALUATE = 277, /* EVALUATE */ IGNORE = 278, /* IGNORE */ COMPARE = 279, /* COMPARE */ RTR = 280, /* RTR */ PORT = 281, /* PORT */ MINVERSION = 282, /* MINVERSION */ STALETIME = 283, /* STALETIME */ GROUP = 284, /* GROUP */ NEIGHBOR = 285, /* NEIGHBOR */ NETWORK = 286, /* NETWORK */ EBGP = 287, /* EBGP */ IBGP = 288, /* IBGP */ FLOWSPEC = 289, /* FLOWSPEC */ PROTO = 290, /* PROTO */ FLAGS = 291, /* FLAGS */ FRAGMENT = 292, /* FRAGMENT */ TOS = 293, /* TOS */ LENGTH = 294, /* LENGTH */ ICMPTYPE = 295, /* ICMPTYPE */ CODE = 296, /* CODE */ LOCALAS = 297, /* LOCALAS */ REMOTEAS = 298, /* REMOTEAS */ DESCR = 299, /* DESCR */ LOCALADDR = 300, /* LOCALADDR */ MULTIHOP = 301, /* MULTIHOP */ PASSIVE = 302, /* PASSIVE */ MAXPREFIX = 303, /* MAXPREFIX */ RESTART = 304, /* RESTART */ ANNOUNCE = 305, /* ANNOUNCE */ REFRESH = 306, /* REFRESH */ AS4BYTE = 307, /* AS4BYTE */ CONNECTRETRY = 308, /* CONNECTRETRY */ ENHANCED = 309, /* ENHANCED */ ADDPATH = 310, /* ADDPATH */ EXTENDED = 311, /* EXTENDED */ SEND = 312, /* SEND */ RECV = 313, /* RECV */ PLUS = 314, /* PLUS */ POLICY = 315, /* POLICY */ ROLE = 316, /* ROLE */ GRACEFUL = 317, /* GRACEFUL */ NOTIFICATION = 318, /* NOTIFICATION */ MESSAGE = 319, /* MESSAGE */ DEMOTE = 320, /* DEMOTE */ ENFORCE = 321, /* ENFORCE */ NEIGHBORAS = 322, /* NEIGHBORAS */ ASOVERRIDE = 323, /* ASOVERRIDE */ REFLECTOR = 324, /* REFLECTOR */ DEPEND = 325, /* DEPEND */ DOWN = 326, /* DOWN */ DUMP = 327, /* DUMP */ IN = 328, /* IN */ OUT = 329, /* OUT */ SOCKET = 330, /* SOCKET */ RESTRICTED = 331, /* RESTRICTED */ LOG = 332, /* LOG */ TRANSPARENT = 333, /* TRANSPARENT */ FILTERED = 334, /* FILTERED */ TCP = 335, /* TCP */ MD5SIG = 336, /* MD5SIG */ PASSWORD = 337, /* PASSWORD */ KEY = 338, /* KEY */ TTLSECURITY = 339, /* TTLSECURITY */ ALLOW = 340, /* ALLOW */ DENY = 341, /* DENY */ MATCH = 342, /* MATCH */ QUICK = 343, /* QUICK */ FROM = 344, /* FROM */ TO = 345, /* TO */ ANY = 346, /* ANY */ CONNECTED = 347, /* CONNECTED */ STATIC = 348, /* STATIC */ COMMUNITY = 349, /* COMMUNITY */ EXTCOMMUNITY = 350, /* EXTCOMMUNITY */ LARGECOMMUNITY = 351, /* LARGECOMMUNITY */ DELETE = 352, /* DELETE */ MAXCOMMUNITIES = 353, /* MAXCOMMUNITIES */ MAXEXTCOMMUNITIES = 354, /* MAXEXTCOMMUNITIES */ MAXLARGECOMMUNITIES = 355, /* MAXLARGECOMMUNITIES */ PREFIX = 356, /* PREFIX */ PREFIXLEN = 357, /* PREFIXLEN */ PREFIXSET = 358, /* PREFIXSET */ ASPASET = 359, /* ASPASET */ ROASET = 360, /* ROASET */ ORIGINSET = 361, /* ORIGINSET */ OVS = 362, /* OVS */ AVS = 363, /* AVS */ EXPIRES = 364, /* EXPIRES */ ASSET = 365, /* ASSET */ SOURCEAS = 366, /* SOURCEAS */ TRANSITAS = 367, /* TRANSITAS */ PEERAS = 368, /* PEERAS */ PROVIDERAS = 369, /* PROVIDERAS */ CUSTOMERAS = 370, /* CUSTOMERAS */ MAXASLEN = 371, /* MAXASLEN */ MAXASSEQ = 372, /* MAXASSEQ */ SET = 373, /* SET */ LOCALPREF = 374, /* LOCALPREF */ MED = 375, /* MED */ METRIC = 376, /* METRIC */ NEXTHOP = 377, /* NEXTHOP */ REJECT = 378, /* REJECT */ BLACKHOLE = 379, /* BLACKHOLE */ NOMODIFY = 380, /* NOMODIFY */ SELF = 381, /* SELF */ PREPEND_SELF = 382, /* PREPEND_SELF */ PREPEND_PEER = 383, /* PREPEND_PEER */ PFTABLE = 384, /* PFTABLE */ WEIGHT = 385, /* WEIGHT */ RTLABEL = 386, /* RTLABEL */ ORIGIN = 387, /* ORIGIN */ PRIORITY = 388, /* PRIORITY */ ERROR = 389, /* ERROR */ INCLUDE = 390, /* INCLUDE */ IPSEC = 391, /* IPSEC */ ESP = 392, /* ESP */ AH = 393, /* AH */ SPI = 394, /* SPI */ IKE = 395, /* IKE */ IPV4 = 396, /* IPV4 */ IPV6 = 397, /* IPV6 */ EVPN = 398, /* EVPN */ QUALIFY = 399, /* QUALIFY */ VIA = 400, /* VIA */ NE = 401, /* NE */ LE = 402, /* LE */ GE = 403, /* GE */ XRANGE = 404, /* XRANGE */ LONGER = 405, /* LONGER */ MAXLEN = 406, /* MAXLEN */ MAX = 407, /* MAX */ STRING = 408, /* STRING */ NUMBER = 409 /* NUMBER */ }; typedef enum yytokentype yytoken_kind_t; #endif /* Token kinds. */ #define YYEMPTY -2 #define YYEOF 0 #define YYerror 256 #define YYUNDEF 257 #define AS 258 #define ROUTERID 259 #define HOLDTIME 260 #define YMIN 261 #define LISTEN 262 #define ON 263 #define FIBUPDATE 264 #define FIBPRIORITY 265 #define RTABLE 266 #define NONE 267 #define UNICAST 268 #define VPN 269 #define RD 270 #define EXPORT 271 #define EXPORTTRGT 272 #define IMPORTTRGT 273 #define DEFAULTROUTE 274 #define RDE 275 #define RIB 276 #define EVALUATE 277 #define IGNORE 278 #define COMPARE 279 #define RTR 280 #define PORT 281 #define MINVERSION 282 #define STALETIME 283 #define GROUP 284 #define NEIGHBOR 285 #define NETWORK 286 #define EBGP 287 #define IBGP 288 #define FLOWSPEC 289 #define PROTO 290 #define FLAGS 291 #define FRAGMENT 292 #define TOS 293 #define LENGTH 294 #define ICMPTYPE 295 #define CODE 296 #define LOCALAS 297 #define REMOTEAS 298 #define DESCR 299 #define LOCALADDR 300 #define MULTIHOP 301 #define PASSIVE 302 #define MAXPREFIX 303 #define RESTART 304 #define ANNOUNCE 305 #define REFRESH 306 #define AS4BYTE 307 #define CONNECTRETRY 308 #define ENHANCED 309 #define ADDPATH 310 #define EXTENDED 311 #define SEND 312 #define RECV 313 #define PLUS 314 #define POLICY 315 #define ROLE 316 #define GRACEFUL 317 #define NOTIFICATION 318 #define MESSAGE 319 #define DEMOTE 320 #define ENFORCE 321 #define NEIGHBORAS 322 #define ASOVERRIDE 323 #define REFLECTOR 324 #define DEPEND 325 #define DOWN 326 #define DUMP 327 #define IN 328 #define OUT 329 #define SOCKET 330 #define RESTRICTED 331 #define LOG 332 #define TRANSPARENT 333 #define FILTERED 334 #define TCP 335 #define MD5SIG 336 #define PASSWORD 337 #define KEY 338 #define TTLSECURITY 339 #define ALLOW 340 #define DENY 341 #define MATCH 342 #define QUICK 343 #define FROM 344 #define TO 345 #define ANY 346 #define CONNECTED 347 #define STATIC 348 #define COMMUNITY 349 #define EXTCOMMUNITY 350 #define LARGECOMMUNITY 351 #define DELETE 352 #define MAXCOMMUNITIES 353 #define MAXEXTCOMMUNITIES 354 #define MAXLARGECOMMUNITIES 355 #define PREFIX 356 #define PREFIXLEN 357 #define PREFIXSET 358 #define ASPASET 359 #define ROASET 360 #define ORIGINSET 361 #define OVS 362 #define AVS 363 #define EXPIRES 364 #define ASSET 365 #define SOURCEAS 366 #define TRANSITAS 367 #define PEERAS 368 #define PROVIDERAS 369 #define CUSTOMERAS 370 #define MAXASLEN 371 #define MAXASSEQ 372 #define SET 373 #define LOCALPREF 374 #define MED 375 #define METRIC 376 #define NEXTHOP 377 #define REJECT 378 #define BLACKHOLE 379 #define NOMODIFY 380 #define SELF 381 #define PREPEND_SELF 382 #define PREPEND_PEER 383 #define PFTABLE 384 #define WEIGHT 385 #define RTLABEL 386 #define ORIGIN 387 #define PRIORITY 388 #define ERROR 389 #define INCLUDE 390 #define IPSEC 391 #define ESP 392 #define AH 393 #define SPI 394 #define IKE 395 #define IPV4 396 #define IPV6 397 #define EVPN 398 #define QUALIFY 399 #define VIA 400 #define NE 401 #define LE 402 #define GE 403 #define XRANGE 404 #define LONGER 405 #define MAXLEN 406 #define MAX 407 #define STRING 408 #define NUMBER 409 /* Value type. */ extern YYSTYPE yylval; int yyparse (void); /* Symbol kind. */ enum yysymbol_kind_t { YYSYMBOL_YYEMPTY = -2, YYSYMBOL_YYEOF = 0, /* "end of file" */ YYSYMBOL_YYerror = 1, /* error */ YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ YYSYMBOL_AS = 3, /* AS */ YYSYMBOL_ROUTERID = 4, /* ROUTERID */ YYSYMBOL_HOLDTIME = 5, /* HOLDTIME */ YYSYMBOL_YMIN = 6, /* YMIN */ YYSYMBOL_LISTEN = 7, /* LISTEN */ YYSYMBOL_ON = 8, /* ON */ YYSYMBOL_FIBUPDATE = 9, /* FIBUPDATE */ YYSYMBOL_FIBPRIORITY = 10, /* FIBPRIORITY */ YYSYMBOL_RTABLE = 11, /* RTABLE */ YYSYMBOL_NONE = 12, /* NONE */ YYSYMBOL_UNICAST = 13, /* UNICAST */ YYSYMBOL_VPN = 14, /* VPN */ YYSYMBOL_RD = 15, /* RD */ YYSYMBOL_EXPORT = 16, /* EXPORT */ YYSYMBOL_EXPORTTRGT = 17, /* EXPORTTRGT */ YYSYMBOL_IMPORTTRGT = 18, /* IMPORTTRGT */ YYSYMBOL_DEFAULTROUTE = 19, /* DEFAULTROUTE */ YYSYMBOL_RDE = 20, /* RDE */ YYSYMBOL_RIB = 21, /* RIB */ YYSYMBOL_EVALUATE = 22, /* EVALUATE */ YYSYMBOL_IGNORE = 23, /* IGNORE */ YYSYMBOL_COMPARE = 24, /* COMPARE */ YYSYMBOL_RTR = 25, /* RTR */ YYSYMBOL_PORT = 26, /* PORT */ YYSYMBOL_MINVERSION = 27, /* MINVERSION */ YYSYMBOL_STALETIME = 28, /* STALETIME */ YYSYMBOL_GROUP = 29, /* GROUP */ YYSYMBOL_NEIGHBOR = 30, /* NEIGHBOR */ YYSYMBOL_NETWORK = 31, /* NETWORK */ YYSYMBOL_EBGP = 32, /* EBGP */ YYSYMBOL_IBGP = 33, /* IBGP */ YYSYMBOL_FLOWSPEC = 34, /* FLOWSPEC */ YYSYMBOL_PROTO = 35, /* PROTO */ YYSYMBOL_FLAGS = 36, /* FLAGS */ YYSYMBOL_FRAGMENT = 37, /* FRAGMENT */ YYSYMBOL_TOS = 38, /* TOS */ YYSYMBOL_LENGTH = 39, /* LENGTH */ YYSYMBOL_ICMPTYPE = 40, /* ICMPTYPE */ YYSYMBOL_CODE = 41, /* CODE */ YYSYMBOL_LOCALAS = 42, /* LOCALAS */ YYSYMBOL_REMOTEAS = 43, /* REMOTEAS */ YYSYMBOL_DESCR = 44, /* DESCR */ YYSYMBOL_LOCALADDR = 45, /* LOCALADDR */ YYSYMBOL_MULTIHOP = 46, /* MULTIHOP */ YYSYMBOL_PASSIVE = 47, /* PASSIVE */ YYSYMBOL_MAXPREFIX = 48, /* MAXPREFIX */ YYSYMBOL_RESTART = 49, /* RESTART */ YYSYMBOL_ANNOUNCE = 50, /* ANNOUNCE */ YYSYMBOL_REFRESH = 51, /* REFRESH */ YYSYMBOL_AS4BYTE = 52, /* AS4BYTE */ YYSYMBOL_CONNECTRETRY = 53, /* CONNECTRETRY */ YYSYMBOL_ENHANCED = 54, /* ENHANCED */ YYSYMBOL_ADDPATH = 55, /* ADDPATH */ YYSYMBOL_EXTENDED = 56, /* EXTENDED */ YYSYMBOL_SEND = 57, /* SEND */ YYSYMBOL_RECV = 58, /* RECV */ YYSYMBOL_PLUS = 59, /* PLUS */ YYSYMBOL_POLICY = 60, /* POLICY */ YYSYMBOL_ROLE = 61, /* ROLE */ YYSYMBOL_GRACEFUL = 62, /* GRACEFUL */ YYSYMBOL_NOTIFICATION = 63, /* NOTIFICATION */ YYSYMBOL_MESSAGE = 64, /* MESSAGE */ YYSYMBOL_DEMOTE = 65, /* DEMOTE */ YYSYMBOL_ENFORCE = 66, /* ENFORCE */ YYSYMBOL_NEIGHBORAS = 67, /* NEIGHBORAS */ YYSYMBOL_ASOVERRIDE = 68, /* ASOVERRIDE */ YYSYMBOL_REFLECTOR = 69, /* REFLECTOR */ YYSYMBOL_DEPEND = 70, /* DEPEND */ YYSYMBOL_DOWN = 71, /* DOWN */ YYSYMBOL_DUMP = 72, /* DUMP */ YYSYMBOL_IN = 73, /* IN */ YYSYMBOL_OUT = 74, /* OUT */ YYSYMBOL_SOCKET = 75, /* SOCKET */ YYSYMBOL_RESTRICTED = 76, /* RESTRICTED */ YYSYMBOL_LOG = 77, /* LOG */ YYSYMBOL_TRANSPARENT = 78, /* TRANSPARENT */ YYSYMBOL_FILTERED = 79, /* FILTERED */ YYSYMBOL_TCP = 80, /* TCP */ YYSYMBOL_MD5SIG = 81, /* MD5SIG */ YYSYMBOL_PASSWORD = 82, /* PASSWORD */ YYSYMBOL_KEY = 83, /* KEY */ YYSYMBOL_TTLSECURITY = 84, /* TTLSECURITY */ YYSYMBOL_ALLOW = 85, /* ALLOW */ YYSYMBOL_DENY = 86, /* DENY */ YYSYMBOL_MATCH = 87, /* MATCH */ YYSYMBOL_QUICK = 88, /* QUICK */ YYSYMBOL_FROM = 89, /* FROM */ YYSYMBOL_TO = 90, /* TO */ YYSYMBOL_ANY = 91, /* ANY */ YYSYMBOL_CONNECTED = 92, /* CONNECTED */ YYSYMBOL_STATIC = 93, /* STATIC */ YYSYMBOL_COMMUNITY = 94, /* COMMUNITY */ YYSYMBOL_EXTCOMMUNITY = 95, /* EXTCOMMUNITY */ YYSYMBOL_LARGECOMMUNITY = 96, /* LARGECOMMUNITY */ YYSYMBOL_DELETE = 97, /* DELETE */ YYSYMBOL_MAXCOMMUNITIES = 98, /* MAXCOMMUNITIES */ YYSYMBOL_MAXEXTCOMMUNITIES = 99, /* MAXEXTCOMMUNITIES */ YYSYMBOL_MAXLARGECOMMUNITIES = 100, /* MAXLARGECOMMUNITIES */ YYSYMBOL_PREFIX = 101, /* PREFIX */ YYSYMBOL_PREFIXLEN = 102, /* PREFIXLEN */ YYSYMBOL_PREFIXSET = 103, /* PREFIXSET */ YYSYMBOL_ASPASET = 104, /* ASPASET */ YYSYMBOL_ROASET = 105, /* ROASET */ YYSYMBOL_ORIGINSET = 106, /* ORIGINSET */ YYSYMBOL_OVS = 107, /* OVS */ YYSYMBOL_AVS = 108, /* AVS */ YYSYMBOL_EXPIRES = 109, /* EXPIRES */ YYSYMBOL_ASSET = 110, /* ASSET */ YYSYMBOL_SOURCEAS = 111, /* SOURCEAS */ YYSYMBOL_TRANSITAS = 112, /* TRANSITAS */ YYSYMBOL_PEERAS = 113, /* PEERAS */ YYSYMBOL_PROVIDERAS = 114, /* PROVIDERAS */ YYSYMBOL_CUSTOMERAS = 115, /* CUSTOMERAS */ YYSYMBOL_MAXASLEN = 116, /* MAXASLEN */ YYSYMBOL_MAXASSEQ = 117, /* MAXASSEQ */ YYSYMBOL_SET = 118, /* SET */ YYSYMBOL_LOCALPREF = 119, /* LOCALPREF */ YYSYMBOL_MED = 120, /* MED */ YYSYMBOL_METRIC = 121, /* METRIC */ YYSYMBOL_NEXTHOP = 122, /* NEXTHOP */ YYSYMBOL_REJECT = 123, /* REJECT */ YYSYMBOL_BLACKHOLE = 124, /* BLACKHOLE */ YYSYMBOL_NOMODIFY = 125, /* NOMODIFY */ YYSYMBOL_SELF = 126, /* SELF */ YYSYMBOL_PREPEND_SELF = 127, /* PREPEND_SELF */ YYSYMBOL_PREPEND_PEER = 128, /* PREPEND_PEER */ YYSYMBOL_PFTABLE = 129, /* PFTABLE */ YYSYMBOL_WEIGHT = 130, /* WEIGHT */ YYSYMBOL_RTLABEL = 131, /* RTLABEL */ YYSYMBOL_ORIGIN = 132, /* ORIGIN */ YYSYMBOL_PRIORITY = 133, /* PRIORITY */ YYSYMBOL_ERROR = 134, /* ERROR */ YYSYMBOL_INCLUDE = 135, /* INCLUDE */ YYSYMBOL_IPSEC = 136, /* IPSEC */ YYSYMBOL_ESP = 137, /* ESP */ YYSYMBOL_AH = 138, /* AH */ YYSYMBOL_SPI = 139, /* SPI */ YYSYMBOL_IKE = 140, /* IKE */ YYSYMBOL_IPV4 = 141, /* IPV4 */ YYSYMBOL_IPV6 = 142, /* IPV6 */ YYSYMBOL_EVPN = 143, /* EVPN */ YYSYMBOL_QUALIFY = 144, /* QUALIFY */ YYSYMBOL_VIA = 145, /* VIA */ YYSYMBOL_NE = 146, /* NE */ YYSYMBOL_LE = 147, /* LE */ YYSYMBOL_GE = 148, /* GE */ YYSYMBOL_XRANGE = 149, /* XRANGE */ YYSYMBOL_LONGER = 150, /* LONGER */ YYSYMBOL_MAXLEN = 151, /* MAXLEN */ YYSYMBOL_MAX = 152, /* MAX */ YYSYMBOL_STRING = 153, /* STRING */ YYSYMBOL_NUMBER = 154, /* NUMBER */ YYSYMBOL_155_n_ = 155, /* '\n' */ YYSYMBOL_156_ = 156, /* '=' */ YYSYMBOL_157_ = 157, /* '{' */ YYSYMBOL_158_ = 158, /* '}' */ YYSYMBOL_159_ = 159, /* '/' */ YYSYMBOL_160_ = 160, /* '+' */ YYSYMBOL_161_ = 161, /* '-' */ YYSYMBOL_162_ = 162, /* ',' */ YYSYMBOL_163_ = 163, /* '<' */ YYSYMBOL_164_ = 164, /* '>' */ YYSYMBOL_YYACCEPT = 165, /* $accept */ YYSYMBOL_grammar = 166, /* grammar */ YYSYMBOL_asnumber = 167, /* asnumber */ YYSYMBOL_as4number = 168, /* as4number */ YYSYMBOL_as4number_any = 169, /* as4number_any */ YYSYMBOL_string = 170, /* string */ YYSYMBOL_yesno = 171, /* yesno */ YYSYMBOL_varset = 172, /* varset */ YYSYMBOL_include = 173, /* include */ YYSYMBOL_as_set = 174, /* as_set */ YYSYMBOL_175_1 = 175, /* $@1 */ YYSYMBOL_as_set_l = 176, /* as_set_l */ YYSYMBOL_prefixset = 177, /* prefixset */ YYSYMBOL_178_2 = 178, /* $@2 */ YYSYMBOL_prefixset_l = 179, /* prefixset_l */ YYSYMBOL_prefixset_item = 180, /* prefixset_item */ YYSYMBOL_roa_set = 181, /* roa_set */ YYSYMBOL_182_3 = 182, /* $@3 */ YYSYMBOL_origin_set = 183, /* origin_set */ YYSYMBOL_184_4 = 184, /* $@4 */ YYSYMBOL_expires = 185, /* expires */ YYSYMBOL_roa_set_l = 186, /* roa_set_l */ YYSYMBOL_aspa_set = 187, /* aspa_set */ YYSYMBOL_aspa_set_l = 188, /* aspa_set_l */ YYSYMBOL_aspa_elm = 189, /* aspa_elm */ YYSYMBOL_aspa_tas_l = 190, /* aspa_tas_l */ YYSYMBOL_aspa_tas = 191, /* aspa_tas */ YYSYMBOL_rtr = 192, /* rtr */ YYSYMBOL_193_5 = 193, /* $@5 */ YYSYMBOL_rtropt_l = 194, /* rtropt_l */ YYSYMBOL_rtropt = 195, /* rtropt */ YYSYMBOL_conf_main = 196, /* conf_main */ YYSYMBOL_rib = 197, /* rib */ YYSYMBOL_198_6 = 198, /* $@6 */ YYSYMBOL_ribopts = 199, /* ribopts */ YYSYMBOL_fibupdate = 200, /* fibupdate */ YYSYMBOL_mrtdump = 201, /* mrtdump */ YYSYMBOL_network = 202, /* network */ YYSYMBOL_flowspec = 203, /* flowspec */ YYSYMBOL_204_7 = 204, /* $@7 */ YYSYMBOL_proto = 205, /* proto */ YYSYMBOL_proto_list = 206, /* proto_list */ YYSYMBOL_proto_item = 207, /* proto_item */ YYSYMBOL_from = 208, /* from */ YYSYMBOL_209_8 = 209, /* $@8 */ YYSYMBOL_to = 210, /* to */ YYSYMBOL_211_9 = 211, /* $@9 */ YYSYMBOL_ipportspec = 212, /* ipportspec */ YYSYMBOL_ipspec = 213, /* ipspec */ YYSYMBOL_portspec = 214, /* portspec */ YYSYMBOL_port_list = 215, /* port_list */ YYSYMBOL_port_item = 216, /* port_item */ YYSYMBOL_port = 217, /* port */ YYSYMBOL_flow_rules = 218, /* flow_rules */ YYSYMBOL_flow_rules_l = 219, /* flow_rules_l */ YYSYMBOL_flowrule = 220, /* flowrule */ YYSYMBOL_221_10 = 221, /* $@10 */ YYSYMBOL_222_11 = 222, /* $@11 */ YYSYMBOL_flags = 223, /* flags */ YYSYMBOL_flag = 224, /* flag */ YYSYMBOL_icmpspec = 225, /* icmpspec */ YYSYMBOL_icmp_list = 226, /* icmp_list */ YYSYMBOL_icmp_item = 227, /* icmp_item */ YYSYMBOL_icmptype = 228, /* icmptype */ YYSYMBOL_tos = 229, /* tos */ YYSYMBOL_lengthspec = 230, /* lengthspec */ YYSYMBOL_length_list = 231, /* length_list */ YYSYMBOL_length_item = 232, /* length_item */ YYSYMBOL_length = 233, /* length */ YYSYMBOL_inout = 234, /* inout */ YYSYMBOL_restricted = 235, /* restricted */ YYSYMBOL_address = 236, /* address */ YYSYMBOL_prefix = 237, /* prefix */ YYSYMBOL_addrspec = 238, /* addrspec */ YYSYMBOL_optnumber = 239, /* optnumber */ YYSYMBOL_l3vpn = 240, /* l3vpn */ YYSYMBOL_241_12 = 241, /* $@12 */ YYSYMBOL_l3vpnopts_l = 242, /* l3vpnopts_l */ YYSYMBOL_l3vpnopts = 243, /* l3vpnopts */ YYSYMBOL_neighbor = 244, /* neighbor */ YYSYMBOL_245_13 = 245, /* $@13 */ YYSYMBOL_246_14 = 246, /* $@14 */ YYSYMBOL_group = 247, /* group */ YYSYMBOL_248_15 = 248, /* $@15 */ YYSYMBOL_groupopts_l = 249, /* groupopts_l */ YYSYMBOL_addpathextra = 250, /* addpathextra */ YYSYMBOL_addpathmax = 251, /* addpathmax */ YYSYMBOL_peeropts_h = 252, /* peeropts_h */ YYSYMBOL_peeropts_l = 253, /* peeropts_l */ YYSYMBOL_peeropts = 254, /* peeropts */ YYSYMBOL_restart = 255, /* restart */ YYSYMBOL_af = 256, /* af */ YYSYMBOL_safi = 257, /* safi */ YYSYMBOL_nettype = 258, /* nettype */ YYSYMBOL_authconf = 259, /* authconf */ YYSYMBOL_espah = 260, /* espah */ YYSYMBOL_encspec = 261, /* encspec */ YYSYMBOL_filterrule = 262, /* filterrule */ YYSYMBOL_action = 263, /* action */ YYSYMBOL_quick = 264, /* quick */ YYSYMBOL_direction = 265, /* direction */ YYSYMBOL_filter_rib_h = 266, /* filter_rib_h */ YYSYMBOL_filter_rib_l = 267, /* filter_rib_l */ YYSYMBOL_filter_rib = 268, /* filter_rib */ YYSYMBOL_filter_peer_h = 269, /* filter_peer_h */ YYSYMBOL_filter_peer_l = 270, /* filter_peer_l */ YYSYMBOL_filter_peer = 271, /* filter_peer */ YYSYMBOL_filter_prefix_h = 272, /* filter_prefix_h */ YYSYMBOL_filter_prefix_m = 273, /* filter_prefix_m */ YYSYMBOL_filter_prefix_l = 274, /* filter_prefix_l */ YYSYMBOL_filter_prefix = 275, /* filter_prefix */ YYSYMBOL_filter_as_h = 276, /* filter_as_h */ YYSYMBOL_filter_as_t_l = 277, /* filter_as_t_l */ YYSYMBOL_filter_as_t = 278, /* filter_as_t */ YYSYMBOL_filter_as_l_h = 279, /* filter_as_l_h */ YYSYMBOL_filter_as_l = 280, /* filter_as_l */ YYSYMBOL_filter_as = 281, /* filter_as */ YYSYMBOL_filter_match_h = 282, /* filter_match_h */ YYSYMBOL_283_16 = 283, /* $@16 */ YYSYMBOL_filter_match = 284, /* filter_match */ YYSYMBOL_filter_elm = 285, /* filter_elm */ YYSYMBOL_prefixlenop = 286, /* prefixlenop */ YYSYMBOL_filter_as_type = 287, /* filter_as_type */ YYSYMBOL_filter_set = 288, /* filter_set */ YYSYMBOL_filter_set_l = 289, /* filter_set_l */ YYSYMBOL_community = 290, /* community */ YYSYMBOL_delete = 291, /* delete */ YYSYMBOL_enforce = 292, /* enforce */ YYSYMBOL_yesnoenforce = 293, /* yesnoenforce */ YYSYMBOL_filter_set_opt = 294, /* filter_set_opt */ YYSYMBOL_origincode = 295, /* origincode */ YYSYMBOL_validity = 296, /* validity */ YYSYMBOL_aspa_validity = 297, /* aspa_validity */ YYSYMBOL_optnl = 298, /* optnl */ YYSYMBOL_comma = 299, /* comma */ YYSYMBOL_unaryop = 300, /* unaryop */ YYSYMBOL_equalityop = 301, /* equalityop */ YYSYMBOL_binaryop = 302 /* binaryop */ }; typedef enum yysymbol_kind_t yysymbol_kind_t; #ifdef short # undef short #endif /* On compilers that do not define __PTRDIFF_MAX__ etc., make sure and (if available) are included so that the code can choose integer types of a good width. */ #ifndef __PTRDIFF_MAX__ # include /* INFRINGES ON USER NAME SPACE */ # if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YY_STDINT_H # endif #endif /* Narrow types that promote to a signed type and that can represent a signed or unsigned integer of at least N bits. In tables they can save space and decrease cache pressure. Promoting to a signed type helps avoid bugs in integer arithmetic. */ #ifdef __INT_LEAST8_MAX__ typedef __INT_LEAST8_TYPE__ yytype_int8; #elif defined YY_STDINT_H typedef int_least8_t yytype_int8; #else typedef signed char yytype_int8; #endif #ifdef __INT_LEAST16_MAX__ typedef __INT_LEAST16_TYPE__ yytype_int16; #elif defined YY_STDINT_H typedef int_least16_t yytype_int16; #else typedef short yytype_int16; #endif /* Work around bug in HP-UX 11.23, which defines these macros incorrectly for preprocessor constants. This workaround can likely be removed in 2023, as HPE has promised support for HP-UX 11.23 (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of . */ #ifdef __hpux # undef UINT_LEAST8_MAX # undef UINT_LEAST16_MAX # define UINT_LEAST8_MAX 255 # define UINT_LEAST16_MAX 65535 #endif #if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ typedef __UINT_LEAST8_TYPE__ yytype_uint8; #elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ && UINT_LEAST8_MAX <= INT_MAX) typedef uint_least8_t yytype_uint8; #elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX typedef unsigned char yytype_uint8; #else typedef short yytype_uint8; #endif #if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ typedef __UINT_LEAST16_TYPE__ yytype_uint16; #elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ && UINT_LEAST16_MAX <= INT_MAX) typedef uint_least16_t yytype_uint16; #elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX typedef unsigned short yytype_uint16; #else typedef int yytype_uint16; #endif #ifndef YYPTRDIFF_T # if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ # define YYPTRDIFF_T __PTRDIFF_TYPE__ # define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ # elif defined PTRDIFF_MAX # ifndef ptrdiff_t # include /* INFRINGES ON USER NAME SPACE */ # endif # define YYPTRDIFF_T ptrdiff_t # define YYPTRDIFF_MAXIMUM PTRDIFF_MAX # else # define YYPTRDIFF_T long # define YYPTRDIFF_MAXIMUM LONG_MAX # endif #endif #ifndef YYSIZE_T # ifdef __SIZE_TYPE__ # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t # elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else # define YYSIZE_T unsigned # endif #endif #define YYSIZE_MAXIMUM \ YY_CAST (YYPTRDIFF_T, \ (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ ? YYPTRDIFF_MAXIMUM \ : YY_CAST (YYSIZE_T, -1))) #define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) /* Stored state numbers (used for stacks). */ typedef yytype_int16 yy_state_t; /* State numbers in computations. */ typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ # define YY_(Msgid) Msgid # endif #endif #ifndef YY_ATTRIBUTE_PURE # if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) # define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) # else # define YY_ATTRIBUTE_PURE # endif #endif #ifndef YY_ATTRIBUTE_UNUSED # if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) # define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) # else # define YY_ATTRIBUTE_UNUSED # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ # define YY_USE(E) ((void) (E)) #else # define YY_USE(E) /* empty */ #endif /* Suppress an incorrect diagnostic about yylval being uninitialized. */ #if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__ # if __GNUC__ * 100 + __GNUC_MINOR__ < 407 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") # else # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") # endif # define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value #endif #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN # define YY_IGNORE_MAYBE_UNINITIALIZED_END #endif #ifndef YY_INITIAL_VALUE # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif #if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ # define YY_IGNORE_USELESS_CAST_BEGIN \ _Pragma ("GCC diagnostic push") \ _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") # define YY_IGNORE_USELESS_CAST_END \ _Pragma ("GCC diagnostic pop") #endif #ifndef YY_IGNORE_USELESS_CAST_BEGIN # define YY_IGNORE_USELESS_CAST_BEGIN # define YY_IGNORE_USELESS_CAST_END #endif #define YY_ASSERT(E) ((void) (0 && (E))) #if !defined yyoverflow /* The parser invokes alloca or malloc; define the necessary symbols. */ # ifdef YYSTACK_USE_ALLOCA # if YYSTACK_USE_ALLOCA # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca # elif defined __BUILTIN_VA_ARG_INCR # include /* INFRINGES ON USER NAME SPACE */ # elif defined _AIX # define YYSTACK_ALLOC __alloca # elif defined _MSC_VER # include /* INFRINGES ON USER NAME SPACE */ # define alloca _alloca # else # define YYSTACK_ALLOC alloca # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS # include /* INFRINGES ON USER NAME SPACE */ /* Use EXIT_SUCCESS as a witness for stdlib.h. */ # ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 # endif # endif # endif # endif # endif # ifdef YYSTACK_ALLOC /* Pacify GCC's 'empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely invoke alloca (N) if N exceeds 4096. Use a slightly smaller number to allow for a few compiler-allocated temporary stack slots. */ # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ # endif # else # define YYSTACK_ALLOC YYMALLOC # define YYSTACK_FREE YYFREE # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif # if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ # ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc # if ! defined malloc && ! defined EXIT_SUCCESS void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free # if ! defined free && ! defined EXIT_SUCCESS void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif #endif /* !defined yyoverflow */ #if (! defined yyoverflow \ && (! defined __cplusplus \ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ YYPTRDIFF_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / YYSIZEOF (*yyptr); \ } \ while (0) #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED /* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ while (0) # endif # endif #endif /* !YYCOPY_NEEDED */ /* YYFINAL -- State number of the termination state. */ #define YYFINAL 2 /* YYLAST -- Last index in YYTABLE. */ #define YYLAST 986 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 165 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 138 /* YYNRULES -- Number of rules. */ #define YYNRULES 420 /* YYNSTATES -- Number of states. */ #define YYNSTATES 772 /* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 409 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM as returned by yylex, with out-of-bounds checking. */ #define YYTRANSLATE(YYX) \ (0 <= (YYX) && (YYX) <= YYMAXUTOK \ ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM as returned by yylex. */ static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 155, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 160, 162, 161, 2, 159, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 163, 156, 164, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 157, 2, 158, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154 }; #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_int16 yyrline[] = { 0, 303, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 325, 336, 368, 378, 405, 410, 416, 419, 434, 462, 477, 477, 491, 499, 500, 502, 502, 512, 522, 536, 552, 569, 569, 574, 577, 577, 591, 603, 606, 614, 624, 636, 637, 640, 641, 644, 661, 662, 669, 675, 683, 692, 692, 704, 705, 708, 719, 727, 730, 738, 744, 751, 755, 762, 770, 778, 786, 800, 814, 821, 832, 838, 844, 853, 881, 913, 923, 933, 946, 959, 967, 980, 996, 1003, 1019, 1019, 1029, 1030, 1039, 1048, 1049, 1057, 1087, 1108, 1137, 1156, 1179, 1199, 1199, 1228, 1229, 1232, 1237, 1244, 1256, 1265, 1265, 1271, 1271, 1277, 1278, 1279, 1282, 1283, 1289, 1290, 1293, 1294, 1297, 1301, 1305, 1311, 1319, 1329, 1330, 1333, 1334, 1337, 1338, 1339, 1339, 1342, 1342, 1345, 1346, 1349, 1350, 1357, 1372, 1376, 1380, 1383, 1393, 1394, 1397, 1398, 1401, 1406, 1424, 1438, 1450, 1459, 1479, 1488, 1489, 1492, 1493, 1496, 1500, 1504, 1510, 1518, 1519, 1522, 1523, 1526, 1547, 1565, 1585, 1592, 1595, 1596, 1599, 1599, 1644, 1645, 1646, 1647, 1650, 1668, 1686, 1704, 1710, 1713, 1714, 1713, 1767, 1767, 1799, 1800, 1801, 1802, 1803, 1806, 1807, 1817, 1818, 1828, 1829, 1830, 1833, 1834, 1835, 1836, 1839, 1842, 1849, 1853, 1864, 1877, 1887, 1894, 1897, 1900, 1911, 1927, 1935, 1943, 1951, 1973, 1979, 1982, 1985, 1988, 1991, 1994, 2007, 2055, 2058, 2061, 2065, 2084, 2087, 2090, 2093, 2099, 2105, 2120, 2128, 2136, 2140, 2143, 2150, 2162, 2163, 2173, 2189, 2201, 2225, 2231, 2242, 2248, 2251, 2266, 2267, 2277, 2278, 2281, 2282, 2283, 2284, 2287, 2288, 2291, 2304, 2314, 2321, 2396, 2397, 2400, 2403, 2436, 2463, 2464, 2465, 2468, 2469, 2472, 2473, 2476, 2477, 2478, 2480, 2481, 2487, 2509, 2510, 2513, 2514, 2520, 2527, 2547, 2554, 2575, 2581, 2589, 2604, 2619, 2620, 2623, 2624, 2625, 2637, 2638, 2644, 2659, 2660, 2663, 2664, 2676, 2680, 2687, 2710, 2711, 2712, 2725, 2726, 2732, 2740, 2746, 2754, 2768, 2771, 2771, 2779, 2780, 2783, 2796, 2803, 2815, 2827, 2845, 2867, 2886, 2902, 2914, 2926, 2934, 2941, 2990, 3010, 3018, 3028, 3029, 3035, 3046, 3089, 3105, 3106, 3107, 3108, 3111, 3112, 3119, 3122, 3127, 3136, 3137, 3140, 3141, 3144, 3145, 3148, 3149, 3152, 3167, 3177, 3187, 3202, 3212, 3222, 3237, 3247, 3257, 3272, 3282, 3292, 3299, 3304, 3309, 3314, 3319, 3329, 3339, 3344, 3371, 3385, 3413, 3431, 3447, 3455, 3470, 3485, 3500, 3501, 3504, 3505, 3506, 3507, 3510, 3511, 3512, 3513, 3514, 3515, 3518, 3519, 3522, 3523 }; #endif /** Accessing symbol of state STATE. */ #define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) #if YYDEBUG || 0 /* The user-facing name of the symbol whose (internal) number is YYSYMBOL. No bounds checking. */ static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { "\"end of file\"", "error", "\"invalid token\"", "AS", "ROUTERID", "HOLDTIME", "YMIN", "LISTEN", "ON", "FIBUPDATE", "FIBPRIORITY", "RTABLE", "NONE", "UNICAST", "VPN", "RD", "EXPORT", "EXPORTTRGT", "IMPORTTRGT", "DEFAULTROUTE", "RDE", "RIB", "EVALUATE", "IGNORE", "COMPARE", "RTR", "PORT", "MINVERSION", "STALETIME", "GROUP", "NEIGHBOR", "NETWORK", "EBGP", "IBGP", "FLOWSPEC", "PROTO", "FLAGS", "FRAGMENT", "TOS", "LENGTH", "ICMPTYPE", "CODE", "LOCALAS", "REMOTEAS", "DESCR", "LOCALADDR", "MULTIHOP", "PASSIVE", "MAXPREFIX", "RESTART", "ANNOUNCE", "REFRESH", "AS4BYTE", "CONNECTRETRY", "ENHANCED", "ADDPATH", "EXTENDED", "SEND", "RECV", "PLUS", "POLICY", "ROLE", "GRACEFUL", "NOTIFICATION", "MESSAGE", "DEMOTE", "ENFORCE", "NEIGHBORAS", "ASOVERRIDE", "REFLECTOR", "DEPEND", "DOWN", "DUMP", "IN", "OUT", "SOCKET", "RESTRICTED", "LOG", "TRANSPARENT", "FILTERED", "TCP", "MD5SIG", "PASSWORD", "KEY", "TTLSECURITY", "ALLOW", "DENY", "MATCH", "QUICK", "FROM", "TO", "ANY", "CONNECTED", "STATIC", "COMMUNITY", "EXTCOMMUNITY", "LARGECOMMUNITY", "DELETE", "MAXCOMMUNITIES", "MAXEXTCOMMUNITIES", "MAXLARGECOMMUNITIES", "PREFIX", "PREFIXLEN", "PREFIXSET", "ASPASET", "ROASET", "ORIGINSET", "OVS", "AVS", "EXPIRES", "ASSET", "SOURCEAS", "TRANSITAS", "PEERAS", "PROVIDERAS", "CUSTOMERAS", "MAXASLEN", "MAXASSEQ", "SET", "LOCALPREF", "MED", "METRIC", "NEXTHOP", "REJECT", "BLACKHOLE", "NOMODIFY", "SELF", "PREPEND_SELF", "PREPEND_PEER", "PFTABLE", "WEIGHT", "RTLABEL", "ORIGIN", "PRIORITY", "ERROR", "INCLUDE", "IPSEC", "ESP", "AH", "SPI", "IKE", "IPV4", "IPV6", "EVPN", "QUALIFY", "VIA", "NE", "LE", "GE", "XRANGE", "LONGER", "MAXLEN", "MAX", "STRING", "NUMBER", "'\\n'", "'='", "'{'", "'}'", "'/'", "'+'", "'-'", "','", "'<'", "'>'", "$accept", "grammar", "asnumber", "as4number", "as4number_any", "string", "yesno", "varset", "include", "as_set", "$@1", "as_set_l", "prefixset", "$@2", "prefixset_l", "prefixset_item", "roa_set", "$@3", "origin_set", "$@4", "expires", "roa_set_l", "aspa_set", "aspa_set_l", "aspa_elm", "aspa_tas_l", "aspa_tas", "rtr", "$@5", "rtropt_l", "rtropt", "conf_main", "rib", "$@6", "ribopts", "fibupdate", "mrtdump", "network", "flowspec", "$@7", "proto", "proto_list", "proto_item", "from", "$@8", "to", "$@9", "ipportspec", "ipspec", "portspec", "port_list", "port_item", "port", "flow_rules", "flow_rules_l", "flowrule", "$@10", "$@11", "flags", "flag", "icmpspec", "icmp_list", "icmp_item", "icmptype", "tos", "lengthspec", "length_list", "length_item", "length", "inout", "restricted", "address", "prefix", "addrspec", "optnumber", "l3vpn", "$@12", "l3vpnopts_l", "l3vpnopts", "neighbor", "$@13", "$@14", "group", "$@15", "groupopts_l", "addpathextra", "addpathmax", "peeropts_h", "peeropts_l", "peeropts", "restart", "af", "safi", "nettype", "authconf", "espah", "encspec", "filterrule", "action", "quick", "direction", "filter_rib_h", "filter_rib_l", "filter_rib", "filter_peer_h", "filter_peer_l", "filter_peer", "filter_prefix_h", "filter_prefix_m", "filter_prefix_l", "filter_prefix", "filter_as_h", "filter_as_t_l", "filter_as_t", "filter_as_l_h", "filter_as_l", "filter_as", "filter_match_h", "$@16", "filter_match", "filter_elm", "prefixlenop", "filter_as_type", "filter_set", "filter_set_l", "community", "delete", "enforce", "yesnoenforce", "filter_set_opt", "origincode", "validity", "aspa_validity", "optnl", "comma", "unaryop", "equalityop", "binaryop", YY_NULLPTR }; static const char * yysymbol_name (yysymbol_kind_t yysymbol) { return yytname[yysymbol]; } #endif #define YYPACT_NINF (-581) #define yypact_value_is_default(Yyn) \ ((Yyn) == YYPACT_NINF) #define YYTABLE_NINF (-408) #define yytable_value_is_error(Yyn) \ 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ static const yytype_int16 yypact[] = { -581, 727, -581, -82, 229, -77, 26, 71, -72, -65, -46, -58, 64, -77, -25, -48, 111, 249, -20, 12, -30, -6, -72, -581, -581, -581, 13, -2, 25, 19, 59, 54, 108, 87, 68, -581, 96, 117, 136, 151, 154, 168, 175, 195, 199, 212, 245, 255, 282, 286, 309, 252, 313, 317, 213, -581, -581, -581, -581, 178, -581, -581, 258, -581, -77, -581, -581, -581, -581, 411, 281, 297, 437, 375, 344, -581, -581, 321, 323, -581, -581, 349, 354, 385, 177, -581, -581, 369, 18, 451, -581, -581, 388, 398, 398, 401, 402, 415, -72, -581, -48, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, 264, -581, -581, -581, 540, -581, -581, 537, 413, 429, -581, 414, -581, -581, 420, -581, 421, 385, 417, 425, 257, -581, -581, -581, 427, 431, 385, 239, 430, -581, -581, 432, 434, -581, -581, 398, 398, -45, 410, 398, 398, 436, -581, 321, 349, -581, -581, -581, 114, 340, 304, -581, 511, 40, -581, 398, -581, -581, -581, -581, -581, -581, 494, -581, 134, 144, 185, 298, 438, 440, 442, 220, 443, 444, 398, 494, -581, 385, 385, -581, 133, -581, -581, 345, 306, 163, -581, -581, -581, -581, -581, 385, 239, -581, -581, 445, -581, -581, 432, 446, -581, 229, -581, -31, -581, -581, 353, 447, 449, -581, 452, -581, 398, -581, -581, -581, 39, -581, -581, -581, 453, -581, -72, 448, 578, -581, -581, 183, 504, -581, -42, -581, 454, 457, -581, 458, 460, -581, 461, 462, -581, -581, -581, -581, -581, -581, -581, -581, -581, 463, 464, -581, -581, -581, 697, 450, -581, -581, -581, -581, 398, -581, -37, -37, -581, -581, -581, -581, -581, -581, -581, -581, 398, -581, -581, -581, -581, -62, 465, -581, -581, 398, -581, 560, 15, 15, -581, -581, 432, -581, -581, 353, 512, 398, 468, 455, 505, 514, 92, -49, -581, 353, -581, 362, 831, -581, 473, 229, 475, -581, -581, -581, 398, -581, -38, -581, -581, -581, 621, -581, 304, 478, 481, -77, 554, 381, 398, -581, -581, 483, 37, 295, 614, 484, 304, 485, 229, 229, -48, -77, 487, -581, 488, 206, 22, 492, 48, -72, -77, 638, 497, 498, 499, -72, -72, 274, 543, -581, -581, 602, -581, 500, 503, -581, 507, 508, -581, -581, -581, -581, -581, -581, -581, -581, 92, -581, -581, 382, -581, -581, 510, -581, 506, -581, 319, -581, -581, 465, -581, 384, 386, 279, -581, -581, 640, -581, -581, -581, 92, -581, 513, 550, 519, 398, -581, -581, 362, 521, 353, 348, -581, 515, -581, 92, -581, -581, -581, 92, -581, 522, -59, -581, -581, -581, 28, 385, 45, 21, -581, -581, -581, -581, -581, 459, -581, -581, 9, 83, -581, 527, -581, -581, -581, 529, -581, -581, -581, 178, -581, 321, -581, -581, 58, -11, -11, -11, 617, 486, -8, -11, 620, 618, 299, -581, -581, -581, -72, -72, -581, -581, 532, -581, 482, -581, -581, -581, 398, -581, -72, -581, -581, -581, -581, -581, 528, 697, 92, -581, -581, 510, 92, -581, -581, 92, -581, -581, -581, 398, -581, -581, -62, 304, 279, 530, 353, -581, 533, -581, 512, -581, 576, -62, 538, -581, 544, 545, 362, 628, -581, 546, 473, 92, -581, -581, -581, -3, 547, 553, 555, 218, 557, 558, 561, 562, -581, -581, -581, 559, 563, 7, -49, -49, 95, -581, -581, -581, 45, -581, 146, 565, 536, -72, 566, 568, 569, -581, -581, -581, 571, -48, -48, -581, 577, -581, -581, -581, -581, -581, 570, 674, -581, -581, -581, -581, -581, -581, -11, 580, -11, -11, -11, -581, -72, -581, -581, -581, -581, -581, -581, 618, -581, -581, -581, 697, -581, -581, -581, 581, 382, -581, 582, 319, 585, 384, 292, 304, -581, -581, -581, -581, 398, -581, 362, 575, -581, -581, -581, -581, 589, -581, -581, 590, -581, -581, 591, 28, 595, 597, -581, -581, -581, 254, -49, -581, -49, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, -581, 201, -581, -581, -581, 600, -581, -581, 181, -62, -581, 362, -581, -581, -581, -581, 601, 606, -581, 321, 321, 608, -581, -581, -581, 676, -581, -581, -581, -581, -581, 92, -581, -581, -581, -581, -581, -581, 92, -581, -581, 362, 512, -581, -581, -581, -581, -581, -581, -581, 353, 605, 329, -581, -581, -581, 398, -581, 95, -581, 127, 609, 330, -581, 362, -581, -581, -581, 607, 612, 616, 611, 613, 292, 249, 92, -581, -581, 335, -581, 353, -581, -581, 359, -581, 127, -581, 619, -581, 622, 618, -581, -581, -581, -581, 615, 362, 254, -581, 181, -581, 624, -581, -581, -581, -581, -581, -581, 625, -581, -581 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. Performed when YYTABLE does not specify something else to do. Zero means the default is an error. */ static const yytype_int16 yydefact[] = { 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 284, 285, 286, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 287, 21, 23, 22, 24, 72, 177, 74, 0, 75, 0, 29, 81, 80, 93, 0, 0, 0, 0, 0, 62, 77, 28, 198, 0, 267, 268, 0, 0, 363, 0, 109, 94, 0, 0, 175, 84, 82, 0, 405, 405, 0, 0, 0, 0, 31, 0, 4, 5, 6, 7, 8, 10, 9, 11, 16, 12, 15, 13, 14, 17, 18, 0, 19, 20, 288, 291, 73, 76, 78, 0, 96, 90, 0, 87, 88, 0, 27, 0, 363, 0, 0, 0, 104, 274, 273, 0, 0, 363, 135, 0, 173, 174, 182, 0, 176, 95, 405, 405, 0, 43, 405, 405, 0, 83, 30, 177, 180, 181, 196, 0, 0, 0, 184, 0, 101, 89, 405, 200, 105, 178, 179, 395, 368, 370, 369, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 405, 370, 364, 363, 363, 108, 0, 141, 143, 0, 0, 0, 117, 119, 147, 139, 140, 363, 136, 137, 145, 0, 183, 85, 182, 37, 406, 0, 54, 405, 55, 45, 0, 46, 32, 92, 211, 296, 405, 292, 289, 290, 0, 134, 133, 79, 0, 91, 0, 0, 0, 97, 98, 0, 0, 371, 0, 376, 0, 0, 379, 0, 0, 382, 0, 0, 390, 389, 391, 392, 388, 393, 394, 396, 385, 0, 0, 397, 402, 401, 0, 0, 106, 107, 115, 116, 405, 111, 0, 0, 163, 164, 148, 412, 413, 415, 172, 411, 405, 414, 416, 146, 165, 169, 0, 161, 162, 405, 154, 158, 0, 0, 110, 138, 182, 103, 39, 0, 49, 405, 408, 0, 0, 0, 407, 354, 48, 0, 34, 0, 0, 197, 0, 0, 0, 305, 306, 301, 405, 302, 334, 297, 186, 102, 101, 100, 0, 0, 0, 0, 0, 0, 405, 65, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 223, 0, 0, 0, 0, 0, 0, 256, 0, 224, 0, 0, 0, 0, 0, 0, 201, 199, 0, 255, 0, 0, 251, 0, 0, 377, 378, 380, 381, 383, 384, 386, 387, 407, 367, 398, 0, 152, 153, 0, 142, 151, 144, 0, 420, 419, 0, 170, 0, 0, 0, 124, 118, 121, 125, 120, 86, 407, 40, 0, 0, 409, 405, 53, 56, 0, 0, 0, 0, 355, 0, 42, 407, 25, 26, 35, 407, 212, 0, 405, 294, 303, 304, 0, 363, 0, 0, 99, 69, 70, 67, 68, 0, 279, 280, 0, 0, 204, 0, 227, 244, 245, 0, 226, 263, 229, 217, 216, 219, 220, 222, 265, 0, 0, 0, 0, 0, 0, 0, 0, 372, 0, 243, 242, 259, 0, 0, 248, 257, 0, 225, 0, 261, 260, 252, 405, 253, 0, 221, 203, 202, 400, 399, 0, 0, 407, 113, 150, 0, 407, 167, 171, 407, 156, 159, 160, 405, 123, 126, 130, 0, 0, 0, 0, 50, 0, 410, 49, 44, 0, 0, 0, 356, 0, 0, 0, 0, 210, 0, 0, 407, 299, 283, 359, 0, 0, 0, 0, 0, 0, 0, 0, 0, 360, 361, 362, 0, 0, 0, 354, 354, 0, 338, 339, 317, 335, 336, 0, 0, 0, 0, 0, 0, 0, 187, 185, 194, 0, 0, 0, 277, 0, 64, 66, 228, 264, 218, 0, 265, 249, 375, 374, 234, 232, 236, 0, 0, 0, 0, 0, 239, 0, 373, 231, 269, 270, 271, 272, 372, 247, 246, 258, 0, 262, 365, 366, 0, 0, 149, 0, 0, 0, 0, 0, 0, 131, 122, 38, 41, 405, 51, 0, 0, 357, 47, 33, 36, 0, 213, 209, 0, 293, 295, 0, 0, 0, 0, 345, 346, 347, 0, 354, 309, 354, 351, 403, 352, 404, 353, 340, 341, 349, 348, 307, 308, 407, 319, 337, 330, 0, 418, 417, 0, 329, 321, 0, 342, 189, 193, 190, 0, 0, 188, 275, 276, 0, 266, 250, 233, 205, 237, 240, 241, 235, 230, 407, 112, 114, 166, 168, 155, 157, 407, 128, 132, 0, 49, 358, 215, 214, 298, 300, 344, 343, 0, 0, 407, 314, 316, 350, 405, 318, 0, 323, 0, 0, 407, 327, 0, 331, 191, 192, 0, 0, 207, 0, 0, 0, 60, 407, 58, 52, 407, 310, 0, 409, 320, 407, 322, 0, 332, 0, 206, 0, 372, 254, 127, 129, 61, 0, 0, 312, 315, 325, 328, 281, 208, 238, 57, 59, 313, 326, 0, 278, 282 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int16 yypgoto[] = { -581, -581, 8, -153, -310, -95, -5, -581, -581, -581, -581, -581, -581, -581, -581, -291, -581, -581, -581, -581, -498, 467, -581, -581, 470, -581, 17, -581, -581, -581, 322, -581, -581, -581, -581, 456, 769, 336, -581, -581, -581, -581, -383, -581, -581, -581, -581, 493, -581, 267, -581, -580, -162, -581, -581, 579, -581, -581, 509, -346, -581, -581, -385, -581, -581, -581, -581, -387, -225, 337, -581, 2, -16, -581, -167, -581, -581, -581, -581, 551, -581, -581, -581, -581, -581, -581, -581, -581, -581, -296, 211, -15, -581, -581, -215, -581, -581, -581, -581, -581, -581, -581, -581, -304, -581, -581, -415, -581, 42, 86, -526, -581, -581, -529, 38, 80, -543, -581, -581, -581, 241, -512, -581, -119, 197, -365, 629, -578, -350, -128, -581, -581, -581, -93, -213, -189, -581, -481 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int16 yydefgoto[] = { 0, 1, 431, 59, 670, 77, 588, 36, 37, 38, 319, 433, 39, 307, 414, 313, 40, 222, 41, 317, 417, 314, 42, 219, 220, 736, 737, 43, 130, 342, 343, 44, 45, 169, 241, 242, 376, 47, 48, 143, 204, 502, 277, 205, 300, 206, 301, 409, 410, 514, 699, 515, 516, 207, 208, 209, 278, 279, 397, 398, 210, 509, 298, 299, 282, 291, 506, 292, 293, 148, 150, 329, 315, 163, 213, 49, 236, 443, 574, 50, 51, 226, 52, 132, 244, 731, 751, 321, 533, 378, 586, 84, 605, 142, 379, 452, 770, 53, 54, 120, 232, 165, 436, 229, 330, 537, 331, 559, 712, 713, 714, 560, 662, 561, 722, 723, 724, 441, 442, 562, 563, 428, 564, 137, 390, 191, 246, 600, 589, 391, 269, 653, 655, 153, 424, 517, 672, 403 }; /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule whose number is the opposite. If YYTABLE_NINF, syntax error. */ static const yytype_int16 yytable[] = { 83, 154, 85, 66, 235, 159, 312, 61, 192, 432, 503, 294, 58, 507, 173, 74, 415, 91, 437, 649, 510, 671, 566, 195, 435, 538, 627, 691, 344, 663, 567, 323, 62, 87, 479, 621, 568, 658, 569, 570, 700, 407, 323, 455, 660, 661, 629, 305, 540, 238, 504, 239, 16, 425, 394, 587, 595, 324, 215, 216, 325, 326, 223, 224, 308, 380, 123, 121, 324, 404, 217, 325, 326, 55, 272, 273, 60, 565, 243, 64, -333, 65, 145, 146, -407, 70, 71, 401, 302, 67, 482, 145, 146, 158, -407, 69, 309, 270, 540, 402, 162, 426, 427, 310, 642, 76, 408, 584, 68, 336, 337, 381, 524, 218, 596, 483, 395, -333, 161, 327, 590, 591, 396, 89, 309, 597, 311, 338, 339, 75, 327, 310, 585, 526, 86, 322, 715, 413, 716, 177, 541, 179, 65, 542, 543, 544, 545, 90, 546, 577, 643, 547, 548, 549, 754, 93, 550, 551, 552, 615, 60, 553, 554, 340, 240, 88, 92, 555, 81, 82, 438, 147, 95, 764, 445, 480, 571, 501, 508, 572, 63, 60, 94, 393, 72, 260, 556, 557, 461, 725, 743, 456, 60, 65, 665, 400, 328, 565, 97, 463, 464, 520, 558, 761, 405, 738, 550, 551, 552, 336, 337, 294, 96, 665, 78, 759, 418, 73, 98, 341, 532, 423, 633, 536, 100, 58, 708, 338, 339, 625, 696, 694, 639, 333, 698, 440, 528, 637, 344, 375, 99, 579, 685, 493, 687, 688, 689, 309, 665, 453, -405, 101, 79, 80, 310, 469, 666, 470, 471, 465, 472, 473, 474, 340, 81, 82, 475, 227, 476, 138, 139, 228, 102, 667, 196, 197, 198, 199, 200, 201, 430, 57, 116, 668, 411, 411, 274, 275, 247, 614, 276, 103, 667, 617, 248, 249, 619, 500, 250, 430, 57, 119, 668, 669, 251, 252, 104, 457, 140, 105, 141, 601, 602, 603, 458, 375, 295, 296, 703, 341, 297, 519, 539, 106, 641, 176, 523, 667, 202, 203, 107, 58, 57, 604, 430, 57, 530, 668, 721, 253, 531, 448, 176, 535, 478, 254, 255, 79, 80, 477, 108, 177, 178, 179, 109, 622, 717, 466, 484, 718, 58, 58, 726, 310, 490, 491, 485, 110, 177, 178, 179, 81, 82, 612, 264, 647, 180, 181, 182, 183, 265, 266, 56, 57, 184, 185, 186, 187, 188, 189, 79, 80, 735, 180, 181, 182, 183, 128, 129, 609, 111, 184, 185, 186, 187, 188, 189, 81, 82, 613, 112, 711, 122, 616, 190, 747, 618, 160, 82, 124, 620, 256, 257, 258, 259, 283, 284, 285, 294, 230, 231, 492, 233, 234, 125, 287, 513, 113, 283, 284, 285, 114, 289, 290, 640, 233, 234, 735, 287, 719, 126, 60, 283, 284, 285, 289, 290, 233, 234, 701, 286, 127, 287, 288, 115, 283, 284, 285, 117, 289, 290, 583, 118, 286, 131, 287, 133, 606, 607, 501, 680, 681, 289, 290, 717, 717, 734, -311, -324, 610, 717, 310, 310, 758, 283, 284, 285, 310, 280, 281, 741, -63, 527, 136, 287, 345, 81, 82, 134, 346, 746, 289, 290, 135, 717, 430, 57, 760, 450, 451, 347, 310, 144, 757, 348, 349, 741, 149, 375, 648, 350, 746, 351, 702, -195, 274, 275, 295, 296, 511, 512, 575, 576, 593, 594, 151, 352, 353, 354, 355, 356, 357, 358, 152, 359, 145, 146, 659, 155, 156, 157, 164, 675, 166, 168, 360, 167, 170, 221, 361, 362, 174, 363, 364, 365, 366, 367, 171, 172, 175, 193, 368, 369, 211, 340, 194, 212, 214, 370, 225, 237, 245, 261, 690, 262, 263, 267, 268, 304, 732, 335, 406, 334, 392, 306, 316, 733, 318, 382, 320, 332, 383, 384, 420, 385, 386, 387, 388, 389, 286, 217, 416, 371, 419, 742, 422, 227, 372, 439, 634, 238, 648, 446, 346, 447, 449, 459, 460, 454, 462, 341, 467, 468, 756, 347, 481, 486, 495, 348, 349, 487, 488, 489, 494, 350, 496, 351, 65, 497, 373, 498, 499, 374, 395, 522, 505, 518, 521, 592, 529, 352, 353, 354, 355, 356, 357, 358, -406, 359, 525, 534, 581, 582, 598, 599, 608, 611, 628, 624, 360, 626, 674, 630, 361, 362, 648, 363, 364, 365, 366, 367, 644, 631, 632, 638, 368, 369, 645, 340, 646, 650, 651, 370, 656, 652, 654, 682, 657, 673, 676, 755, 677, 678, 584, 683, 648, 679, 2, 3, 704, 4, 5, 6, 686, 7, 730, 8, 9, 10, 693, 695, 11, 648, 697, 705, 706, 371, 12, 709, 707, 710, 372, 13, 720, 727, 14, 15, -195, 16, 728, 748, 17, 729, 740, 341, 176, 749, 745, 750, 752, 46, 753, 762, 765, 766, 580, 763, 769, 771, 573, 18, 65, 421, 635, 429, 623, 636, 303, 399, 578, 444, 177, 178, 179, 412, 377, 684, 739, 768, 19, 767, 744, 20, 664, 21, 22, 692, 0, 0, 0, 0, 0, 23, 24, 25, 0, 180, 181, 182, 183, 271, 0, 0, 0, 184, 185, 186, 187, 188, 189, 26, 27, 28, 29, 0, 0, 346, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 347, 0, 31, 32, 348, 349, 0, 0, 0, 0, 350, 0, 351, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 352, 353, 354, 355, 356, 357, 358, 34, 359, 35, 0, 0, 0, 0, 0, 0, 0, 0, 0, 360, 0, 0, 0, 361, 362, 0, 363, 364, 365, 366, 367, 0, 0, 0, 0, 368, 369, 0, 340, 0, 0, 0, 370, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 371, 0, 0, 0, 0, 372, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 341, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 0, 434 }; static const yytype_int16 yycheck[] = { 16, 94, 17, 8, 166, 100, 219, 5, 136, 319, 393, 200, 4, 400, 133, 13, 307, 22, 322, 545, 405, 564, 1, 142, 320, 440, 524, 605, 243, 558, 9, 3, 6, 21, 12, 516, 15, 30, 17, 18, 620, 26, 3, 6, 556, 557, 527, 214, 3, 9, 396, 11, 31, 102, 91, 66, 64, 29, 151, 152, 32, 33, 155, 156, 217, 107, 64, 59, 29, 294, 115, 32, 33, 155, 193, 194, 153, 442, 171, 8, 118, 153, 73, 74, 115, 21, 22, 149, 207, 154, 42, 73, 74, 98, 153, 153, 155, 190, 3, 161, 116, 150, 151, 162, 107, 153, 91, 49, 154, 26, 27, 153, 422, 158, 122, 67, 153, 155, 116, 91, 470, 471, 159, 153, 155, 475, 219, 44, 45, 154, 91, 162, 74, 424, 154, 228, 648, 304, 650, 94, 95, 96, 153, 98, 99, 100, 101, 153, 103, 140, 153, 106, 107, 108, 734, 157, 111, 112, 113, 505, 153, 116, 117, 80, 169, 153, 153, 122, 153, 154, 323, 153, 153, 751, 336, 153, 155, 390, 403, 158, 154, 153, 157, 276, 120, 183, 141, 142, 350, 670, 719, 154, 153, 153, 67, 288, 157, 562, 144, 352, 353, 414, 157, 746, 297, 703, 111, 112, 113, 26, 27, 400, 153, 67, 103, 741, 309, 153, 110, 136, 433, 314, 532, 436, 156, 217, 641, 44, 45, 520, 617, 614, 536, 238, 619, 328, 425, 533, 453, 244, 153, 158, 592, 371, 594, 595, 596, 155, 67, 342, 158, 155, 141, 142, 162, 49, 110, 51, 52, 354, 54, 55, 56, 80, 153, 154, 60, 153, 62, 92, 93, 157, 155, 146, 35, 36, 37, 38, 39, 40, 153, 154, 30, 156, 300, 301, 153, 154, 154, 502, 157, 155, 146, 506, 160, 161, 509, 390, 154, 153, 154, 88, 156, 157, 160, 161, 155, 12, 131, 155, 133, 12, 13, 14, 19, 320, 153, 154, 628, 136, 157, 414, 441, 155, 537, 68, 419, 146, 89, 90, 155, 323, 154, 34, 153, 154, 429, 156, 157, 154, 433, 339, 68, 436, 359, 160, 161, 141, 142, 143, 155, 94, 95, 96, 155, 517, 155, 355, 363, 158, 352, 353, 672, 162, 369, 370, 364, 155, 94, 95, 96, 153, 154, 501, 154, 157, 119, 120, 121, 122, 160, 161, 153, 154, 127, 128, 129, 130, 131, 132, 141, 142, 702, 119, 120, 121, 122, 22, 23, 492, 155, 127, 128, 129, 130, 131, 132, 153, 154, 502, 155, 157, 154, 506, 157, 725, 509, 153, 154, 8, 513, 123, 124, 125, 126, 146, 147, 148, 617, 89, 90, 157, 153, 154, 153, 156, 157, 155, 146, 147, 148, 155, 163, 164, 537, 153, 154, 757, 156, 662, 153, 153, 146, 147, 148, 163, 164, 153, 154, 621, 154, 24, 156, 157, 155, 146, 147, 148, 155, 163, 164, 463, 155, 154, 153, 156, 153, 482, 483, 692, 575, 576, 163, 164, 155, 155, 699, 158, 158, 494, 155, 162, 162, 158, 146, 147, 148, 162, 153, 154, 713, 157, 154, 118, 156, 1, 153, 154, 159, 5, 723, 163, 164, 159, 155, 153, 154, 158, 137, 138, 16, 162, 153, 736, 20, 21, 739, 76, 533, 545, 26, 744, 28, 626, 30, 153, 154, 153, 154, 153, 154, 82, 83, 57, 58, 157, 42, 43, 44, 45, 46, 47, 48, 155, 50, 73, 74, 555, 157, 157, 145, 21, 567, 26, 135, 61, 153, 153, 158, 65, 66, 154, 68, 69, 70, 71, 72, 157, 157, 154, 153, 77, 78, 153, 80, 154, 154, 153, 84, 153, 79, 97, 154, 598, 154, 153, 153, 153, 153, 692, 22, 41, 154, 153, 158, 158, 699, 158, 154, 157, 157, 154, 154, 158, 154, 154, 154, 154, 154, 154, 115, 109, 118, 155, 717, 111, 153, 123, 153, 1, 9, 647, 154, 5, 153, 81, 22, 153, 155, 154, 136, 154, 154, 736, 16, 153, 8, 45, 20, 21, 153, 153, 153, 110, 26, 155, 28, 153, 155, 155, 153, 153, 158, 153, 114, 159, 26, 154, 51, 154, 42, 43, 44, 45, 46, 47, 48, 158, 50, 158, 158, 154, 153, 63, 66, 153, 158, 111, 158, 61, 157, 155, 154, 65, 66, 711, 68, 69, 70, 71, 72, 154, 158, 158, 158, 77, 78, 154, 80, 154, 153, 153, 84, 154, 153, 153, 139, 154, 153, 153, 735, 153, 153, 49, 154, 741, 155, 0, 1, 154, 3, 4, 5, 153, 7, 59, 9, 10, 11, 158, 158, 14, 758, 158, 155, 155, 118, 20, 153, 158, 153, 123, 25, 153, 153, 28, 29, 30, 31, 153, 153, 34, 154, 158, 136, 68, 154, 158, 152, 158, 1, 158, 153, 158, 757, 453, 154, 153, 153, 443, 53, 153, 312, 155, 317, 518, 158, 208, 279, 452, 334, 94, 95, 96, 301, 244, 585, 711, 760, 72, 758, 721, 75, 562, 77, 78, 609, -1, -1, -1, -1, -1, 85, 86, 87, -1, 119, 120, 121, 122, 191, -1, -1, -1, 127, 128, 129, 130, 131, 132, 103, 104, 105, 106, -1, -1, 5, 110, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16, -1, 122, 123, 20, 21, -1, -1, -1, -1, 26, -1, 28, -1, -1, 135, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 42, 43, 44, 45, 46, 47, 48, 153, 50, 155, -1, -1, -1, -1, -1, -1, -1, -1, -1, 61, -1, -1, -1, 65, 66, -1, 68, 69, 70, 71, 72, -1, -1, -1, -1, 77, 78, -1, 80, -1, -1, -1, 84, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 118, -1, -1, -1, -1, 123, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 136, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 153, -1, 155 }; /* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of state STATE-NUM. */ static const yytype_int16 yystos[] = { 0, 166, 0, 1, 3, 4, 5, 7, 9, 10, 11, 14, 20, 25, 28, 29, 31, 34, 53, 72, 75, 77, 78, 85, 86, 87, 103, 104, 105, 106, 110, 122, 123, 135, 153, 155, 172, 173, 174, 177, 181, 183, 187, 192, 196, 197, 201, 202, 203, 240, 244, 245, 247, 262, 263, 155, 153, 154, 167, 168, 153, 236, 6, 154, 8, 153, 171, 154, 154, 153, 21, 22, 120, 153, 236, 154, 153, 170, 103, 141, 142, 153, 154, 237, 256, 256, 154, 21, 153, 153, 153, 171, 153, 157, 157, 153, 153, 144, 110, 153, 156, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 155, 30, 155, 155, 88, 264, 167, 154, 236, 8, 153, 153, 24, 22, 23, 193, 153, 248, 153, 159, 159, 118, 288, 92, 93, 131, 133, 258, 204, 153, 73, 74, 153, 234, 76, 235, 157, 155, 298, 298, 157, 157, 145, 171, 170, 153, 236, 237, 238, 21, 266, 26, 153, 135, 198, 153, 157, 157, 288, 154, 154, 68, 94, 95, 96, 119, 120, 121, 122, 127, 128, 129, 130, 131, 132, 157, 290, 294, 153, 154, 288, 35, 36, 37, 38, 39, 40, 89, 90, 205, 208, 210, 218, 219, 220, 225, 153, 154, 239, 153, 298, 298, 115, 158, 188, 189, 158, 182, 298, 298, 153, 246, 153, 157, 268, 89, 90, 265, 153, 154, 217, 241, 79, 9, 11, 171, 199, 200, 298, 249, 97, 291, 154, 160, 161, 154, 160, 161, 154, 160, 161, 123, 124, 125, 126, 236, 154, 154, 153, 154, 160, 161, 153, 153, 295, 298, 291, 288, 288, 153, 154, 157, 207, 221, 222, 153, 154, 229, 146, 147, 148, 154, 156, 157, 163, 164, 230, 232, 233, 300, 153, 154, 157, 227, 228, 209, 211, 288, 220, 153, 239, 158, 178, 168, 155, 162, 298, 299, 180, 186, 237, 158, 184, 158, 175, 157, 252, 298, 3, 29, 32, 33, 91, 157, 236, 269, 271, 157, 171, 154, 22, 26, 27, 44, 45, 80, 136, 194, 195, 259, 1, 5, 16, 20, 21, 26, 28, 42, 43, 44, 45, 46, 47, 48, 50, 61, 65, 66, 68, 69, 70, 71, 72, 77, 78, 84, 118, 123, 155, 158, 171, 201, 244, 254, 259, 107, 153, 154, 154, 154, 154, 154, 154, 154, 154, 289, 294, 153, 298, 91, 153, 159, 223, 224, 223, 298, 149, 161, 302, 233, 298, 41, 26, 91, 212, 213, 237, 212, 239, 179, 180, 109, 185, 298, 155, 158, 189, 111, 298, 299, 102, 150, 151, 286, 186, 153, 167, 169, 176, 155, 254, 267, 268, 168, 153, 298, 282, 283, 242, 200, 217, 154, 153, 236, 81, 137, 138, 260, 298, 155, 6, 154, 12, 19, 22, 153, 217, 154, 168, 168, 170, 236, 154, 154, 49, 51, 52, 54, 55, 56, 60, 62, 143, 256, 12, 153, 153, 42, 67, 171, 236, 8, 153, 153, 153, 171, 171, 157, 294, 110, 45, 155, 155, 153, 153, 298, 299, 206, 207, 224, 159, 231, 232, 233, 226, 227, 153, 154, 157, 214, 216, 217, 300, 26, 298, 299, 154, 114, 298, 169, 158, 180, 154, 300, 154, 298, 298, 299, 253, 158, 298, 299, 270, 271, 288, 3, 95, 98, 99, 100, 101, 103, 106, 107, 108, 111, 112, 113, 116, 117, 122, 141, 142, 157, 272, 276, 278, 284, 285, 287, 290, 1, 9, 15, 17, 18, 155, 158, 202, 243, 82, 83, 140, 234, 158, 195, 154, 153, 167, 49, 74, 255, 66, 171, 293, 293, 293, 51, 57, 58, 64, 122, 293, 63, 66, 292, 12, 13, 14, 34, 257, 171, 171, 153, 298, 171, 158, 294, 298, 299, 224, 298, 299, 298, 299, 298, 302, 217, 214, 158, 180, 157, 185, 111, 302, 154, 158, 158, 169, 1, 155, 158, 254, 158, 268, 298, 299, 107, 153, 154, 154, 154, 157, 237, 275, 153, 153, 153, 296, 153, 297, 154, 154, 30, 236, 286, 286, 277, 278, 285, 67, 110, 146, 156, 157, 169, 281, 301, 153, 155, 171, 153, 153, 153, 155, 170, 170, 139, 154, 255, 293, 153, 293, 293, 293, 171, 292, 289, 158, 207, 158, 232, 158, 227, 215, 216, 217, 298, 169, 154, 155, 155, 158, 271, 153, 153, 157, 273, 274, 275, 286, 286, 155, 158, 299, 153, 157, 279, 280, 281, 302, 169, 153, 153, 154, 59, 250, 298, 298, 299, 169, 190, 191, 185, 274, 158, 299, 298, 278, 280, 158, 299, 169, 153, 154, 152, 251, 158, 158, 216, 256, 298, 299, 158, 275, 158, 281, 153, 154, 292, 158, 191, 273, 279, 153, 261, 153 }; /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ static const yytype_int16 yyr1[] = { 0, 165, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 166, 167, 168, 168, 169, 169, 170, 170, 171, 172, 173, 175, 174, 174, 176, 176, 178, 177, 177, 179, 179, 180, 182, 181, 181, 184, 183, 183, 185, 185, 186, 186, 187, 187, 188, 188, 189, 190, 190, 191, 191, 192, 193, 192, 194, 194, 195, 195, 195, 195, 195, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 198, 197, 199, 199, 199, 200, 200, 201, 202, 202, 202, 202, 202, 204, 203, 205, 205, 206, 206, 207, 207, 209, 208, 211, 210, 212, 212, 212, 213, 213, 214, 214, 215, 215, 216, 216, 216, 217, 217, 218, 218, 219, 219, 220, 220, 221, 220, 222, 220, 220, 220, 220, 220, 223, 223, 223, 223, 224, 225, 225, 226, 226, 227, 227, 227, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 232, 233, 234, 234, 235, 235, 236, 237, 237, 238, 238, 239, 239, 241, 240, 242, 242, 242, 242, 243, 243, 243, 243, 243, 245, 246, 244, 248, 247, 249, 249, 249, 249, 249, 250, 250, 251, 251, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 256, 256, 257, 257, 257, 257, 258, 258, 259, 259, 259, 259, 260, 260, 261, 261, 262, 263, 263, 263, 264, 264, 265, 265, 266, 266, 266, 267, 267, 268, 269, 269, 270, 270, 271, 271, 271, 271, 271, 271, 272, 272, 272, 272, 273, 273, 273, 274, 274, 275, 276, 276, 277, 277, 278, 278, 278, 279, 279, 279, 280, 280, 281, 281, 281, 281, 282, 283, 282, 284, 284, 285, 285, 285, 285, 285, 285, 285, 285, 285, 285, 285, 285, 285, 285, 285, 285, 286, 286, 286, 286, 286, 287, 287, 287, 287, 288, 288, 288, 289, 289, 290, 290, 291, 291, 292, 292, 293, 293, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 294, 295, 296, 297, 298, 298, 299, 299, 299, 299, 300, 300, 300, 300, 300, 300, 301, 301, 302, 302 }; /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ static const yytype_int8 yyr2[] = { 0, 2, 0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 2, 1, 1, 3, 2, 0, 8, 5, 1, 3, 0, 8, 5, 1, 3, 2, 0, 7, 4, 0, 8, 5, 0, 2, 4, 6, 6, 4, 1, 3, 9, 1, 3, 1, 2, 2, 0, 8, 1, 3, 2, 2, 2, 2, 1, 2, 3, 2, 2, 3, 2, 3, 5, 2, 2, 2, 3, 2, 4, 6, 3, 3, 4, 3, 5, 4, 2, 2, 3, 0, 5, 1, 3, 2, 0, 2, 5, 3, 4, 5, 5, 4, 0, 5, 2, 6, 1, 3, 1, 1, 0, 3, 0, 3, 1, 3, 2, 1, 1, 1, 5, 1, 3, 1, 2, 3, 1, 1, 0, 1, 1, 2, 1, 1, 0, 3, 0, 3, 1, 2, 1, 2, 3, 2, 1, 1, 1, 2, 6, 1, 3, 1, 3, 3, 1, 1, 1, 1, 1, 5, 1, 3, 1, 2, 3, 1, 1, 1, 0, 1, 1, 3, 3, 1, 1, 0, 1, 0, 8, 0, 2, 3, 3, 2, 3, 3, 2, 1, 0, 0, 5, 0, 6, 0, 2, 3, 3, 3, 0, 2, 0, 2, 4, 3, 0, 0, 2, 3, 3, 2, 2, 3, 2, 2, 2, 2, 1, 1, 2, 2, 2, 3, 2, 4, 3, 3, 4, 3, 4, 3, 4, 7, 3, 4, 4, 2, 2, 2, 2, 3, 3, 2, 3, 4, 1, 2, 2, 6, 1, 1, 2, 3, 2, 2, 2, 3, 2, 3, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 3, 8, 1, 1, 0, 2, 7, 1, 1, 1, 0, 1, 1, 1, 0, 2, 6, 1, 3, 1, 1, 5, 1, 3, 1, 1, 2, 2, 1, 1, 2, 2, 2, 4, 1, 3, 4, 1, 3, 2, 1, 3, 1, 3, 2, 4, 3, 1, 3, 4, 1, 3, 1, 1, 2, 3, 0, 0, 2, 1, 2, 1, 1, 2, 2, 2, 3, 3, 2, 2, 2, 2, 2, 3, 2, 2, 2, 0, 1, 2, 3, 4, 1, 1, 1, 1, 0, 2, 6, 3, 1, 1, 1, 0, 1, 0, 1, 1, 1, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 3, 4, 4, 2, 1, 1, 1, 0, 2, 0, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; enum { YYENOMEM = -2 }; #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab #define YYNOMEM goto yyexhaustedlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY) \ { \ yychar = (Token); \ yylval = (Value); \ YYPOPSTACK (yylen); \ yystate = *yyssp; \ goto yybackup; \ } \ else \ { \ yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (0) /* Backward compatibility with an undocumented macro. Use YYerror or YYUNDEF. */ #define YYERRCODE YYUNDEF /* Enable debugging if requested. */ #if YYDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ # define YYFPRINTF fprintf # endif # define YYDPRINTF(Args) \ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (0) # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ Kind, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) /*-----------------------------------. | Print this symbol's value on YYO. | `-----------------------------------*/ static void yy_symbol_value_print (FILE *yyo, yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { FILE *yyoutput = yyo; YY_USE (yyoutput); if (!yyvaluep) return; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YY_USE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } /*---------------------------. | Print this symbol on YYO. | `---------------------------*/ static void yy_symbol_print (FILE *yyo, yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { YYFPRINTF (yyo, "%s %s (", yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); yy_symbol_value_print (yyo, yykind, yyvaluep); YYFPRINTF (yyo, ")"); } /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | | TOP (included). | `------------------------------------------------------------------*/ static void yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) { int yybot = *yybottom; YYFPRINTF (stderr, " %d", yybot); } YYFPRINTF (stderr, "\n"); } # define YY_STACK_PRINT(Bottom, Top) \ do { \ if (yydebug) \ yy_stack_print ((Bottom), (Top)); \ } while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ static void yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, int yyrule) { int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), &yyvsp[(yyi + 1) - (yynrhs)]); YYFPRINTF (stderr, "\n"); } } # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ yy_reduce_print (yyssp, yyvsp, Rule); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) ((void) 0) # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ static void yydestruct (const char *yymsg, yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { YY_USE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN YY_USE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } /* Lookahead token kind. */ int yychar; /* The semantic value of the lookahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs; /*----------. | yyparse. | `----------*/ int yyparse (void) { yy_state_fast_t yystate = 0; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus = 0; /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* Their size. */ YYPTRDIFF_T yystacksize = YYINITDEPTH; /* The state stack: array, bottom, top. */ yy_state_t yyssa[YYINITDEPTH]; yy_state_t *yyss = yyssa; yy_state_t *yyssp = yyss; /* The semantic value stack: array, bottom, top. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs = yyvsa; YYSTYPE *yyvsp = yyvs; int yyn; /* The return value of yyparse. */ int yyresult; /* Lookahead symbol kind. */ yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; YYDPRINTF ((stderr, "Starting parse\n")); yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; /*------------------------------------------------------------. | yynewstate -- push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; /*--------------------------------------------------------------------. | yysetstate -- set current state (the top of the stack) to yystate. | `--------------------------------------------------------------------*/ yysetstate: YYDPRINTF ((stderr, "Entering state %d\n", yystate)); YY_ASSERT (0 <= yystate && yystate < YYNSTATES); YY_IGNORE_USELESS_CAST_BEGIN *yyssp = YY_CAST (yy_state_t, yystate); YY_IGNORE_USELESS_CAST_END YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) #if !defined yyoverflow && !defined YYSTACK_RELOCATE YYNOMEM; #else { /* Get the current used size of the three stacks, in elements. */ YYPTRDIFF_T yysize = yyssp - yyss + 1; # if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ yy_state_t *yyss1 = yyss; YYSTYPE *yyvs1 = yyvs; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), &yyss1, yysize * YYSIZEOF (*yyssp), &yyvs1, yysize * YYSIZEOF (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } # else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) YYNOMEM; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { yy_state_t *yyss1 = yyss; union yyalloc *yyptr = YY_CAST (union yyalloc *, YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) YYNOMEM; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YY_IGNORE_USELESS_CAST_BEGIN YYDPRINTF ((stderr, "Stack size increased to %ld\n", YY_CAST (long, yystacksize))); YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ if (yystate == YYFINAL) YYACCEPT; goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yypact_value_is_default (yyn)) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token\n")); yychar = yylex (); } if (yychar <= YYEOF) { yychar = YYEOF; yytoken = YYSYMBOL_YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else if (yychar == YYerror) { /* The scanner already issued an error message, process directly to error recovery. But do not keep the error token as lookahead, it is too special and may lead us to an endless loop in error recovery. */ yychar = YYUNDEF; yytoken = YYSYMBOL_YYerror; goto yyerrlab1; } else { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yytable_value_is_error (yyn)) goto yyerrlab; yyn = -yyn; goto yyreduce; } /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END /* Discard the shifted token. */ yychar = YYEMPTY; goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: '$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 21: /* grammar: grammar error '\n' */ #line 322 "../../../openbgpd-portable/src/bgpd/parse.y" { file->errors++; } #line 2547 "parse.c" break; case 22: /* asnumber: NUMBER */ #line 325 "../../../openbgpd-portable/src/bgpd/parse.y" { /* * According to iana 65535 and 4294967295 are reserved * but enforcing this is not duty of the parser. */ if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > UINT_MAX) { yyerror("AS too big: max %u", UINT_MAX); YYERROR; } } #line 2562 "parse.c" break; case 23: /* as4number: STRING */ #line 336 "../../../openbgpd-portable/src/bgpd/parse.y" { const char *errstr; char *dot; uint32_t uvalh = 0, uval; if ((dot = strchr((yyvsp[0].v.string),'.')) != NULL) { *dot++ = '\0'; uvalh = strtonum((yyvsp[0].v.string), 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", (yyvsp[0].v.string), errstr); free((yyvsp[0].v.string)); YYERROR; } uval = strtonum(dot, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", dot, errstr); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } else { yyerror("AS %s is bad", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } if (uvalh == 0 && (uval == AS_TRANS || uval == 0)) { yyerror("AS %u is reserved and may not be used", uval); YYERROR; } (yyval.v.number) = uval | (uvalh << 16); } #line 2599 "parse.c" break; case 24: /* as4number: asnumber */ #line 368 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) == AS_TRANS || (yyvsp[0].v.number) == 0) { yyerror("AS %u is reserved and may not be used", (uint32_t)(yyvsp[0].v.number)); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 2612 "parse.c" break; case 25: /* as4number_any: STRING */ #line 378 "../../../openbgpd-portable/src/bgpd/parse.y" { const char *errstr; char *dot; uint32_t uvalh = 0, uval; if ((dot = strchr((yyvsp[0].v.string),'.')) != NULL) { *dot++ = '\0'; uvalh = strtonum((yyvsp[0].v.string), 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", (yyvsp[0].v.string), errstr); free((yyvsp[0].v.string)); YYERROR; } uval = strtonum(dot, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", dot, errstr); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } else { yyerror("AS %s is bad", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } (yyval.v.number) = uval | (uvalh << 16); } #line 2644 "parse.c" break; case 26: /* as4number_any: asnumber */ #line 405 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = (yyvsp[0].v.number); } #line 2652 "parse.c" break; case 27: /* string: string STRING */ #line 410 "../../../openbgpd-portable/src/bgpd/parse.y" { if (asprintf(&(yyval.v.string), "%s %s", (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) fatal("string: asprintf"); free((yyvsp[-1].v.string)); free((yyvsp[0].v.string)); } #line 2663 "parse.c" break; case 29: /* yesno: STRING */ #line 419 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "yes")) (yyval.v.number) = 1; else if (!strcmp((yyvsp[0].v.string), "no")) (yyval.v.number) = 0; else { yyerror("syntax error, " "either yes or no expected"); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 2681 "parse.c" break; case 30: /* varset: STRING '=' string */ #line 434 "../../../openbgpd-portable/src/bgpd/parse.y" { char *s = (yyvsp[-2].v.string); if (strlen((yyvsp[-2].v.string)) >= MACRO_NAME_LEN) { yyerror("macro name to long, max %d characters", MACRO_NAME_LEN - 1); free((yyvsp[-2].v.string)); free((yyvsp[0].v.string)); YYERROR; } do { if (isalnum((unsigned char)*s) || *s == '_') continue; yyerror("macro name can only contain " "alphanumerics and '_'"); free((yyvsp[-2].v.string)); free((yyvsp[0].v.string)); YYERROR; } while (*++s); if (cmd_opts & BGPD_OPT_VERBOSE) printf("%s = \"%s\"\n", (yyvsp[-2].v.string), (yyvsp[0].v.string)); if (symset((yyvsp[-2].v.string), (yyvsp[0].v.string), 0) == -1) fatal("cannot store variable"); free((yyvsp[-2].v.string)); free((yyvsp[0].v.string)); } #line 2712 "parse.c" break; case 31: /* include: INCLUDE STRING */ #line 462 "../../../openbgpd-portable/src/bgpd/parse.y" { struct file *nfile; if ((nfile = pushfile((yyvsp[0].v.string), 1)) == NULL) { yyerror("failed to include file %s", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); file = nfile; lungetc('\n'); } #line 2730 "parse.c" break; case 32: /* $@1: %empty */ #line 477 "../../../openbgpd-portable/src/bgpd/parse.y" { if (strlen((yyvsp[-2].v.string)) >= SET_NAME_LEN) { yyerror("as-set name %s too long", (yyvsp[-2].v.string)); free((yyvsp[-2].v.string)); YYERROR; } if (new_as_set((yyvsp[-2].v.string)) != 0) { free((yyvsp[-2].v.string)); YYERROR; } free((yyvsp[-2].v.string)); } #line 2747 "parse.c" break; case 33: /* as_set: ASSET STRING '{' optnl $@1 as_set_l optnl '}' */ #line 488 "../../../openbgpd-portable/src/bgpd/parse.y" { done_as_set(); } #line 2755 "parse.c" break; case 34: /* as_set: ASSET STRING '{' optnl '}' */ #line 491 "../../../openbgpd-portable/src/bgpd/parse.y" { if (new_as_set((yyvsp[-3].v.string)) != 0) { free((yyvsp[-3].v.string)); YYERROR; } free((yyvsp[-3].v.string)); } #line 2767 "parse.c" break; case 35: /* as_set_l: as4number_any */ #line 499 "../../../openbgpd-portable/src/bgpd/parse.y" { add_as_set((yyvsp[0].v.number)); } #line 2773 "parse.c" break; case 36: /* as_set_l: as_set_l comma as4number_any */ #line 500 "../../../openbgpd-portable/src/bgpd/parse.y" { add_as_set((yyvsp[0].v.number)); } #line 2779 "parse.c" break; case 37: /* $@2: %empty */ #line 502 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((curpset = new_prefix_set((yyvsp[-2].v.string), 0)) == NULL) { free((yyvsp[-2].v.string)); YYERROR; } free((yyvsp[-2].v.string)); } #line 2791 "parse.c" break; case 38: /* prefixset: PREFIXSET STRING '{' optnl $@2 prefixset_l optnl '}' */ #line 508 "../../../openbgpd-portable/src/bgpd/parse.y" { SIMPLEQ_INSERT_TAIL(&conf->prefixsets, curpset, entry); curpset = NULL; } #line 2800 "parse.c" break; case 39: /* prefixset: PREFIXSET STRING '{' optnl '}' */ #line 512 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((curpset = new_prefix_set((yyvsp[-3].v.string), 0)) == NULL) { free((yyvsp[-3].v.string)); YYERROR; } free((yyvsp[-3].v.string)); SIMPLEQ_INSERT_TAIL(&conf->prefixsets, curpset, entry); curpset = NULL; } #line 2814 "parse.c" break; case 40: /* prefixset_l: prefixset_item */ #line 522 "../../../openbgpd-portable/src/bgpd/parse.y" { struct prefixset_item *psi; if ((yyvsp[0].v.prefixset_item)->p.op != OP_NONE) curpset->sflags |= PREFIXSET_FLAG_OPS; psi = RB_INSERT(prefixset_tree, &curpset->psitems, (yyvsp[0].v.prefixset_item)); if (psi != NULL) { if (cmd_opts & BGPD_OPT_VERBOSE2) log_warnx("warning: duplicate entry in " "prefixset \"%s\" for %s/%u", curpset->name, log_addr(&(yyvsp[0].v.prefixset_item)->p.addr), (yyvsp[0].v.prefixset_item)->p.len); free((yyvsp[0].v.prefixset_item)); } } #line 2833 "parse.c" break; case 41: /* prefixset_l: prefixset_l comma prefixset_item */ #line 536 "../../../openbgpd-portable/src/bgpd/parse.y" { struct prefixset_item *psi; if ((yyvsp[0].v.prefixset_item)->p.op != OP_NONE) curpset->sflags |= PREFIXSET_FLAG_OPS; psi = RB_INSERT(prefixset_tree, &curpset->psitems, (yyvsp[0].v.prefixset_item)); if (psi != NULL) { if (cmd_opts & BGPD_OPT_VERBOSE2) log_warnx("warning: duplicate entry in " "prefixset \"%s\" for %s/%u", curpset->name, log_addr(&(yyvsp[0].v.prefixset_item)->p.addr), (yyvsp[0].v.prefixset_item)->p.len); free((yyvsp[0].v.prefixset_item)); } } #line 2852 "parse.c" break; case 42: /* prefixset_item: prefix prefixlenop */ #line 552 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.prefixlen).op != OP_NONE && (yyvsp[0].v.prefixlen).op != OP_RANGE) { yyerror("unsupported prefixlen operation in " "prefix-set"); YYERROR; } if (((yyval.v.prefixset_item) = calloc(1, sizeof(*(yyval.v.prefixset_item)))) == NULL) fatal(NULL); memcpy(&(yyval.v.prefixset_item)->p.addr, &(yyvsp[-1].v.prefix).prefix, sizeof((yyval.v.prefixset_item)->p.addr)); (yyval.v.prefixset_item)->p.len = (yyvsp[-1].v.prefix).len; if (merge_prefixspec(&(yyval.v.prefixset_item)->p, &(yyvsp[0].v.prefixlen)) == -1) { free((yyval.v.prefixset_item)); YYERROR; } } #line 2872 "parse.c" break; case 43: /* $@3: %empty */ #line 569 "../../../openbgpd-portable/src/bgpd/parse.y" { curroatree = &conf->roa; } #line 2880 "parse.c" break; case 44: /* roa_set: ROASET '{' optnl $@3 roa_set_l optnl '}' */ #line 571 "../../../openbgpd-portable/src/bgpd/parse.y" { curroatree = NULL; } #line 2888 "parse.c" break; case 46: /* $@4: %empty */ #line 577 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((curoset = new_prefix_set((yyvsp[-2].v.string), 1)) == NULL) { free((yyvsp[-2].v.string)); YYERROR; } curroatree = &curoset->roaitems; noexpires = 1; free((yyvsp[-2].v.string)); } #line 2902 "parse.c" break; case 47: /* origin_set: ORIGINSET STRING '{' optnl $@4 roa_set_l optnl '}' */ #line 585 "../../../openbgpd-portable/src/bgpd/parse.y" { SIMPLEQ_INSERT_TAIL(&conf->originsets, curoset, entry); curoset = NULL; curroatree = NULL; noexpires = 0; } #line 2913 "parse.c" break; case 48: /* origin_set: ORIGINSET STRING '{' optnl '}' */ #line 591 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((curoset = new_prefix_set((yyvsp[-3].v.string), 1)) == NULL) { free((yyvsp[-3].v.string)); YYERROR; } free((yyvsp[-3].v.string)); SIMPLEQ_INSERT_TAIL(&conf->originsets, curoset, entry); curoset = NULL; curroatree = NULL; } #line 2928 "parse.c" break; case 49: /* expires: %empty */ #line 603 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 2936 "parse.c" break; case 50: /* expires: EXPIRES NUMBER */ #line 606 "../../../openbgpd-portable/src/bgpd/parse.y" { if (noexpires) { yyerror("syntax error, expires not allowed"); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 2948 "parse.c" break; case 51: /* roa_set_l: prefixset_item SOURCEAS as4number_any expires */ #line 614 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[-3].v.prefixset_item)->p.len_min != (yyvsp[-3].v.prefixset_item)->p.len) { yyerror("unsupported prefixlen operation in " "roa-set"); free((yyvsp[-3].v.prefixset_item)); YYERROR; } add_roa_set((yyvsp[-3].v.prefixset_item), (yyvsp[-1].v.number), (yyvsp[-3].v.prefixset_item)->p.len_max, (yyvsp[0].v.number)); free((yyvsp[-3].v.prefixset_item)); } #line 2963 "parse.c" break; case 52: /* roa_set_l: roa_set_l comma prefixset_item SOURCEAS as4number_any expires */ #line 624 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[-3].v.prefixset_item)->p.len_min != (yyvsp[-3].v.prefixset_item)->p.len) { yyerror("unsupported prefixlen operation in " "roa-set"); free((yyvsp[-3].v.prefixset_item)); YYERROR; } add_roa_set((yyvsp[-3].v.prefixset_item), (yyvsp[-1].v.number), (yyvsp[-3].v.prefixset_item)->p.len_max, (yyvsp[0].v.number)); free((yyvsp[-3].v.prefixset_item)); } #line 2978 "parse.c" break; case 57: /* aspa_elm: CUSTOMERAS as4number expires PROVIDERAS '{' optnl aspa_tas_l optnl '}' */ #line 645 "../../../openbgpd-portable/src/bgpd/parse.y" { int rv; struct aspa_tas_l *a, *n; rv = merge_aspa_set((yyvsp[-7].v.number), (yyvsp[-2].v.aspa_elm), (yyvsp[-6].v.number)); for (a = (yyvsp[-2].v.aspa_elm); a != NULL; a = n) { n = a->next; free(a); } if (rv == -1) YYERROR; } #line 2997 "parse.c" break; case 58: /* aspa_tas_l: aspa_tas */ #line 661 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.aspa_elm) = (yyvsp[0].v.aspa_elm); } #line 3003 "parse.c" break; case 59: /* aspa_tas_l: aspa_tas_l comma aspa_tas */ #line 662 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyvsp[0].v.aspa_elm)->next = (yyvsp[-2].v.aspa_elm); (yyvsp[0].v.aspa_elm)->num = (yyvsp[-2].v.aspa_elm)->num + 1; (yyval.v.aspa_elm) = (yyvsp[0].v.aspa_elm); } #line 3013 "parse.c" break; case 60: /* aspa_tas: as4number_any */ #line 669 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.aspa_elm) = calloc(1, sizeof(*(yyval.v.aspa_elm)))) == NULL) fatal(NULL); (yyval.v.aspa_elm)->as = (yyvsp[0].v.number); (yyval.v.aspa_elm)->num = 1; } #line 3024 "parse.c" break; case 61: /* aspa_tas: as4number_any af */ #line 675 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.aspa_elm) = calloc(1, sizeof(*(yyval.v.aspa_elm)))) == NULL) fatal(NULL); (yyval.v.aspa_elm)->as = (yyvsp[-1].v.number); (yyval.v.aspa_elm)->num = 1; } #line 3035 "parse.c" break; case 62: /* rtr: RTR address */ #line 683 "../../../openbgpd-portable/src/bgpd/parse.y" { currtr = get_rtr(&(yyvsp[0].v.addr)); currtr->remote_port = RTR_PORT; if (insert_rtr(currtr) == -1) { free(currtr); YYERROR; } currtr = NULL; } #line 3049 "parse.c" break; case 63: /* $@5: %empty */ #line 692 "../../../openbgpd-portable/src/bgpd/parse.y" { currtr = get_rtr(&(yyvsp[0].v.addr)); currtr->remote_port = RTR_PORT; } #line 3058 "parse.c" break; case 64: /* rtr: RTR address $@5 '{' optnl rtropt_l optnl '}' */ #line 695 "../../../openbgpd-portable/src/bgpd/parse.y" { if (insert_rtr(currtr) == -1) { free(currtr); YYERROR; } currtr = NULL; } #line 3070 "parse.c" break; case 67: /* rtropt: DESCR STRING */ #line 708 "../../../openbgpd-portable/src/bgpd/parse.y" { if (strlcpy(currtr->descr, (yyvsp[0].v.string), sizeof(currtr->descr)) >= sizeof(currtr->descr)) { yyerror("descr \"%s\" too long: max %zu", (yyvsp[0].v.string), sizeof(currtr->descr) - 1); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3086 "parse.c" break; case 68: /* rtropt: LOCALADDR address */ #line 719 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.addr).aid != currtr->remote_addr.aid) { yyerror("Bad address family %s for " "local-addr", aid2str((yyvsp[0].v.addr).aid)); YYERROR; } currtr->local_addr = (yyvsp[0].v.addr); } #line 3099 "parse.c" break; case 69: /* rtropt: PORT port */ #line 727 "../../../openbgpd-portable/src/bgpd/parse.y" { currtr->remote_port = (yyvsp[0].v.number); } #line 3107 "parse.c" break; case 70: /* rtropt: MINVERSION NUMBER */ #line 730 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > RTR_MAX_VERSION) { yyerror("min-version must be between %u and %u", 0, RTR_MAX_VERSION); YYERROR; } currtr->min_version = (yyvsp[0].v.number); } #line 3120 "parse.c" break; case 71: /* rtropt: authconf */ #line 738 "../../../openbgpd-portable/src/bgpd/parse.y" { if (merge_auth_conf(&currtr->auth, &(yyvsp[0].v.authconf)) == 0) YYERROR; } #line 3129 "parse.c" break; case 72: /* conf_main: AS as4number */ #line 744 "../../../openbgpd-portable/src/bgpd/parse.y" { conf->as = (yyvsp[0].v.number); if ((yyvsp[0].v.number) > USHRT_MAX) conf->short_as = AS_TRANS; else conf->short_as = (yyvsp[0].v.number); } #line 3141 "parse.c" break; case 73: /* conf_main: AS as4number asnumber */ #line 751 "../../../openbgpd-portable/src/bgpd/parse.y" { conf->as = (yyvsp[-1].v.number); conf->short_as = (yyvsp[0].v.number); } #line 3150 "parse.c" break; case 74: /* conf_main: ROUTERID address */ #line 755 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.addr).aid != AID_INET) { yyerror("router-id must be an IPv4 address"); YYERROR; } conf->bgpid = ntohl((yyvsp[0].v.addr).v4.s_addr); } #line 3162 "parse.c" break; case 75: /* conf_main: HOLDTIME NUMBER */ #line 762 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } conf->holdtime = (yyvsp[0].v.number); } #line 3175 "parse.c" break; case 76: /* conf_main: HOLDTIME YMIN NUMBER */ #line 770 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } conf->min_holdtime = (yyvsp[0].v.number); } #line 3188 "parse.c" break; case 77: /* conf_main: STALETIME NUMBER */ #line 778 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("staletime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } conf->staletime = (yyvsp[0].v.number); } #line 3201 "parse.c" break; case 78: /* conf_main: LISTEN ON address */ #line 786 "../../../openbgpd-portable/src/bgpd/parse.y" { struct listen_addr *la; struct sockaddr *sa; if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("parse conf_main listen on calloc"); la->fd = -1; la->reconf = RECONF_REINIT; sa = addr2sa(&(yyvsp[0].v.addr), BGP_PORT, &la->sa_len); memcpy(&la->sa, sa, la->sa_len); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); } #line 3220 "parse.c" break; case 79: /* conf_main: LISTEN ON address PORT port */ #line 800 "../../../openbgpd-portable/src/bgpd/parse.y" { struct listen_addr *la; struct sockaddr *sa; if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("parse conf_main listen on calloc"); la->fd = -1; la->reconf = RECONF_REINIT; sa = addr2sa(&(yyvsp[-2].v.addr), (yyvsp[0].v.number), &la->sa_len); memcpy(&la->sa, sa, la->sa_len); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); } #line 3239 "parse.c" break; case 80: /* conf_main: FIBPRIORITY NUMBER */ #line 814 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!kr_check_prio((yyvsp[0].v.number))) { yyerror("fib-priority %lld out of range", (yyvsp[0].v.number)); YYERROR; } conf->fib_priority = (yyvsp[0].v.number); } #line 3251 "parse.c" break; case 81: /* conf_main: FIBUPDATE yesno */ #line 821 "../../../openbgpd-portable/src/bgpd/parse.y" { struct rde_rib *rr; rr = find_rib("Loc-RIB"); if (rr == NULL) fatalx("RTABLE cannot find the main RIB!"); if ((yyvsp[0].v.number) == 0) rr->flags |= F_RIB_NOFIBSYNC; else rr->flags &= ~F_RIB_NOFIBSYNC; } #line 3267 "parse.c" break; case 82: /* conf_main: TRANSPARENT yesno */ #line 832 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) == 1) conf->flags |= BGPD_FLAG_DECISION_TRANS_AS; else conf->flags &= ~BGPD_FLAG_DECISION_TRANS_AS; } #line 3278 "parse.c" break; case 83: /* conf_main: REJECT ASSET yesno */ #line 838 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) == 1) conf->flags &= ~BGPD_FLAG_PERMIT_AS_SET; else conf->flags |= BGPD_FLAG_PERMIT_AS_SET; } #line 3289 "parse.c" break; case 84: /* conf_main: LOG STRING */ #line 844 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "updates")) conf->log |= BGPD_LOG_UPDATES; else { free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3303 "parse.c" break; case 85: /* conf_main: DUMP STRING STRING optnumber */ #line 853 "../../../openbgpd-portable/src/bgpd/parse.y" { int action; if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad timeout"); free((yyvsp[-2].v.string)); free((yyvsp[-1].v.string)); YYERROR; } if (!strcmp((yyvsp[-2].v.string), "table")) action = MRT_TABLE_DUMP; else if (!strcmp((yyvsp[-2].v.string), "table-mp")) action = MRT_TABLE_DUMP_MP; else if (!strcmp((yyvsp[-2].v.string), "table-v2")) action = MRT_TABLE_DUMP_V2; else { yyerror("unknown mrt dump type"); free((yyvsp[-2].v.string)); free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-2].v.string)); if (add_mrtconfig(action, (yyvsp[-1].v.string), (yyvsp[0].v.number), NULL, NULL) == -1) { free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-1].v.string)); } #line 3336 "parse.c" break; case 86: /* conf_main: DUMP RIB STRING STRING STRING optnumber */ #line 881 "../../../openbgpd-portable/src/bgpd/parse.y" { int action; if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad timeout"); free((yyvsp[-3].v.string)); free((yyvsp[-2].v.string)); free((yyvsp[-1].v.string)); YYERROR; } if (!strcmp((yyvsp[-2].v.string), "table")) action = MRT_TABLE_DUMP; else if (!strcmp((yyvsp[-2].v.string), "table-mp")) action = MRT_TABLE_DUMP_MP; else if (!strcmp((yyvsp[-2].v.string), "table-v2")) action = MRT_TABLE_DUMP_V2; else { yyerror("unknown mrt dump type"); free((yyvsp[-3].v.string)); free((yyvsp[-2].v.string)); free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-2].v.string)); if (add_mrtconfig(action, (yyvsp[-1].v.string), (yyvsp[0].v.number), NULL, (yyvsp[-3].v.string)) == -1) { free((yyvsp[-3].v.string)); free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-3].v.string)); free((yyvsp[-1].v.string)); } #line 3373 "parse.c" break; case 87: /* conf_main: RDE STRING EVALUATE */ #line 913 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[-1].v.string), "route-age")) conf->flags |= BGPD_FLAG_DECISION_ROUTEAGE; else { yyerror("unknown route decision type"); free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-1].v.string)); } #line 3388 "parse.c" break; case 88: /* conf_main: RDE STRING IGNORE */ #line 923 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[-1].v.string), "route-age")) conf->flags &= ~BGPD_FLAG_DECISION_ROUTEAGE; else { yyerror("unknown route decision type"); free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-1].v.string)); } #line 3403 "parse.c" break; case 89: /* conf_main: RDE MED COMPARE STRING */ #line 933 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "always")) conf->flags |= BGPD_FLAG_DECISION_MED_ALWAYS; else if (!strcmp((yyvsp[0].v.string), "strict")) conf->flags &= ~BGPD_FLAG_DECISION_MED_ALWAYS; else { yyerror("rde med compare: " "unknown setting \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3421 "parse.c" break; case 90: /* conf_main: RDE EVALUATE STRING */ #line 946 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "all")) conf->flags |= BGPD_FLAG_DECISION_ALL_PATHS; else if (!strcmp((yyvsp[0].v.string), "default")) conf->flags &= ~BGPD_FLAG_DECISION_ALL_PATHS; else { yyerror("rde evaluate: " "unknown setting \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3439 "parse.c" break; case 91: /* conf_main: RDE RIB STRING INCLUDE FILTERED */ #line 959 "../../../openbgpd-portable/src/bgpd/parse.y" { if (strcmp((yyvsp[-2].v.string), "Loc-RIB") != 0) { yyerror("include filtered only supported in " "Loc-RIB"); YYERROR; } conf->filtered_in_locrib = 1; } #line 3452 "parse.c" break; case 92: /* conf_main: NEXTHOP QUALIFY VIA STRING */ #line 967 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "bgp")) conf->flags |= BGPD_FLAG_NEXTHOP_BGP; else if (!strcmp((yyvsp[0].v.string), "default")) conf->flags |= BGPD_FLAG_NEXTHOP_DEFAULT; else { yyerror("nexthop depend on: " "unknown setting \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3470 "parse.c" break; case 93: /* conf_main: RTABLE NUMBER */ #line 980 "../../../openbgpd-portable/src/bgpd/parse.y" { struct rde_rib *rr; if ((yyvsp[0].v.number) > RT_TABLEID_MAX) { yyerror("rtable %llu too big: max %u", (yyvsp[0].v.number), RT_TABLEID_MAX); YYERROR; } if (!ktable_exists((yyvsp[0].v.number), NULL)) { yyerror("rtable id %lld does not exist", (yyvsp[0].v.number)); YYERROR; } rr = find_rib("Loc-RIB"); if (rr == NULL) fatalx("RTABLE cannot find the main RIB!"); rr->rtableid = (yyvsp[0].v.number); } #line 3491 "parse.c" break; case 94: /* conf_main: CONNECTRETRY NUMBER */ #line 996 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) > USHRT_MAX || (yyvsp[0].v.number) < 1) { yyerror("invalid connect-retry"); YYERROR; } conf->connectretry = (yyvsp[0].v.number); } #line 3503 "parse.c" break; case 95: /* conf_main: SOCKET STRING restricted */ #line 1003 "../../../openbgpd-portable/src/bgpd/parse.y" { if (strlen((yyvsp[-1].v.string)) >= sizeof(((struct sockaddr_un *)0)->sun_path)) { yyerror("socket path too long"); YYERROR; } if ((yyvsp[0].v.number)) { free(conf->rcsock); conf->rcsock = (yyvsp[-1].v.string); } else { free(conf->csock); conf->csock = (yyvsp[-1].v.string); } } #line 3522 "parse.c" break; case 96: /* $@6: %empty */ #line 1019 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((currib = add_rib((yyvsp[0].v.string))) == NULL) { free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3534 "parse.c" break; case 97: /* rib: RDE RIB STRING $@6 ribopts */ #line 1025 "../../../openbgpd-portable/src/bgpd/parse.y" { currib = NULL; } #line 3542 "parse.c" break; case 99: /* ribopts: RTABLE NUMBER fibupdate */ #line 1030 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[-1].v.number) > RT_TABLEID_MAX) { yyerror("rtable %llu too big: max %u", (yyvsp[-1].v.number), RT_TABLEID_MAX); YYERROR; } if (rib_add_fib(currib, (yyvsp[-1].v.number)) == -1) YYERROR; } #line 3556 "parse.c" break; case 100: /* ribopts: yesno EVALUATE */ #line 1039 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[-1].v.number)) { yyerror("bad rde rib definition"); YYERROR; } currib->flags |= F_RIB_NOEVALUATE; } #line 3568 "parse.c" break; case 102: /* fibupdate: FIBUPDATE yesno */ #line 1049 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) == 0) currib->flags |= F_RIB_NOFIBSYNC; else currib->flags &= ~F_RIB_NOFIBSYNC; } #line 3579 "parse.c" break; case 103: /* mrtdump: DUMP STRING inout STRING optnumber */ #line 1057 "../../../openbgpd-portable/src/bgpd/parse.y" { int action; if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad timeout"); free((yyvsp[-3].v.string)); free((yyvsp[-1].v.string)); YYERROR; } if (!strcmp((yyvsp[-3].v.string), "all")) action = (yyvsp[-2].v.number) ? MRT_ALL_IN : MRT_ALL_OUT; else if (!strcmp((yyvsp[-3].v.string), "updates")) action = (yyvsp[-2].v.number) ? MRT_UPDATE_IN : MRT_UPDATE_OUT; else { yyerror("unknown mrt msg dump type"); free((yyvsp[-3].v.string)); free((yyvsp[-1].v.string)); YYERROR; } if (add_mrtconfig(action, (yyvsp[-1].v.string), (yyvsp[0].v.number), curpeer, NULL) == -1) { free((yyvsp[-3].v.string)); free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-3].v.string)); free((yyvsp[-1].v.string)); } #line 3612 "parse.c" break; case 104: /* network: NETWORK prefix filter_set */ #line 1087 "../../../openbgpd-portable/src/bgpd/parse.y" { struct network *n, *m; if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); memcpy(&n->net.prefix, &(yyvsp[-1].v.prefix).prefix, sizeof(n->net.prefix)); n->net.prefixlen = (yyvsp[-1].v.prefix).len; filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset); free((yyvsp[0].v.filter_set_head)); TAILQ_FOREACH(m, netconf, entry) { if (n->net.type == m->net.type && n->net.prefixlen == m->net.prefixlen && prefix_compare(&n->net.prefix, &m->net.prefix, n->net.prefixlen) == 0) yyerror("duplicate prefix " "in network statement"); } TAILQ_INSERT_TAIL(netconf, n, entry); } #line 3638 "parse.c" break; case 105: /* network: NETWORK PREFIXSET STRING filter_set */ #line 1108 "../../../openbgpd-portable/src/bgpd/parse.y" { struct prefixset *ps; struct network *n; if ((ps = find_prefixset((yyvsp[-1].v.string), &conf->prefixsets)) == NULL) { yyerror("prefix-set '%s' not defined", (yyvsp[-1].v.string)); free((yyvsp[-1].v.string)); filterset_free((yyvsp[0].v.filter_set_head)); free((yyvsp[0].v.filter_set_head)); YYERROR; } if (ps->sflags & PREFIXSET_FLAG_OPS) { yyerror("prefix-set %s has prefixlen operators " "and cannot be used in network statements.", ps->name); free((yyvsp[-1].v.string)); filterset_free((yyvsp[0].v.filter_set_head)); free((yyvsp[0].v.filter_set_head)); YYERROR; } if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); strlcpy(n->net.psname, ps->name, sizeof(n->net.psname)); filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset); n->net.type = NETWORK_PREFIXSET; TAILQ_INSERT_TAIL(netconf, n, entry); free((yyvsp[-1].v.string)); free((yyvsp[0].v.filter_set_head)); } #line 3672 "parse.c" break; case 106: /* network: NETWORK af RTLABEL STRING filter_set */ #line 1137 "../../../openbgpd-portable/src/bgpd/parse.y" { struct network *n; if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); if (afi2aid((yyvsp[-3].v.number), SAFI_UNICAST, &n->net.prefix.aid) == -1) { yyerror("unknown address family"); filterset_free((yyvsp[0].v.filter_set_head)); free((yyvsp[0].v.filter_set_head)); YYERROR; } n->net.type = NETWORK_RTLABEL; n->net.rtlabel = rtlabel_name2id((yyvsp[-1].v.string)); filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset); free((yyvsp[0].v.filter_set_head)); TAILQ_INSERT_TAIL(netconf, n, entry); } #line 3696 "parse.c" break; case 107: /* network: NETWORK af PRIORITY NUMBER filter_set */ #line 1156 "../../../openbgpd-portable/src/bgpd/parse.y" { struct network *n; if (!kr_check_prio((yyvsp[-1].v.number))) { yyerror("priority %lld out of range", (yyvsp[-1].v.number)); YYERROR; } if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); if (afi2aid((yyvsp[-3].v.number), SAFI_UNICAST, &n->net.prefix.aid) == -1) { yyerror("unknown address family"); filterset_free((yyvsp[0].v.filter_set_head)); free((yyvsp[0].v.filter_set_head)); YYERROR; } n->net.type = NETWORK_PRIORITY; n->net.priority = (yyvsp[-1].v.number); filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset); free((yyvsp[0].v.filter_set_head)); TAILQ_INSERT_TAIL(netconf, n, entry); } #line 3724 "parse.c" break; case 108: /* network: NETWORK af nettype filter_set */ #line 1179 "../../../openbgpd-portable/src/bgpd/parse.y" { struct network *n; if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); if (afi2aid((yyvsp[-2].v.number), SAFI_UNICAST, &n->net.prefix.aid) == -1) { yyerror("unknown address family"); filterset_free((yyvsp[0].v.filter_set_head)); free((yyvsp[0].v.filter_set_head)); YYERROR; } n->net.type = (yyvsp[-1].v.number) ? NETWORK_STATIC : NETWORK_CONNECTED; filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset); free((yyvsp[0].v.filter_set_head)); TAILQ_INSERT_TAIL(netconf, n, entry); } #line 3747 "parse.c" break; case 109: /* $@7: %empty */ #line 1199 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((curflow = calloc(1, sizeof(*curflow))) == NULL) fatal("new_flowspec"); curflow->aid = (yyvsp[0].v.number); } #line 3757 "parse.c" break; case 110: /* flowspec: FLOWSPEC af $@7 flow_rules filter_set */ #line 1203 "../../../openbgpd-portable/src/bgpd/parse.y" { struct flowspec_config *f; f = flow_to_flowspec(curflow); if (f == NULL) { yyerror("out of memory"); free((yyvsp[0].v.filter_set_head)); flow_free(curflow); curflow = NULL; YYERROR; } filterset_move((yyvsp[0].v.filter_set_head), &f->attrset); free((yyvsp[0].v.filter_set_head)); flow_free(curflow); curflow = NULL; if (RB_INSERT(flowspec_tree, &conf->flowspecs, f) != NULL) { yyerror("duplicate flowspec definition"); flowspec_free(f); YYERROR; } } #line 3785 "parse.c" break; case 113: /* proto_list: proto_item */ #line 1232 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_PROTO; if (push_unary_numop(OP_EQ, (yyvsp[0].v.number)) == -1) YYERROR; } #line 3795 "parse.c" break; case 114: /* proto_list: proto_list comma proto_item */ #line 1237 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_PROTO; if (push_unary_numop(OP_EQ, (yyvsp[0].v.number)) == -1) YYERROR; } #line 3805 "parse.c" break; case 115: /* proto_item: STRING */ #line 1244 "../../../openbgpd-portable/src/bgpd/parse.y" { struct protoent *p; p = getprotobyname((yyvsp[0].v.string)); if (p == NULL) { yyerror("unknown protocol %s", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } (yyval.v.number) = p->p_proto; free((yyvsp[0].v.string)); } #line 3822 "parse.c" break; case 116: /* proto_item: NUMBER */ #line 1256 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 255) { yyerror("protocol outside range"); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 3834 "parse.c" break; case 117: /* $@8: %empty */ #line 1265 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_SRC_PORT; curflow->addr_type = FLOWSPEC_TYPE_SOURCE; } #line 3843 "parse.c" break; case 119: /* $@9: %empty */ #line 1271 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_DST_PORT; curflow->addr_type = FLOWSPEC_TYPE_DEST; } #line 3852 "parse.c" break; case 125: /* ipspec: prefix */ #line 1283 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_prefix(&(yyvsp[0].v.prefix).prefix, (yyvsp[0].v.prefix).len) == -1) YYERROR; } #line 3861 "parse.c" break; case 130: /* port_item: port */ #line 1297 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_unary_numop(OP_EQ, (yyvsp[0].v.number)) == -1) YYERROR; } #line 3870 "parse.c" break; case 131: /* port_item: unaryop port */ #line 1301 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_unary_numop((yyvsp[-1].v.u8), (yyvsp[0].v.number)) == -1) YYERROR; } #line 3879 "parse.c" break; case 132: /* port_item: port binaryop port */ #line 1305 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_binary_numop((yyvsp[-1].v.u8), (yyvsp[-2].v.number), (yyvsp[0].v.number))) YYERROR; } #line 3888 "parse.c" break; case 133: /* port: NUMBER */ #line 1311 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 1 || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("port must be between %u and %u", 1, USHRT_MAX); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 3901 "parse.c" break; case 134: /* port: STRING */ #line 1319 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.number) = getservice((yyvsp[0].v.string))) == -1) { yyerror("unknown port '%s'", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3914 "parse.c" break; case 141: /* $@10: %empty */ #line 1339 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_TCP_FLAGS; } #line 3922 "parse.c" break; case 143: /* $@11: %empty */ #line 1342 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_FRAG; } #line 3930 "parse.c" break; case 146: /* flowrule: LENGTH lengthspec */ #line 1346 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_PKT_LEN; } #line 3938 "parse.c" break; case 148: /* flowrule: TOS tos */ #line 1350 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_DSCP; if (push_unary_numop(OP_EQ, (yyvsp[0].v.number) >> 2) == -1) YYERROR; } #line 3948 "parse.c" break; case 149: /* flags: flag '/' flag */ #line 1357 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyvsp[-2].v.number) & (yyvsp[0].v.number)) != (yyvsp[-2].v.number)) { yyerror("bad flag combination, " "check bit not in mask"); YYERROR; } if (push_binop(FLOWSPEC_OP_BIT_MATCH, (yyvsp[-2].v.number)) == -1) YYERROR; /* check if extra mask op is needed */ if ((yyvsp[0].v.number) & ~(yyvsp[-2].v.number)) { if (push_binop(FLOWSPEC_OP_BIT_NOT | FLOWSPEC_OP_AND, (yyvsp[0].v.number) & ~(yyvsp[-2].v.number)) == -1) YYERROR; } } #line 3968 "parse.c" break; case 150: /* flags: '/' flag */ #line 1372 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_binop(FLOWSPEC_OP_BIT_NOT, (yyvsp[0].v.number)) == -1) YYERROR; } #line 3977 "parse.c" break; case 151: /* flags: flag */ #line 1376 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_binop(0, (yyvsp[0].v.number)) == -1) YYERROR; } #line 3986 "parse.c" break; case 153: /* flag: STRING */ #line 1383 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.number) = parse_flags((yyvsp[0].v.string))) < 0) { yyerror("bad flags %s", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 3999 "parse.c" break; case 158: /* icmp_item: icmptype */ #line 1401 "../../../openbgpd-portable/src/bgpd/parse.y" { curflow->type = FLOWSPEC_TYPE_ICMP_TYPE; if (push_unary_numop(OP_EQ, (yyvsp[0].v.number)) == -1) YYERROR; } #line 4009 "parse.c" break; case 159: /* icmp_item: icmptype CODE STRING */ #line 1406 "../../../openbgpd-portable/src/bgpd/parse.y" { int code; if ((code = geticmpcodebyname((yyvsp[-2].v.number), (yyvsp[0].v.string), curflow->aid)) == -1) { yyerror("unknown icmp-code %s", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); curflow->type = FLOWSPEC_TYPE_ICMP_TYPE; if (push_unary_numop(OP_EQ, (yyvsp[-2].v.number)) == -1) YYERROR; curflow->type = FLOWSPEC_TYPE_ICMP_CODE; if (push_unary_numop(OP_EQ, code) == -1) YYERROR; } #line 4032 "parse.c" break; case 160: /* icmp_item: icmptype CODE NUMBER */ #line 1424 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 255) { yyerror("illegal icmp-code %lld", (yyvsp[0].v.number)); YYERROR; } curflow->type = FLOWSPEC_TYPE_ICMP_TYPE; if (push_unary_numop(OP_EQ, (yyvsp[-2].v.number)) == -1) YYERROR; curflow->type = FLOWSPEC_TYPE_ICMP_CODE; if (push_unary_numop(OP_EQ, (yyvsp[0].v.number)) == -1) YYERROR; } #line 4049 "parse.c" break; case 161: /* icmptype: STRING */ #line 1438 "../../../openbgpd-portable/src/bgpd/parse.y" { int type; if ((type = geticmptypebyname((yyvsp[0].v.string), curflow->aid)) == -1) { yyerror("unknown icmp-type %s", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } (yyval.v.number) = type; free((yyvsp[0].v.string)); } #line 4066 "parse.c" break; case 162: /* icmptype: NUMBER */ #line 1450 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 255) { yyerror("illegal icmp-type %lld", (yyvsp[0].v.number)); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 4078 "parse.c" break; case 163: /* tos: STRING */ #line 1459 "../../../openbgpd-portable/src/bgpd/parse.y" { int val; char *end; if (map_tos((yyvsp[0].v.string), &val)) (yyval.v.number) = val; else if ((yyvsp[0].v.string)[0] == '0' && (yyvsp[0].v.string)[1] == 'x') { errno = 0; (yyval.v.number) = strtoul((yyvsp[0].v.string), &end, 16); if (errno || *end != '\0') (yyval.v.number) = 256; } else (yyval.v.number) = 256; if ((yyval.v.number) < 0 || (yyval.v.number) > 255) { yyerror("illegal tos value %s", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 4103 "parse.c" break; case 164: /* tos: NUMBER */ #line 1479 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyval.v.number) < 0 || (yyval.v.number) > 255) { yyerror("illegal tos value %lld", (yyvsp[0].v.number)); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 4115 "parse.c" break; case 169: /* length_item: length */ #line 1496 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_unary_numop(OP_EQ, (yyvsp[0].v.number)) == -1) YYERROR; } #line 4124 "parse.c" break; case 170: /* length_item: unaryop length */ #line 1500 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_unary_numop((yyvsp[-1].v.u8), (yyvsp[0].v.number)) == -1) YYERROR; } #line 4133 "parse.c" break; case 171: /* length_item: length binaryop length */ #line 1504 "../../../openbgpd-portable/src/bgpd/parse.y" { if (push_binary_numop((yyvsp[-1].v.u8), (yyvsp[-2].v.number), (yyvsp[0].v.number)) == -1) YYERROR; } #line 4142 "parse.c" break; case 172: /* length: NUMBER */ #line 1510 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyval.v.number) < 0 || (yyval.v.number) > USHRT_MAX) { yyerror("illegal ptk length value %lld", (yyvsp[0].v.number)); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 4154 "parse.c" break; case 173: /* inout: IN */ #line 1518 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 1; } #line 4160 "parse.c" break; case 174: /* inout: OUT */ #line 1519 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 4166 "parse.c" break; case 175: /* restricted: %empty */ #line 1522 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 4172 "parse.c" break; case 176: /* restricted: RESTRICTED */ #line 1523 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 1; } #line 4178 "parse.c" break; case 177: /* address: STRING */ #line 1526 "../../../openbgpd-portable/src/bgpd/parse.y" { uint8_t len; if (!host((yyvsp[0].v.string), &(yyval.v.addr), &len)) { yyerror("could not parse address spec \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); if (((yyval.v.addr).aid == AID_INET && len != 32) || ((yyval.v.addr).aid == AID_INET6 && len != 128)) { /* unreachable */ yyerror("got prefixlen %u, expected %u", len, (yyval.v.addr).aid == AID_INET ? 32 : 128); YYERROR; } } #line 4202 "parse.c" break; case 178: /* prefix: STRING '/' NUMBER */ #line 1547 "../../../openbgpd-portable/src/bgpd/parse.y" { char *s; if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) { yyerror("bad prefixlen %lld", (yyvsp[0].v.number)); free((yyvsp[-2].v.string)); YYERROR; } if (asprintf(&s, "%s/%lld", (yyvsp[-2].v.string), (yyvsp[0].v.number)) == -1) fatal(NULL); free((yyvsp[-2].v.string)); if (!host(s, &(yyval.v.prefix).prefix, &(yyval.v.prefix).len)) { yyerror("could not parse address \"%s\"", s); free(s); YYERROR; } free(s); } #line 4225 "parse.c" break; case 179: /* prefix: NUMBER '/' NUMBER */ #line 1565 "../../../openbgpd-portable/src/bgpd/parse.y" { char *s; /* does not match IPv6 */ if ((yyvsp[-2].v.number) < 0 || (yyvsp[-2].v.number) > 255 || (yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 32) { yyerror("bad prefix %lld/%lld", (yyvsp[-2].v.number), (yyvsp[0].v.number)); YYERROR; } if (asprintf(&s, "%lld/%lld", (yyvsp[-2].v.number), (yyvsp[0].v.number)) == -1) fatal(NULL); if (!host(s, &(yyval.v.prefix).prefix, &(yyval.v.prefix).len)) { yyerror("could not parse address \"%s\"", s); free(s); YYERROR; } free(s); } #line 4248 "parse.c" break; case 180: /* addrspec: address */ #line 1585 "../../../openbgpd-portable/src/bgpd/parse.y" { memcpy(&(yyval.v.prefix).prefix, &(yyvsp[0].v.addr), sizeof(struct bgpd_addr)); if ((yyval.v.prefix).prefix.aid == AID_INET) (yyval.v.prefix).len = 32; else (yyval.v.prefix).len = 128; } #line 4260 "parse.c" break; case 182: /* optnumber: %empty */ #line 1595 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 4266 "parse.c" break; case 184: /* $@12: %empty */ #line 1599 "../../../openbgpd-portable/src/bgpd/parse.y" { u_int rdomain, label; if (get_mpe_config((yyvsp[0].v.string), &rdomain, &label) == -1) { if ((cmd_opts & BGPD_OPT_NOACTION) == 0) { yyerror("troubles getting config of %s", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); free((yyvsp[-2].v.string)); YYERROR; } } if (!(curvpn = calloc(1, sizeof(struct l3vpn)))) fatal(NULL); strlcpy(curvpn->ifmpe, (yyvsp[0].v.string), IFNAMSIZ); if (strlcpy(curvpn->descr, (yyvsp[-2].v.string), sizeof(curvpn->descr)) >= sizeof(curvpn->descr)) { yyerror("descr \"%s\" too long: max %zu", (yyvsp[-2].v.string), sizeof(curvpn->descr) - 1); free((yyvsp[-2].v.string)); free((yyvsp[0].v.string)); free(curvpn); curvpn = NULL; YYERROR; } free((yyvsp[-2].v.string)); free((yyvsp[0].v.string)); TAILQ_INIT(&curvpn->import); TAILQ_INIT(&curvpn->export); TAILQ_INIT(&curvpn->net_l); curvpn->label = label; curvpn->rtableid = rdomain; netconf = &curvpn->net_l; } #line 4309 "parse.c" break; case 185: /* l3vpn: VPN STRING ON STRING $@12 '{' l3vpnopts_l '}' */ #line 1636 "../../../openbgpd-portable/src/bgpd/parse.y" { /* insert into list */ SIMPLEQ_INSERT_TAIL(&conf->l3vpns, curvpn, entry); curvpn = NULL; netconf = &conf->networks; } #line 4320 "parse.c" break; case 190: /* l3vpnopts: RD STRING */ #line 1650 "../../../openbgpd-portable/src/bgpd/parse.y" { struct community ext; memset(&ext, 0, sizeof(ext)); if (parseextcommunity(&ext, "rt", (yyvsp[0].v.string)) == -1) { free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); /* * RD is almost encoded like an ext-community, * but only almost so convert here. */ if (community_to_rd(&ext, &curvpn->rd) == -1) { yyerror("bad encoding of rd"); YYERROR; } } #line 4343 "parse.c" break; case 191: /* l3vpnopts: EXPORTTRGT STRING STRING */ #line 1668 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_set *set; if ((set = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); set->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&set->action.community, (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) { free((yyvsp[0].v.string)); free((yyvsp[-1].v.string)); free(set); YYERROR; } free((yyvsp[0].v.string)); free((yyvsp[-1].v.string)); TAILQ_INSERT_TAIL(&curvpn->export, set, entry); } #line 4366 "parse.c" break; case 192: /* l3vpnopts: IMPORTTRGT STRING STRING */ #line 1686 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_set *set; if ((set = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); set->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&set->action.community, (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) { free((yyvsp[0].v.string)); free((yyvsp[-1].v.string)); free(set); YYERROR; } free((yyvsp[0].v.string)); free((yyvsp[-1].v.string)); TAILQ_INSERT_TAIL(&curvpn->import, set, entry); } #line 4389 "parse.c" break; case 193: /* l3vpnopts: FIBUPDATE yesno */ #line 1704 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) == 0) curvpn->flags |= F_RIB_NOFIBSYNC; else curvpn->flags &= ~F_RIB_NOFIBSYNC; } #line 4400 "parse.c" break; case 195: /* $@13: %empty */ #line 1713 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer = new_peer(); } #line 4406 "parse.c" break; case 196: /* $@14: %empty */ #line 1714 "../../../openbgpd-portable/src/bgpd/parse.y" { memcpy(&curpeer->conf.remote_addr, &(yyvsp[0].v.prefix).prefix, sizeof(curpeer->conf.remote_addr)); curpeer->conf.remote_masklen = (yyvsp[0].v.prefix).len; if (((yyvsp[0].v.prefix).prefix.aid == AID_INET && (yyvsp[0].v.prefix).len != 32) || ((yyvsp[0].v.prefix).prefix.aid == AID_INET6 && (yyvsp[0].v.prefix).len != 128)) curpeer->conf.template = 1; if (get_id(curpeer)) { yyerror("get_id failed"); YYERROR; } } #line 4423 "parse.c" break; case 197: /* neighbor: $@13 NEIGHBOR addrspec $@14 peeropts_h */ #line 1726 "../../../openbgpd-portable/src/bgpd/parse.y" { uint8_t aid; if (curpeer_filter[0] != NULL) TAILQ_INSERT_TAIL(peerfilter_l, curpeer_filter[0], entry); if (curpeer_filter[1] != NULL) TAILQ_INSERT_TAIL(peerfilter_l, curpeer_filter[1], entry); curpeer_filter[0] = NULL; curpeer_filter[1] = NULL; /* * Check if any MP capa is set, if none is set and * and the default AID was not disabled via none then * enable it. Finally fixup the disabled AID. */ for (aid = AID_MIN; aid < AID_MAX; aid++) { if (curpeer->conf.capabilities.mp[aid] > 0) break; } if (aid == AID_MAX && curpeer->conf.capabilities.mp[ curpeer->conf.remote_addr.aid] != -1) curpeer->conf.capabilities.mp[ curpeer->conf.remote_addr.aid] = 1; for (aid = AID_MIN; aid < AID_MAX; aid++) { if (curpeer->conf.capabilities.mp[aid] == -1) curpeer->conf.capabilities.mp[aid] = 0; } if (neighbor_consistent(curpeer) == -1) { free(curpeer); YYERROR; } if (RB_INSERT(peer_head, new_peers, curpeer) != NULL) fatalx("%s: peer tree is corrupt", __func__); curpeer = curgroup; } #line 4467 "parse.c" break; case 198: /* $@15: %empty */ #line 1767 "../../../openbgpd-portable/src/bgpd/parse.y" { curgroup = curpeer = new_group(); if (strlcpy(curgroup->conf.group, (yyvsp[0].v.string), sizeof(curgroup->conf.group)) >= sizeof(curgroup->conf.group)) { yyerror("group name \"%s\" too long: max %zu", (yyvsp[0].v.string), sizeof(curgroup->conf.group) - 1); free((yyvsp[0].v.string)); free(curgroup); YYERROR; } free((yyvsp[0].v.string)); if (get_id(curgroup)) { yyerror("get_id failed"); free(curgroup); YYERROR; } } #line 4490 "parse.c" break; case 199: /* group: GROUP string $@15 '{' groupopts_l '}' */ #line 1784 "../../../openbgpd-portable/src/bgpd/parse.y" { if (curgroup_filter[0] != NULL) TAILQ_INSERT_TAIL(groupfilter_l, curgroup_filter[0], entry); if (curgroup_filter[1] != NULL) TAILQ_INSERT_TAIL(groupfilter_l, curgroup_filter[1], entry); curgroup_filter[0] = NULL; curgroup_filter[1] = NULL; free(curgroup); curgroup = NULL; } #line 4508 "parse.c" break; case 205: /* addpathextra: %empty */ #line 1806 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 4514 "parse.c" break; case 206: /* addpathextra: PLUS NUMBER */ #line 1807 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 1 || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("additional paths must be between " "%u and %u", 1, USHRT_MAX); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 4527 "parse.c" break; case 207: /* addpathmax: %empty */ #line 1817 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 4533 "parse.c" break; case 208: /* addpathmax: MAX NUMBER */ #line 1818 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 1 || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("maximum additional paths must be " "between %u and %u", 1, USHRT_MAX); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 4546 "parse.c" break; case 216: /* peeropts: REMOTEAS as4number */ #line 1839 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.remote_as = (yyvsp[0].v.number); } #line 4554 "parse.c" break; case 217: /* peeropts: LOCALAS as4number */ #line 1842 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.local_as = (yyvsp[0].v.number); if ((yyvsp[0].v.number) > USHRT_MAX) curpeer->conf.local_short_as = AS_TRANS; else curpeer->conf.local_short_as = (yyvsp[0].v.number); } #line 4566 "parse.c" break; case 218: /* peeropts: LOCALAS as4number asnumber */ #line 1849 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.local_as = (yyvsp[-1].v.number); curpeer->conf.local_short_as = (yyvsp[0].v.number); } #line 4575 "parse.c" break; case 219: /* peeropts: DESCR string */ #line 1853 "../../../openbgpd-portable/src/bgpd/parse.y" { if (strlcpy(curpeer->conf.descr, (yyvsp[0].v.string), sizeof(curpeer->conf.descr)) >= sizeof(curpeer->conf.descr)) { yyerror("descr \"%s\" too long: max %zu", (yyvsp[0].v.string), sizeof(curpeer->conf.descr) - 1); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 4591 "parse.c" break; case 220: /* peeropts: LOCALADDR address */ #line 1864 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.addr).aid == AID_INET) memcpy(&curpeer->conf.local_addr_v4, &(yyvsp[0].v.addr), sizeof(curpeer->conf.local_addr_v4)); else if ((yyvsp[0].v.addr).aid == AID_INET6) memcpy(&curpeer->conf.local_addr_v6, &(yyvsp[0].v.addr), sizeof(curpeer->conf.local_addr_v6)); else { yyerror("Unsupported address family %s for " "local-addr", aid2str((yyvsp[0].v.addr).aid)); YYERROR; } } #line 4609 "parse.c" break; case 221: /* peeropts: yesno LOCALADDR */ #line 1877 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[-1].v.number)) { yyerror("bad local-address definition"); YYERROR; } memset(&curpeer->conf.local_addr_v4, 0, sizeof(curpeer->conf.local_addr_v4)); memset(&curpeer->conf.local_addr_v6, 0, sizeof(curpeer->conf.local_addr_v6)); } #line 4624 "parse.c" break; case 222: /* peeropts: MULTIHOP NUMBER */ #line 1887 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 2 || (yyvsp[0].v.number) > 255) { yyerror("invalid multihop distance %lld", (yyvsp[0].v.number)); YYERROR; } curpeer->conf.distance = (yyvsp[0].v.number); } #line 4636 "parse.c" break; case 223: /* peeropts: PASSIVE */ #line 1894 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.passive = 1; } #line 4644 "parse.c" break; case 224: /* peeropts: DOWN */ #line 1897 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.down = 1; } #line 4652 "parse.c" break; case 225: /* peeropts: DOWN STRING */ #line 1900 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.down = 1; if (strlcpy(curpeer->conf.reason, (yyvsp[0].v.string), sizeof(curpeer->conf.reason)) >= sizeof(curpeer->conf.reason)) { yyerror("shutdown reason too long"); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 4668 "parse.c" break; case 226: /* peeropts: RIB STRING */ #line 1911 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!find_rib((yyvsp[0].v.string))) { yyerror("rib \"%s\" does not exist.", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } if (strlcpy(curpeer->conf.rib, (yyvsp[0].v.string), sizeof(curpeer->conf.rib)) >= sizeof(curpeer->conf.rib)) { yyerror("rib name \"%s\" too long: max %zu", (yyvsp[0].v.string), sizeof(curpeer->conf.rib) - 1); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 4689 "parse.c" break; case 227: /* peeropts: HOLDTIME NUMBER */ #line 1927 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } curpeer->conf.holdtime = (yyvsp[0].v.number); } #line 4702 "parse.c" break; case 228: /* peeropts: HOLDTIME YMIN NUMBER */ #line 1935 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } curpeer->conf.min_holdtime = (yyvsp[0].v.number); } #line 4715 "parse.c" break; case 229: /* peeropts: STALETIME NUMBER */ #line 1943 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("staletime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } curpeer->conf.staletime = (yyvsp[0].v.number); } #line 4728 "parse.c" break; case 230: /* peeropts: ANNOUNCE af safi enforce */ #line 1951 "../../../openbgpd-portable/src/bgpd/parse.y" { uint8_t aid, safi; uint16_t afi; if ((yyvsp[-1].v.number) == SAFI_NONE) { for (aid = AID_MIN; aid < AID_MAX; aid++) { if (aid2afi(aid, &afi, &safi) == -1 || afi != (yyvsp[-2].v.number)) continue; curpeer->conf.capabilities.mp[aid] = -1; } } else { if (afi2aid((yyvsp[-2].v.number), (yyvsp[-1].v.number), &aid) == -1) { yyerror("unknown AFI/SAFI pair"); YYERROR; } if ((yyvsp[0].v.number)) curpeer->conf.capabilities.mp[aid] = 2; else curpeer->conf.capabilities.mp[aid] = 1; } } #line 4755 "parse.c" break; case 231: /* peeropts: ANNOUNCE EVPN enforce */ #line 1973 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number)) curpeer->conf.capabilities.mp[AID_EVPN] = 2; else curpeer->conf.capabilities.mp[AID_EVPN] = 1; } #line 4766 "parse.c" break; case 232: /* peeropts: ANNOUNCE REFRESH yesnoenforce */ #line 1979 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.refresh = (yyvsp[0].v.number); } #line 4774 "parse.c" break; case 233: /* peeropts: ANNOUNCE ENHANCED REFRESH yesnoenforce */ #line 1982 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.enhanced_rr = (yyvsp[0].v.number); } #line 4782 "parse.c" break; case 234: /* peeropts: ANNOUNCE RESTART yesnoenforce */ #line 1985 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.grestart.restart = (yyvsp[0].v.number); } #line 4790 "parse.c" break; case 235: /* peeropts: ANNOUNCE GRACEFUL NOTIFICATION yesno */ #line 1988 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.grestart.grnotification = (yyvsp[0].v.number); } #line 4798 "parse.c" break; case 236: /* peeropts: ANNOUNCE AS4BYTE yesnoenforce */ #line 1991 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.as4byte = (yyvsp[0].v.number); } #line 4806 "parse.c" break; case 237: /* peeropts: ANNOUNCE ADDPATH RECV yesnoenforce */ #line 1994 "../../../openbgpd-portable/src/bgpd/parse.y" { int8_t *ap = curpeer->conf.capabilities.add_path; uint8_t i; for (i = AID_MIN; i < AID_MAX; i++) { if ((yyvsp[0].v.number)) { if ((yyvsp[0].v.number) == 2) ap[i] |= CAPA_AP_RECV_ENFORCE; ap[i] |= CAPA_AP_RECV; } else ap[i] &= ~CAPA_AP_RECV; } } #line 4824 "parse.c" break; case 238: /* peeropts: ANNOUNCE ADDPATH SEND STRING addpathextra addpathmax enforce */ #line 2007 "../../../openbgpd-portable/src/bgpd/parse.y" { int8_t *ap = curpeer->conf.capabilities.add_path; enum addpath_mode mode; u_int8_t i; if (!strcmp((yyvsp[-3].v.string), "no")) { free((yyvsp[-3].v.string)); if ((yyvsp[-2].v.number) != 0 || (yyvsp[-1].v.number) != 0 || (yyvsp[0].v.number) != 0) { yyerror("no additional option allowed " "for 'add-path send no'"); YYERROR; } mode = ADDPATH_EVAL_NONE; } else if (!strcmp((yyvsp[-3].v.string), "all")) { free((yyvsp[-3].v.string)); if ((yyvsp[-2].v.number) != 0 || (yyvsp[-1].v.number) != 0) { yyerror("no additional option allowed " "for 'add-path send all'"); YYERROR; } mode = ADDPATH_EVAL_ALL; } else if (!strcmp((yyvsp[-3].v.string), "best")) { free((yyvsp[-3].v.string)); mode = ADDPATH_EVAL_BEST; } else if (!strcmp((yyvsp[-3].v.string), "ecmp")) { free((yyvsp[-3].v.string)); mode = ADDPATH_EVAL_ECMP; } else if (!strcmp((yyvsp[-3].v.string), "as-wide-best")) { free((yyvsp[-3].v.string)); mode = ADDPATH_EVAL_AS_WIDE; } else { yyerror("announce add-path send: " "unknown mode \"%s\"", (yyvsp[-3].v.string)); free((yyvsp[-3].v.string)); YYERROR; } for (i = AID_MIN; i < AID_MAX; i++) { if (mode != ADDPATH_EVAL_NONE) { if ((yyvsp[0].v.number)) ap[i] |= CAPA_AP_SEND_ENFORCE; ap[i] |= CAPA_AP_SEND; } else ap[i] &= ~CAPA_AP_SEND; } curpeer->conf.eval.mode = mode; curpeer->conf.eval.extrapaths = (yyvsp[-2].v.number); curpeer->conf.eval.maxpaths = (yyvsp[-1].v.number); } #line 4877 "parse.c" break; case 239: /* peeropts: ANNOUNCE POLICY yesnoenforce */ #line 2055 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.policy = (yyvsp[0].v.number); } #line 4885 "parse.c" break; case 240: /* peeropts: ANNOUNCE EXTENDED MESSAGE yesnoenforce */ #line 2058 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.ext_msg = (yyvsp[0].v.number); } #line 4893 "parse.c" break; case 241: /* peeropts: ANNOUNCE EXTENDED NEXTHOP yesnoenforce */ #line 2061 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.capabilities.ext_nh[AID_VPN_IPv4] = curpeer->conf.capabilities.ext_nh[AID_INET] = (yyvsp[0].v.number); } #line 4902 "parse.c" break; case 242: /* peeropts: ROLE STRING */ #line 2065 "../../../openbgpd-portable/src/bgpd/parse.y" { if (strcmp((yyvsp[0].v.string), "provider") == 0) { curpeer->conf.role = ROLE_PROVIDER; } else if (strcmp((yyvsp[0].v.string), "rs") == 0) { curpeer->conf.role = ROLE_RS; } else if (strcmp((yyvsp[0].v.string), "rs-client") == 0) { curpeer->conf.role = ROLE_RS_CLIENT; } else if (strcmp((yyvsp[0].v.string), "customer") == 0) { curpeer->conf.role = ROLE_CUSTOMER; } else if (strcmp((yyvsp[0].v.string), "peer") == 0) { curpeer->conf.role = ROLE_PEER; } else { yyerror("syntax error, one of none, provider, " "rs, rs-client, customer, peer expected"); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 4926 "parse.c" break; case 243: /* peeropts: ROLE NONE */ #line 2084 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.role = ROLE_NONE; } #line 4934 "parse.c" break; case 244: /* peeropts: EXPORT NONE */ #line 2087 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.export_type = EXPORT_NONE; } #line 4942 "parse.c" break; case 245: /* peeropts: EXPORT DEFAULTROUTE */ #line 2090 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.export_type = EXPORT_DEFAULT_ROUTE; } #line 4950 "parse.c" break; case 246: /* peeropts: ENFORCE NEIGHBORAS yesno */ #line 2093 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number)) curpeer->conf.enforce_as = ENFORCE_AS_ON; else curpeer->conf.enforce_as = ENFORCE_AS_OFF; } #line 4961 "parse.c" break; case 247: /* peeropts: ENFORCE LOCALAS yesno */ #line 2099 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number)) curpeer->conf.enforce_local_as = ENFORCE_AS_ON; else curpeer->conf.enforce_local_as = ENFORCE_AS_OFF; } #line 4972 "parse.c" break; case 248: /* peeropts: ASOVERRIDE yesno */ #line 2105 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number)) { struct filter_rule *r; struct filter_set *s; if ((s = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); s->type = ACTION_SET_AS_OVERRIDE; r = get_rule(s->type); if (merge_filterset(&r->set, s) == -1) YYERROR; } } #line 4992 "parse.c" break; case 249: /* peeropts: MAXPREFIX NUMBER restart */ #line 2120 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[-1].v.number) < 0 || (yyvsp[-1].v.number) > UINT_MAX) { yyerror("bad maximum number of prefixes"); YYERROR; } curpeer->conf.max_prefix = (yyvsp[-1].v.number); curpeer->conf.max_prefix_restart = (yyvsp[0].v.number); } #line 5005 "parse.c" break; case 250: /* peeropts: MAXPREFIX NUMBER OUT restart */ #line 2128 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[-2].v.number) < 0 || (yyvsp[-2].v.number) > UINT_MAX) { yyerror("bad maximum number of prefixes"); YYERROR; } curpeer->conf.max_out_prefix = (yyvsp[-2].v.number); curpeer->conf.max_out_prefix_restart = (yyvsp[0].v.number); } #line 5018 "parse.c" break; case 251: /* peeropts: authconf */ #line 2136 "../../../openbgpd-portable/src/bgpd/parse.y" { if (merge_auth_conf(&curpeer->auth_conf, &(yyvsp[0].v.authconf)) == 0) YYERROR; } #line 5027 "parse.c" break; case 252: /* peeropts: TTLSECURITY yesno */ #line 2140 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.ttlsec = (yyvsp[0].v.number); } #line 5035 "parse.c" break; case 253: /* peeropts: SET filter_set_opt */ #line 2143 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_rule *r; r = get_rule((yyvsp[0].v.filter_set)->type); if (merge_filterset(&r->set, (yyvsp[0].v.filter_set)) == -1) YYERROR; } #line 5047 "parse.c" break; case 254: /* peeropts: SET '{' optnl filter_set_l optnl '}' */ #line 2150 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_rule *r; struct filter_set *s; while ((s = TAILQ_FIRST((yyvsp[-2].v.filter_set_head))) != NULL) { TAILQ_REMOVE((yyvsp[-2].v.filter_set_head), s, entry); r = get_rule(s->type); if (merge_filterset(&r->set, s) == -1) YYERROR; } free((yyvsp[-2].v.filter_set_head)); } #line 5064 "parse.c" break; case 256: /* peeropts: REFLECTOR */ #line 2163 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid != 0) { yyerror("only one route reflector " "cluster allowed"); YYERROR; } conf->flags |= BGPD_FLAG_REFLECTOR; curpeer->conf.reflector_client = 1; } #line 5079 "parse.c" break; case 257: /* peeropts: REFLECTOR address */ #line 2173 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.addr).aid != AID_INET) { yyerror("route reflector cluster-id must be " "an IPv4 address"); YYERROR; } if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid != ntohl((yyvsp[0].v.addr).v4.s_addr)) { yyerror("only one route reflector " "cluster allowed"); YYERROR; } conf->flags |= BGPD_FLAG_REFLECTOR; curpeer->conf.reflector_client = 1; conf->clusterid = ntohl((yyvsp[0].v.addr).v4.s_addr); } #line 5100 "parse.c" break; case 258: /* peeropts: DEPEND ON STRING */ #line 2189 "../../../openbgpd-portable/src/bgpd/parse.y" { if (strlcpy(curpeer->conf.if_depend, (yyvsp[0].v.string), sizeof(curpeer->conf.if_depend)) >= sizeof(curpeer->conf.if_depend)) { yyerror("interface name \"%s\" too long: " "max %zu", (yyvsp[0].v.string), sizeof(curpeer->conf.if_depend) - 1); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 5117 "parse.c" break; case 259: /* peeropts: DEMOTE STRING */ #line 2201 "../../../openbgpd-portable/src/bgpd/parse.y" { #ifdef HAVE_CARP if (strlcpy(curpeer->conf.demote_group, (yyvsp[0].v.string), sizeof(curpeer->conf.demote_group)) >= sizeof(curpeer->conf.demote_group)) { yyerror("demote group name \"%s\" too long: " "max %zu", (yyvsp[0].v.string), sizeof(curpeer->conf.demote_group) - 1); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); if (carp_demote_init(curpeer->conf.demote_group, cmd_opts & BGPD_OPT_FORCE_DEMOTE) == -1) { yyerror("error initializing group \"%s\"", curpeer->conf.demote_group); YYERROR; } #else yyerror("carp demote not supported"); free((yyvsp[0].v.string)); YYERROR; #endif } #line 5146 "parse.c" break; case 260: /* peeropts: TRANSPARENT yesno */ #line 2225 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) == 1) curpeer->conf.flags |= PEERFLAG_TRANS_AS; else curpeer->conf.flags &= ~PEERFLAG_TRANS_AS; } #line 5157 "parse.c" break; case 261: /* peeropts: LOG STRING */ #line 2231 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "updates")) curpeer->conf.flags |= PEERFLAG_LOG_UPDATES; else if (!strcmp((yyvsp[0].v.string), "no")) curpeer->conf.flags &= ~PEERFLAG_LOG_UPDATES; else { free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 5173 "parse.c" break; case 262: /* peeropts: REJECT ASSET yesno */ #line 2242 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) == 1) curpeer->conf.flags &= ~PEERFLAG_PERMIT_AS_SET; else curpeer->conf.flags |= PEERFLAG_PERMIT_AS_SET; } #line 5184 "parse.c" break; case 263: /* peeropts: PORT port */ #line 2248 "../../../openbgpd-portable/src/bgpd/parse.y" { curpeer->conf.remote_port = (yyvsp[0].v.number); } #line 5192 "parse.c" break; case 264: /* peeropts: RDE EVALUATE STRING */ #line 2251 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "all")) curpeer->conf.flags |= PEERFLAG_EVALUATE_ALL; else if (!strcmp((yyvsp[0].v.string), "default")) curpeer->conf.flags &= ~PEERFLAG_EVALUATE_ALL; else { yyerror("rde evaluate: " "unknown setting \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 5210 "parse.c" break; case 265: /* restart: %empty */ #line 2266 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 5216 "parse.c" break; case 266: /* restart: RESTART NUMBER */ #line 2267 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 1 || (yyvsp[0].v.number) > USHRT_MAX) { yyerror("restart out of range. 1 to %u minutes", USHRT_MAX); YYERROR; } (yyval.v.number) = (yyvsp[0].v.number); } #line 5229 "parse.c" break; case 267: /* af: IPV4 */ #line 2277 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = AFI_IPv4; } #line 5235 "parse.c" break; case 268: /* af: IPV6 */ #line 2278 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = AFI_IPv6; } #line 5241 "parse.c" break; case 269: /* safi: NONE */ #line 2281 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = SAFI_NONE; } #line 5247 "parse.c" break; case 270: /* safi: UNICAST */ #line 2282 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = SAFI_UNICAST; } #line 5253 "parse.c" break; case 271: /* safi: VPN */ #line 2283 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = SAFI_MPLSVPN; } #line 5259 "parse.c" break; case 272: /* safi: FLOWSPEC */ #line 2284 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = SAFI_FLOWSPEC; } #line 5265 "parse.c" break; case 273: /* nettype: STATIC */ #line 2287 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 1; } #line 5271 "parse.c" break; case 274: /* nettype: CONNECTED */ #line 2288 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 5277 "parse.c" break; case 275: /* authconf: TCP MD5SIG PASSWORD string */ #line 2291 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.authconf), 0, sizeof((yyval.v.authconf))); if (strlcpy((yyval.v.authconf).md5key, (yyvsp[0].v.string), sizeof((yyval.v.authconf).md5key)) >= sizeof((yyval.v.authconf).md5key)) { yyerror("tcp md5sig password too long: max %zu", sizeof((yyval.v.authconf).md5key) - 1); free((yyvsp[0].v.string)); YYERROR; } (yyval.v.authconf).method = AUTH_MD5SIG; (yyval.v.authconf).md5key_len = strlen((yyvsp[0].v.string)); free((yyvsp[0].v.string)); } #line 5295 "parse.c" break; case 276: /* authconf: TCP MD5SIG KEY string */ #line 2304 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.authconf), 0, sizeof((yyval.v.authconf))); if (str2key((yyvsp[0].v.string), (yyval.v.authconf).md5key, sizeof((yyval.v.authconf).md5key)) == -1) { free((yyvsp[0].v.string)); YYERROR; } (yyval.v.authconf).method = AUTH_MD5SIG; (yyval.v.authconf).md5key_len = strlen((yyvsp[0].v.string)) / 2; free((yyvsp[0].v.string)); } #line 5310 "parse.c" break; case 277: /* authconf: IPSEC espah IKE */ #line 2314 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.authconf), 0, sizeof((yyval.v.authconf))); if ((yyvsp[-1].v.number)) (yyval.v.authconf).method = AUTH_IPSEC_IKE_ESP; else (yyval.v.authconf).method = AUTH_IPSEC_IKE_AH; } #line 5322 "parse.c" break; case 278: /* authconf: IPSEC espah inout SPI NUMBER STRING STRING encspec */ #line 2321 "../../../openbgpd-portable/src/bgpd/parse.y" { enum auth_alg auth_alg; uint8_t keylen; memset(&(yyval.v.authconf), 0, sizeof((yyval.v.authconf))); if (!strcmp((yyvsp[-2].v.string), "sha1")) { auth_alg = AUTH_AALG_SHA1HMAC; keylen = 20; } else if (!strcmp((yyvsp[-2].v.string), "md5")) { auth_alg = AUTH_AALG_MD5HMAC; keylen = 16; } else { yyerror("unknown auth algorithm \"%s\"", (yyvsp[-2].v.string)); free((yyvsp[-2].v.string)); free((yyvsp[-1].v.string)); YYERROR; } free((yyvsp[-2].v.string)); if (strlen((yyvsp[-1].v.string)) / 2 != keylen) { yyerror("auth key len: must be %u bytes, " "is %zu bytes", keylen, strlen((yyvsp[-1].v.string)) / 2); free((yyvsp[-1].v.string)); YYERROR; } if ((yyvsp[-6].v.number)) (yyval.v.authconf).method = AUTH_IPSEC_MANUAL_ESP; else { if ((yyvsp[0].v.encspec).enc_alg) { yyerror("\"ipsec ah\" doesn't take " "encryption keys"); free((yyvsp[-1].v.string)); YYERROR; } (yyval.v.authconf).method = AUTH_IPSEC_MANUAL_AH; } if ((yyvsp[-3].v.number) <= SPI_RESERVED_MAX || (yyvsp[-3].v.number) > UINT_MAX) { yyerror("bad spi number %lld", (yyvsp[-3].v.number)); free((yyvsp[-1].v.string)); YYERROR; } if ((yyvsp[-5].v.number) == 1) { if (str2key((yyvsp[-1].v.string), (yyval.v.authconf).auth_key_in, sizeof((yyval.v.authconf).auth_key_in)) == -1) { free((yyvsp[-1].v.string)); YYERROR; } (yyval.v.authconf).spi_in = (yyvsp[-3].v.number); (yyval.v.authconf).auth_alg_in = auth_alg; (yyval.v.authconf).enc_alg_in = (yyvsp[0].v.encspec).enc_alg; memcpy(&(yyval.v.authconf).enc_key_in, &(yyvsp[0].v.encspec).enc_key, sizeof((yyval.v.authconf).enc_key_in)); (yyval.v.authconf).enc_keylen_in = (yyvsp[0].v.encspec).enc_key_len; (yyval.v.authconf).auth_keylen_in = keylen; } else { if (str2key((yyvsp[-1].v.string), (yyval.v.authconf).auth_key_out, sizeof((yyval.v.authconf).auth_key_out)) == -1) { free((yyvsp[-1].v.string)); YYERROR; } (yyval.v.authconf).spi_out = (yyvsp[-3].v.number); (yyval.v.authconf).auth_alg_out = auth_alg; (yyval.v.authconf).enc_alg_out = (yyvsp[0].v.encspec).enc_alg; memcpy(&(yyval.v.authconf).enc_key_out, &(yyvsp[0].v.encspec).enc_key, sizeof((yyval.v.authconf).enc_key_out)); (yyval.v.authconf).enc_keylen_out = (yyvsp[0].v.encspec).enc_key_len; (yyval.v.authconf).auth_keylen_out = keylen; } free((yyvsp[-1].v.string)); } #line 5400 "parse.c" break; case 279: /* espah: ESP */ #line 2396 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 1; } #line 5406 "parse.c" break; case 280: /* espah: AH */ #line 2397 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 5412 "parse.c" break; case 281: /* encspec: %empty */ #line 2400 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.encspec), 0, sizeof((yyval.v.encspec))); } #line 5420 "parse.c" break; case 282: /* encspec: STRING STRING */ #line 2403 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.encspec), 0, sizeof((yyval.v.encspec))); if (!strcmp((yyvsp[-1].v.string), "3des") || !strcmp((yyvsp[-1].v.string), "3des-cbc")) { (yyval.v.encspec).enc_alg = AUTH_EALG_3DESCBC; (yyval.v.encspec).enc_key_len = 21; /* XXX verify */ } else if (!strcmp((yyvsp[-1].v.string), "aes") || !strcmp((yyvsp[-1].v.string), "aes-128-cbc")) { (yyval.v.encspec).enc_alg = AUTH_EALG_AES; (yyval.v.encspec).enc_key_len = 16; } else { yyerror("unknown enc algorithm \"%s\"", (yyvsp[-1].v.string)); free((yyvsp[-1].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[-1].v.string)); if (strlen((yyvsp[0].v.string)) / 2 != (yyval.v.encspec).enc_key_len) { yyerror("enc key length wrong: should be %u " "bytes, is %zu bytes", (yyval.v.encspec).enc_key_len * 2, strlen((yyvsp[0].v.string))); free((yyvsp[0].v.string)); YYERROR; } if (str2key((yyvsp[0].v.string), (yyval.v.encspec).enc_key, sizeof((yyval.v.encspec).enc_key)) == -1) { free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 5456 "parse.c" break; case 283: /* filterrule: action quick filter_rib_h direction filter_peer_h filter_match_h filter_set */ #line 2438 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_rule r; struct filter_rib_l *rb, *rbnext; memset(&r, 0, sizeof(r)); r.action = (yyvsp[-6].v.u8); r.quick = (yyvsp[-5].v.u8); r.dir = (yyvsp[-3].v.u8); if ((yyvsp[-4].v.filter_rib)) { if (r.dir != DIR_IN) { yyerror("rib only allowed on \"from\" " "rules."); for (rb = (yyvsp[-4].v.filter_rib); rb != NULL; rb = rbnext) { rbnext = rb->next; free(rb); } YYERROR; } } if (expand_rule(&r, (yyvsp[-4].v.filter_rib), (yyvsp[-2].v.filter_peers), &(yyvsp[-1].v.filter_match), (yyvsp[0].v.filter_set_head)) == -1) YYERROR; } #line 5484 "parse.c" break; case 284: /* action: ALLOW */ #line 2463 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = ACTION_ALLOW; } #line 5490 "parse.c" break; case 285: /* action: DENY */ #line 2464 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = ACTION_DENY; } #line 5496 "parse.c" break; case 286: /* action: MATCH */ #line 2465 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = ACTION_NONE; } #line 5502 "parse.c" break; case 287: /* quick: %empty */ #line 2468 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = 0; } #line 5508 "parse.c" break; case 288: /* quick: QUICK */ #line 2469 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = 1; } #line 5514 "parse.c" break; case 289: /* direction: FROM */ #line 2472 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = DIR_IN; } #line 5520 "parse.c" break; case 290: /* direction: TO */ #line 2473 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = DIR_OUT; } #line 5526 "parse.c" break; case 291: /* filter_rib_h: %empty */ #line 2476 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_rib) = NULL; } #line 5532 "parse.c" break; case 292: /* filter_rib_h: RIB filter_rib */ #line 2477 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_rib) = (yyvsp[0].v.filter_rib); } #line 5538 "parse.c" break; case 293: /* filter_rib_h: RIB '{' optnl filter_rib_l optnl '}' */ #line 2478 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_rib) = (yyvsp[-2].v.filter_rib); } #line 5544 "parse.c" break; case 294: /* filter_rib_l: filter_rib */ #line 2480 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_rib) = (yyvsp[0].v.filter_rib); } #line 5550 "parse.c" break; case 295: /* filter_rib_l: filter_rib_l comma filter_rib */ #line 2481 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyvsp[0].v.filter_rib)->next = (yyvsp[-2].v.filter_rib); (yyval.v.filter_rib) = (yyvsp[0].v.filter_rib); } #line 5559 "parse.c" break; case 296: /* filter_rib: STRING */ #line 2487 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!find_rib((yyvsp[0].v.string))) { yyerror("rib \"%s\" does not exist.", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } if (((yyval.v.filter_rib) = calloc(1, sizeof(struct filter_rib_l))) == NULL) fatal(NULL); (yyval.v.filter_rib)->next = NULL; if (strlcpy((yyval.v.filter_rib)->name, (yyvsp[0].v.string), sizeof((yyval.v.filter_rib)->name)) >= sizeof((yyval.v.filter_rib)->name)) { yyerror("rib name \"%s\" too long: " "max %zu", (yyvsp[0].v.string), sizeof((yyval.v.filter_rib)->name) - 1); free((yyvsp[0].v.string)); free((yyval.v.filter_rib)); YYERROR; } free((yyvsp[0].v.string)); } #line 5584 "parse.c" break; case 298: /* filter_peer_h: '{' optnl filter_peer_l optnl '}' */ #line 2510 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_peers) = (yyvsp[-2].v.filter_peers); } #line 5590 "parse.c" break; case 299: /* filter_peer_l: filter_peer */ #line 2513 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_peers) = (yyvsp[0].v.filter_peers); } #line 5596 "parse.c" break; case 300: /* filter_peer_l: filter_peer_l comma filter_peer */ #line 2514 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyvsp[0].v.filter_peers)->next = (yyvsp[-2].v.filter_peers); (yyval.v.filter_peers) = (yyvsp[0].v.filter_peers); } #line 5605 "parse.c" break; case 301: /* filter_peer: ANY */ #line 2520 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); (yyval.v.filter_peers)->p.peerid = (yyval.v.filter_peers)->p.groupid = 0; (yyval.v.filter_peers)->next = NULL; } #line 5617 "parse.c" break; case 302: /* filter_peer: address */ #line 2527 "../../../openbgpd-portable/src/bgpd/parse.y" { struct peer *p; if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); (yyval.v.filter_peers)->p.remote_as = (yyval.v.filter_peers)->p.groupid = (yyval.v.filter_peers)->p.peerid = 0; (yyval.v.filter_peers)->next = NULL; RB_FOREACH(p, peer_head, new_peers) if (!memcmp(&p->conf.remote_addr, &(yyvsp[0].v.addr), sizeof(p->conf.remote_addr))) { (yyval.v.filter_peers)->p.peerid = p->conf.id; break; } if ((yyval.v.filter_peers)->p.peerid == 0) { yyerror("no such peer: %s", log_addr(&(yyvsp[0].v.addr))); free((yyval.v.filter_peers)); YYERROR; } } #line 5642 "parse.c" break; case 303: /* filter_peer: AS as4number */ #line 2547 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); (yyval.v.filter_peers)->p.groupid = (yyval.v.filter_peers)->p.peerid = 0; (yyval.v.filter_peers)->p.remote_as = (yyvsp[0].v.number); } #line 5654 "parse.c" break; case 304: /* filter_peer: GROUP STRING */ #line 2554 "../../../openbgpd-portable/src/bgpd/parse.y" { struct peer *p; if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); (yyval.v.filter_peers)->p.remote_as = (yyval.v.filter_peers)->p.peerid = 0; (yyval.v.filter_peers)->next = NULL; RB_FOREACH(p, peer_head, new_peers) if (!strcmp(p->conf.group, (yyvsp[0].v.string))) { (yyval.v.filter_peers)->p.groupid = p->conf.groupid; break; } if ((yyval.v.filter_peers)->p.groupid == 0) { yyerror("no such group: \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); free((yyval.v.filter_peers)); YYERROR; } free((yyvsp[0].v.string)); } #line 5680 "parse.c" break; case 305: /* filter_peer: EBGP */ #line 2575 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); (yyval.v.filter_peers)->p.ebgp = 1; } #line 5691 "parse.c" break; case 306: /* filter_peer: IBGP */ #line 2581 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); (yyval.v.filter_peers)->p.ibgp = 1; } #line 5702 "parse.c" break; case 307: /* filter_prefix_h: IPV4 prefixlenop */ #line 2589 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.prefixlen).op == OP_NONE) { (yyvsp[0].v.prefixlen).op = OP_RANGE; (yyvsp[0].v.prefixlen).len_min = 0; (yyvsp[0].v.prefixlen).len_max = -1; } if (((yyval.v.filter_prefix) = calloc(1, sizeof(struct filter_prefix_l))) == NULL) fatal(NULL); (yyval.v.filter_prefix)->p.addr.aid = AID_INET; if (merge_prefixspec(&(yyval.v.filter_prefix)->p, &(yyvsp[0].v.prefixlen)) == -1) { free((yyval.v.filter_prefix)); YYERROR; } } #line 5722 "parse.c" break; case 308: /* filter_prefix_h: IPV6 prefixlenop */ #line 2604 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.prefixlen).op == OP_NONE) { (yyvsp[0].v.prefixlen).op = OP_RANGE; (yyvsp[0].v.prefixlen).len_min = 0; (yyvsp[0].v.prefixlen).len_max = -1; } if (((yyval.v.filter_prefix) = calloc(1, sizeof(struct filter_prefix_l))) == NULL) fatal(NULL); (yyval.v.filter_prefix)->p.addr.aid = AID_INET6; if (merge_prefixspec(&(yyval.v.filter_prefix)->p, &(yyvsp[0].v.prefixlen)) == -1) { free((yyval.v.filter_prefix)); YYERROR; } } #line 5742 "parse.c" break; case 309: /* filter_prefix_h: PREFIX filter_prefix */ #line 2619 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_prefix) = (yyvsp[0].v.filter_prefix); } #line 5748 "parse.c" break; case 310: /* filter_prefix_h: PREFIX '{' filter_prefix_m '}' */ #line 2620 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_prefix) = (yyvsp[-1].v.filter_prefix); } #line 5754 "parse.c" break; case 312: /* filter_prefix_m: '{' filter_prefix_l '}' */ #line 2624 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_prefix) = (yyvsp[-1].v.filter_prefix); } #line 5760 "parse.c" break; case 313: /* filter_prefix_m: '{' filter_prefix_l '}' filter_prefix_m */ #line 2626 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_prefix_l *p; /* merge, both can be lists */ for (p = (yyvsp[-2].v.filter_prefix); p != NULL && p->next != NULL; p = p->next) ; /* nothing */ if (p != NULL) p->next = (yyvsp[0].v.filter_prefix); (yyval.v.filter_prefix) = (yyvsp[-2].v.filter_prefix); } #line 5775 "parse.c" break; case 314: /* filter_prefix_l: filter_prefix */ #line 2637 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_prefix) = (yyvsp[0].v.filter_prefix); } #line 5781 "parse.c" break; case 315: /* filter_prefix_l: filter_prefix_l comma filter_prefix */ #line 2638 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyvsp[0].v.filter_prefix)->next = (yyvsp[-2].v.filter_prefix); (yyval.v.filter_prefix) = (yyvsp[0].v.filter_prefix); } #line 5790 "parse.c" break; case 316: /* filter_prefix: prefix prefixlenop */ #line 2644 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_prefix) = calloc(1, sizeof(struct filter_prefix_l))) == NULL) fatal(NULL); memcpy(&(yyval.v.filter_prefix)->p.addr, &(yyvsp[-1].v.prefix).prefix, sizeof((yyval.v.filter_prefix)->p.addr)); (yyval.v.filter_prefix)->p.len = (yyvsp[-1].v.prefix).len; if (merge_prefixspec(&(yyval.v.filter_prefix)->p, &(yyvsp[0].v.prefixlen)) == -1) { free((yyval.v.filter_prefix)); YYERROR; } } #line 5808 "parse.c" break; case 318: /* filter_as_h: '{' filter_as_t_l '}' */ #line 2660 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_as) = (yyvsp[-1].v.filter_as); } #line 5814 "parse.c" break; case 320: /* filter_as_t_l: filter_as_t_l comma filter_as_t */ #line 2664 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_as_l *a; /* merge, both can be lists */ for (a = (yyvsp[-2].v.filter_as); a != NULL && a->next != NULL; a = a->next) ; /* nothing */ if (a != NULL) a->next = (yyvsp[0].v.filter_as); (yyval.v.filter_as) = (yyvsp[-2].v.filter_as); } #line 5829 "parse.c" break; case 321: /* filter_as_t: filter_as_type filter_as */ #line 2676 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_as) = (yyvsp[0].v.filter_as); (yyval.v.filter_as)->a.type = (yyvsp[-1].v.u8); } #line 5838 "parse.c" break; case 322: /* filter_as_t: filter_as_type '{' filter_as_l_h '}' */ #line 2680 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_as_l *a; (yyval.v.filter_as) = (yyvsp[-1].v.filter_as); for (a = (yyval.v.filter_as); a != NULL; a = a->next) a->a.type = (yyvsp[-3].v.u8); } #line 5850 "parse.c" break; case 323: /* filter_as_t: filter_as_type ASSET STRING */ #line 2687 "../../../openbgpd-portable/src/bgpd/parse.y" { if (as_sets_lookup(&conf->as_sets, (yyvsp[0].v.string)) == NULL) { yyerror("as-set \"%s\" not defined", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); (yyval.v.filter_as)->a.type = (yyvsp[-2].v.u8); (yyval.v.filter_as)->a.flags = AS_FLAG_AS_SET_NAME; if (strlcpy((yyval.v.filter_as)->a.name, (yyvsp[0].v.string), sizeof((yyval.v.filter_as)->a.name)) >= sizeof((yyval.v.filter_as)->a.name)) { yyerror("as-set name \"%s\" too long: " "max %zu", (yyvsp[0].v.string), sizeof((yyval.v.filter_as)->a.name) - 1); free((yyvsp[0].v.string)); free((yyval.v.filter_as)); YYERROR; } free((yyvsp[0].v.string)); } #line 5876 "parse.c" break; case 325: /* filter_as_l_h: '{' filter_as_l '}' */ #line 2711 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_as) = (yyvsp[-1].v.filter_as); } #line 5882 "parse.c" break; case 326: /* filter_as_l_h: '{' filter_as_l '}' filter_as_l_h */ #line 2713 "../../../openbgpd-portable/src/bgpd/parse.y" { struct filter_as_l *a; /* merge, both can be lists */ for (a = (yyvsp[-2].v.filter_as); a != NULL && a->next != NULL; a = a->next) ; /* nothing */ if (a != NULL) a->next = (yyvsp[0].v.filter_as); (yyval.v.filter_as) = (yyvsp[-2].v.filter_as); } #line 5897 "parse.c" break; case 328: /* filter_as_l: filter_as_l comma filter_as */ #line 2726 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyvsp[0].v.filter_as)->next = (yyvsp[-2].v.filter_as); (yyval.v.filter_as) = (yyvsp[0].v.filter_as); } #line 5906 "parse.c" break; case 329: /* filter_as: as4number_any */ #line 2732 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); (yyval.v.filter_as)->a.as_min = (yyvsp[0].v.number); (yyval.v.filter_as)->a.as_max = (yyvsp[0].v.number); (yyval.v.filter_as)->a.op = OP_EQ; } #line 5919 "parse.c" break; case 330: /* filter_as: NEIGHBORAS */ #line 2740 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); (yyval.v.filter_as)->a.flags = AS_FLAG_NEIGHBORAS; } #line 5930 "parse.c" break; case 331: /* filter_as: equalityop as4number_any */ #line 2746 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); (yyval.v.filter_as)->a.op = (yyvsp[-1].v.u8); (yyval.v.filter_as)->a.as_min = (yyvsp[0].v.number); (yyval.v.filter_as)->a.as_max = (yyvsp[0].v.number); } #line 5943 "parse.c" break; case 332: /* filter_as: as4number_any binaryop as4number_any */ #line 2754 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); if ((yyvsp[-2].v.number) >= (yyvsp[0].v.number)) { yyerror("start AS is bigger than end"); YYERROR; } (yyval.v.filter_as)->a.op = (yyvsp[-1].v.u8); (yyval.v.filter_as)->a.as_min = (yyvsp[-2].v.number); (yyval.v.filter_as)->a.as_max = (yyvsp[0].v.number); } #line 5960 "parse.c" break; case 333: /* filter_match_h: %empty */ #line 2768 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.filter_match), 0, sizeof((yyval.v.filter_match))); } #line 5968 "parse.c" break; case 334: /* $@16: %empty */ #line 2771 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&fmopts, 0, sizeof(fmopts)); } #line 5976 "parse.c" break; case 335: /* filter_match_h: $@16 filter_match */ #line 2774 "../../../openbgpd-portable/src/bgpd/parse.y" { memcpy(&(yyval.v.filter_match), &fmopts, sizeof((yyval.v.filter_match))); } #line 5984 "parse.c" break; case 338: /* filter_elm: filter_prefix_h */ #line 2783 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.prefix_l != NULL) { yyerror("\"prefix\" already specified"); YYERROR; } if (fmopts.m.prefixset.name[0] != '\0') { yyerror("\"prefix-set\" already specified, " "cannot be used with \"prefix\" in the " "same filter rule"); YYERROR; } fmopts.prefix_l = (yyvsp[0].v.filter_prefix); } #line 6002 "parse.c" break; case 339: /* filter_elm: filter_as_h */ #line 2796 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.as_l != NULL) { yyerror("AS filters already specified"); YYERROR; } fmopts.as_l = (yyvsp[0].v.filter_as); } #line 6014 "parse.c" break; case 340: /* filter_elm: MAXASLEN NUMBER */ #line 2803 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.m.aslen.type != ASLEN_NONE) { yyerror("AS length filters already specified"); YYERROR; } if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > UINT_MAX) { yyerror("bad max-as-len %lld", (yyvsp[0].v.number)); YYERROR; } fmopts.m.aslen.type = ASLEN_MAX; fmopts.m.aslen.aslen = (yyvsp[0].v.number); } #line 6031 "parse.c" break; case 341: /* filter_elm: MAXASSEQ NUMBER */ #line 2815 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.m.aslen.type != ASLEN_NONE) { yyerror("AS length filters already specified"); YYERROR; } if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > UINT_MAX) { yyerror("bad max-as-seq %lld", (yyvsp[0].v.number)); YYERROR; } fmopts.m.aslen.type = ASLEN_SEQ; fmopts.m.aslen.aslen = (yyvsp[0].v.number); } #line 6048 "parse.c" break; case 342: /* filter_elm: community STRING */ #line 2827 "../../../openbgpd-portable/src/bgpd/parse.y" { int i; for (i = 0; i < MAX_COMM_MATCH; i++) { if (fmopts.m.community[i].flags == 0) break; } if (i >= MAX_COMM_MATCH) { yyerror("too many \"community\" filters " "specified"); free((yyvsp[0].v.string)); YYERROR; } if (parsecommunity(&fmopts.m.community[i], (yyvsp[-1].v.u8), (yyvsp[0].v.string)) == -1) { free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 6071 "parse.c" break; case 343: /* filter_elm: EXTCOMMUNITY STRING STRING */ #line 2845 "../../../openbgpd-portable/src/bgpd/parse.y" { int i; for (i = 0; i < MAX_COMM_MATCH; i++) { if (fmopts.m.community[i].flags == 0) break; } if (i >= MAX_COMM_MATCH) { yyerror("too many \"community\" filters " "specified"); free((yyvsp[-1].v.string)); free((yyvsp[0].v.string)); YYERROR; } if (parseextcommunity(&fmopts.m.community[i], (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) { free((yyvsp[-1].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[-1].v.string)); free((yyvsp[0].v.string)); } #line 6098 "parse.c" break; case 344: /* filter_elm: EXTCOMMUNITY OVS STRING */ #line 2867 "../../../openbgpd-portable/src/bgpd/parse.y" { int i; for (i = 0; i < MAX_COMM_MATCH; i++) { if (fmopts.m.community[i].flags == 0) break; } if (i >= MAX_COMM_MATCH) { yyerror("too many \"community\" filters " "specified"); free((yyvsp[0].v.string)); YYERROR; } if (parseextcommunity(&fmopts.m.community[i], "ovs", (yyvsp[0].v.string)) == -1) { free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 6122 "parse.c" break; case 345: /* filter_elm: MAXCOMMUNITIES NUMBER */ #line 2886 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT16_MAX) { yyerror("bad max-comunities %lld", (yyvsp[0].v.number)); YYERROR; } if (fmopts.m.maxcomm != 0) { yyerror("%s already specified", "max-communities"); YYERROR; } /* * Offset by 1 since 0 means not used. * The match function then uses >= to compensate. */ fmopts.m.maxcomm = (yyvsp[0].v.number) + 1; } #line 6143 "parse.c" break; case 346: /* filter_elm: MAXEXTCOMMUNITIES NUMBER */ #line 2902 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT16_MAX) { yyerror("bad max-ext-communities %lld", (yyvsp[0].v.number)); YYERROR; } if (fmopts.m.maxextcomm != 0) { yyerror("%s already specified", "max-ext-communities"); YYERROR; } fmopts.m.maxextcomm = (yyvsp[0].v.number) + 1; } #line 6160 "parse.c" break; case 347: /* filter_elm: MAXLARGECOMMUNITIES NUMBER */ #line 2914 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT16_MAX) { yyerror("bad max-large-communities %lld", (yyvsp[0].v.number)); YYERROR; } if (fmopts.m.maxlargecomm != 0) { yyerror("%s already specified", "max-large-communities"); YYERROR; } fmopts.m.maxlargecomm = (yyvsp[0].v.number) + 1; } #line 6177 "parse.c" break; case 348: /* filter_elm: NEXTHOP address */ #line 2926 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.m.nexthop.flags) { yyerror("nexthop already specified"); YYERROR; } fmopts.m.nexthop.addr = (yyvsp[0].v.addr); fmopts.m.nexthop.flags = FILTER_NEXTHOP_ADDR; } #line 6190 "parse.c" break; case 349: /* filter_elm: NEXTHOP NEIGHBOR */ #line 2934 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.m.nexthop.flags) { yyerror("nexthop already specified"); YYERROR; } fmopts.m.nexthop.flags = FILTER_NEXTHOP_NEIGHBOR; } #line 6202 "parse.c" break; case 350: /* filter_elm: PREFIXSET STRING prefixlenop */ #line 2941 "../../../openbgpd-portable/src/bgpd/parse.y" { struct prefixset *ps; if (fmopts.prefix_l != NULL) { yyerror("\"prefix\" already specified, cannot " "be used with \"prefix-set\" in the same " "filter rule"); free((yyvsp[-1].v.string)); YYERROR; } if (fmopts.m.prefixset.name[0] != '\0') { yyerror("prefix-set filter already specified"); free((yyvsp[-1].v.string)); YYERROR; } if ((ps = find_prefixset((yyvsp[-1].v.string), &conf->prefixsets)) == NULL) { yyerror("prefix-set '%s' not defined", (yyvsp[-1].v.string)); free((yyvsp[-1].v.string)); YYERROR; } if (strlcpy(fmopts.m.prefixset.name, (yyvsp[-1].v.string), sizeof(fmopts.m.prefixset.name)) >= sizeof(fmopts.m.prefixset.name)) { yyerror("prefix-set name too long"); free((yyvsp[-1].v.string)); YYERROR; } if (!((yyvsp[0].v.prefixlen).op == OP_NONE || ((yyvsp[0].v.prefixlen).op == OP_RANGE && (yyvsp[0].v.prefixlen).len_min == -1 && (yyvsp[0].v.prefixlen).len_max == -1))) { yyerror("prefix-sets can only use option " "or-longer"); free((yyvsp[-1].v.string)); YYERROR; } if ((yyvsp[0].v.prefixlen).op == OP_RANGE && ps->sflags & PREFIXSET_FLAG_OPS) { yyerror("prefix-set %s contains prefixlen " "operators and cannot be used with an " "or-longer filter", (yyvsp[-1].v.string)); free((yyvsp[-1].v.string)); YYERROR; } if ((yyvsp[0].v.prefixlen).op == OP_RANGE && (yyvsp[0].v.prefixlen).len_min == -1 && (yyvsp[0].v.prefixlen).len_min == -1) fmopts.m.prefixset.flags |= PREFIXSET_FLAG_LONGER; fmopts.m.prefixset.flags |= PREFIXSET_FLAG_FILTER; free((yyvsp[-1].v.string)); } #line 6256 "parse.c" break; case 351: /* filter_elm: ORIGINSET STRING */ #line 2990 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.m.originset.name[0] != '\0') { yyerror("origin-set filter already specified"); free((yyvsp[0].v.string)); YYERROR; } if (find_prefixset((yyvsp[0].v.string), &conf->originsets) == NULL) { yyerror("origin-set '%s' not defined", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } if (strlcpy(fmopts.m.originset.name, (yyvsp[0].v.string), sizeof(fmopts.m.originset.name)) >= sizeof(fmopts.m.originset.name)) { yyerror("origin-set name too long"); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 6281 "parse.c" break; case 352: /* filter_elm: OVS validity */ #line 3010 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.m.ovs.is_set) { yyerror("ovs filter already specified"); YYERROR; } fmopts.m.ovs.validity = (yyvsp[0].v.number); fmopts.m.ovs.is_set = 1; } #line 6294 "parse.c" break; case 353: /* filter_elm: AVS aspa_validity */ #line 3018 "../../../openbgpd-portable/src/bgpd/parse.y" { if (fmopts.m.avs.is_set) { yyerror("avs filter already specified"); YYERROR; } fmopts.m.avs.validity = (yyvsp[0].v.number); fmopts.m.avs.is_set = 1; } #line 6307 "parse.c" break; case 354: /* prefixlenop: %empty */ #line 3028 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.prefixlen), 0, sizeof((yyval.v.prefixlen))); } #line 6313 "parse.c" break; case 355: /* prefixlenop: LONGER */ #line 3029 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.prefixlen), 0, sizeof((yyval.v.prefixlen))); (yyval.v.prefixlen).op = OP_RANGE; (yyval.v.prefixlen).len_min = -1; (yyval.v.prefixlen).len_max = -1; } #line 6324 "parse.c" break; case 356: /* prefixlenop: MAXLEN NUMBER */ #line 3035 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.prefixlen), 0, sizeof((yyval.v.prefixlen))); if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) { yyerror("prefixlen must be >= 0 and <= 128"); YYERROR; } (yyval.v.prefixlen).op = OP_RANGE; (yyval.v.prefixlen).len_min = -1; (yyval.v.prefixlen).len_max = (yyvsp[0].v.number); } #line 6340 "parse.c" break; case 357: /* prefixlenop: PREFIXLEN unaryop NUMBER */ #line 3046 "../../../openbgpd-portable/src/bgpd/parse.y" { int min, max; memset(&(yyval.v.prefixlen), 0, sizeof((yyval.v.prefixlen))); if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) { yyerror("prefixlen must be >= 0 and <= 128"); YYERROR; } /* * convert the unary operation into the equivalent * range check */ (yyval.v.prefixlen).op = OP_RANGE; switch ((yyvsp[-1].v.u8)) { case OP_NE: (yyval.v.prefixlen).op = (yyvsp[-1].v.u8); case OP_EQ: min = max = (yyvsp[0].v.number); break; case OP_LT: if ((yyvsp[0].v.number) == 0) { yyerror("prefixlen must be > 0"); YYERROR; } (yyvsp[0].v.number) -= 1; case OP_LE: min = -1; max = (yyvsp[0].v.number); break; case OP_GT: (yyvsp[0].v.number) += 1; case OP_GE: min = (yyvsp[0].v.number); max = -1; break; default: yyerror("unknown prefixlen operation"); YYERROR; } (yyval.v.prefixlen).len_min = min; (yyval.v.prefixlen).len_max = max; } #line 6388 "parse.c" break; case 358: /* prefixlenop: PREFIXLEN NUMBER binaryop NUMBER */ #line 3089 "../../../openbgpd-portable/src/bgpd/parse.y" { memset(&(yyval.v.prefixlen), 0, sizeof((yyval.v.prefixlen))); if ((yyvsp[-2].v.number) < 0 || (yyvsp[-2].v.number) > 128 || (yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) { yyerror("prefixlen must be < 128"); YYERROR; } if ((yyvsp[-2].v.number) > (yyvsp[0].v.number)) { yyerror("start prefixlen is bigger than end"); YYERROR; } (yyval.v.prefixlen).op = (yyvsp[-1].v.u8); (yyval.v.prefixlen).len_min = (yyvsp[-2].v.number); (yyval.v.prefixlen).len_max = (yyvsp[0].v.number); } #line 6407 "parse.c" break; case 359: /* filter_as_type: AS */ #line 3105 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = AS_ALL; } #line 6413 "parse.c" break; case 360: /* filter_as_type: SOURCEAS */ #line 3106 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = AS_SOURCE; } #line 6419 "parse.c" break; case 361: /* filter_as_type: TRANSITAS */ #line 3107 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = AS_TRANSIT; } #line 6425 "parse.c" break; case 362: /* filter_as_type: PEERAS */ #line 3108 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = AS_PEER; } #line 6431 "parse.c" break; case 363: /* filter_set: %empty */ #line 3111 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_set_head) = NULL; } #line 6437 "parse.c" break; case 364: /* filter_set: SET filter_set_opt */ #line 3112 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set_head) = calloc(1, sizeof(struct filter_set_head))) == NULL) fatal(NULL); TAILQ_INIT((yyval.v.filter_set_head)); TAILQ_INSERT_TAIL((yyval.v.filter_set_head), (yyvsp[0].v.filter_set), entry); } #line 6449 "parse.c" break; case 365: /* filter_set: SET '{' optnl filter_set_l optnl '}' */ #line 3119 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_set_head) = (yyvsp[-2].v.filter_set_head); } #line 6455 "parse.c" break; case 366: /* filter_set_l: filter_set_l comma filter_set_opt */ #line 3122 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.filter_set_head) = (yyvsp[-2].v.filter_set_head); if (merge_filterset((yyval.v.filter_set_head), (yyvsp[0].v.filter_set)) == 1) YYERROR; } #line 6465 "parse.c" break; case 367: /* filter_set_l: filter_set_opt */ #line 3127 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set_head) = calloc(1, sizeof(struct filter_set_head))) == NULL) fatal(NULL); TAILQ_INIT((yyval.v.filter_set_head)); TAILQ_INSERT_TAIL((yyval.v.filter_set_head), (yyvsp[0].v.filter_set), entry); } #line 6477 "parse.c" break; case 368: /* community: COMMUNITY */ #line 3136 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = COMMUNITY_TYPE_BASIC; } #line 6483 "parse.c" break; case 369: /* community: LARGECOMMUNITY */ #line 3137 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = COMMUNITY_TYPE_LARGE; } #line 6489 "parse.c" break; case 370: /* delete: %empty */ #line 3140 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = 0; } #line 6495 "parse.c" break; case 371: /* delete: DELETE */ #line 3141 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = 1; } #line 6501 "parse.c" break; case 372: /* enforce: %empty */ #line 3144 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 0; } #line 6507 "parse.c" break; case 373: /* enforce: ENFORCE */ #line 3145 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 2; } #line 6513 "parse.c" break; case 374: /* yesnoenforce: yesno */ #line 3148 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = (yyvsp[0].v.number); } #line 6519 "parse.c" break; case 375: /* yesnoenforce: ENFORCE */ #line 3149 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.number) = 2; } #line 6525 "parse.c" break; case 376: /* filter_set_opt: LOCALPREF NUMBER */ #line 3152 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) { yyerror("bad localpref %lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ((yyvsp[0].v.number) >= 0) { (yyval.v.filter_set)->type = ACTION_SET_LOCALPREF; (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number); } else { (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_LOCALPREF; (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number); } } #line 6545 "parse.c" break; case 377: /* filter_set_opt: LOCALPREF '+' NUMBER */ #line 3167 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad localpref +%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_LOCALPREF; (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number); } #line 6560 "parse.c" break; case 378: /* filter_set_opt: LOCALPREF '-' NUMBER */ #line 3177 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad localpref -%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_LOCALPREF; (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number); } #line 6575 "parse.c" break; case 379: /* filter_set_opt: MED NUMBER */ #line 3187 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) { yyerror("bad metric %lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ((yyvsp[0].v.number) >= 0) { (yyval.v.filter_set)->type = ACTION_SET_MED; (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number); } else { (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED; (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number); } } #line 6595 "parse.c" break; case 380: /* filter_set_opt: MED '+' NUMBER */ #line 3202 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad metric +%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED; (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number); } #line 6610 "parse.c" break; case 381: /* filter_set_opt: MED '-' NUMBER */ #line 3212 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad metric -%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED; (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number); } #line 6625 "parse.c" break; case 382: /* filter_set_opt: METRIC NUMBER */ #line 3222 "../../../openbgpd-portable/src/bgpd/parse.y" { /* alias for MED */ if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) { yyerror("bad metric %lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ((yyvsp[0].v.number) >= 0) { (yyval.v.filter_set)->type = ACTION_SET_MED; (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number); } else { (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED; (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number); } } #line 6645 "parse.c" break; case 383: /* filter_set_opt: METRIC '+' NUMBER */ #line 3237 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad metric +%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED; (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number); } #line 6660 "parse.c" break; case 384: /* filter_set_opt: METRIC '-' NUMBER */ #line 3247 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad metric -%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED; (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number); } #line 6675 "parse.c" break; case 385: /* filter_set_opt: WEIGHT NUMBER */ #line 3257 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) { yyerror("bad weight %lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ((yyvsp[0].v.number) > 0) { (yyval.v.filter_set)->type = ACTION_SET_WEIGHT; (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number); } else { (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_WEIGHT; (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number); } } #line 6695 "parse.c" break; case 386: /* filter_set_opt: WEIGHT '+' NUMBER */ #line 3272 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad weight +%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_WEIGHT; (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number); } #line 6710 "parse.c" break; case 387: /* filter_set_opt: WEIGHT '-' NUMBER */ #line 3282 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) { yyerror("bad weight -%lld", (yyvsp[0].v.number)); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_WEIGHT; (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number); } #line 6725 "parse.c" break; case 388: /* filter_set_opt: NEXTHOP address */ #line 3292 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP; memcpy(&(yyval.v.filter_set)->action.nexthop, &(yyvsp[0].v.addr), sizeof((yyval.v.filter_set)->action.nexthop)); } #line 6737 "parse.c" break; case 389: /* filter_set_opt: NEXTHOP BLACKHOLE */ #line 3299 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_BLACKHOLE; } #line 6747 "parse.c" break; case 390: /* filter_set_opt: NEXTHOP REJECT */ #line 3304 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_REJECT; } #line 6757 "parse.c" break; case 391: /* filter_set_opt: NEXTHOP NOMODIFY */ #line 3309 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_NOMODIFY; } #line 6767 "parse.c" break; case 392: /* filter_set_opt: NEXTHOP SELF */ #line 3314 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_SELF; } #line 6777 "parse.c" break; case 393: /* filter_set_opt: PREPEND_SELF NUMBER */ #line 3319 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) { yyerror("bad number of prepends"); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_PREPEND_SELF; (yyval.v.filter_set)->action.prepend = (yyvsp[0].v.number); } #line 6792 "parse.c" break; case 394: /* filter_set_opt: PREPEND_PEER NUMBER */ #line 3329 "../../../openbgpd-portable/src/bgpd/parse.y" { if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) { yyerror("bad number of prepends"); YYERROR; } if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_PREPEND_PEER; (yyval.v.filter_set)->action.prepend = (yyvsp[0].v.number); } #line 6807 "parse.c" break; case 395: /* filter_set_opt: ASOVERRIDE */ #line 3339 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_AS_OVERRIDE; } #line 6817 "parse.c" break; case 396: /* filter_set_opt: PFTABLE STRING */ #line 3344 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_PFTABLE; if (!(cmd_opts & BGPD_OPT_NOACTION) && pftable_exists((yyvsp[0].v.string)) != 0) { yyerror("pftable name does not exist"); free((yyvsp[0].v.string)); free((yyval.v.filter_set)); YYERROR; } if (strlcpy((yyval.v.filter_set)->action.pftable, (yyvsp[0].v.string), sizeof((yyval.v.filter_set)->action.pftable)) >= sizeof((yyval.v.filter_set)->action.pftable)) { yyerror("pftable name too long"); free((yyvsp[0].v.string)); free((yyval.v.filter_set)); YYERROR; } if (pftable_add((yyvsp[0].v.string)) != 0) { yyerror("Couldn't register table"); free((yyvsp[0].v.string)); free((yyval.v.filter_set)); YYERROR; } free((yyvsp[0].v.string)); } #line 6849 "parse.c" break; case 397: /* filter_set_opt: RTLABEL STRING */ #line 3371 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_RTLABEL; if (strlcpy((yyval.v.filter_set)->action.rtlabel, (yyvsp[0].v.string), sizeof((yyval.v.filter_set)->action.rtlabel)) >= sizeof((yyval.v.filter_set)->action.rtlabel)) { yyerror("rtlabel name too long"); free((yyvsp[0].v.string)); free((yyval.v.filter_set)); YYERROR; } free((yyvsp[0].v.string)); } #line 6868 "parse.c" break; case 398: /* filter_set_opt: community delete STRING */ #line 3385 "../../../openbgpd-portable/src/bgpd/parse.y" { uint8_t f1, f2, f3; if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ((yyvsp[-1].v.u8)) (yyval.v.filter_set)->type = ACTION_DEL_COMMUNITY; else (yyval.v.filter_set)->type = ACTION_SET_COMMUNITY; if (parsecommunity(&(yyval.v.filter_set)->action.community, (yyvsp[-2].v.u8), (yyvsp[0].v.string)) == -1) { free((yyvsp[0].v.string)); free((yyval.v.filter_set)); YYERROR; } free((yyvsp[0].v.string)); /* Don't allow setting of any match */ f1 = (yyval.v.filter_set)->action.community.flags >> 8; f2 = (yyval.v.filter_set)->action.community.flags >> 16; f3 = (yyval.v.filter_set)->action.community.flags >> 24; if (!(yyvsp[-1].v.u8) && (f1 == COMMUNITY_ANY || f2 == COMMUNITY_ANY || f3 == COMMUNITY_ANY)) { yyerror("'*' is not allowed in set community"); free((yyval.v.filter_set)); YYERROR; } } #line 6901 "parse.c" break; case 399: /* filter_set_opt: EXTCOMMUNITY delete STRING STRING */ #line 3413 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ((yyvsp[-2].v.u8)) (yyval.v.filter_set)->type = ACTION_DEL_COMMUNITY; else (yyval.v.filter_set)->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&(yyval.v.filter_set)->action.community, (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) { free((yyvsp[-1].v.string)); free((yyvsp[0].v.string)); free((yyval.v.filter_set)); YYERROR; } free((yyvsp[-1].v.string)); free((yyvsp[0].v.string)); } #line 6924 "parse.c" break; case 400: /* filter_set_opt: EXTCOMMUNITY delete OVS STRING */ #line 3431 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ((yyvsp[-2].v.u8)) (yyval.v.filter_set)->type = ACTION_DEL_COMMUNITY; else (yyval.v.filter_set)->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&(yyval.v.filter_set)->action.community, "ovs", (yyvsp[0].v.string)) == -1) { free((yyvsp[0].v.string)); free((yyval.v.filter_set)); YYERROR; } free((yyvsp[0].v.string)); } #line 6945 "parse.c" break; case 401: /* filter_set_opt: ORIGIN origincode */ #line 3447 "../../../openbgpd-portable/src/bgpd/parse.y" { if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); (yyval.v.filter_set)->type = ACTION_SET_ORIGIN; (yyval.v.filter_set)->action.origin = (yyvsp[0].v.number); } #line 6956 "parse.c" break; case 402: /* origincode: STRING */ #line 3455 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "egp")) (yyval.v.number) = ORIGIN_EGP; else if (!strcmp((yyvsp[0].v.string), "igp")) (yyval.v.number) = ORIGIN_IGP; else if (!strcmp((yyvsp[0].v.string), "incomplete")) (yyval.v.number) = ORIGIN_INCOMPLETE; else { yyerror("unknown origin \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 6975 "parse.c" break; case 403: /* validity: STRING */ #line 3470 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "not-found")) (yyval.v.number) = ROA_NOTFOUND; else if (!strcmp((yyvsp[0].v.string), "invalid")) (yyval.v.number) = ROA_INVALID; else if (!strcmp((yyvsp[0].v.string), "valid")) (yyval.v.number) = ROA_VALID; else { yyerror("unknown roa validity \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 6994 "parse.c" break; case 404: /* aspa_validity: STRING */ #line 3485 "../../../openbgpd-portable/src/bgpd/parse.y" { if (!strcmp((yyvsp[0].v.string), "unknown")) (yyval.v.number) = ASPA_UNKNOWN; else if (!strcmp((yyvsp[0].v.string), "invalid")) (yyval.v.number) = ASPA_INVALID; else if (!strcmp((yyvsp[0].v.string), "valid")) (yyval.v.number) = ASPA_VALID; else { yyerror("unknown aspa validity \"%s\"", (yyvsp[0].v.string)); free((yyvsp[0].v.string)); YYERROR; } free((yyvsp[0].v.string)); } #line 7013 "parse.c" break; case 411: /* unaryop: '=' */ #line 3510 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_EQ; } #line 7019 "parse.c" break; case 412: /* unaryop: NE */ #line 3511 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_NE; } #line 7025 "parse.c" break; case 413: /* unaryop: LE */ #line 3512 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_LE; } #line 7031 "parse.c" break; case 414: /* unaryop: '<' */ #line 3513 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_LT; } #line 7037 "parse.c" break; case 415: /* unaryop: GE */ #line 3514 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_GE; } #line 7043 "parse.c" break; case 416: /* unaryop: '>' */ #line 3515 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_GT; } #line 7049 "parse.c" break; case 417: /* equalityop: '=' */ #line 3518 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_EQ; } #line 7055 "parse.c" break; case 418: /* equalityop: NE */ #line 3519 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_NE; } #line 7061 "parse.c" break; case 419: /* binaryop: '-' */ #line 3522 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_RANGE; } #line 7067 "parse.c" break; case 420: /* binaryop: XRANGE */ #line 3523 "../../../openbgpd-portable/src/bgpd/parse.y" { (yyval.v.u8) = OP_XRANGE; } #line 7073 "parse.c" break; #line 7077 "parse.c" default: break; } /* User semantic actions sometimes alter yychar, and that requires that yytoken be updated with the new translation. We take the approach of translating immediately before every use of yytoken. One alternative is translating here after every semantic action, but that translation would be missed if the semantic action invokes YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an incorrect destructor might then be invoked immediately. In the case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; *++yyvsp = yyval; /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ { const int yylhs = yyr1[yyn] - YYNTOKENS; const int yyi = yypgoto[yylhs] + *yyssp; yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp ? yytable[yyi] : yydefgoto[yylhs]); } goto yynewstate; /*--------------------------------------. | yyerrlab -- here on detecting error. | `--------------------------------------*/ yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; yyerror (YY_("syntax error")); } if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: /* Pacify compilers when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (0) YYERROR; ++yynerrs; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { yyn += YYSYMBOL_YYerror; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; yydestruct ("Error: popping", YY_ACCESSING_SYMBOL (yystate), yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturnlab; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturnlab; /*-----------------------------------------------------------. | yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. | `-----------------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; goto yyreturnlab; /*----------------------------------------------------------. | yyreturnlab -- parsing is finished, clean up and return. | `----------------------------------------------------------*/ yyreturnlab: if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif return yyresult; } #line 3526 "../../../openbgpd-portable/src/bgpd/parse.y" struct keywords { const char *k_name; int k_val; }; int yyerror(const char *fmt, ...) { va_list ap; char *msg; file->errors++; va_start(ap, fmt); if (vasprintf(&msg, fmt, ap) == -1) fatalx("yyerror vasprintf"); va_end(ap); logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg); free(msg); return (0); } int kw_cmp(const void *k, const void *e) { return (strcmp(k, ((const struct keywords *)e)->k_name)); } int lookup(char *s) { /* this has to be sorted always */ static const struct keywords keywords[] = { { "AS", AS }, { "EVPN", EVPN }, { "IPv4", IPV4 }, { "IPv6", IPV6 }, { "add-path", ADDPATH }, { "ah", AH }, { "allow", ALLOW }, { "announce", ANNOUNCE }, { "any", ANY }, { "as-4byte", AS4BYTE }, { "as-override", ASOVERRIDE }, { "as-set", ASSET }, { "aspa-set", ASPASET }, { "avs", AVS }, { "blackhole", BLACKHOLE }, { "community", COMMUNITY }, { "compare", COMPARE }, { "connect-retry", CONNECTRETRY }, { "connected", CONNECTED }, { "customer-as", CUSTOMERAS }, { "default-route", DEFAULTROUTE }, { "delete", DELETE }, { "demote", DEMOTE }, { "deny", DENY }, { "depend", DEPEND }, { "descr", DESCR }, { "down", DOWN }, { "dump", DUMP }, { "ebgp", EBGP }, { "enforce", ENFORCE }, { "enhanced", ENHANCED }, { "esp", ESP }, { "evaluate", EVALUATE }, { "expires", EXPIRES }, { "export", EXPORT }, { "export-target", EXPORTTRGT }, { "ext-community", EXTCOMMUNITY }, { "extended", EXTENDED }, { "fib-priority", FIBPRIORITY }, { "fib-update", FIBUPDATE }, { "filtered", FILTERED }, { "flags", FLAGS }, { "flowspec", FLOWSPEC }, { "fragment", FRAGMENT }, { "from", FROM }, { "graceful", GRACEFUL }, { "group", GROUP }, { "holdtime", HOLDTIME }, { "ibgp", IBGP }, { "ignore", IGNORE }, { "ike", IKE }, { "import-target", IMPORTTRGT }, { "in", IN }, { "include", INCLUDE }, { "inet", IPV4 }, { "inet6", IPV6 }, { "ipsec", IPSEC }, { "key", KEY }, { "large-community", LARGECOMMUNITY }, { "listen", LISTEN }, { "local-address", LOCALADDR }, { "local-as", LOCALAS }, { "localpref", LOCALPREF }, { "log", LOG }, { "match", MATCH }, { "max", MAX }, { "max-as-len", MAXASLEN }, { "max-as-seq", MAXASSEQ }, { "max-communities", MAXCOMMUNITIES }, { "max-ext-communities", MAXEXTCOMMUNITIES }, { "max-large-communities", MAXLARGECOMMUNITIES }, { "max-prefix", MAXPREFIX }, { "maxlen", MAXLEN }, { "md5sig", MD5SIG }, { "med", MED }, { "message", MESSAGE }, { "metric", METRIC }, { "min", YMIN }, { "min-version", MINVERSION }, { "multihop", MULTIHOP }, { "neighbor", NEIGHBOR }, { "neighbor-as", NEIGHBORAS }, { "network", NETWORK }, { "nexthop", NEXTHOP }, { "no-modify", NOMODIFY }, { "none", NONE }, { "notification", NOTIFICATION }, { "on", ON }, { "or-longer", LONGER }, { "origin", ORIGIN }, { "origin-set", ORIGINSET }, { "out", OUT }, { "ovs", OVS }, { "passive", PASSIVE }, { "password", PASSWORD }, { "peer-as", PEERAS }, { "pftable", PFTABLE }, { "plus", PLUS }, { "policy", POLICY }, { "port", PORT }, { "prefix", PREFIX }, { "prefix-set", PREFIXSET }, { "prefixlen", PREFIXLEN }, { "prepend-neighbor", PREPEND_PEER }, { "prepend-self", PREPEND_SELF }, { "priority", PRIORITY }, { "proto", PROTO }, { "provider-as", PROVIDERAS }, { "qualify", QUALIFY }, { "quick", QUICK }, { "rd", RD }, { "rde", RDE }, { "recv", RECV }, { "refresh", REFRESH }, { "reject", REJECT }, { "remote-as", REMOTEAS }, { "restart", RESTART }, { "restricted", RESTRICTED }, { "rib", RIB }, { "roa-set", ROASET }, { "role", ROLE }, { "route-reflector", REFLECTOR }, { "router-id", ROUTERID }, { "rtable", RTABLE }, { "rtlabel", RTLABEL }, { "rtr", RTR }, { "self", SELF }, { "send", SEND }, { "set", SET }, { "socket", SOCKET }, { "source-as", SOURCEAS }, { "spi", SPI }, { "staletime", STALETIME }, { "static", STATIC }, { "tcp", TCP }, { "to", TO }, { "tos", TOS }, { "transit-as", TRANSITAS }, { "transparent-as", TRANSPARENT }, { "ttl-security", TTLSECURITY }, { "unicast", UNICAST }, { "via", VIA }, { "vpn", VPN }, { "weight", WEIGHT }, }; const struct keywords *p; p = bsearch(s, keywords, nitems(keywords), sizeof(keywords[0]), kw_cmp); if (p) return (p->k_val); else return (STRING); } #define START_EXPAND 1 #define DONE_EXPAND 2 static int expanding; int igetc(void) { int c; while (1) { if (file->ungetpos > 0) c = file->ungetbuf[--file->ungetpos]; else c = getc(file->stream); if (c == START_EXPAND) expanding = 1; else if (c == DONE_EXPAND) expanding = 0; else break; } return (c); } int lgetc(int quotec) { int c, next; if (quotec) { if ((c = igetc()) == EOF) { yyerror("reached end of file while parsing " "quoted string"); if (file == topfile || popfile() == EOF) return (EOF); return (quotec); } return (c); } while ((c = igetc()) == '\\') { next = igetc(); if (next != '\n') { c = next; break; } yylval.lineno = file->lineno; file->lineno++; } if (c == EOF) { /* * Fake EOL when hit EOF for the first time. This gets line * count right if last line in included file is syntactically * invalid and has no newline. */ if (file->eof_reached == 0) { file->eof_reached = 1; return ('\n'); } while (c == EOF) { if (file == topfile || popfile() == EOF) return (EOF); c = igetc(); } } return (c); } void lungetc(int c) { if (c == EOF) return; if (file->ungetpos >= file->ungetsize) { void *p = reallocarray(file->ungetbuf, file->ungetsize, 2); if (p == NULL) err(1, "lungetc"); file->ungetbuf = p; file->ungetsize *= 2; } file->ungetbuf[file->ungetpos++] = c; } int findeol(void) { int c; /* skip to either EOF or the first real EOL */ while (1) { c = lgetc(0); if (c == '\n') { file->lineno++; break; } if (c == EOF) break; } return (ERROR); } int expand_macro(void) { char buf[MACRO_NAME_LEN]; char *p, *val; int c; p = buf; while (1) { if ((c = lgetc('$')) == EOF) return (ERROR); if (p + 1 >= buf + sizeof(buf) - 1) { yyerror("macro name too long"); return (ERROR); } if (isalnum(c) || c == '_') { *p++ = c; continue; } *p = '\0'; lungetc(c); break; } val = symget(buf); if (val == NULL) { yyerror("macro '%s' not defined", buf); return (ERROR); } p = val + strlen(val) - 1; lungetc(DONE_EXPAND); while (p >= val) { lungetc((unsigned char)*p); p--; } lungetc(START_EXPAND); return (0); } int yylex(void) { char buf[8096]; char *p; int quotec, next, c; int token; top: p = buf; while ((c = lgetc(0)) == ' ' || c == '\t') ; /* nothing */ yylval.lineno = file->lineno; if (c == '#') while ((c = lgetc(0)) != '\n' && c != EOF) ; /* nothing */ if (c == '$' && !expanding) { c = expand_macro(); if (c != 0) return (c); goto top; } switch (c) { case '\'': case '"': quotec = c; while (1) { if ((c = lgetc(quotec)) == EOF) return (0); if (c == '\n') { file->lineno++; continue; } else if (c == '\\') { if ((next = lgetc(quotec)) == EOF) return (0); if (next == quotec || next == ' ' || next == '\t') c = next; else if (next == '\n') { file->lineno++; continue; } else lungetc(next); } else if (c == quotec) { *p = '\0'; break; } else if (c == '\0') { yyerror("syntax error: unterminated quote"); return (findeol()); } if (p + 1 >= buf + sizeof(buf) - 1) { yyerror("string too long"); return (findeol()); } *p++ = c; } yylval.v.string = strdup(buf); if (yylval.v.string == NULL) fatal("yylex: strdup"); return (STRING); case '!': next = lgetc(0); if (next == '=') return (NE); lungetc(next); break; case '<': next = lgetc(0); if (next == '=') return (LE); lungetc(next); break; case '>': next = lgetc(0); if (next == '<') return (XRANGE); else if (next == '=') return (GE); lungetc(next); break; } #define allowed_to_end_number(x) \ (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') if (c == '-' || isdigit(c)) { do { *p++ = c; if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } } while ((c = lgetc(0)) != EOF && isdigit(c)); lungetc(c); if (p == buf + 1 && buf[0] == '-') goto nodigits; if (c == EOF || allowed_to_end_number(c)) { const char *errstr = NULL; *p = '\0'; yylval.v.number = strtonum(buf, LLONG_MIN, LLONG_MAX, &errstr); if (errstr) { yyerror("\"%s\" invalid number: %s", buf, errstr); return (findeol()); } return (NUMBER); } else { nodigits: while (p > buf + 1) lungetc((unsigned char)*--p); c = (unsigned char)*--p; if (c == '-') return (c); } } #define allowed_in_string(x) \ (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ x != '{' && x != '}' && x != '<' && x != '>' && \ x != '!' && x != '=' && x != '/' && x != '#' && \ x != ',')) if (isalnum(c) || c == ':' || c == '_' || c == '*') { do { if (c == '$' && !expanding) { c = expand_macro(); if (c != 0) return (c); } else *p++ = c; if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } } while ((c = lgetc(0)) != EOF && (allowed_in_string(c))); lungetc(c); *p = '\0'; if ((token = lookup(buf)) == STRING) if ((yylval.v.string = strdup(buf)) == NULL) fatal("yylex: strdup"); return (token); } if (c == '\n') { yylval.lineno = file->lineno; file->lineno++; } if (c == EOF) return (0); return (c); } int check_file_secrecy(int fd, const char *fname) { struct stat st; if (fstat(fd, &st)) { log_warn("cannot stat %s", fname); return (-1); } return (0); } struct file * pushfile(const char *name, int secret) { struct file *nfile; if ((nfile = calloc(1, sizeof(struct file))) == NULL) { log_warn("%s", __func__); return (NULL); } if ((nfile->name = strdup(name)) == NULL) { log_warn("%s", __func__); free(nfile); return (NULL); } if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { log_warn("%s: %s", __func__, nfile->name); free(nfile->name); free(nfile); return (NULL); } if (secret && check_file_secrecy(fileno(nfile->stream), nfile->name)) { fclose(nfile->stream); free(nfile->name); free(nfile); return (NULL); } nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0; nfile->ungetsize = 16; nfile->ungetbuf = malloc(nfile->ungetsize); if (nfile->ungetbuf == NULL) { log_warn("%s", __func__); fclose(nfile->stream); free(nfile->name); free(nfile); return (NULL); } TAILQ_INSERT_TAIL(&files, nfile, entry); return (nfile); } int popfile(void) { struct file *prev; if ((prev = TAILQ_PREV(file, files, entry)) != NULL) prev->errors += file->errors; TAILQ_REMOVE(&files, file, entry); fclose(file->stream); free(file->name); free(file->ungetbuf); free(file); file = prev; return (file ? 0 : EOF); } static void init_config(struct bgpd_config *c) { u_int rdomid; c->min_holdtime = MIN_HOLDTIME; c->holdtime = INTERVAL_HOLD; c->staletime = INTERVAL_STALE; c->connectretry = INTERVAL_CONNECTRETRY; c->bgpid = get_bgpid(); c->fib_priority = kr_default_prio(); c->default_tableid = getrtable(); if (!ktable_exists(c->default_tableid, &rdomid)) fatalx("current routing table %u does not exist", c->default_tableid); if (rdomid != c->default_tableid) fatalx("current routing table %u is not a routing domain", c->default_tableid); if (asprintf(&c->csock, "%s.%d", SOCKET_NAME, c->default_tableid) == -1) fatal(NULL); } struct bgpd_config * parse_config(char *filename, struct peer_head *ph, struct rtr_config_head *rh) { struct sym *sym, *next; struct rde_rib *rr; struct network *n; int errors = 0; conf = new_config(); init_config(conf); if ((filter_l = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); if ((peerfilter_l = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); if ((groupfilter_l = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); TAILQ_INIT(filter_l); TAILQ_INIT(peerfilter_l); TAILQ_INIT(groupfilter_l); curpeer = NULL; curgroup = NULL; cur_peers = ph; cur_rtrs = rh; new_peers = &conf->peers; netconf = &conf->networks; if ((rr = add_rib("Adj-RIB-In")) == NULL) fatal("add_rib failed"); rr->flags = F_RIB_NOFIB | F_RIB_NOEVALUATE; if ((rr = add_rib("Loc-RIB")) == NULL) fatal("add_rib failed"); rib_add_fib(rr, conf->default_tableid); rr->flags = F_RIB_LOCAL; if ((file = pushfile(filename, 1)) == NULL) goto errors; topfile = file; yyparse(); errors = file->errors; popfile(); /* check that we dont try to announce our own routes */ TAILQ_FOREACH(n, netconf, entry) if (n->net.priority == conf->fib_priority) { errors++; logit(LOG_CRIT, "network priority %d == fib-priority " "%d is not allowed.", n->net.priority, conf->fib_priority); } /* Free macros and check which have not been used. */ TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) { if ((cmd_opts & BGPD_OPT_VERBOSE2) && !sym->used) fprintf(stderr, "warning: macro \"%s\" not " "used\n", sym->nam); if (!sym->persist) { free(sym->nam); free(sym->val); TAILQ_REMOVE(&symhead, sym, entry); free(sym); } } if (!conf->as) { log_warnx("configuration error: AS not given"); errors++; } /* clear the globals */ curpeer = NULL; curgroup = NULL; cur_peers = NULL; new_peers = NULL; netconf = NULL; curflow = NULL; if (errors) { errors: while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) { SIMPLEQ_REMOVE_HEAD(&ribnames, entry); free(rr); } filterlist_free(filter_l); filterlist_free(peerfilter_l); filterlist_free(groupfilter_l); free_config(conf); return (NULL); } /* Create default listeners if none where specified. */ if (TAILQ_EMPTY(conf->listen_addrs)) { struct listen_addr *la; if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("setup_listeners calloc"); la->fd = -1; la->flags = DEFAULT_LISTENER; la->reconf = RECONF_REINIT; la->sa_len = sizeof(struct sockaddr_in); ((struct sockaddr_in *)&la->sa)->sin_family = AF_INET; ((struct sockaddr_in *)&la->sa)->sin_addr.s_addr = htonl(INADDR_ANY); ((struct sockaddr_in *)&la->sa)->sin_port = htons(BGP_PORT); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("setup_listeners calloc"); la->fd = -1; la->flags = DEFAULT_LISTENER; la->reconf = RECONF_REINIT; la->sa_len = sizeof(struct sockaddr_in6); ((struct sockaddr_in6 *)&la->sa)->sin6_family = AF_INET6; ((struct sockaddr_in6 *)&la->sa)->sin6_port = htons(BGP_PORT); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); } /* update clusterid in case it was not set explicitly */ if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid == 0) conf->clusterid = conf->bgpid; /* * Concatenate filter list and static group and peer filtersets * together. Static group sets come first then peer sets * last normal filter rules. */ TAILQ_CONCAT(conf->filters, groupfilter_l, entry); TAILQ_CONCAT(conf->filters, peerfilter_l, entry); TAILQ_CONCAT(conf->filters, filter_l, entry); optimize_filters(conf->filters); free(filter_l); free(peerfilter_l); free(groupfilter_l); return (conf); } int symset(const char *nam, const char *val, int persist) { struct sym *sym; TAILQ_FOREACH(sym, &symhead, entry) { if (strcmp(nam, sym->nam) == 0) break; } if (sym != NULL) { if (sym->persist == 1) return (0); else { free(sym->nam); free(sym->val); TAILQ_REMOVE(&symhead, sym, entry); free(sym); } } if ((sym = calloc(1, sizeof(*sym))) == NULL) return (-1); sym->nam = strdup(nam); if (sym->nam == NULL) { free(sym); return (-1); } sym->val = strdup(val); if (sym->val == NULL) { free(sym->nam); free(sym); return (-1); } sym->used = 0; sym->persist = persist; TAILQ_INSERT_TAIL(&symhead, sym, entry); return (0); } int cmdline_symset(char *s) { char *sym, *val; int ret; if ((val = strrchr(s, '=')) == NULL) return (-1); sym = strndup(s, val - s); if (sym == NULL) fatal("%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); return (ret); } char * symget(const char *nam) { struct sym *sym; TAILQ_FOREACH(sym, &symhead, entry) { if (strcmp(nam, sym->nam) == 0) { sym->used = 1; return (sym->val); } } return (NULL); } static int cmpcommunity(struct community *a, struct community *b) { if (a->flags > b->flags) return 1; if (a->flags < b->flags) return -1; if (a->data1 > b->data1) return 1; if (a->data1 < b->data1) return -1; if (a->data2 > b->data2) return 1; if (a->data2 < b->data2) return -1; if (a->data3 > b->data3) return 1; if (a->data3 < b->data3) return -1; return 0; } static int getcommunity(char *s, int large, uint32_t *val, uint32_t *flag) { long long max = USHRT_MAX; const char *errstr; *flag = 0; *val = 0; if (strcmp(s, "*") == 0) { *flag = COMMUNITY_ANY; return 0; } else if (strcmp(s, "neighbor-as") == 0) { *flag = COMMUNITY_NEIGHBOR_AS; return 0; } else if (strcmp(s, "local-as") == 0) { *flag = COMMUNITY_LOCAL_AS; return 0; } if (large) max = UINT_MAX; *val = strtonum(s, 0, max, &errstr); if (errstr) { yyerror("Community %s is %s (max: %lld)", s, errstr, max); return -1; } return 0; } static void setcommunity(struct community *c, uint32_t as, uint32_t data, uint32_t asflag, uint32_t dataflag) { c->flags = COMMUNITY_TYPE_BASIC; c->flags |= asflag << 8; c->flags |= dataflag << 16; c->data1 = as; c->data2 = data; c->data3 = 0; } static int parselargecommunity(struct community *c, char *s) { char *p, *q; uint32_t dflag1, dflag2, dflag3; if ((p = strchr(s, ':')) == NULL) { yyerror("Bad community syntax"); return (-1); } *p++ = 0; if ((q = strchr(p, ':')) == NULL) { yyerror("Bad community syntax"); return (-1); } *q++ = 0; if (getcommunity(s, 1, &c->data1, &dflag1) == -1 || getcommunity(p, 1, &c->data2, &dflag2) == -1 || getcommunity(q, 1, &c->data3, &dflag3) == -1) return (-1); c->flags = COMMUNITY_TYPE_LARGE; c->flags |= dflag1 << 8; c->flags |= dflag2 << 16; c->flags |= dflag3 << 24; return (0); } int parsecommunity(struct community *c, int type, char *s) { char *p; uint32_t as, data, asflag, dataflag; if (type == COMMUNITY_TYPE_LARGE) return parselargecommunity(c, s); /* Well-known communities */ if (strcasecmp(s, "GRACEFUL_SHUTDOWN") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_GRACEFUL_SHUTDOWN, 0, 0); return (0); } else if (strcasecmp(s, "NO_EXPORT") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPORT, 0, 0); return (0); } else if (strcasecmp(s, "NO_ADVERTISE") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_ADVERTISE, 0, 0); return (0); } else if (strcasecmp(s, "NO_EXPORT_SUBCONFED") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPSUBCONFED, 0, 0); return (0); } else if (strcasecmp(s, "NO_PEER") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_PEER, 0, 0); return (0); } else if (strcasecmp(s, "BLACKHOLE") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_BLACKHOLE, 0, 0); return (0); } if ((p = strchr(s, ':')) == NULL) { yyerror("Bad community syntax"); return (-1); } *p++ = 0; if (getcommunity(s, 0, &as, &asflag) == -1 || getcommunity(p, 0, &data, &dataflag) == -1) return (-1); setcommunity(c, as, data, asflag, dataflag); return (0); } static int parsesubtype(char *name, int *type, int *subtype) { const struct ext_comm_pairs *cp; int found = 0; for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if (strcmp(name, cp->subname) == 0) { if (found == 0) { *type = cp->type; *subtype = cp->subtype; } found++; } } if (found > 1) *type = -1; return (found); } static int parseextvalue(int type, char *s, uint32_t *v, uint32_t *flag) { const char *errstr; char *p; struct in_addr ip; uint32_t uvalh, uval; if (type != -1) { /* nothing */ } else if (strcmp(s, "neighbor-as") == 0) { *flag = COMMUNITY_NEIGHBOR_AS; *v = 0; return EXT_COMMUNITY_TRANS_TWO_AS; } else if (strcmp(s, "local-as") == 0) { *flag = COMMUNITY_LOCAL_AS; *v = 0; return EXT_COMMUNITY_TRANS_TWO_AS; } else if ((p = strchr(s, '.')) == NULL) { /* AS_PLAIN number (4 or 2 byte) */ strtonum(s, 0, USHRT_MAX, &errstr); if (errstr == NULL) type = EXT_COMMUNITY_TRANS_TWO_AS; else type = EXT_COMMUNITY_TRANS_FOUR_AS; } else if (strchr(p + 1, '.') == NULL) { /* AS_DOT number (4-byte) */ type = EXT_COMMUNITY_TRANS_FOUR_AS; } else { /* more than one dot -> IP address */ type = EXT_COMMUNITY_TRANS_IPV4; } switch (type & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: uval = strtonum(s, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", s, errstr); return (-1); } *v = uval; break; case EXT_COMMUNITY_TRANS_FOUR_AS: if ((p = strchr(s, '.')) == NULL) { uval = strtonum(s, 0, UINT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", s, errstr); return (-1); } *v = uval; break; } *p++ = '\0'; uvalh = strtonum(s, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", s, errstr); return (-1); } uval = strtonum(p, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", p, errstr); return (-1); } *v = uval | (uvalh << 16); break; case EXT_COMMUNITY_TRANS_IPV4: if (inet_pton(AF_INET, s, &ip) != 1) { yyerror("Bad ext-community %s not parseable", s); return (-1); } *v = ntohl(ip.s_addr); break; default: fatalx("%s: unexpected type %d", __func__, type); } return (type); } int parseextcommunity(struct community *c, char *t, char *s) { const struct ext_comm_pairs *cp; char *p, *ep; uint64_t ullval; uint32_t uval, uval2, dflag1 = 0, dflag2 = 0; int type = 0, subtype = 0; if (strcmp(t, "*") == 0 && strcmp(s, "*") == 0) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= COMMUNITY_ANY << 24; return (0); } if (parsesubtype(t, &type, &subtype) == 0) { yyerror("Bad ext-community unknown type"); return (-1); } switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_GEN_TWO_AS: case EXT_COMMUNITY_GEN_FOUR_AS: case EXT_COMMUNITY_GEN_IPV4: case -1: if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } if ((p = strchr(s, ':')) == NULL) { yyerror("Bad ext-community %s", s); return (-1); } *p++ = '\0'; if ((type = parseextvalue(type, s, &uval, &dflag1)) == -1) return (-1); switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_GEN_TWO_AS: if (getcommunity(p, 1, &uval2, &dflag2) == -1) return (-1); break; case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_GEN_IPV4: case EXT_COMMUNITY_GEN_FOUR_AS: if (getcommunity(p, 0, &uval2, &dflag2) == -1) return (-1); break; default: fatalx("parseextcommunity: unexpected result"); } c->data1 = uval; c->data2 = uval2; break; case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } errno = 0; ullval = strtoull(s, &ep, 0); if (s[0] == '\0' || *ep != '\0') { yyerror("Bad ext-community bad value"); return (-1); } if (errno == ERANGE && ullval > EXT_COMMUNITY_OPAQUE_MAX) { yyerror("Bad ext-community value too big"); return (-1); } c->data1 = ullval >> 32; c->data2 = ullval; break; case EXT_COMMUNITY_NON_TRANS_OPAQUE: if (subtype == EXT_COMMUNITY_SUBTYPE_OVS) { if (strcmp(s, "valid") == 0) { c->data2 = EXT_COMMUNITY_OVS_VALID; break; } else if (strcmp(s, "invalid") == 0) { c->data2 = EXT_COMMUNITY_OVS_INVALID; break; } else if (strcmp(s, "not-found") == 0) { c->data2 = EXT_COMMUNITY_OVS_NOTFOUND; break; } else if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } } yyerror("Bad ext-community %s", s); return (-1); } c->data3 = type << 8 | subtype; /* special handling of ext-community rt * since type is not known */ if (dflag1 == COMMUNITY_ANY && type == -1) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= dflag1 << 8; return (0); } /* verify type/subtype combo */ for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if (cp->type == type && cp->subtype == subtype) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= dflag1 << 8; c->flags |= dflag2 << 16; return (0); } } yyerror("Bad ext-community bad format for type"); return (-1); } struct peer * alloc_peer(void) { struct peer *p; if ((p = calloc(1, sizeof(struct peer))) == NULL) fatal("new_peer"); /* some sane defaults */ p->state = STATE_NONE; p->reconf_action = RECONF_REINIT; p->conf.distance = 1; p->conf.export_type = EXPORT_UNSET; p->conf.capabilities.refresh = 1; p->conf.capabilities.grestart.restart = 1; p->conf.capabilities.as4byte = 1; p->conf.capabilities.policy = 1; p->conf.local_as = conf->as; p->conf.local_short_as = conf->short_as; p->conf.remote_port = BGP_PORT; if (conf->flags & BGPD_FLAG_DECISION_TRANS_AS) p->conf.flags |= PEERFLAG_TRANS_AS; if (conf->flags & BGPD_FLAG_DECISION_ALL_PATHS) p->conf.flags |= PEERFLAG_EVALUATE_ALL; if (conf->flags & BGPD_FLAG_PERMIT_AS_SET) p->conf.flags |= PEERFLAG_PERMIT_AS_SET; return (p); } struct peer * new_peer(void) { struct peer *p; p = alloc_peer(); if (curgroup != NULL) { p->conf = curgroup->conf; p->auth_conf = curgroup->auth_conf; p->conf.groupid = curgroup->conf.id; } return (p); } struct peer * new_group(void) { return (alloc_peer()); } int add_mrtconfig(enum mrt_type type, char *name, int timeout, struct peer *p, char *rib) { struct mrt *m, *n; LIST_FOREACH(m, conf->mrt, entry) { if ((rib && strcmp(rib, m->rib)) || (!rib && *m->rib)) continue; if (p == NULL) { if (m->peer_id != 0 || m->group_id != 0) continue; } else { if (m->peer_id != p->conf.id || m->group_id != p->conf.groupid) continue; } if (m->type == type) { yyerror("only one mrtdump per type allowed."); return (-1); } } if ((n = calloc(1, sizeof(struct mrt_config))) == NULL) fatal("add_mrtconfig"); n->type = type; n->state = MRT_STATE_OPEN; if (strlcpy(MRT2MC(n)->name, name, sizeof(MRT2MC(n)->name)) >= sizeof(MRT2MC(n)->name)) { yyerror("filename \"%s\" too long: max %zu", name, sizeof(MRT2MC(n)->name) - 1); free(n); return (-1); } MRT2MC(n)->ReopenTimerInterval = timeout; if (p != NULL) { if (curgroup == p) { n->peer_id = 0; n->group_id = p->conf.id; } else { n->peer_id = p->conf.id; n->group_id = p->conf.groupid; } } if (rib) { if (!find_rib(rib)) { yyerror("rib \"%s\" does not exist.", rib); free(n); return (-1); } if (strlcpy(n->rib, rib, sizeof(n->rib)) >= sizeof(n->rib)) { yyerror("rib name \"%s\" too long: max %zu", name, sizeof(n->rib) - 1); free(n); return (-1); } } LIST_INSERT_HEAD(conf->mrt, n, entry); return (0); } struct rde_rib * add_rib(char *name) { struct rde_rib *rr; if ((rr = find_rib(name)) == NULL) { if ((rr = calloc(1, sizeof(*rr))) == NULL) { log_warn("add_rib"); return (NULL); } if (strlcpy(rr->name, name, sizeof(rr->name)) >= sizeof(rr->name)) { yyerror("rib name \"%s\" too long: max %zu", name, sizeof(rr->name) - 1); free(rr); return (NULL); } rr->flags = F_RIB_NOFIB; SIMPLEQ_INSERT_TAIL(&ribnames, rr, entry); } return (rr); } struct rde_rib * find_rib(char *name) { struct rde_rib *rr; SIMPLEQ_FOREACH(rr, &ribnames, entry) { if (!strcmp(rr->name, name)) return (rr); } return (NULL); } int rib_add_fib(struct rde_rib *rr, u_int rtableid) { u_int rdom; if (!ktable_exists(rtableid, &rdom)) { yyerror("rtable id %u does not exist", rtableid); return (-1); } /* * conf->default_tableid is also a rdomain because that is checked * in init_config() */ if (rdom != conf->default_tableid) { log_warnx("rtable %u does not belong to rdomain %u", rtableid, conf->default_tableid); return (-1); } rr->rtableid = rtableid; rr->flags &= ~F_RIB_NOFIB; return (0); } struct prefixset * find_prefixset(char *name, struct prefixset_head *p) { struct prefixset *ps; SIMPLEQ_FOREACH(ps, p, entry) { if (!strcmp(ps->name, name)) return (ps); } return (NULL); } int get_id(struct peer *newpeer) { static uint32_t id = PEER_ID_STATIC_MIN; struct peer *p = NULL; /* check if the peer already existed before */ if (newpeer->conf.remote_addr.aid) { /* neighbor */ if (cur_peers) RB_FOREACH(p, peer_head, cur_peers) if (p->conf.remote_masklen == newpeer->conf.remote_masklen && memcmp(&p->conf.remote_addr, &newpeer->conf.remote_addr, sizeof(p->conf.remote_addr)) == 0) break; if (p) { newpeer->conf.id = p->conf.id; return (0); } } else { /* group */ if (cur_peers) RB_FOREACH(p, peer_head, cur_peers) if (strcmp(p->conf.group, newpeer->conf.group) == 0) break; if (p) { newpeer->conf.id = p->conf.groupid; return (0); } } /* else new one */ if (id < PEER_ID_STATIC_MAX) { newpeer->conf.id = id++; return (0); } return (-1); } int merge_prefixspec(struct filter_prefix *p, struct filter_prefixlen *pl) { uint8_t max_len = 0; switch (p->addr.aid) { case AID_INET: case AID_VPN_IPv4: max_len = 32; break; case AID_INET6: case AID_VPN_IPv6: max_len = 128; break; } if (pl->op == OP_NONE) { p->len_min = p->len_max = p->len; return (0); } if (pl->len_min == -1) pl->len_min = p->len; if (pl->len_max == -1) pl->len_max = max_len; if (pl->len_max > max_len) { yyerror("prefixlen %d too big, limit %d", pl->len_max, max_len); return (-1); } if (pl->len_min > pl->len_max) { yyerror("prefixlen %d too big, limit %d", pl->len_min, pl->len_max); return (-1); } if (pl->len_min < p->len) { yyerror("prefixlen %d smaller than prefix, limit %d", pl->len_min, p->len); return (-1); } p->op = pl->op; p->len_min = pl->len_min; p->len_max = pl->len_max; return (0); } int expand_rule(struct filter_rule *rule, struct filter_rib_l *rib, struct filter_peers_l *peer, struct filter_match_l *match, struct filter_set_head *set) { struct filter_rule *r; struct filter_rib_l *rb, *rbnext; struct filter_peers_l *p, *pnext; struct filter_prefix_l *prefix, *prefix_next; struct filter_as_l *a, *anext; struct filter_set *s; rb = rib; do { p = peer; do { a = match->as_l; do { prefix = match->prefix_l; do { if ((r = calloc(1, sizeof(struct filter_rule))) == NULL) { log_warn("expand_rule"); return (-1); } memcpy(r, rule, sizeof(struct filter_rule)); memcpy(&r->match, match, sizeof(struct filter_match)); filterset_copy(set, &r->set); if (rb != NULL) strlcpy(r->rib, rb->name, sizeof(r->rib)); if (p != NULL) memcpy(&r->peer, &p->p, sizeof(struct filter_peers)); if (prefix != NULL) memcpy(&r->match.prefix, &prefix->p, sizeof(r->match.prefix)); if (a != NULL) memcpy(&r->match.as, &a->a, sizeof(struct filter_as)); TAILQ_INSERT_TAIL(filter_l, r, entry); if (prefix != NULL) prefix = prefix->next; } while (prefix != NULL); if (a != NULL) a = a->next; } while (a != NULL); if (p != NULL) p = p->next; } while (p != NULL); if (rb != NULL) rb = rb->next; } while (rb != NULL); for (rb = rib; rb != NULL; rb = rbnext) { rbnext = rb->next; free(rb); } for (p = peer; p != NULL; p = pnext) { pnext = p->next; free(p); } for (a = match->as_l; a != NULL; a = anext) { anext = a->next; free(a); } for (prefix = match->prefix_l; prefix != NULL; prefix = prefix_next) { prefix_next = prefix->next; free(prefix); } if (set != NULL) { while ((s = TAILQ_FIRST(set)) != NULL) { TAILQ_REMOVE(set, s, entry); free(s); } free(set); } return (0); } static int h2i(char c) { if (c >= '0' && c <= '9') return c - '0'; else if (c >= 'a' && c <= 'f') return c - 'a' + 10; else if (c >= 'A' && c <= 'F') return c - 'A' + 10; else return -1; } int str2key(char *s, char *dest, size_t max_len) { size_t i; if (strlen(s) / 2 > max_len) { yyerror("key too long"); return (-1); } if (strlen(s) % 2) { yyerror("key must be of even length"); return (-1); } for (i = 0; i < strlen(s) / 2; i++) { int hi, lo; hi = h2i(s[2 * i]); lo = h2i(s[2 * i + 1]); if (hi == -1 || lo == -1) { yyerror("key must be specified in hex"); return (-1); } dest[i] = (hi << 4) | lo; } return (0); } int neighbor_consistent(struct peer *p) { struct bgpd_addr *local_addr; struct peer *xp; switch (p->conf.remote_addr.aid) { case AID_INET: local_addr = &p->conf.local_addr_v4; break; case AID_INET6: local_addr = &p->conf.local_addr_v6; break; default: yyerror("Bad address family for remote-addr"); return (-1); } /* with any form of ipsec local-address is required */ if ((p->auth_conf.method == AUTH_IPSEC_IKE_ESP || p->auth_conf.method == AUTH_IPSEC_IKE_AH || p->auth_conf.method == AUTH_IPSEC_MANUAL_ESP || p->auth_conf.method == AUTH_IPSEC_MANUAL_AH) && local_addr->aid == AID_UNSPEC) { yyerror("neighbors with any form of IPsec configured " "need local-address to be specified"); return (-1); } /* with static keying we need both directions */ if ((p->auth_conf.method == AUTH_IPSEC_MANUAL_ESP || p->auth_conf.method == AUTH_IPSEC_MANUAL_AH) && (!p->auth_conf.spi_in || !p->auth_conf.spi_out)) { yyerror("with manual keyed IPsec, SPIs and keys " "for both directions are required"); return (-1); } if (!conf->as) { yyerror("AS needs to be given before neighbor definitions"); return (-1); } /* set default values if they where undefined */ p->conf.ebgp = (p->conf.remote_as != conf->as); if (p->conf.enforce_as == ENFORCE_AS_UNDEF) p->conf.enforce_as = p->conf.ebgp ? ENFORCE_AS_ON : ENFORCE_AS_OFF; if (p->conf.enforce_local_as == ENFORCE_AS_UNDEF) p->conf.enforce_local_as = ENFORCE_AS_ON; if (p->conf.remote_as == 0 && !p->conf.template) { yyerror("peer AS may not be zero"); return (-1); } /* EBGP neighbors are not allowed in route reflector clusters */ if (p->conf.reflector_client && p->conf.ebgp) { yyerror("EBGP neighbors are not allowed in route " "reflector clusters"); return (-1); } /* BGP role and RFC 9234 role are only valid for EBGP neighbors */ if (!p->conf.ebgp) { p->conf.role = ROLE_NONE; p->conf.capabilities.policy = 0; } else if (p->conf.role == ROLE_NONE) { /* no role, no policy capability */ p->conf.capabilities.policy = 0; } /* check for duplicate peer definitions */ RB_FOREACH(xp, peer_head, new_peers) if (xp->conf.remote_masklen == p->conf.remote_masklen && memcmp(&xp->conf.remote_addr, &p->conf.remote_addr, sizeof(p->conf.remote_addr)) == 0) break; if (xp != NULL) { char *descr = log_fmt_peer(&p->conf); yyerror("duplicate %s", descr); free(descr); return (-1); } return (0); } static void filterset_add(struct filter_set_head *sh, struct filter_set *s) { struct filter_set *t; TAILQ_FOREACH(t, sh, entry) { if (s->type < t->type) { TAILQ_INSERT_BEFORE(t, s, entry); return; } if (s->type == t->type) { switch (s->type) { case ACTION_SET_COMMUNITY: case ACTION_DEL_COMMUNITY: switch (cmpcommunity(&s->action.community, &t->action.community)) { case -1: TAILQ_INSERT_BEFORE(t, s, entry); return; case 0: break; case 1: continue; } break; case ACTION_SET_NEXTHOP: /* only last nexthop per AF matters */ if (s->action.nexthop.aid < t->action.nexthop.aid) { TAILQ_INSERT_BEFORE(t, s, entry); return; } else if (s->action.nexthop.aid == t->action.nexthop.aid) { t->action.nexthop = s->action.nexthop; break; } continue; case ACTION_SET_NEXTHOP_BLACKHOLE: case ACTION_SET_NEXTHOP_REJECT: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: /* set it only once */ break; case ACTION_SET_LOCALPREF: case ACTION_SET_MED: case ACTION_SET_WEIGHT: /* only last set matters */ t->action.metric = s->action.metric; break; case ACTION_SET_RELATIVE_LOCALPREF: case ACTION_SET_RELATIVE_MED: case ACTION_SET_RELATIVE_WEIGHT: /* sum all relative numbers */ t->action.relative += s->action.relative; break; case ACTION_SET_ORIGIN: /* only last set matters */ t->action.origin = s->action.origin; break; case ACTION_PFTABLE: /* only last set matters */ strlcpy(t->action.pftable, s->action.pftable, sizeof(t->action.pftable)); break; case ACTION_RTLABEL: /* only last set matters */ strlcpy(t->action.rtlabel, s->action.rtlabel, sizeof(t->action.rtlabel)); break; default: break; } free(s); return; } } TAILQ_INSERT_TAIL(sh, s, entry); } int merge_filterset(struct filter_set_head *sh, struct filter_set *s) { struct filter_set *t; TAILQ_FOREACH(t, sh, entry) { /* * need to cycle across the full list because even * if types are not equal filterset_cmp() may return 0. */ if (filterset_cmp(s, t) == 0) { if (s->type == ACTION_SET_COMMUNITY) yyerror("community is already set"); else if (s->type == ACTION_DEL_COMMUNITY) yyerror("community will already be deleted"); else yyerror("redefining set parameter %s", filterset_name(s->type)); return (-1); } } filterset_add(sh, s); return (0); } static int filter_equal(struct filter_rule *fa, struct filter_rule *fb) { if (fa == NULL || fb == NULL) return 0; if (fa->action != fb->action || fa->quick != fb->quick || fa->dir != fb->dir) return 0; if (memcmp(&fa->peer, &fb->peer, sizeof(fa->peer))) return 0; if (memcmp(&fa->match, &fb->match, sizeof(fa->match))) return 0; return 1; } /* do a basic optimization by folding equal rules together */ void optimize_filters(struct filter_head *fh) { struct filter_rule *r, *nr; TAILQ_FOREACH_SAFE(r, fh, entry, nr) { while (filter_equal(r, nr)) { struct filter_set *t; while ((t = TAILQ_FIRST(&nr->set)) != NULL) { TAILQ_REMOVE(&nr->set, t, entry); filterset_add(&r->set, t); } TAILQ_REMOVE(fh, nr, entry); free(nr); nr = TAILQ_NEXT(r, entry); } } } struct filter_rule * get_rule(enum action_types type) { struct filter_rule *r; int out; switch (type) { case ACTION_SET_PREPEND_SELF: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: out = 1; break; default: out = 0; break; } r = (curpeer == curgroup) ? curgroup_filter[out] : curpeer_filter[out]; if (r == NULL) { if ((r = calloc(1, sizeof(struct filter_rule))) == NULL) fatal(NULL); r->quick = 0; r->dir = out ? DIR_OUT : DIR_IN; r->action = ACTION_NONE; TAILQ_INIT(&r->set); if (curpeer == curgroup) { /* group */ r->peer.groupid = curgroup->conf.id; curgroup_filter[out] = r; } else { /* peer */ r->peer.peerid = curpeer->conf.id; curpeer_filter[out] = r; } } return (r); } struct set_table *curset; static int new_as_set(char *name) { struct as_set *aset; if (as_sets_lookup(&conf->as_sets, name) != NULL) { yyerror("as-set \"%s\" already exists", name); return -1; } aset = as_sets_new(&conf->as_sets, name, 0, sizeof(uint32_t)); if (aset == NULL) fatal(NULL); curset = aset->set; return 0; } static void add_as_set(uint32_t as) { if (curset == NULL) fatalx("%s: bad mojo jojo", __func__); if (set_add(curset, &as, 1) != 0) fatal(NULL); } static void done_as_set(void) { curset = NULL; } static struct prefixset * new_prefix_set(char *name, int is_roa) { const char *type = "prefix-set"; struct prefixset_head *sets = &conf->prefixsets; struct prefixset *pset; if (is_roa) { type = "origin-set"; sets = &conf->originsets; } if (find_prefixset(name, sets) != NULL) { yyerror("%s \"%s\" already exists", type, name); return NULL; } if ((pset = calloc(1, sizeof(*pset))) == NULL) fatal("prefixset"); if (strlcpy(pset->name, name, sizeof(pset->name)) >= sizeof(pset->name)) { yyerror("%s \"%s\" too long: max %zu", type, name, sizeof(pset->name) - 1); free(pset); return NULL; } RB_INIT(&pset->psitems); RB_INIT(&pset->roaitems); return pset; } static void add_roa_set(struct prefixset_item *npsi, uint32_t as, uint8_t max, time_t expires) { struct roa *roa, *r; if ((roa = calloc(1, sizeof(*roa))) == NULL) fatal("add_roa_set"); roa->aid = npsi->p.addr.aid; roa->prefixlen = npsi->p.len; roa->maxlen = max; roa->asnum = as; roa->expires = expires; switch (roa->aid) { case AID_INET: roa->prefix.inet = npsi->p.addr.v4; break; case AID_INET6: roa->prefix.inet6 = npsi->p.addr.v6; break; default: fatalx("Bad address family for roa_set address"); } r = RB_INSERT(roa_tree, curroatree, roa); if (r != NULL) { /* just ignore duplicates */ if (r->expires != 0 && expires != 0 && expires > r->expires) r->expires = expires; free(roa); } } static struct rtr_config * get_rtr(struct bgpd_addr *addr) { struct rtr_config *n; n = calloc(1, sizeof(*n)); if (n == NULL) { yyerror("out of memory"); return NULL; } n->remote_addr = *addr; strlcpy(n->descr, log_addr(addr), sizeof(currtr->descr)); return n; } static int insert_rtr(struct rtr_config *new) { static uint32_t id; struct rtr_config *r; if (id == UINT32_MAX) { yyerror("out of rtr session IDs"); return -1; } SIMPLEQ_FOREACH(r, &conf->rtrs, entry) if (memcmp(&r->remote_addr, &new->remote_addr, sizeof(r->remote_addr)) == 0 && r->remote_port == new->remote_port) { yyerror("duplicate rtr session to %s:%u", log_addr(&new->remote_addr), new->remote_port); return -1; } if (cur_rtrs) SIMPLEQ_FOREACH(r, cur_rtrs, entry) if (memcmp(&r->remote_addr, &new->remote_addr, sizeof(r->remote_addr)) == 0 && r->remote_port == new->remote_port) { new->id = r->id; break; } if (new->id == 0) new->id = ++id; SIMPLEQ_INSERT_TAIL(&conf->rtrs, currtr, entry); return 0; } static int merge_aspa_set(uint32_t as, struct aspa_tas_l *tas, time_t expires) { struct aspa_set *aspa, needle = { .as = as }; uint32_t i, num, *newtas; aspa = RB_FIND(aspa_tree, &conf->aspa, &needle); if (aspa == NULL) { if ((aspa = calloc(1, sizeof(*aspa))) == NULL) { yyerror("out of memory"); return -1; } aspa->as = as; aspa->expires = expires; RB_INSERT(aspa_tree, &conf->aspa, aspa); } if (MAX_ASPA_SPAS_COUNT - aspa->num <= tas->num) { yyerror("too many providers for customer-as %u", as); return -1; } num = aspa->num + tas->num; newtas = recallocarray(aspa->tas, aspa->num, num, sizeof(uint32_t)); if (newtas == NULL) { yyerror("out of memory"); return -1; } /* fill starting at the end since the tas list is reversed */ if (num > 0) { for (i = num - 1; tas; tas = tas->next, i--) newtas[i] = tas->as; } aspa->num = num; aspa->tas = newtas; /* take the longest expiry time, same logic as for ROA entries */ if (aspa->expires != 0 && expires != 0 && expires > aspa->expires) aspa->expires = expires; return 0; } static int kw_casecmp(const void *k, const void *e) { return (strcasecmp(k, ((const struct keywords *)e)->k_name)); } static int map_tos(char *s, int *val) { /* DiffServ Codepoints and other TOS mappings */ const struct keywords toswords[] = { { "af11", IPTOS_DSCP_AF11 }, { "af12", IPTOS_DSCP_AF12 }, { "af13", IPTOS_DSCP_AF13 }, { "af21", IPTOS_DSCP_AF21 }, { "af22", IPTOS_DSCP_AF22 }, { "af23", IPTOS_DSCP_AF23 }, { "af31", IPTOS_DSCP_AF31 }, { "af32", IPTOS_DSCP_AF32 }, { "af33", IPTOS_DSCP_AF33 }, { "af41", IPTOS_DSCP_AF41 }, { "af42", IPTOS_DSCP_AF42 }, { "af43", IPTOS_DSCP_AF43 }, { "critical", IPTOS_PREC_CRITIC_ECP }, { "cs0", IPTOS_DSCP_CS0 }, { "cs1", IPTOS_DSCP_CS1 }, { "cs2", IPTOS_DSCP_CS2 }, { "cs3", IPTOS_DSCP_CS3 }, { "cs4", IPTOS_DSCP_CS4 }, { "cs5", IPTOS_DSCP_CS5 }, { "cs6", IPTOS_DSCP_CS6 }, { "cs7", IPTOS_DSCP_CS7 }, { "ef", IPTOS_DSCP_EF }, { "inetcontrol", IPTOS_PREC_INTERNETCONTROL }, { "lowdelay", IPTOS_LOWDELAY }, { "netcontrol", IPTOS_PREC_NETCONTROL }, { "reliability", IPTOS_RELIABILITY }, { "throughput", IPTOS_THROUGHPUT }, }; const struct keywords *p; p = bsearch(s, toswords, nitems(toswords), sizeof(toswords[0]), kw_casecmp); if (p) { *val = p->k_val; return (1); } return (0); } static int getservice(char *n) { struct servent *s; s = getservbyname(n, "tcp"); if (s == NULL) s = getservbyname(n, "udp"); if (s == NULL) return -1; return s->s_port; } static int parse_flags(char *s) { const char *flags = FLOWSPEC_TCP_FLAG_STRING; char *p, *q; uint8_t f = 0; if (curflow->type == FLOWSPEC_TYPE_FRAG) { if (curflow->aid == AID_INET) flags = FLOWSPEC_FRAG_STRING4; else flags = FLOWSPEC_FRAG_STRING6; } for (p = s; *p; p++) { if ((q = strchr(flags, *p)) == NULL) return -1; f |= 1 << (q - flags); } return (f ? f : 0xff); } static void component_finish(int type, uint8_t *data, int len) { uint8_t *last; int i; switch (type) { case FLOWSPEC_TYPE_DEST: case FLOWSPEC_TYPE_SOURCE: /* nothing to do */ return; default: break; } i = 0; do { last = data + i; i += FLOWSPEC_OP_LEN(*last) + 1; } while (i < len); *last |= FLOWSPEC_OP_EOL; } static struct flowspec_config * flow_to_flowspec(struct flowspec_context *ctx) { struct flowspec_config *f; int i, len = 0; uint8_t aid; switch (ctx->aid) { case AID_INET: aid = AID_FLOWSPECv4; break; case AID_INET6: aid = AID_FLOWSPECv6; break; default: return NULL; } for (i = FLOWSPEC_TYPE_MIN; i < FLOWSPEC_TYPE_MAX; i++) if (ctx->components[i] != NULL) len += ctx->complen[i] + 1; f = flowspec_alloc(aid, len); if (f == NULL) return NULL; len = 0; for (i = FLOWSPEC_TYPE_MIN; i < FLOWSPEC_TYPE_MAX; i++) if (ctx->components[i] != NULL) { f->flow->data[len++] = i; component_finish(i, ctx->components[i], ctx->complen[i]); memcpy(f->flow->data + len, ctx->components[i], ctx->complen[i]); len += ctx->complen[i]; } return f; } static void flow_free(struct flowspec_context *ctx) { int i; for (i = 0; i < FLOWSPEC_TYPE_MAX; i++) free(ctx->components[i]); free(ctx); } static int push_prefix(struct bgpd_addr *addr, uint8_t len) { void *data; uint8_t *comp; int complen, l; if (curflow->components[curflow->addr_type] != NULL) { yyerror("flowspec address already set"); return -1; } if (curflow->aid != addr->aid) { yyerror("wrong address family for flowspec address"); return -1; } switch (curflow->aid) { case AID_INET: complen = PREFIX_SIZE(len); data = &addr->v4; break; case AID_INET6: /* IPv6 includes an offset byte */ complen = PREFIX_SIZE(len) + 1; data = &addr->v6; break; default: yyerror("unsupported address family for flowspec address"); return -1; } comp = malloc(complen); if (comp == NULL) { yyerror("out of memory"); return -1; } l = 0; comp[l++] = len; if (curflow->aid == AID_INET6) comp[l++] = 0; memcpy(comp + l, data, complen - l); curflow->complen[curflow->addr_type] = complen; curflow->components[curflow->addr_type] = comp; return 0; } static int push_binop(uint8_t binop, long long val) { uint8_t *comp; int complen; uint8_t u8; if (val < 0 || val > 0xff) { yyerror("unsupported value for flowspec bin_op"); return -1; } u8 = val; complen = curflow->complen[curflow->type]; comp = realloc(curflow->components[curflow->type], complen + 2); if (comp == NULL) { yyerror("out of memory"); return -1; } comp[complen++] = binop; comp[complen++] = u8; curflow->complen[curflow->type] = complen; curflow->components[curflow->type] = comp; return 0; } static uint8_t component_numop(enum comp_ops op, int and, int len) { uint8_t flag = 0; switch (op) { case OP_EQ: flag |= FLOWSPEC_OP_NUM_EQ; break; case OP_NE: flag |= FLOWSPEC_OP_NUM_NOT; break; case OP_LE: flag |= FLOWSPEC_OP_NUM_LE; break; case OP_LT: flag |= FLOWSPEC_OP_NUM_LT; break; case OP_GE: flag |= FLOWSPEC_OP_NUM_GE; break; case OP_GT: flag |= FLOWSPEC_OP_NUM_GT; break; default: fatalx("unsupported op"); } switch (len) { case 2: flag |= 1 << FLOWSPEC_OP_LEN_SHIFT; break; case 4: flag |= 2 << FLOWSPEC_OP_LEN_SHIFT; break; case 8: flag |= 3 << FLOWSPEC_OP_LEN_SHIFT; break; } if (and) flag |= FLOWSPEC_OP_AND; return flag; } static int push_numop(enum comp_ops op, int and, long long val) { uint8_t *comp; void *data; uint32_t u32; uint16_t u16; uint8_t u8; int len, complen; if (val < 0 || val > 0xffffffff) { yyerror("unsupported value for flowspec num_op"); return -1; } else if (val <= 255) { len = 1; u8 = val; data = &u8; } else if (val <= 0xffff) { len = 2; u16 = htons(val); data = &u16; } else { len = 4; u32 = htonl(val); data = &u32; } complen = curflow->complen[curflow->type]; comp = realloc(curflow->components[curflow->type], complen + len + 1); if (comp == NULL) { yyerror("out of memory"); return -1; } comp[complen++] = component_numop(op, and, len); memcpy(comp + complen, data, len); complen += len; curflow->complen[curflow->type] = complen; curflow->components[curflow->type] = comp; return 0; } static int push_unary_numop(enum comp_ops op, long long val) { return push_numop(op, 0, val); } static int push_binary_numop(enum comp_ops op, long long min, long long max) { switch (op) { case OP_RANGE: if (push_numop(OP_GE, 0, min) == -1) return -1; return push_numop(OP_LE, 1, max); case OP_XRANGE: if (push_numop(OP_LT, 0, min) == -1) return -1; return push_numop(OP_GT, 0, max); default: yyerror("unsupported binary flowspec num_op"); return -1; } } struct icmptypeent { const char *name; u_int8_t type; }; struct icmpcodeent { const char *name; u_int8_t type; u_int8_t code; }; static const struct icmptypeent icmp_type[] = { { "echoreq", ICMP_ECHO }, { "echorep", ICMP_ECHOREPLY }, { "unreach", ICMP_UNREACH }, { "squench", ICMP_SOURCEQUENCH }, { "redir", ICMP_REDIRECT }, { "althost", ICMP_ALTHOSTADDR }, { "routeradv", ICMP_ROUTERADVERT }, { "routersol", ICMP_ROUTERSOLICIT }, { "timex", ICMP_TIMXCEED }, { "paramprob", ICMP_PARAMPROB }, { "timereq", ICMP_TSTAMP }, { "timerep", ICMP_TSTAMPREPLY }, { "inforeq", ICMP_IREQ }, { "inforep", ICMP_IREQREPLY }, { "maskreq", ICMP_MASKREQ }, { "maskrep", ICMP_MASKREPLY }, { "trace", ICMP_TRACEROUTE }, { "dataconv", ICMP_DATACONVERR }, { "mobredir", ICMP_MOBILE_REDIRECT }, { "ipv6-where", ICMP_IPV6_WHEREAREYOU }, { "ipv6-here", ICMP_IPV6_IAMHERE }, { "mobregreq", ICMP_MOBILE_REGREQUEST }, { "mobregrep", ICMP_MOBILE_REGREPLY }, { "skip", ICMP_SKIP }, { "photuris", ICMP_PHOTURIS }, }; static const struct icmptypeent icmp6_type[] = { { "unreach", ICMP6_DST_UNREACH }, { "toobig", ICMP6_PACKET_TOO_BIG }, { "timex", ICMP6_TIME_EXCEEDED }, { "paramprob", ICMP6_PARAM_PROB }, { "echoreq", ICMP6_ECHO_REQUEST }, { "echorep", ICMP6_ECHO_REPLY }, { "groupqry", ICMP6_MEMBERSHIP_QUERY }, { "listqry", MLD_LISTENER_QUERY }, { "grouprep", ICMP6_MEMBERSHIP_REPORT }, { "listenrep", MLD_LISTENER_REPORT }, { "groupterm", ICMP6_MEMBERSHIP_REDUCTION }, { "listendone", MLD_LISTENER_DONE }, { "routersol", ND_ROUTER_SOLICIT }, { "routeradv", ND_ROUTER_ADVERT }, { "neighbrsol", ND_NEIGHBOR_SOLICIT }, { "neighbradv", ND_NEIGHBOR_ADVERT }, { "redir", ND_REDIRECT }, { "routrrenum", ICMP6_ROUTER_RENUMBERING }, { "wrureq", ICMP6_WRUREQUEST }, { "wrurep", ICMP6_WRUREPLY }, { "fqdnreq", ICMP6_FQDN_QUERY }, { "fqdnrep", ICMP6_FQDN_REPLY }, { "niqry", ICMP6_NI_QUERY }, { "nirep", ICMP6_NI_REPLY }, { "mtraceresp", MLD_MTRACE_RESP }, { "mtrace", MLD_MTRACE }, { "listenrepv2", MLDV2_LISTENER_REPORT }, }; static const struct icmpcodeent icmp_code[] = { { "net-unr", ICMP_UNREACH, ICMP_UNREACH_NET }, { "host-unr", ICMP_UNREACH, ICMP_UNREACH_HOST }, { "proto-unr", ICMP_UNREACH, ICMP_UNREACH_PROTOCOL }, { "port-unr", ICMP_UNREACH, ICMP_UNREACH_PORT }, { "needfrag", ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG }, { "srcfail", ICMP_UNREACH, ICMP_UNREACH_SRCFAIL }, { "net-unk", ICMP_UNREACH, ICMP_UNREACH_NET_UNKNOWN }, { "host-unk", ICMP_UNREACH, ICMP_UNREACH_HOST_UNKNOWN }, { "isolate", ICMP_UNREACH, ICMP_UNREACH_ISOLATED }, { "net-prohib", ICMP_UNREACH, ICMP_UNREACH_NET_PROHIB }, { "host-prohib", ICMP_UNREACH, ICMP_UNREACH_HOST_PROHIB }, { "net-tos", ICMP_UNREACH, ICMP_UNREACH_TOSNET }, { "host-tos", ICMP_UNREACH, ICMP_UNREACH_TOSHOST }, { "filter-prohib", ICMP_UNREACH, ICMP_UNREACH_FILTER_PROHIB }, { "host-preced", ICMP_UNREACH, ICMP_UNREACH_HOST_PRECEDENCE }, { "cutoff-preced", ICMP_UNREACH, ICMP_UNREACH_PRECEDENCE_CUTOFF }, { "redir-net", ICMP_REDIRECT, ICMP_REDIRECT_NET }, { "redir-host", ICMP_REDIRECT, ICMP_REDIRECT_HOST }, { "redir-tos-net", ICMP_REDIRECT, ICMP_REDIRECT_TOSNET }, { "redir-tos-host", ICMP_REDIRECT, ICMP_REDIRECT_TOSHOST }, { "normal-adv", ICMP_ROUTERADVERT, ICMP_ROUTERADVERT_NORMAL }, { "common-adv", ICMP_ROUTERADVERT, ICMP_ROUTERADVERT_NOROUTE_COMMON }, { "transit", ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS }, { "reassemb", ICMP_TIMXCEED, ICMP_TIMXCEED_REASS }, { "badhead", ICMP_PARAMPROB, ICMP_PARAMPROB_ERRATPTR }, { "optmiss", ICMP_PARAMPROB, ICMP_PARAMPROB_OPTABSENT }, { "badlen", ICMP_PARAMPROB, ICMP_PARAMPROB_LENGTH }, { "unknown-ind", ICMP_PHOTURIS, ICMP_PHOTURIS_UNKNOWN_INDEX }, { "auth-fail", ICMP_PHOTURIS, ICMP_PHOTURIS_AUTH_FAILED }, { "decrypt-fail", ICMP_PHOTURIS, ICMP_PHOTURIS_DECRYPT_FAILED }, }; static const struct icmpcodeent icmp6_code[] = { { "admin-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN }, { "noroute-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE }, { "beyond-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_BEYONDSCOPE }, { "addr-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR }, { "port-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT }, { "transit", ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_TRANSIT }, { "reassemb", ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_REASSEMBLY }, { "badhead", ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER }, { "nxthdr", ICMP6_PARAM_PROB, ICMP6_PARAMPROB_NEXTHEADER }, { "redironlink", ND_REDIRECT, ND_REDIRECT_ONLINK }, { "redirrouter", ND_REDIRECT, ND_REDIRECT_ROUTER }, }; static int geticmptypebyname(char *w, uint8_t aid) { size_t i; switch (aid) { case AID_INET: for (i = 0; i < nitems(icmp_type); i++) { if (!strcmp(w, icmp_type[i].name)) return (icmp_type[i].type); } break; case AID_INET6: for (i = 0; i < nitems(icmp6_type); i++) { if (!strcmp(w, icmp6_type[i].name)) return (icmp6_type[i].type); } break; } return -1; } static int geticmpcodebyname(u_long type, char *w, uint8_t aid) { size_t i; switch (aid) { case AID_INET: for (i = 0; i < nitems(icmp_code); i++) { if (type == icmp_code[i].type && !strcmp(w, icmp_code[i].name)) return (icmp_code[i].code); } break; case AID_INET6: for (i = 0; i < nitems(icmp6_code); i++) { if (type == icmp6_code[i].type && !strcmp(w, icmp6_code[i].name)) return (icmp6_code[i].code); } break; } return -1; } static int merge_auth_conf(struct auth_config *to, struct auth_config *from) { if (to->method != 0) { /* extra magic for manual ipsec rules */ if (to->method == from->method && (to->method == AUTH_IPSEC_MANUAL_ESP || to->method == AUTH_IPSEC_MANUAL_AH)) { if (to->spi_in == 0 && from->spi_in != 0) { to->spi_in = from->spi_in; to->auth_alg_in = from->auth_alg_in; to->enc_alg_in = from->enc_alg_in; memcpy(to->enc_key_in, from->enc_key_in, sizeof(to->enc_key_in)); to->enc_keylen_in = from->enc_keylen_in; to->auth_keylen_in = from->auth_keylen_in; return 1; } else if (to->spi_out == 0 && from->spi_out != 0) { to->spi_out = from->spi_out; to->auth_alg_out = from->auth_alg_out; to->enc_alg_out = from->enc_alg_out; memcpy(to->enc_key_out, from->enc_key_out, sizeof(to->enc_key_out)); to->enc_keylen_out = from->enc_keylen_out; to->auth_keylen_out = from->auth_keylen_out; return 1; } } yyerror("auth method cannot be redefined"); return 0; } *to = *from; return 1; } openbgpd-8.8/src/bgpd/bgpd.c100644 001750 001750 00000110105 14730105010 0011441/* $OpenBSD: bgpd.c,v 1.280 2024/12/03 13:46:53 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" #include "version.h" void sighdlr(int); __dead void usage(void); int main(int, char *[]); pid_t start_child(enum bgpd_process, char *, int, int, int); int send_filterset(struct imsgbuf *, struct filter_set_head *); int reconfigure(char *, struct bgpd_config *); int send_config(struct bgpd_config *); int dispatch_imsg(struct imsgbuf *, int, struct bgpd_config *); int control_setup(struct bgpd_config *); static void getsockpair(int [2]); int imsg_send_sockets(struct imsgbuf *, struct imsgbuf *, struct imsgbuf *); void bgpd_rtr_conn_setup(struct rtr_config *); void bgpd_rtr_conn_setup_done(int, struct bgpd_config *); void bgpd_rtr_conn_teardown(uint32_t); int cflags; volatile sig_atomic_t mrtdump; volatile sig_atomic_t quit; volatile sig_atomic_t reconfig; pid_t reconfpid; int reconfpending; struct imsgbuf *ibuf_se; struct imsgbuf *ibuf_rde; struct imsgbuf *ibuf_rtr; struct rib_names ribnames = SIMPLEQ_HEAD_INITIALIZER(ribnames); char *cname; char *rcname; struct connect_elm { TAILQ_ENTRY(connect_elm) entry; struct auth_state auth_state; uint32_t id; int fd; }; TAILQ_HEAD(, connect_elm) connect_queue = \ TAILQ_HEAD_INITIALIZER(connect_queue), socket_queue = \ TAILQ_HEAD_INITIALIZER(socket_queue); u_int connect_cnt; #define MAX_CONNECT_CNT 32 void sighdlr(int sig) { switch (sig) { case SIGTERM: case SIGINT: quit = 1; break; case SIGHUP: reconfig = 1; break; case SIGALRM: case SIGUSR1: mrtdump = 1; break; } } __dead void usage(void) { extern char *__progname; fprintf(stderr, "usage: %s [-cdnvV] [-D macro=value] [-f file]\n", __progname); exit(1); } #define PFD_PIPE_SESSION 0 #define PFD_PIPE_RDE 1 #define PFD_PIPE_RTR 2 #define PFD_SOCK_ROUTE 3 #define PFD_SOCK_PFKEY 4 #define PFD_CONNECT_START 5 #define MAX_TIMEOUT 3600 int cmd_opts; int main(int argc, char *argv[]) { struct bgpd_config *conf; enum bgpd_process proc = PROC_MAIN; struct rde_rib *rr; struct peer *p; struct pollfd *pfd = NULL; struct connect_elm *ce; time_t timeout; pid_t se_pid = 0, rde_pid = 0, rtr_pid = 0, pid; char *conffile; char *saved_argv0; u_int pfd_elms = 0, npfd, i; int debug = 0; int rfd, keyfd; int ch, status; int pipe_m2s[2]; int pipe_m2r[2]; int pipe_m2roa[2]; conffile = CONFFILE; log_init(1, LOG_DAEMON); /* log to stderr until daemonized */ log_procinit(log_procnames[PROC_MAIN]); log_setverbose(1); saved_argv0 = argv[0]; if (saved_argv0 == NULL) saved_argv0 = "bgpd"; while ((ch = getopt(argc, argv, "cdD:f:nRSTvV")) != -1) { switch (ch) { case 'c': cmd_opts |= BGPD_OPT_FORCE_DEMOTE; break; case 'd': debug = 1; break; case 'D': if (cmdline_symset(optarg) < 0) log_warnx("could not parse macro definition %s", optarg); break; case 'f': conffile = optarg; break; case 'n': cmd_opts |= BGPD_OPT_NOACTION; break; case 'v': if (cmd_opts & BGPD_OPT_VERBOSE) cmd_opts |= BGPD_OPT_VERBOSE2; cmd_opts |= BGPD_OPT_VERBOSE; break; case 'R': proc = PROC_RDE; break; case 'S': proc = PROC_SE; break; case 'T': proc = PROC_RTR; break; case 'V': fprintf(stderr, "OpenBGPD %s\n", BGPD_VERSION); return 0; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if (argc > 0) usage(); if (cmd_opts & BGPD_OPT_NOACTION) { if ((conf = parse_config(conffile, NULL, NULL)) == NULL) exit(1); if (cmd_opts & BGPD_OPT_VERBOSE) print_config(conf, &ribnames); else fprintf(stderr, "configuration OK\n"); while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) { SIMPLEQ_REMOVE_HEAD(&ribnames, entry); free(rr); } free_config(conf); exit(0); } switch (proc) { case PROC_MAIN: break; case PROC_RDE: rde_main(debug, cmd_opts & BGPD_OPT_VERBOSE); /* NOTREACHED */ case PROC_SE: session_main(debug, cmd_opts & BGPD_OPT_VERBOSE); /* NOTREACHED */ case PROC_RTR: rtr_main(debug, cmd_opts & BGPD_OPT_VERBOSE); /* NOTREACHED */ } if (geteuid()) errx(1, "need root privileges"); if (getpwnam(BGPD_USER) == NULL) errx(1, "unknown user %s", BGPD_USER); if ((conf = parse_config(conffile, NULL, NULL)) == NULL) { log_warnx("config file %s has errors", conffile); exit(1); } if (prepare_listeners(conf) == -1) exit(1); log_init(debug, LOG_DAEMON); log_setverbose(cmd_opts & BGPD_OPT_VERBOSE); if (!debug) daemon(1, 0); log_info("startup"); getsockpair(pipe_m2s); getsockpair(pipe_m2r); getsockpair(pipe_m2roa); /* fork children */ rde_pid = start_child(PROC_RDE, saved_argv0, pipe_m2r[1], debug, cmd_opts & BGPD_OPT_VERBOSE); se_pid = start_child(PROC_SE, saved_argv0, pipe_m2s[1], debug, cmd_opts & BGPD_OPT_VERBOSE); rtr_pid = start_child(PROC_RTR, saved_argv0, pipe_m2roa[1], debug, cmd_opts & BGPD_OPT_VERBOSE); signal(SIGTERM, sighdlr); signal(SIGINT, sighdlr); signal(SIGHUP, sighdlr); signal(SIGALRM, sighdlr); signal(SIGUSR1, sighdlr); signal(SIGPIPE, SIG_IGN); if ((ibuf_se = malloc(sizeof(struct imsgbuf))) == NULL || (ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL || (ibuf_rtr = malloc(sizeof(struct imsgbuf))) == NULL) fatal(NULL); if (imsgbuf_init(ibuf_se, pipe_m2s[0]) == -1 || imsgbuf_set_maxsize(ibuf_se, MAX_BGPD_IMSGSIZE) == -1 || imsgbuf_init(ibuf_rde, pipe_m2r[0]) == -1 || imsgbuf_set_maxsize(ibuf_rde, MAX_BGPD_IMSGSIZE) == -1 || imsgbuf_init(ibuf_rtr, pipe_m2roa[0]) == -1 || imsgbuf_set_maxsize(ibuf_rtr, MAX_BGPD_IMSGSIZE) == -1) fatal(NULL); imsgbuf_allow_fdpass(ibuf_se); imsgbuf_allow_fdpass(ibuf_rde); imsgbuf_allow_fdpass(ibuf_rtr); mrt_init(ibuf_rde, ibuf_se); if (kr_init(&rfd, conf->fib_priority) == -1) quit = 1; keyfd = pfkey_init(); /* * rpath, read config file * cpath, unlink control socket * fattr, chmod on control socket * wpath, needed if we are doing mrt dumps * * pledge placed here because kr_init() does a setsockopt on the * routing socket thats not allowed at all. */ #if 0 /* * disabled because we do ioctls on /dev/pf and SIOCSIFGATTR * this needs some redesign of bgpd to be fixed. */ BROKEN if (pledge("stdio rpath wpath cpath fattr unix route recvfd sendfd", NULL) == -1) fatal("pledge"); #endif if (imsg_send_sockets(ibuf_se, ibuf_rde, ibuf_rtr)) fatal("could not establish imsg links"); /* control setup needs to happen late since it sends imsgs */ if (control_setup(conf) == -1) quit = 1; if (send_config(conf) != 0) quit = 1; if (pftable_clear_all() != 0) quit = 1; while (quit == 0) { if (pfd_elms < PFD_CONNECT_START + connect_cnt) { struct pollfd *newp; if ((newp = reallocarray(pfd, PFD_CONNECT_START + connect_cnt, sizeof(struct pollfd))) == NULL) { log_warn("could not resize pfd from %u -> %u" " entries", pfd_elms, PFD_CONNECT_START + connect_cnt); fatalx("exiting"); } pfd = newp; pfd_elms = PFD_CONNECT_START + connect_cnt; } memset(pfd, 0, sizeof(struct pollfd) * pfd_elms); timeout = mrt_timeout(conf->mrt); pfd[PFD_SOCK_ROUTE].fd = rfd; pfd[PFD_SOCK_ROUTE].events = POLLIN; pfd[PFD_SOCK_PFKEY].fd = keyfd; pfd[PFD_SOCK_PFKEY].events = POLLIN; set_pollfd(&pfd[PFD_PIPE_SESSION], ibuf_se); set_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde); set_pollfd(&pfd[PFD_PIPE_RTR], ibuf_rtr); npfd = PFD_CONNECT_START; TAILQ_FOREACH(ce, &connect_queue, entry) { pfd[npfd].fd = ce->fd; pfd[npfd++].events = POLLOUT; if (npfd > pfd_elms) fatalx("polli pfd overflow"); } if (timeout < 0 || timeout > MAX_TIMEOUT) timeout = MAX_TIMEOUT; if (poll(pfd, npfd, timeout * 1000) == -1) { if (errno != EINTR) { log_warn("poll error"); quit = 1; } goto next_loop; } if (handle_pollfd(&pfd[PFD_PIPE_SESSION], ibuf_se) == -1) { log_warnx("main: Lost connection to SE"); imsgbuf_clear(ibuf_se); free(ibuf_se); ibuf_se = NULL; quit = 1; } else { if (dispatch_imsg(ibuf_se, PFD_PIPE_SESSION, conf) == -1) quit = 1; } if (handle_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde) == -1) { log_warnx("main: Lost connection to RDE"); imsgbuf_clear(ibuf_rde); free(ibuf_rde); ibuf_rde = NULL; quit = 1; } else { if (dispatch_imsg(ibuf_rde, PFD_PIPE_RDE, conf) == -1) quit = 1; } if (handle_pollfd(&pfd[PFD_PIPE_RTR], ibuf_rtr) == -1) { log_warnx("main: Lost connection to RTR"); imsgbuf_clear(ibuf_rtr); free(ibuf_rtr); ibuf_rtr = NULL; quit = 1; } else { if (dispatch_imsg(ibuf_rtr, PFD_PIPE_RTR, conf) == -1) quit = 1; } if (pfd[PFD_SOCK_ROUTE].revents & POLLIN) { if (kr_dispatch_msg() == -1) quit = 1; } if (pfd[PFD_SOCK_PFKEY].revents & POLLIN) { if (pfkey_read(keyfd, NULL) == -1) { log_warnx("pfkey_read failed, exiting..."); quit = 1; } } for (i = PFD_CONNECT_START; i < npfd; i++) if (pfd[i].revents != 0) bgpd_rtr_conn_setup_done(pfd[i].fd, conf); next_loop: if (reconfig) { u_int error; reconfig = 0; switch (reconfigure(conffile, conf)) { case -1: /* fatal error */ quit = 1; break; case 0: /* all OK */ error = 0; break; case 2: log_info("previous reload still running"); error = CTL_RES_PENDING; break; default: /* parse error */ log_warnx("config file %s has errors, " "not reloading", conffile); error = CTL_RES_PARSE_ERROR; break; } if (reconfpid != 0) { send_imsg_session(IMSG_CTL_RESULT, reconfpid, &error, sizeof(error)); reconfpid = 0; } } if (mrtdump) { mrtdump = 0; mrt_handler(conf->mrt); } } /* close pipes */ if (ibuf_se) { imsgbuf_clear(ibuf_se); close(ibuf_se->fd); free(ibuf_se); ibuf_se = NULL; } if (ibuf_rde) { imsgbuf_clear(ibuf_rde); close(ibuf_rde->fd); free(ibuf_rde); ibuf_rde = NULL; } if (ibuf_rtr) { imsgbuf_clear(ibuf_rtr); close(ibuf_rtr->fd); free(ibuf_rtr); ibuf_rtr = NULL; } /* cleanup kernel data structures */ carp_demote_shutdown(); kr_shutdown(); pftable_clear_all(); RB_FOREACH(p, peer_head, &conf->peers) pfkey_remove(&p->auth_state); while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) { SIMPLEQ_REMOVE_HEAD(&ribnames, entry); free(rr); } free_config(conf); log_debug("waiting for children to terminate"); do { pid = wait(&status); if (pid == -1) { if (errno != EINTR && errno != ECHILD) fatal("wait"); } else if (WIFSIGNALED(status)) { char *name = "unknown process"; if (pid == rde_pid) name = "route decision engine"; else if (pid == se_pid) name = "session engine"; else if (pid == rtr_pid) name = "rtr engine"; log_warnx("%s terminated; signal %d", name, WTERMSIG(status)); } } while (pid != -1 || (pid == -1 && errno == EINTR)); free(rcname); free(cname); log_info("terminating"); return (0); } pid_t start_child(enum bgpd_process p, char *argv0, int fd, int debug, int verbose) { char *argv[5]; int argc = 0; pid_t pid; switch (pid = fork()) { case -1: fatal("cannot fork"); case 0: break; default: close(fd); return (pid); } if (fd != 3) { if (dup2(fd, 3) == -1) fatal("cannot setup imsg fd"); } else if (fcntl(fd, F_SETFD, 0) == -1) fatal("cannot setup imsg fd"); argv[argc++] = argv0; switch (p) { case PROC_MAIN: fatalx("Can not start main process"); case PROC_RDE: argv[argc++] = "-R"; break; case PROC_SE: argv[argc++] = "-S"; break; case PROC_RTR: argv[argc++] = "-T"; break; } if (debug) argv[argc++] = "-d"; if (verbose) argv[argc++] = "-v"; argv[argc++] = NULL; execvp(argv0, argv); fatal("execvp"); } int send_filterset(struct imsgbuf *i, struct filter_set_head *set) { struct filter_set *s; TAILQ_FOREACH(s, set, entry) if (imsg_compose(i, IMSG_FILTER_SET, 0, 0, -1, s, sizeof(struct filter_set)) == -1) return (-1); return (0); } int reconfigure(char *conffile, struct bgpd_config *conf) { struct bgpd_config *new_conf; if (reconfpending) return (2); log_info("rereading config"); if ((new_conf = parse_config(conffile, &conf->peers, &conf->rtrs)) == NULL) return (1); merge_config(conf, new_conf); if (prepare_listeners(conf) == -1) return (1); if (control_setup(conf) == -1) return (1); return send_config(conf); } int send_config(struct bgpd_config *conf) { struct peer *p; struct filter_rule *r; struct listen_addr *la; struct rde_rib *rr; struct l3vpn *vpn; struct as_set *aset; struct prefixset *ps; struct prefixset_item *psi, *npsi; struct roa *roa; struct aspa_set *aspa; struct rtr_config *rtr; struct flowspec_config *f, *nf; reconfpending = 3; /* one per child */ expand_networks(conf, &conf->networks); SIMPLEQ_FOREACH(vpn, &conf->l3vpns, entry) expand_networks(conf, &vpn->net_l); cflags = conf->flags; /* start reconfiguration */ if (imsg_compose(ibuf_se, IMSG_RECONF_CONF, 0, 0, -1, conf, sizeof(*conf)) == -1) return (-1); if (imsg_compose(ibuf_rde, IMSG_RECONF_CONF, 0, 0, -1, conf, sizeof(*conf)) == -1) return (-1); if (imsg_compose(ibuf_rtr, IMSG_RECONF_CONF, 0, 0, -1, conf, sizeof(*conf)) == -1) return (-1); TAILQ_FOREACH(la, conf->listen_addrs, entry) { if (imsg_compose(ibuf_se, IMSG_RECONF_LISTENER, 0, 0, la->fd, la, sizeof(*la)) == -1) return (-1); la->fd = -1; } /* adjust fib syncing on reload */ ktable_preload(); /* RIBs for the RDE */ while ((rr = SIMPLEQ_FIRST(&ribnames))) { SIMPLEQ_REMOVE_HEAD(&ribnames, entry); if (ktable_update(rr->rtableid, rr->name, rr->flags) == -1) { log_warnx("failed to load routing table %d", rr->rtableid); return (-1); } if (imsg_compose(ibuf_rde, IMSG_RECONF_RIB, 0, 0, -1, rr, sizeof(*rr)) == -1) return (-1); free(rr); } /* send peer list to the SE */ RB_FOREACH(p, peer_head, &conf->peers) { if (p->reconf_action == RECONF_DELETE) continue; if (imsg_compose(ibuf_se, IMSG_RECONF_PEER, p->conf.id, 0, -1, &p->conf, sizeof(p->conf)) == -1) return (-1); if (pfkey_send_conf(ibuf_se, p->conf.id, &p->auth_conf) == -1) return (-1); if (p->reconf_action == RECONF_REINIT) if (pfkey_establish(&p->auth_state, &p->auth_conf, session_localaddr(p), &p->conf.remote_addr) == -1) log_peer_warnx(&p->conf, "auth setup failed"); } /* networks go via kroute to the RDE */ kr_net_reload(conf->default_tableid, 0, &conf->networks); /* flowspec goes directly to the RDE, also remove old objects */ RB_FOREACH_SAFE(f, flowspec_tree, &conf->flowspecs, nf) { if (f->reconf_action != RECONF_DELETE) { if (imsg_compose(ibuf_rde, IMSG_FLOWSPEC_ADD, 0, 0, -1, f->flow, FLOWSPEC_SIZE + f->flow->len) == -1) return (-1); if (send_filterset(ibuf_rde, &f->attrset) == -1) return (-1); if (imsg_compose(ibuf_rde, IMSG_FLOWSPEC_DONE, 0, 0, -1, NULL, 0) == -1) return (-1); } else { if (imsg_compose(ibuf_rde, IMSG_FLOWSPEC_REMOVE, 0, 0, -1, f->flow, FLOWSPEC_SIZE + f->flow->len) == -1) return (-1); RB_REMOVE(flowspec_tree, &conf->flowspecs, f); flowspec_free(f); } } /* prefixsets for filters in the RDE */ while ((ps = SIMPLEQ_FIRST(&conf->prefixsets)) != NULL) { SIMPLEQ_REMOVE_HEAD(&conf->prefixsets, entry); if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIX_SET, 0, 0, -1, ps->name, sizeof(ps->name)) == -1) return (-1); RB_FOREACH_SAFE(psi, prefixset_tree, &ps->psitems, npsi) { RB_REMOVE(prefixset_tree, &ps->psitems, psi); if (imsg_compose(ibuf_rde, IMSG_RECONF_PREFIX_SET_ITEM, 0, 0, -1, psi, sizeof(*psi)) == -1) return (-1); free(psi); } free(ps); } /* originsets for filters in the RDE */ while ((ps = SIMPLEQ_FIRST(&conf->originsets)) != NULL) { SIMPLEQ_REMOVE_HEAD(&conf->originsets, entry); if (imsg_compose(ibuf_rde, IMSG_RECONF_ORIGIN_SET, 0, 0, -1, ps->name, sizeof(ps->name)) == -1) return (-1); RB_FOREACH(roa, roa_tree, &ps->roaitems) { if (imsg_compose(ibuf_rde, IMSG_RECONF_ROA_ITEM, 0, 0, -1, roa, sizeof(*roa)) == -1) return (-1); } free_roatree(&ps->roaitems); free(ps); } /* roa table, aspa table and rtr config are sent to the RTR engine */ RB_FOREACH(roa, roa_tree, &conf->roa) { if (imsg_compose(ibuf_rtr, IMSG_RECONF_ROA_ITEM, 0, 0, -1, roa, sizeof(*roa)) == -1) return (-1); } free_roatree(&conf->roa); RB_FOREACH(aspa, aspa_tree, &conf->aspa) { if (imsg_compose(ibuf_rtr, IMSG_RECONF_ASPA, 0, 0, -1, aspa, offsetof(struct aspa_set, tas)) == -1) return (-1); if (imsg_compose(ibuf_rtr, IMSG_RECONF_ASPA_TAS, 0, 0, -1, aspa->tas, aspa->num * sizeof(*aspa->tas)) == -1) return (-1); if (imsg_compose(ibuf_rtr, IMSG_RECONF_ASPA_DONE, 0, 0, -1, NULL, 0) == -1) return -1; } free_aspatree(&conf->aspa); SIMPLEQ_FOREACH(rtr, &conf->rtrs, entry) { struct rtr_config_msg rtrconf = { 0 }; strlcpy(rtrconf.descr, rtr->descr, sizeof(rtrconf.descr)); rtrconf.min_version = rtr->min_version; if (imsg_compose(ibuf_rtr, IMSG_RECONF_RTR_CONFIG, rtr->id, 0, -1, &rtrconf, sizeof(rtrconf)) == -1) return (-1); } /* as-sets for filters in the RDE */ while ((aset = SIMPLEQ_FIRST(&conf->as_sets)) != NULL) { struct ibuf *wbuf; uint32_t *as; size_t i, l, n; SIMPLEQ_REMOVE_HEAD(&conf->as_sets, entry); as = set_get(aset->set, &n); if ((wbuf = imsg_create(ibuf_rde, IMSG_RECONF_AS_SET, 0, 0, sizeof(n) + sizeof(aset->name))) == NULL) return -1; if (imsg_add(wbuf, &n, sizeof(n)) == -1 || imsg_add(wbuf, aset->name, sizeof(aset->name)) == -1) return -1; imsg_close(ibuf_rde, wbuf); for (i = 0; i < n; i += l) { l = (n - i > 1024 ? 1024 : n - i); if (imsg_compose(ibuf_rde, IMSG_RECONF_AS_SET_ITEMS, 0, 0, -1, as + i, l * sizeof(*as)) == -1) return -1; } if (imsg_compose(ibuf_rde, IMSG_RECONF_AS_SET_DONE, 0, 0, -1, NULL, 0) == -1) return -1; set_free(aset->set); free(aset); } /* filters for the RDE */ while ((r = TAILQ_FIRST(conf->filters)) != NULL) { TAILQ_REMOVE(conf->filters, r, entry); if (send_filterset(ibuf_rde, &r->set) == -1) return (-1); if (imsg_compose(ibuf_rde, IMSG_RECONF_FILTER, 0, 0, -1, r, sizeof(struct filter_rule)) == -1) return (-1); filterset_free(&r->set); free(r); } while ((vpn = SIMPLEQ_FIRST(&conf->l3vpns)) != NULL) { SIMPLEQ_REMOVE_HEAD(&conf->l3vpns, entry); if (ktable_update(vpn->rtableid, vpn->descr, vpn->flags) == -1) { log_warnx("failed to load routing table %d", vpn->rtableid); return (-1); } /* networks go via kroute to the RDE */ kr_net_reload(vpn->rtableid, vpn->rd, &vpn->net_l); if (imsg_compose(ibuf_rde, IMSG_RECONF_VPN, 0, 0, -1, vpn, sizeof(*vpn)) == -1) return (-1); /* export targets */ if (send_filterset(ibuf_rde, &vpn->export) == -1) return (-1); if (imsg_compose(ibuf_rde, IMSG_RECONF_VPN_EXPORT, 0, 0, -1, NULL, 0) == -1) return (-1); filterset_free(&vpn->export); /* import targets */ if (send_filterset(ibuf_rde, &vpn->import) == -1) return (-1); if (imsg_compose(ibuf_rde, IMSG_RECONF_VPN_IMPORT, 0, 0, -1, NULL, 0) == -1) return (-1); filterset_free(&vpn->import); if (imsg_compose(ibuf_rde, IMSG_RECONF_VPN_DONE, 0, 0, -1, NULL, 0) == -1) return (-1); free(vpn); } /* send a drain message to know when all messages where processed */ if (imsg_compose(ibuf_se, IMSG_RECONF_DRAIN, 0, 0, -1, NULL, 0) == -1) return (-1); if (imsg_compose(ibuf_rde, IMSG_RECONF_DRAIN, 0, 0, -1, NULL, 0) == -1) return (-1); if (imsg_compose(ibuf_rtr, IMSG_RECONF_DRAIN, 0, 0, -1, NULL, 0) == -1) return (-1); /* mrt changes can be sent out of bound */ mrt_reconfigure(conf->mrt); return (0); } int dispatch_imsg(struct imsgbuf *imsgbuf, int idx, struct bgpd_config *conf) { struct imsg imsg; struct peer *p; struct rtr_config *r; struct kroute_full kf; struct bgpd_addr addr; struct pftable_msg pfmsg; struct demote_msg demote; char reason[REASON_LEN], ifname[IFNAMSIZ]; ssize_t n; u_int rtableid; int rv, verbose; rv = 0; while (imsgbuf) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) return (-1); if (n == 0) break; switch (imsg_get_type(&imsg)) { case IMSG_KROUTE_CHANGE: if (idx != PFD_PIPE_RDE) log_warnx("route request not from RDE"); else if (imsg_get_data(&imsg, &kf, sizeof(kf)) == -1) log_warn("wrong imsg len"); else if (kr_change(imsg_get_id(&imsg), &kf)) rv = -1; break; case IMSG_KROUTE_DELETE: if (idx != PFD_PIPE_RDE) log_warnx("route request not from RDE"); else if (imsg_get_data(&imsg, &kf, sizeof(kf)) == -1) log_warn("wrong imsg len"); else if (kr_delete(imsg_get_id(&imsg), &kf)) rv = -1; break; case IMSG_KROUTE_FLUSH: if (idx != PFD_PIPE_RDE) log_warnx("route request not from RDE"); else if (kr_flush(imsg_get_id(&imsg))) rv = -1; break; case IMSG_NEXTHOP_ADD: if (idx != PFD_PIPE_RDE) log_warnx("nexthop request not from RDE"); else if (imsg_get_data(&imsg, &addr, sizeof(addr)) == -1) log_warn("wrong imsg len"); else { rtableid = conf->default_tableid; if (kr_nexthop_add(rtableid, &addr) == -1) rv = -1; } break; case IMSG_NEXTHOP_REMOVE: if (idx != PFD_PIPE_RDE) log_warnx("nexthop request not from RDE"); else if (imsg_get_data(&imsg, &addr, sizeof(addr)) == -1) log_warn("wrong imsg len"); else { rtableid = conf->default_tableid; kr_nexthop_delete(rtableid, &addr); } break; case IMSG_PFTABLE_ADD: if (idx != PFD_PIPE_RDE) log_warnx("pftable request not from RDE"); else if (imsg_get_data(&imsg, &pfmsg, sizeof(pfmsg)) == -1) log_warn("wrong imsg len"); else if (pftable_addr_add(&pfmsg) != 0) rv = -1; break; case IMSG_PFTABLE_REMOVE: if (idx != PFD_PIPE_RDE) log_warnx("pftable request not from RDE"); else if (imsg_get_data(&imsg, &pfmsg, sizeof(pfmsg)) == -1) log_warn("wrong imsg len"); else if (pftable_addr_remove(&pfmsg) != 0) rv = -1; break; case IMSG_PFTABLE_COMMIT: if (idx != PFD_PIPE_RDE) log_warnx("pftable request not from RDE"); else if (pftable_commit() != 0) rv = -1; break; case IMSG_PFKEY_RELOAD: if (idx != PFD_PIPE_SESSION) { log_warnx("pfkey reload request not from SE"); break; } p = getpeerbyid(conf, imsg_get_id(&imsg)); if (p != NULL) { if (pfkey_establish(&p->auth_state, &p->auth_conf, session_localaddr(p), &p->conf.remote_addr) == -1) log_peer_warnx(&p->conf, "pfkey setup failed"); } break; case IMSG_CTL_RELOAD: if (idx != PFD_PIPE_SESSION) log_warnx("reload request not from SE"); else { reconfig = 1; reconfpid = imsg_get_pid(&imsg); if (imsg_get_data(&imsg, reason, sizeof(reason)) == 0 && reason[0] != '\0') log_info("reload due to: %s", log_reason(reason)); } break; case IMSG_CTL_FIB_COUPLE: if (idx != PFD_PIPE_SESSION) log_warnx("couple request not from SE"); else kr_fib_couple(imsg_get_id(&imsg)); break; case IMSG_CTL_FIB_DECOUPLE: if (idx != PFD_PIPE_SESSION) log_warnx("decouple request not from SE"); else kr_fib_decouple(imsg_get_id(&imsg)); break; case IMSG_CTL_KROUTE: case IMSG_CTL_KROUTE_ADDR: case IMSG_CTL_SHOW_NEXTHOP: case IMSG_CTL_SHOW_INTERFACE: case IMSG_CTL_SHOW_FIB_TABLES: if (idx != PFD_PIPE_SESSION) log_warnx("kroute request not from SE"); else kr_show_route(&imsg); break; case IMSG_SESSION_DEPENDON: if (idx != PFD_PIPE_SESSION) log_warnx("DEPENDON request not from SE"); else if (imsg_get_data(&imsg, ifname, sizeof(ifname)) == -1) log_warn("wrong imsg len"); else kr_ifinfo(ifname); break; case IMSG_DEMOTE: if (idx != PFD_PIPE_SESSION) log_warnx("demote request not from SE"); else if (imsg_get_data(&imsg, &demote, sizeof(demote)) == -1) log_warn("wrong imsg len"); else carp_demote_set(demote.demote_group, demote.level); break; case IMSG_CTL_LOG_VERBOSE: /* already checked by SE */ if (imsg_get_data(&imsg, &verbose, sizeof(verbose)) == -1) log_warn("wrong imsg len"); else log_setverbose(verbose); break; case IMSG_RECONF_DONE: if (reconfpending == 0) { log_warnx("unexpected RECONF_DONE received"); break; } if (idx == PFD_PIPE_SESSION) { /* RDE and RTR engine can reload concurrently */ imsg_compose(ibuf_rtr, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0); imsg_compose(ibuf_rde, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0); /* finally fix kroute information */ ktable_postload(); /* redistribute list needs to be reloaded too */ kr_reload(); /* also remove old peers */ free_deleted_peers(conf); } reconfpending--; break; case IMSG_RECONF_DRAIN: if (reconfpending == 0) { log_warnx("unexpected RECONF_DRAIN received"); break; } reconfpending--; if (reconfpending == 0) { /* * SE goes first to bring templated neighbors * in sync. */ imsg_compose(ibuf_se, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0); reconfpending = 3; /* expecting 2 DONE msg */ } break; case IMSG_SOCKET_SETUP: if (idx != PFD_PIPE_RTR) { log_warnx("connect request not from RTR"); } else { uint32_t rtrid = imsg_get_id(&imsg); SIMPLEQ_FOREACH(r, &conf->rtrs, entry) { if (rtrid == r->id) break; } if (r == NULL) log_warnx("unknown rtr id %d", rtrid); else bgpd_rtr_conn_setup(r); } break; case IMSG_SOCKET_TEARDOWN: if (idx != PFD_PIPE_RTR) { log_warnx("connect request not from RTR"); } else { uint32_t rtrid = imsg_get_id(&imsg); bgpd_rtr_conn_teardown(rtrid); } break; case IMSG_CTL_SHOW_RTR: if (idx == PFD_PIPE_SESSION) { SIMPLEQ_FOREACH(r, &conf->rtrs, entry) { imsg_compose(ibuf_rtr, IMSG_CTL_SHOW_RTR, r->id, imsg_get_pid(&imsg), -1, NULL, 0); } imsg_compose(ibuf_rtr, IMSG_CTL_END, 0, imsg_get_pid(&imsg), -1, NULL, 0); } else if (idx == PFD_PIPE_RTR) { struct ctl_show_rtr rtr; if (imsg_get_data(&imsg, &rtr, sizeof(rtr)) == -1) { log_warn("wrong imsg len"); break; } SIMPLEQ_FOREACH(r, &conf->rtrs, entry) { if (imsg_get_id(&imsg) == r->id) break; } if (r != NULL) { strlcpy(rtr.descr, r->descr, sizeof(rtr.descr)); rtr.local_addr = r->local_addr; rtr.remote_addr = r->remote_addr; rtr.remote_port = r->remote_port; imsg_compose(ibuf_se, IMSG_CTL_SHOW_RTR, imsg_get_id(&imsg), imsg_get_pid(&imsg), -1, &rtr, sizeof(rtr)); } } break; case IMSG_CTL_END: case IMSG_CTL_SHOW_TIMER: if (idx != PFD_PIPE_RTR) { log_warnx("connect request not from RTR"); break; } imsg_forward(ibuf_se, &imsg); break; default: break; } imsg_free(&imsg); if (rv != 0) return (rv); } return (0); } void send_nexthop_update(struct kroute_nexthop *msg) { char *gw = NULL; if (msg->gateway.aid) if (asprintf(&gw, ": via %s", log_addr(&msg->gateway)) == -1) { log_warn("send_nexthop_update"); quit = 1; } log_debug("nexthop %s now %s%s%s", log_addr(&msg->nexthop), msg->valid ? "valid" : "invalid", msg->connected ? ": directly connected" : "", msg->gateway.aid ? gw : ""); free(gw); if (imsg_compose(ibuf_rde, IMSG_NEXTHOP_UPDATE, 0, 0, -1, msg, sizeof(struct kroute_nexthop)) == -1) quit = 1; } void send_imsg_session(int type, pid_t pid, void *data, uint16_t datalen) { imsg_compose(ibuf_se, type, 0, pid, -1, data, datalen); } int send_network(int type, struct network_config *net, struct filter_set_head *h) { if (quit) return (0); if (imsg_compose(ibuf_rde, type, 0, 0, -1, net, sizeof(struct network_config)) == -1) return (-1); /* networks that get deleted don't need to send the filter set */ if (type == IMSG_NETWORK_REMOVE) return (0); if (send_filterset(ibuf_rde, h) == -1) return (-1); if (imsg_compose(ibuf_rde, IMSG_NETWORK_DONE, 0, 0, -1, NULL, 0) == -1) return (-1); return (0); } /* * Return true if a route can be used for nexthop resolution. */ int bgpd_oknexthop(struct kroute_full *kf) { if (kf->flags & F_BGPD) return ((cflags & BGPD_FLAG_NEXTHOP_BGP) != 0); if (kf->prefixlen == 0) return ((cflags & BGPD_FLAG_NEXTHOP_DEFAULT) != 0); /* any other route is fine */ return (1); } int bgpd_has_bgpnh(void) { return ((cflags & BGPD_FLAG_NEXTHOP_BGP) != 0); } int control_setup(struct bgpd_config *conf) { int fd, restricted; /* control socket is outside chroot */ if (!cname || strcmp(cname, conf->csock)) { if (cname) { free(cname); } if ((cname = strdup(conf->csock)) == NULL) fatal("strdup"); if (control_check(cname) == -1) return (-1); if ((fd = control_init(0, cname)) == -1) fatalx("control socket setup failed"); if (control_listen(fd) == -1) fatalx("control socket setup failed"); restricted = 0; if (imsg_compose(ibuf_se, IMSG_RECONF_CTRL, 0, 0, fd, &restricted, sizeof(restricted)) == -1) return (-1); } if (!conf->rcsock) { /* remove restricted socket */ free(rcname); rcname = NULL; } else if (!rcname || strcmp(rcname, conf->rcsock)) { if (rcname) { free(rcname); } if ((rcname = strdup(conf->rcsock)) == NULL) fatal("strdup"); if (control_check(rcname) == -1) return (-1); if ((fd = control_init(1, rcname)) == -1) fatalx("control socket setup failed"); if (control_listen(fd) == -1) fatalx("control socket setup failed"); restricted = 1; if (imsg_compose(ibuf_se, IMSG_RECONF_CTRL, 0, 0, fd, &restricted, sizeof(restricted)) == -1) return (-1); } return (0); } void set_pollfd(struct pollfd *pfd, struct imsgbuf *i) { if (i == NULL || i->fd == -1) { pfd->fd = -1; return; } pfd->fd = i->fd; pfd->events = POLLIN; if (imsgbuf_queuelen(i) > 0) pfd->events |= POLLOUT; } int handle_pollfd(struct pollfd *pfd, struct imsgbuf *i) { ssize_t n; if (i == NULL) return (0); if (pfd->revents & POLLOUT) if (imsgbuf_write(i) == -1) { log_warn("imsg write error"); close(i->fd); i->fd = -1; return (-1); } if (pfd->revents & POLLIN) { if ((n = imsgbuf_read(i)) == -1) { log_warn("imsg read error"); close(i->fd); i->fd = -1; return (-1); } if (n == 0) { log_warnx("peer closed imsg connection"); close(i->fd); i->fd = -1; return (-1); } } return (0); } static void getsockpair(int pipe[2]) { int bsize, i; if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, PF_UNSPEC, pipe) == -1) fatal("socketpair"); for (i = 0; i < 2; i++) { bsize = MAX_SOCK_BUF; if (setsockopt(pipe[i], SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)) == -1) { if (errno != ENOBUFS) fatal("setsockopt(SO_RCVBUF, %d)", bsize); log_warn("setsockopt(SO_RCVBUF, %d)", bsize); } } for (i = 0; i < 2; i++) { bsize = MAX_SOCK_BUF; if (setsockopt(pipe[i], SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize)) == -1) { if (errno != ENOBUFS) fatal("setsockopt(SO_SNDBUF, %d)", bsize); log_warn("setsockopt(SO_SNDBUF, %d)", bsize); } } } int imsg_send_sockets(struct imsgbuf *se, struct imsgbuf *rde, struct imsgbuf *rtr) { int pipe_s2r[2]; int pipe_s2r_ctl[2]; int pipe_r2r[2]; getsockpair(pipe_s2r); getsockpair(pipe_s2r_ctl); getsockpair(pipe_r2r); if (imsg_compose(se, IMSG_SOCKET_CONN, 0, 0, pipe_s2r[0], NULL, 0) == -1) return (-1); if (imsg_compose(rde, IMSG_SOCKET_CONN, 0, 0, pipe_s2r[1], NULL, 0) == -1) return (-1); if (imsg_compose(se, IMSG_SOCKET_CONN_CTL, 0, 0, pipe_s2r_ctl[0], NULL, 0) == -1) return (-1); if (imsg_compose(rde, IMSG_SOCKET_CONN_CTL, 0, 0, pipe_s2r_ctl[1], NULL, 0) == -1) return (-1); if (imsg_compose(rtr, IMSG_SOCKET_CONN_RTR, 0, 0, pipe_r2r[0], NULL, 0) == -1) return (-1); if (imsg_compose(rde, IMSG_SOCKET_CONN_RTR, 0, 0, pipe_r2r[1], NULL, 0) == -1) return (-1); return (0); } void bgpd_rtr_conn_setup(struct rtr_config *r) { struct connect_elm *ce; struct sockaddr *sa; socklen_t len; int nodelay = 1; int pre = IPTOS_PREC_INTERNETCONTROL; if (connect_cnt >= MAX_CONNECT_CNT) { log_warnx("rtr %s: too many concurrent connection requests", r->descr); return; } if ((ce = calloc(1, sizeof(*ce))) == NULL) { log_warn("rtr %s", r->descr); return; } if (pfkey_establish(&ce->auth_state, &r->auth, &r->local_addr, &r->remote_addr) == -1) log_warnx("rtr %s: pfkey setup failed", r->descr); ce->id = r->id; ce->fd = socket(aid2af(r->remote_addr.aid), SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_TCP); if (ce->fd == -1) { log_warn("rtr %s", r->descr); goto fail; } switch (r->remote_addr.aid) { case AID_INET: if (setsockopt(ce->fd, IPPROTO_IP, IP_TOS, &pre, sizeof(pre)) == -1) { log_warn("rtr %s: setsockopt IP_TOS", r->descr); return; } break; case AID_INET6: if (setsockopt(ce->fd, IPPROTO_IPV6, IPV6_TCLASS, &pre, sizeof(pre)) == -1) { log_warn("rtr %s: setsockopt IP_TOS", r->descr); return; } break; } if (setsockopt(ce->fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)) == -1) { log_warn("rtr %s: setsockopt TCP_NODELAY", r->descr); return; } if (tcp_md5_set(ce->fd, &r->auth, &r->remote_addr) == -1) log_warn("rtr %s: setting md5sig", r->descr); if ((sa = addr2sa(&r->local_addr, 0, &len)) != NULL) { if (bind(ce->fd, sa, len) == -1) { log_warn("rtr %s: bind to %s", r->descr, log_addr(&r->local_addr)); goto fail; } } sa = addr2sa(&r->remote_addr, r->remote_port, &len); if (connect(ce->fd, sa, len) == -1) { if (errno != EINPROGRESS) { log_warn("rtr %s: connect to %s:%u", r->descr, log_addr(&r->remote_addr), r->remote_port); goto fail; } TAILQ_INSERT_TAIL(&connect_queue, ce, entry); connect_cnt++; return; } imsg_compose(ibuf_rtr, IMSG_SOCKET_SETUP, ce->id, 0, ce->fd, NULL, 0); TAILQ_INSERT_TAIL(&socket_queue, ce, entry); return; fail: if (ce->fd != -1) close(ce->fd); free(ce); } void bgpd_rtr_conn_setup_done(int fd, struct bgpd_config *conf) { struct rtr_config *r; struct connect_elm *ce; int error = 0; socklen_t len; TAILQ_FOREACH(ce, &connect_queue, entry) { if (ce->fd == fd) break; } if (ce == NULL) fatalx("connect entry not found"); TAILQ_REMOVE(&connect_queue, ce, entry); connect_cnt--; SIMPLEQ_FOREACH(r, &conf->rtrs, entry) { if (ce->id == r->id) break; } if (r == NULL) { log_warnx("rtr id %d no longer exists", ce->id); goto fail; } len = sizeof(error); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) == -1) { log_warn("rtr %s: getsockopt SO_ERROR", r->descr); goto fail; } if (error != 0) { errno = error; log_warn("rtr %s: connect to %s:%u", r->descr, log_addr(&r->remote_addr), r->remote_port); goto fail; } imsg_compose(ibuf_rtr, IMSG_SOCKET_SETUP, ce->id, 0, ce->fd, NULL, 0); TAILQ_INSERT_TAIL(&socket_queue, ce, entry); return; fail: close(fd); free(ce); } void bgpd_rtr_conn_teardown(uint32_t id) { struct connect_elm *ce; TAILQ_FOREACH(ce, &socket_queue, entry) { if (ce->id == id) { pfkey_remove(&ce->auth_state); TAILQ_REMOVE(&socket_queue, ce, entry); free(ce); return; } } } openbgpd-8.8/src/bgpd/session.c100644 001750 001750 00000304064 14751151130 0012230/* $OpenBSD: session.c,v 1.510 2025/02/06 12:38:58 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer * Copyright (c) 2017 Peter van Dijk * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" #define PFD_PIPE_MAIN 0 #define PFD_PIPE_ROUTE 1 #define PFD_PIPE_ROUTE_CTL 2 #define PFD_SOCK_CTL 3 #define PFD_SOCK_RCTL 4 #define PFD_LISTENERS_START 5 void session_sighdlr(int); int setup_listeners(u_int *); void init_peer(struct peer *); void start_timer_holdtime(struct peer *); void start_timer_sendholdtime(struct peer *); void start_timer_keepalive(struct peer *); void session_close_connection(struct peer *); void change_state(struct peer *, enum session_state, enum session_events); int session_setup_socket(struct peer *); void session_accept(int); int session_connect(struct peer *); void session_tcp_established(struct peer *); int session_capa_add(struct ibuf *, uint8_t, uint8_t); struct ibuf *session_newmsg(enum msg_type, uint16_t); void session_sendmsg(struct ibuf *, struct peer *, enum msg_type); void session_open(struct peer *); void session_keepalive(struct peer *); void session_update(uint32_t, struct ibuf *); void session_notification(struct peer *, uint8_t, uint8_t, struct ibuf *); void session_notification_data(struct peer *, uint8_t, uint8_t, void *, size_t); void session_rrefresh(struct peer *, uint8_t, uint8_t); int session_graceful_restart(struct peer *); int session_graceful_stop(struct peer *); int session_dispatch_msg(struct pollfd *, struct peer *); void session_process_msg(struct peer *); struct ibuf *parse_header(struct ibuf *, void *, int *); int parse_open(struct peer *, struct ibuf *); int parse_update(struct peer *, struct ibuf *); int parse_rrefresh(struct peer *, struct ibuf *); void parse_notification(struct peer *, struct ibuf *); int parse_capabilities(struct peer *, struct ibuf *, uint32_t *); int capa_neg_calc(struct peer *); void session_dispatch_imsg(struct imsgbuf *, int, u_int *); void session_up(struct peer *); void session_down(struct peer *); int imsg_rde(int, uint32_t, void *, uint16_t); void session_demote(struct peer *, int); void merge_peers(struct bgpd_config *, struct bgpd_config *); int la_cmp(struct listen_addr *, struct listen_addr *); void session_template_clone(struct peer *, struct sockaddr *, uint32_t, uint32_t); int session_match_mask(struct peer *, struct bgpd_addr *); static struct bgpd_config *conf, *nconf; static struct imsgbuf *ibuf_rde; static struct imsgbuf *ibuf_rde_ctl; static struct imsgbuf *ibuf_main; struct bgpd_sysdep sysdep; volatile sig_atomic_t session_quit; int pending_reconf; int csock = -1, rcsock = -1; u_int peer_cnt; struct mrt_head mrthead; time_t pauseaccept; static const uint8_t marker[MSGSIZE_HEADER_MARKER] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; static inline int peer_compare(const struct peer *a, const struct peer *b) { return a->conf.id - b->conf.id; } RB_GENERATE(peer_head, peer, entry, peer_compare); void session_sighdlr(int sig) { switch (sig) { case SIGINT: case SIGTERM: session_quit = 1; break; } } int setup_listeners(u_int *la_cnt) { int ttl = 255; struct listen_addr *la; u_int cnt = 0; TAILQ_FOREACH(la, conf->listen_addrs, entry) { la->reconf = RECONF_NONE; cnt++; if (la->flags & LISTENER_LISTENING) continue; if (la->fd == -1) { log_warn("cannot establish listener on %s: invalid fd", log_sockaddr((struct sockaddr *)&la->sa, la->sa_len)); continue; } if (tcp_md5_prep_listener(la, &conf->peers) == -1) fatal("tcp_md5_prep_listener"); /* set ttl to 255 so that ttl-security works */ if (la->sa.ss_family == AF_INET && setsockopt(la->fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) == -1) { log_warn("setup_listeners setsockopt TTL"); continue; } if (la->sa.ss_family == AF_INET6 && setsockopt(la->fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) == -1) { log_warn("setup_listeners setsockopt hoplimit"); continue; } if (listen(la->fd, MAX_BACKLOG)) { close(la->fd); fatal("listen"); } la->flags |= LISTENER_LISTENING; log_info("listening on %s", log_sockaddr((struct sockaddr *)&la->sa, la->sa_len)); } *la_cnt = cnt; return (0); } void session_main(int debug, int verbose) { int timeout; unsigned int i, j, idx_peers, idx_listeners, idx_mrts; u_int pfd_elms = 0, peer_l_elms = 0, mrt_l_elms = 0; u_int listener_cnt, ctl_cnt, mrt_cnt; u_int new_cnt; struct passwd *pw; struct peer *p, **peer_l = NULL, *next; struct mrt *m, *xm, **mrt_l = NULL; struct pollfd *pfd = NULL; struct listen_addr *la; void *newp; time_t now; short events; log_init(debug, LOG_DAEMON); log_setverbose(verbose); log_procinit(log_procnames[PROC_SE]); if ((pw = getpwnam(BGPD_USER)) == NULL) fatal(NULL); if (chroot(pw->pw_dir) == -1) fatal("chroot"); if (chdir("/") == -1) fatal("chdir(\"/\")"); setproctitle("session engine"); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("can't drop privileges"); if (pledge("stdio inet recvfd", NULL) == -1) fatal("pledge"); signal(SIGTERM, session_sighdlr); signal(SIGINT, session_sighdlr); signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGALRM, SIG_IGN); signal(SIGUSR1, SIG_IGN); if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL) fatal(NULL); if (imsgbuf_init(ibuf_main, 3) == -1 || imsgbuf_set_maxsize(ibuf_main, MAX_BGPD_IMSGSIZE) == -1) fatal(NULL); imsgbuf_allow_fdpass(ibuf_main); LIST_INIT(&mrthead); listener_cnt = 0; peer_cnt = 0; ctl_cnt = 0; conf = new_config(); log_info("session engine ready"); while (session_quit == 0) { /* check for peers to be initialized or deleted */ if (!pending_reconf) { RB_FOREACH_SAFE(p, peer_head, &conf->peers, next) { /* new peer that needs init? */ if (p->state == STATE_NONE) init_peer(p); /* deletion due? */ if (p->reconf_action == RECONF_DELETE) { if (p->demoted) session_demote(p, -1); p->conf.demote_group[0] = 0; session_stop(p, ERR_CEASE_PEER_UNCONF, NULL); timer_remove_all(&p->timers); tcp_md5_del_listener(conf, p); if (imsg_rde(IMSG_SESSION_DELETE, p->conf.id, NULL, 0) == -1) fatalx("imsg_compose error"); msgbuf_free(p->wbuf); RB_REMOVE(peer_head, &conf->peers, p); log_peer_warnx(&p->conf, "removed"); free(p); peer_cnt--; continue; } p->reconf_action = RECONF_NONE; } } if (peer_cnt > peer_l_elms) { if ((newp = reallocarray(peer_l, peer_cnt, sizeof(struct peer *))) == NULL) { /* panic for now */ log_warn("could not resize peer_l from %u -> %u" " entries", peer_l_elms, peer_cnt); fatalx("exiting"); } peer_l = newp; peer_l_elms = peer_cnt; } mrt_cnt = 0; for (m = LIST_FIRST(&mrthead); m != NULL; m = xm) { xm = LIST_NEXT(m, entry); if (m->state == MRT_STATE_REMOVE) { mrt_clean(m); LIST_REMOVE(m, entry); free(m); continue; } if (msgbuf_queuelen(m->wbuf) > 0) mrt_cnt++; } if (mrt_cnt > mrt_l_elms) { if ((newp = reallocarray(mrt_l, mrt_cnt, sizeof(struct mrt *))) == NULL) { /* panic for now */ log_warn("could not resize mrt_l from %u -> %u" " entries", mrt_l_elms, mrt_cnt); fatalx("exiting"); } mrt_l = newp; mrt_l_elms = mrt_cnt; } new_cnt = PFD_LISTENERS_START + listener_cnt + peer_cnt + ctl_cnt + mrt_cnt; if (new_cnt > pfd_elms) { if ((newp = reallocarray(pfd, new_cnt, sizeof(struct pollfd))) == NULL) { /* panic for now */ log_warn("could not resize pfd from %u -> %u" " entries", pfd_elms, new_cnt); fatalx("exiting"); } pfd = newp; pfd_elms = new_cnt; } memset(pfd, 0, sizeof(struct pollfd) * pfd_elms); set_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main); set_pollfd(&pfd[PFD_PIPE_ROUTE], ibuf_rde); set_pollfd(&pfd[PFD_PIPE_ROUTE_CTL], ibuf_rde_ctl); if (pauseaccept == 0) { pfd[PFD_SOCK_CTL].fd = csock; pfd[PFD_SOCK_CTL].events = POLLIN; pfd[PFD_SOCK_RCTL].fd = rcsock; pfd[PFD_SOCK_RCTL].events = POLLIN; } else { pfd[PFD_SOCK_CTL].fd = -1; pfd[PFD_SOCK_RCTL].fd = -1; } i = PFD_LISTENERS_START; TAILQ_FOREACH(la, conf->listen_addrs, entry) { if (pauseaccept == 0) { pfd[i].fd = la->fd; pfd[i].events = POLLIN; } else pfd[i].fd = -1; i++; } idx_listeners = i; timeout = 240; /* loop every 240s at least */ now = getmonotime(); RB_FOREACH(p, peer_head, &conf->peers) { time_t nextaction; struct timer *pt; /* check timers */ if ((pt = timer_nextisdue(&p->timers, now)) != NULL) { switch (pt->type) { case Timer_Hold: bgp_fsm(p, EVNT_TIMER_HOLDTIME, NULL); break; case Timer_SendHold: bgp_fsm(p, EVNT_TIMER_SENDHOLD, NULL); break; case Timer_ConnectRetry: bgp_fsm(p, EVNT_TIMER_CONNRETRY, NULL); break; case Timer_Keepalive: bgp_fsm(p, EVNT_TIMER_KEEPALIVE, NULL); break; case Timer_IdleHold: bgp_fsm(p, EVNT_START, NULL); break; case Timer_IdleHoldReset: p->IdleHoldTime = INTERVAL_IDLE_HOLD_INITIAL; p->errcnt = 0; timer_stop(&p->timers, Timer_IdleHoldReset); break; case Timer_CarpUndemote: timer_stop(&p->timers, Timer_CarpUndemote); if (p->demoted && p->state == STATE_ESTABLISHED) session_demote(p, -1); break; case Timer_RestartTimeout: timer_stop(&p->timers, Timer_RestartTimeout); session_graceful_stop(p); break; case Timer_SessionDown: timer_stop(&p->timers, Timer_SessionDown); if (imsg_rde(IMSG_SESSION_DELETE, p->conf.id, NULL, 0) == -1) fatalx("imsg_compose error"); p->rdesession = 0; /* finally delete this cloned peer */ if (p->template) p->reconf_action = RECONF_DELETE; break; default: fatalx("King Bula lost in time"); } } if ((nextaction = timer_nextduein(&p->timers, now)) != -1 && nextaction < timeout) timeout = nextaction; /* are we waiting for a write? */ events = POLLIN; if (msgbuf_queuelen(p->wbuf) > 0 || p->state == STATE_CONNECT) events |= POLLOUT; /* is there still work to do? */ if (p->rpending) timeout = 0; /* poll events */ if (p->fd != -1 && events != 0) { pfd[i].fd = p->fd; pfd[i].events = events; peer_l[i - idx_listeners] = p; i++; } } idx_peers = i; LIST_FOREACH(m, &mrthead, entry) if (msgbuf_queuelen(m->wbuf) > 0) { pfd[i].fd = m->fd; pfd[i].events = POLLOUT; mrt_l[i - idx_peers] = m; i++; } idx_mrts = i; i += control_fill_pfds(pfd + i, pfd_elms -i); if (i > pfd_elms) fatalx("poll pfd overflow"); if (pauseaccept && timeout > 1) timeout = 1; if (timeout < 0) timeout = 0; if (poll(pfd, i, timeout * 1000) == -1) { if (errno == EINTR) continue; fatal("poll error"); } /* * If we previously saw fd exhaustion, we stop accept() * for 1 second to throttle the accept() loop. */ if (pauseaccept && getmonotime() > pauseaccept + 1) pauseaccept = 0; if (handle_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main) == -1) { log_warnx("SE: Lost connection to parent"); session_quit = 1; continue; } else session_dispatch_imsg(ibuf_main, PFD_PIPE_MAIN, &listener_cnt); if (handle_pollfd(&pfd[PFD_PIPE_ROUTE], ibuf_rde) == -1) { log_warnx("SE: Lost connection to RDE"); imsgbuf_clear(ibuf_rde); free(ibuf_rde); ibuf_rde = NULL; } else session_dispatch_imsg(ibuf_rde, PFD_PIPE_ROUTE, &listener_cnt); if (handle_pollfd(&pfd[PFD_PIPE_ROUTE_CTL], ibuf_rde_ctl) == -1) { log_warnx("SE: Lost connection to RDE control"); imsgbuf_clear(ibuf_rde_ctl); free(ibuf_rde_ctl); ibuf_rde_ctl = NULL; } else session_dispatch_imsg(ibuf_rde_ctl, PFD_PIPE_ROUTE_CTL, &listener_cnt); if (pfd[PFD_SOCK_CTL].revents & POLLIN) ctl_cnt += control_accept(csock, 0); if (pfd[PFD_SOCK_RCTL].revents & POLLIN) ctl_cnt += control_accept(rcsock, 1); for (j = PFD_LISTENERS_START; j < idx_listeners; j++) if (pfd[j].revents & POLLIN) session_accept(pfd[j].fd); for (; j < idx_peers; j++) session_dispatch_msg(&pfd[j], peer_l[j - idx_listeners]); RB_FOREACH(p, peer_head, &conf->peers) session_process_msg(p); for (; j < idx_mrts; j++) if (pfd[j].revents & POLLOUT) mrt_write(mrt_l[j - idx_peers]); for (; j < i; j++) ctl_cnt -= control_dispatch_msg(&pfd[j], &conf->peers); } RB_FOREACH_SAFE(p, peer_head, &conf->peers, next) { session_stop(p, ERR_CEASE_ADMIN_DOWN, "bgpd shutting down"); timer_remove_all(&p->timers); tcp_md5_del_listener(conf, p); RB_REMOVE(peer_head, &conf->peers, p); free(p); } while ((m = LIST_FIRST(&mrthead)) != NULL) { mrt_clean(m); LIST_REMOVE(m, entry); free(m); } free_config(conf); free(peer_l); free(mrt_l); free(pfd); /* close pipes */ if (ibuf_rde) { imsgbuf_write(ibuf_rde); imsgbuf_clear(ibuf_rde); close(ibuf_rde->fd); free(ibuf_rde); } if (ibuf_rde_ctl) { imsgbuf_clear(ibuf_rde_ctl); close(ibuf_rde_ctl->fd); free(ibuf_rde_ctl); } imsgbuf_write(ibuf_main); imsgbuf_clear(ibuf_main); close(ibuf_main->fd); free(ibuf_main); control_shutdown(csock); control_shutdown(rcsock); log_info("session engine exiting"); exit(0); } void init_peer(struct peer *p) { TAILQ_INIT(&p->timers); p->fd = -1; if (p->wbuf != NULL) fatalx("%s: msgbuf already set", __func__); if ((p->wbuf = msgbuf_new_reader(MSGSIZE_HEADER, parse_header, p)) == NULL) fatal(NULL); if (p->conf.if_depend[0]) imsg_compose(ibuf_main, IMSG_SESSION_DEPENDON, 0, 0, -1, p->conf.if_depend, sizeof(p->conf.if_depend)); else p->depend_ok = 1; peer_cnt++; change_state(p, STATE_IDLE, EVNT_NONE); if (p->conf.down) timer_stop(&p->timers, Timer_IdleHold); /* no autostart */ else timer_set(&p->timers, Timer_IdleHold, SESSION_CLEAR_DELAY); p->stats.last_updown = getmonotime(); /* * on startup, demote if requested. * do not handle new peers. they must reach ESTABLISHED beforehand. * peers added at runtime have reconf_action set to RECONF_REINIT. */ if (p->reconf_action != RECONF_REINIT && p->conf.demote_group[0]) session_demote(p, +1); } void bgp_fsm(struct peer *peer, enum session_events event, struct ibuf *msg) { switch (peer->state) { case STATE_NONE: /* nothing */ break; case STATE_IDLE: switch (event) { case EVNT_START: timer_stop(&peer->timers, Timer_Hold); timer_stop(&peer->timers, Timer_SendHold); timer_stop(&peer->timers, Timer_Keepalive); timer_stop(&peer->timers, Timer_IdleHold); if (!peer->depend_ok) timer_stop(&peer->timers, Timer_ConnectRetry); else if (peer->passive || peer->conf.passive || peer->conf.template) { change_state(peer, STATE_ACTIVE, event); timer_stop(&peer->timers, Timer_ConnectRetry); } else { change_state(peer, STATE_CONNECT, event); timer_set(&peer->timers, Timer_ConnectRetry, conf->connectretry); session_connect(peer); } peer->passive = 0; break; case EVNT_STOP: timer_stop(&peer->timers, Timer_IdleHold); break; default: /* ignore */ break; } break; case STATE_CONNECT: switch (event) { case EVNT_START: /* ignore */ break; case EVNT_CON_OPEN: session_tcp_established(peer); session_open(peer); timer_stop(&peer->timers, Timer_ConnectRetry); peer->holdtime = INTERVAL_HOLD_INITIAL; start_timer_holdtime(peer); change_state(peer, STATE_OPENSENT, event); break; case EVNT_CON_OPENFAIL: timer_set(&peer->timers, Timer_ConnectRetry, conf->connectretry); session_close_connection(peer); change_state(peer, STATE_ACTIVE, event); break; case EVNT_TIMER_CONNRETRY: timer_set(&peer->timers, Timer_ConnectRetry, conf->connectretry); session_connect(peer); break; default: change_state(peer, STATE_IDLE, event); break; } break; case STATE_ACTIVE: switch (event) { case EVNT_START: /* ignore */ break; case EVNT_CON_OPEN: session_tcp_established(peer); session_open(peer); timer_stop(&peer->timers, Timer_ConnectRetry); peer->holdtime = INTERVAL_HOLD_INITIAL; start_timer_holdtime(peer); change_state(peer, STATE_OPENSENT, event); break; case EVNT_CON_OPENFAIL: timer_set(&peer->timers, Timer_ConnectRetry, conf->connectretry); session_close_connection(peer); change_state(peer, STATE_ACTIVE, event); break; case EVNT_TIMER_CONNRETRY: timer_set(&peer->timers, Timer_ConnectRetry, peer->holdtime); change_state(peer, STATE_CONNECT, event); session_connect(peer); break; default: change_state(peer, STATE_IDLE, event); break; } break; case STATE_OPENSENT: switch (event) { case EVNT_START: /* ignore */ break; case EVNT_STOP: change_state(peer, STATE_IDLE, event); break; case EVNT_CON_CLOSED: session_close_connection(peer); timer_set(&peer->timers, Timer_ConnectRetry, conf->connectretry); change_state(peer, STATE_ACTIVE, event); break; case EVNT_CON_FATAL: change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_HOLDTIME: session_notification(peer, ERR_HOLDTIMEREXPIRED, 0, NULL); change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_SENDHOLD: session_notification(peer, ERR_SENDHOLDTIMEREXPIRED, 0, NULL); change_state(peer, STATE_IDLE, event); break; case EVNT_RCVD_OPEN: /* parse_open calls change_state itself on failure */ if (parse_open(peer, msg)) break; session_keepalive(peer); change_state(peer, STATE_OPENCONFIRM, event); break; case EVNT_RCVD_NOTIFICATION: parse_notification(peer, msg); break; default: session_notification(peer, ERR_FSM, ERR_FSM_UNEX_OPENSENT, NULL); change_state(peer, STATE_IDLE, event); break; } break; case STATE_OPENCONFIRM: switch (event) { case EVNT_START: /* ignore */ break; case EVNT_STOP: change_state(peer, STATE_IDLE, event); break; case EVNT_CON_CLOSED: case EVNT_CON_FATAL: change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_HOLDTIME: session_notification(peer, ERR_HOLDTIMEREXPIRED, 0, NULL); change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_SENDHOLD: session_notification(peer, ERR_SENDHOLDTIMEREXPIRED, 0, NULL); change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_KEEPALIVE: session_keepalive(peer); break; case EVNT_RCVD_KEEPALIVE: start_timer_holdtime(peer); change_state(peer, STATE_ESTABLISHED, event); break; case EVNT_RCVD_NOTIFICATION: parse_notification(peer, msg); break; default: session_notification(peer, ERR_FSM, ERR_FSM_UNEX_OPENCONFIRM, NULL); change_state(peer, STATE_IDLE, event); break; } break; case STATE_ESTABLISHED: switch (event) { case EVNT_START: /* ignore */ break; case EVNT_STOP: change_state(peer, STATE_IDLE, event); break; case EVNT_CON_CLOSED: case EVNT_CON_FATAL: change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_HOLDTIME: session_notification(peer, ERR_HOLDTIMEREXPIRED, 0, NULL); change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_SENDHOLD: session_notification(peer, ERR_SENDHOLDTIMEREXPIRED, 0, NULL); change_state(peer, STATE_IDLE, event); break; case EVNT_TIMER_KEEPALIVE: session_keepalive(peer); break; case EVNT_RCVD_KEEPALIVE: start_timer_holdtime(peer); break; case EVNT_RCVD_UPDATE: start_timer_holdtime(peer); if (parse_update(peer, msg)) change_state(peer, STATE_IDLE, event); else start_timer_holdtime(peer); break; case EVNT_RCVD_NOTIFICATION: parse_notification(peer, msg); break; default: session_notification(peer, ERR_FSM, ERR_FSM_UNEX_ESTABLISHED, NULL); change_state(peer, STATE_IDLE, event); break; } break; } } void start_timer_holdtime(struct peer *peer) { if (peer->holdtime > 0) timer_set(&peer->timers, Timer_Hold, peer->holdtime); else timer_stop(&peer->timers, Timer_Hold); } void start_timer_sendholdtime(struct peer *peer) { uint16_t holdtime = INTERVAL_HOLD; if (peer->holdtime > INTERVAL_HOLD) holdtime = peer->holdtime; if (peer->holdtime > 0) timer_set(&peer->timers, Timer_SendHold, holdtime); else timer_stop(&peer->timers, Timer_SendHold); } void start_timer_keepalive(struct peer *peer) { if (peer->holdtime > 0) timer_set(&peer->timers, Timer_Keepalive, peer->holdtime / 3); else timer_stop(&peer->timers, Timer_Keepalive); } void session_close_connection(struct peer *peer) { if (peer->fd != -1) { close(peer->fd); pauseaccept = 0; } peer->fd = -1; } void change_state(struct peer *peer, enum session_state state, enum session_events event) { struct mrt *mrt; switch (state) { case STATE_IDLE: /* carp demotion first. new peers handled in init_peer */ if (peer->state == STATE_ESTABLISHED && peer->conf.demote_group[0] && !peer->demoted) session_demote(peer, +1); /* * try to write out what's buffered (maybe a notification), * don't bother if it fails */ if (peer->state >= STATE_OPENSENT && msgbuf_queuelen(peer->wbuf) > 0) ibuf_write(peer->fd, peer->wbuf); /* * we must start the timer for the next EVNT_START * if we are coming here due to an error and the * session was not established successfully before, the * starttimerinterval needs to be exponentially increased */ if (peer->IdleHoldTime == 0) peer->IdleHoldTime = INTERVAL_IDLE_HOLD_INITIAL; peer->holdtime = INTERVAL_HOLD_INITIAL; timer_stop(&peer->timers, Timer_ConnectRetry); timer_stop(&peer->timers, Timer_Keepalive); timer_stop(&peer->timers, Timer_Hold); timer_stop(&peer->timers, Timer_SendHold); timer_stop(&peer->timers, Timer_IdleHold); timer_stop(&peer->timers, Timer_IdleHoldReset); session_close_connection(peer); msgbuf_clear(peer->wbuf); peer->rpending = 0; memset(&peer->capa.peer, 0, sizeof(peer->capa.peer)); if (!peer->template) imsg_compose(ibuf_main, IMSG_PFKEY_RELOAD, peer->conf.id, 0, -1, NULL, 0); if (peer->state == STATE_ESTABLISHED) { if (peer->capa.neg.grestart.restart == 2 && (event == EVNT_CON_CLOSED || event == EVNT_CON_FATAL || (peer->capa.neg.grestart.grnotification && (event == EVNT_RCVD_GRACE_NOTIFICATION || event == EVNT_TIMER_HOLDTIME || event == EVNT_TIMER_SENDHOLD)))) { /* don't punish graceful restart */ timer_set(&peer->timers, Timer_IdleHold, 0); session_graceful_restart(peer); } else if (event != EVNT_STOP) { timer_set(&peer->timers, Timer_IdleHold, peer->IdleHoldTime); if (event != EVNT_NONE && peer->IdleHoldTime < MAX_IDLE_HOLD/2) peer->IdleHoldTime *= 2; session_down(peer); } else { session_down(peer); } } else if (event != EVNT_STOP) { timer_set(&peer->timers, Timer_IdleHold, peer->IdleHoldTime); if (event != EVNT_NONE && peer->IdleHoldTime < MAX_IDLE_HOLD / 2) peer->IdleHoldTime *= 2; } if (peer->state == STATE_NONE || peer->state == STATE_ESTABLISHED) { /* initialize capability negotiation structures */ memcpy(&peer->capa.ann, &peer->conf.capabilities, sizeof(peer->capa.ann)); } break; case STATE_CONNECT: if (peer->state == STATE_ESTABLISHED && peer->capa.neg.grestart.restart == 2) { /* do the graceful restart dance */ session_graceful_restart(peer); peer->holdtime = INTERVAL_HOLD_INITIAL; timer_stop(&peer->timers, Timer_ConnectRetry); timer_stop(&peer->timers, Timer_Keepalive); timer_stop(&peer->timers, Timer_Hold); timer_stop(&peer->timers, Timer_SendHold); timer_stop(&peer->timers, Timer_IdleHold); timer_stop(&peer->timers, Timer_IdleHoldReset); session_close_connection(peer); msgbuf_clear(peer->wbuf); memset(&peer->capa.peer, 0, sizeof(peer->capa.peer)); } break; case STATE_ACTIVE: if (!peer->template) imsg_compose(ibuf_main, IMSG_PFKEY_RELOAD, peer->conf.id, 0, -1, NULL, 0); break; case STATE_OPENSENT: break; case STATE_OPENCONFIRM: break; case STATE_ESTABLISHED: timer_set(&peer->timers, Timer_IdleHoldReset, peer->IdleHoldTime); if (peer->demoted) timer_set(&peer->timers, Timer_CarpUndemote, INTERVAL_HOLD_DEMOTED); session_up(peer); break; default: /* something seriously fucked */ break; } log_statechange(peer, state, event); LIST_FOREACH(mrt, &mrthead, entry) { if (!(mrt->type == MRT_ALL_IN || mrt->type == MRT_ALL_OUT)) continue; if ((mrt->peer_id == 0 && mrt->group_id == 0) || mrt->peer_id == peer->conf.id || (mrt->group_id != 0 && mrt->group_id == peer->conf.groupid)) mrt_dump_state(mrt, peer->state, state, peer); } peer->prev_state = peer->state; peer->state = state; } void session_accept(int listenfd) { int connfd; socklen_t len; struct sockaddr_storage cliaddr; struct peer *p = NULL; len = sizeof(cliaddr); if ((connfd = accept4(listenfd, (struct sockaddr *)&cliaddr, &len, SOCK_CLOEXEC | SOCK_NONBLOCK)) == -1) { if (errno == ENFILE || errno == EMFILE) pauseaccept = getmonotime(); else if (errno != EWOULDBLOCK && errno != EINTR && errno != ECONNABORTED) log_warn("accept"); return; } p = getpeerbyip(conf, (struct sockaddr *)&cliaddr); if (p != NULL && p->state == STATE_IDLE && p->errcnt < 2) { if (timer_running(&p->timers, Timer_IdleHold, NULL)) { /* fast reconnect after clear */ p->passive = 1; bgp_fsm(p, EVNT_START, NULL); } } if (p != NULL && (p->state == STATE_CONNECT || p->state == STATE_ACTIVE)) { if (p->fd != -1) { if (p->state == STATE_CONNECT) session_close_connection(p); else { close(connfd); return; } } open: if (p->auth_conf.method != AUTH_NONE && sysdep.no_pfkey) { log_peer_warnx(&p->conf, "ipsec or md5sig configured but not available"); close(connfd); return; } if (tcp_md5_check(connfd, &p->auth_conf) == -1) { log_peer_warn(&p->conf, "check md5sig"); close(connfd); return; } p->fd = connfd; if (session_setup_socket(p)) { close(connfd); return; } bgp_fsm(p, EVNT_CON_OPEN, NULL); return; } else if (p != NULL && p->state == STATE_ESTABLISHED && p->capa.neg.grestart.restart == 2) { /* first do the graceful restart dance */ change_state(p, STATE_CONNECT, EVNT_CON_CLOSED); /* then do part of the open dance */ goto open; } else { log_conn_attempt(p, (struct sockaddr *)&cliaddr, len); close(connfd); } } int session_connect(struct peer *peer) { struct sockaddr *sa; struct bgpd_addr *bind_addr; socklen_t sa_len; /* * we do not need the overcomplicated collision detection RFC 1771 * describes; we simply make sure there is only ever one concurrent * tcp connection per peer. */ if (peer->fd != -1) return (-1); if ((peer->fd = socket(aid2af(peer->conf.remote_addr.aid), SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_TCP)) == -1) { log_peer_warn(&peer->conf, "session_connect socket"); bgp_fsm(peer, EVNT_CON_OPENFAIL, NULL); return (-1); } if (peer->auth_conf.method != AUTH_NONE && sysdep.no_pfkey) { log_peer_warnx(&peer->conf, "ipsec or md5sig configured but not available"); bgp_fsm(peer, EVNT_CON_OPENFAIL, NULL); return (-1); } if (tcp_md5_set(peer->fd, &peer->auth_conf, &peer->conf.remote_addr) == -1) log_peer_warn(&peer->conf, "setting md5sig"); /* if local-address is set we need to bind() */ bind_addr = session_localaddr(peer); if ((sa = addr2sa(bind_addr, 0, &sa_len)) != NULL) { if (bind(peer->fd, sa, sa_len) == -1) { log_peer_warn(&peer->conf, "session_connect bind"); bgp_fsm(peer, EVNT_CON_OPENFAIL, NULL); return (-1); } } if (session_setup_socket(peer)) { bgp_fsm(peer, EVNT_CON_OPENFAIL, NULL); return (-1); } sa = addr2sa(&peer->conf.remote_addr, peer->conf.remote_port, &sa_len); if (connect(peer->fd, sa, sa_len) == -1) { if (errno != EINPROGRESS) { if (errno != peer->lasterr) log_peer_warn(&peer->conf, "connect"); peer->lasterr = errno; bgp_fsm(peer, EVNT_CON_OPENFAIL, NULL); return (-1); } } else bgp_fsm(peer, EVNT_CON_OPEN, NULL); return (0); } int session_setup_socket(struct peer *p) { int ttl = p->conf.distance; int pre = IPTOS_PREC_INTERNETCONTROL; int nodelay = 1; int bsize; switch (p->conf.remote_addr.aid) { case AID_INET: /* set precedence, see RFC 1771 appendix 5 */ if (setsockopt(p->fd, IPPROTO_IP, IP_TOS, &pre, sizeof(pre)) == -1) { log_peer_warn(&p->conf, "session_setup_socket setsockopt TOS"); return (-1); } if (p->conf.ebgp) { /* * set TTL to foreign router's distance * 1=direct n=multihop with ttlsec, we always use 255 */ if (p->conf.ttlsec) { #ifdef IP_MINTTL ttl = 256 - p->conf.distance; if (setsockopt(p->fd, IPPROTO_IP, IP_MINTTL, &ttl, sizeof(ttl)) == -1) { log_peer_warn(&p->conf, "session_setup_socket: " "setsockopt MINTTL"); return (-1); } ttl = 255; #else log_peer_warn(&p->conf, "OS does not support " "ttl-security for IPv4 sessions"); #endif } if (setsockopt(p->fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) == -1) { log_peer_warn(&p->conf, "session_setup_socket setsockopt TTL"); return (-1); } } break; case AID_INET6: if (setsockopt(p->fd, IPPROTO_IPV6, IPV6_TCLASS, &pre, sizeof(pre)) == -1) { log_peer_warn(&p->conf, "session_setup_socket " "setsockopt TCLASS"); return (-1); } if (p->conf.ebgp) { /* * set hoplimit to foreign router's distance * 1=direct n=multihop with ttlsec, we always use 255 */ if (p->conf.ttlsec) { #ifdef IPV6_MINHOPCOUNT ttl = 256 - p->conf.distance; if (setsockopt(p->fd, IPPROTO_IPV6, IPV6_MINHOPCOUNT, &ttl, sizeof(ttl)) == -1) { log_peer_warn(&p->conf, "session_setup_socket: " "setsockopt MINHOPCOUNT"); return (-1); } ttl = 255; #else log_peer_warn(&p->conf, "OS does not support " "ttl-security for IPv6 sessions"); #endif } if (setsockopt(p->fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) == -1) { log_peer_warn(&p->conf, "session_setup_socket setsockopt hoplimit"); return (-1); } } break; } /* set TCP_NODELAY */ if (setsockopt(p->fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof(nodelay)) == -1) { log_peer_warn(&p->conf, "session_setup_socket setsockopt TCP_NODELAY"); return (-1); } /* limit bufsize. no biggie if it fails */ bsize = 65535; setsockopt(p->fd, SOL_SOCKET, SO_RCVBUF, &bsize, sizeof(bsize)); setsockopt(p->fd, SOL_SOCKET, SO_SNDBUF, &bsize, sizeof(bsize)); return (0); } /* * compare the bgpd_addr with the sockaddr by converting the latter into * a bgpd_addr. Return true if the two are equal, including any scope */ static int sa_equal(struct bgpd_addr *ba, struct sockaddr *b) { struct bgpd_addr bb; sa2addr(b, &bb, NULL); return (memcmp(ba, &bb, sizeof(*ba)) == 0); } static void get_alternate_addr(struct bgpd_addr *local, struct bgpd_addr *remote, struct bgpd_addr *alt, unsigned int *scope) { struct ifaddrs *ifap, *ifa, *match; int connected = 0; u_int8_t plen; if (getifaddrs(&ifap) == -1) fatal("getifaddrs"); for (match = ifap; match != NULL; match = match->ifa_next) { if (match->ifa_addr == NULL) continue; if (match->ifa_addr->sa_family != AF_INET && match->ifa_addr->sa_family != AF_INET6) continue; if (sa_equal(local, match->ifa_addr)) { if (remote->aid == AID_INET6 && IN6_IS_ADDR_LINKLOCAL(&remote->v6)) { /* IPv6 LLA are by definition connected */ connected = 1; } else if (match->ifa_flags & IFF_POINTOPOINT && match->ifa_dstaddr != NULL) { if (sa_equal(remote, match->ifa_dstaddr)) connected = 1; } else if (match->ifa_netmask != NULL) { plen = mask2prefixlen( match->ifa_addr->sa_family, match->ifa_netmask); if (prefix_compare(local, remote, plen) == 0) connected = 1; } break; } } if (match == NULL) { log_warnx("%s: local address not found", __func__); return; } if (connected) *scope = if_nametoindex(match->ifa_name); else *scope = 0; switch (local->aid) { case AID_INET6: for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_INET && strcmp(ifa->ifa_name, match->ifa_name) == 0) { sa2addr(ifa->ifa_addr, alt, NULL); break; } } break; case AID_INET: for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { if (ifa->ifa_addr != NULL && ifa->ifa_addr->sa_family == AF_INET6 && strcmp(ifa->ifa_name, match->ifa_name) == 0) { struct sockaddr_in6 *s = (struct sockaddr_in6 *)ifa->ifa_addr; /* only accept global scope addresses */ if (IN6_IS_ADDR_LINKLOCAL(&s->sin6_addr) || IN6_IS_ADDR_SITELOCAL(&s->sin6_addr)) continue; sa2addr(ifa->ifa_addr, alt, NULL); break; } } break; default: log_warnx("%s: unsupported address family %s", __func__, aid2str(local->aid)); break; } freeifaddrs(ifap); } void session_tcp_established(struct peer *peer) { struct sockaddr_storage ss; socklen_t len; len = sizeof(ss); if (getsockname(peer->fd, (struct sockaddr *)&ss, &len) == -1) log_warn("getsockname"); sa2addr((struct sockaddr *)&ss, &peer->local, &peer->local_port); len = sizeof(ss); if (getpeername(peer->fd, (struct sockaddr *)&ss, &len) == -1) log_warn("getpeername"); sa2addr((struct sockaddr *)&ss, &peer->remote, &peer->remote_port); get_alternate_addr(&peer->local, &peer->remote, &peer->local_alt, &peer->if_scope); } int session_capa_add(struct ibuf *opb, uint8_t capa_code, uint8_t capa_len) { int errs = 0; errs += ibuf_add_n8(opb, capa_code); errs += ibuf_add_n8(opb, capa_len); return (errs); } static int session_capa_add_mp(struct ibuf *buf, uint8_t aid) { uint16_t afi; uint8_t safi; int errs = 0; if (aid2afi(aid, &afi, &safi) == -1) { log_warn("%s: bad AID", __func__); return (-1); } errs += ibuf_add_n16(buf, afi); errs += ibuf_add_zero(buf, 1); errs += ibuf_add_n8(buf, safi); return (errs); } static int session_capa_add_afi(struct ibuf *b, uint8_t aid, uint8_t flags) { int errs = 0; uint16_t afi; uint8_t safi; if (aid2afi(aid, &afi, &safi)) { log_warn("%s: bad AID", __func__); return (-1); } errs += ibuf_add_n16(b, afi); errs += ibuf_add_n8(b, safi); errs += ibuf_add_n8(b, flags); return (errs); } static int session_capa_add_ext_nh(struct ibuf *b, uint8_t aid) { int errs = 0; uint16_t afi; uint8_t safi; if (aid2afi(aid, &afi, &safi)) { log_warn("%s: bad AID", __func__); return (-1); } errs += ibuf_add_n16(b, afi); errs += ibuf_add_n16(b, safi); errs += ibuf_add_n16(b, AFI_IPv6); return (errs); } struct ibuf * session_newmsg(enum msg_type msgtype, uint16_t len) { struct ibuf *buf; int errs = 0; if ((buf = ibuf_open(len)) == NULL) return (NULL); errs += ibuf_add(buf, marker, sizeof(marker)); errs += ibuf_add_n16(buf, len); errs += ibuf_add_n8(buf, msgtype); if (errs) { ibuf_free(buf); return (NULL); } return (buf); } void session_sendmsg(struct ibuf *msg, struct peer *p, enum msg_type msgtype) { struct mrt *mrt; LIST_FOREACH(mrt, &mrthead, entry) { if (!(mrt->type == MRT_ALL_OUT || (msgtype == BGP_UPDATE && mrt->type == MRT_UPDATE_OUT))) continue; if ((mrt->peer_id == 0 && mrt->group_id == 0) || mrt->peer_id == p->conf.id || (mrt->group_id != 0 && mrt->group_id == p->conf.groupid)) mrt_dump_bgp_msg(mrt, msg, p, msgtype); } ibuf_close(p->wbuf, msg); if (!p->throttled && msgbuf_queuelen(p->wbuf) > SESS_MSG_HIGH_MARK) { if (imsg_rde(IMSG_XOFF, p->conf.id, NULL, 0) == -1) log_peer_warn(&p->conf, "imsg_compose XOFF"); else p->throttled = 1; } } /* * Translate between internal roles and the value expected by RFC 9234. */ static uint8_t role2capa(enum role role) { switch (role) { case ROLE_CUSTOMER: return CAPA_ROLE_CUSTOMER; case ROLE_PROVIDER: return CAPA_ROLE_PROVIDER; case ROLE_RS: return CAPA_ROLE_RS; case ROLE_RS_CLIENT: return CAPA_ROLE_RS_CLIENT; case ROLE_PEER: return CAPA_ROLE_PEER; default: fatalx("Unsupported role for role capability"); } } static enum role capa2role(uint8_t val) { switch (val) { case CAPA_ROLE_PROVIDER: return ROLE_PROVIDER; case CAPA_ROLE_RS: return ROLE_RS; case CAPA_ROLE_RS_CLIENT: return ROLE_RS_CLIENT; case CAPA_ROLE_CUSTOMER: return ROLE_CUSTOMER; case CAPA_ROLE_PEER: return ROLE_PEER; default: return ROLE_NONE; } } void session_open(struct peer *p) { struct ibuf *buf, *opb; size_t len, optparamlen; uint16_t holdtime; uint8_t i; int errs = 0, extlen = 0; int mpcapa = 0; if ((opb = ibuf_dynamic(0, MAX_PKTSIZE - MSGSIZE_OPEN_MIN - 6)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } /* multiprotocol extensions, RFC 4760 */ for (i = AID_MIN; i < AID_MAX; i++) if (p->capa.ann.mp[i]) { /* 4 bytes data */ errs += session_capa_add(opb, CAPA_MP, 4); errs += session_capa_add_mp(opb, i); mpcapa++; } /* route refresh, RFC 2918 */ if (p->capa.ann.refresh) /* no data */ errs += session_capa_add(opb, CAPA_REFRESH, 0); /* extended nexthop encoding, RFC 8950 */ if (p->capa.ann.ext_nh[AID_INET]) { uint8_t enhlen = 0; if (p->capa.ann.mp[AID_INET]) enhlen += 6; if (p->capa.ann.mp[AID_VPN_IPv4]) enhlen += 6; errs += session_capa_add(opb, CAPA_EXT_NEXTHOP, enhlen); if (p->capa.ann.mp[AID_INET]) errs += session_capa_add_ext_nh(opb, AID_INET); if (p->capa.ann.mp[AID_VPN_IPv4]) errs += session_capa_add_ext_nh(opb, AID_VPN_IPv4); } /* extended message support, RFC 8654 */ if (p->capa.ann.ext_msg) /* no data */ errs += session_capa_add(opb, CAPA_EXT_MSG, 0); /* BGP open policy, RFC 9234, only for ebgp sessions */ if (p->conf.ebgp && p->capa.ann.policy && p->conf.role != ROLE_NONE && (p->capa.ann.mp[AID_INET] || p->capa.ann.mp[AID_INET6] || mpcapa == 0)) { errs += session_capa_add(opb, CAPA_ROLE, 1); errs += ibuf_add_n8(opb, role2capa(p->conf.role)); } /* graceful restart and End-of-RIB marker, RFC 4724 */ if (p->capa.ann.grestart.restart) { int rst = 0; uint16_t hdr = 0; for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.grestart.flags[i] & CAPA_GR_RESTARTING) rst++; } /* Only set the R-flag if no graceful restart is ongoing */ if (!rst) hdr |= CAPA_GR_R_FLAG; if (p->capa.ann.grestart.grnotification) hdr |= CAPA_GR_N_FLAG; errs += session_capa_add(opb, CAPA_RESTART, sizeof(hdr)); errs += ibuf_add_n16(opb, hdr); } /* 4-bytes AS numbers, RFC6793 */ if (p->capa.ann.as4byte) { /* 4 bytes data */ errs += session_capa_add(opb, CAPA_AS4BYTE, sizeof(uint32_t)); errs += ibuf_add_n32(opb, p->conf.local_as); } /* advertisement of multiple paths, RFC7911 */ if (p->capa.ann.add_path[AID_MIN]) { /* variable */ uint8_t aplen; if (mpcapa) aplen = 4 * mpcapa; else /* AID_INET */ aplen = 4; errs += session_capa_add(opb, CAPA_ADD_PATH, aplen); if (mpcapa) { for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.ann.mp[i]) { errs += session_capa_add_afi(opb, i, p->capa.ann.add_path[i] & CAPA_AP_MASK); } } } else { /* AID_INET */ errs += session_capa_add_afi(opb, AID_INET, p->capa.ann.add_path[AID_INET] & CAPA_AP_MASK); } } /* enhanced route-refresh, RFC7313 */ if (p->capa.ann.enhanced_rr) /* no data */ errs += session_capa_add(opb, CAPA_ENHANCED_RR, 0); if (errs) { ibuf_free(opb); bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } optparamlen = ibuf_size(opb); len = MSGSIZE_OPEN_MIN + optparamlen; if (optparamlen == 0) { /* nothing */ } else if (optparamlen + 2 >= 255) { /* RFC9072: use 255 as magic size and request extra header */ optparamlen = 255; extlen = 1; /* 3 byte OPT_PARAM_EXT_LEN and OPT_PARAM_CAPABILITIES */ len += 2 * 3; } else { /* regular capabilities header */ optparamlen += 2; len += 2; } if ((buf = session_newmsg(BGP_OPEN, len)) == NULL) { ibuf_free(opb); bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } if (p->conf.holdtime) holdtime = p->conf.holdtime; else holdtime = conf->holdtime; errs += ibuf_add_n8(buf, 4); errs += ibuf_add_n16(buf, p->conf.local_short_as); errs += ibuf_add_n16(buf, holdtime); /* is already in network byte order */ errs += ibuf_add_n32(buf, conf->bgpid); errs += ibuf_add_n8(buf, optparamlen); if (extlen) { /* RFC9072 extra header which spans over the capabilities hdr */ errs += ibuf_add_n8(buf, OPT_PARAM_EXT_LEN); errs += ibuf_add_n16(buf, ibuf_size(opb) + 1 + 2); } if (optparamlen) { errs += ibuf_add_n8(buf, OPT_PARAM_CAPABILITIES); if (extlen) { /* RFC9072: 2-byte extended length */ errs += ibuf_add_n16(buf, ibuf_size(opb)); } else { errs += ibuf_add_n8(buf, ibuf_size(opb)); } errs += ibuf_add_ibuf(buf, opb); } ibuf_free(opb); if (errs) { ibuf_free(buf); bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } session_sendmsg(buf, p, BGP_OPEN); p->stats.msg_sent_open++; } void session_keepalive(struct peer *p) { struct ibuf *buf; if ((buf = session_newmsg(BGP_KEEPALIVE, MSGSIZE_KEEPALIVE)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } session_sendmsg(buf, p, BGP_KEEPALIVE); start_timer_keepalive(p); p->stats.msg_sent_keepalive++; } void session_update(uint32_t peerid, struct ibuf *ibuf) { struct peer *p; struct ibuf *buf; size_t len, maxsize = MAX_PKTSIZE; if ((p = getpeerbyid(conf, peerid)) == NULL) { log_warnx("%s: no such peer: id=%u", __func__, peerid); return; } if (p->state != STATE_ESTABLISHED) return; if (p->capa.neg.ext_msg) maxsize = MAX_EXT_PKTSIZE; len = ibuf_size(ibuf); if (len < MSGSIZE_UPDATE_MIN - MSGSIZE_HEADER || len > maxsize - MSGSIZE_HEADER) { log_peer_warnx(&p->conf, "bad UDPATE from RDE"); return; } if ((buf = session_newmsg(BGP_UPDATE, MSGSIZE_HEADER + len)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } if (ibuf_add_ibuf(buf, ibuf)) { ibuf_free(buf); bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } session_sendmsg(buf, p, BGP_UPDATE); start_timer_keepalive(p); p->stats.msg_sent_update++; } /* Return 1 if a hard reset should be issued, 0 for a graceful notification */ static int session_req_hard_reset(enum err_codes errcode, uint8_t subcode) { switch (errcode) { case ERR_HEADER: case ERR_OPEN: case ERR_UPDATE: case ERR_FSM: case ERR_RREFRESH: /* * Protocol errors trigger a hard reset. The peer * is not trustworthy and so there is no realistic * hope that forwarding can continue. */ break; case ERR_HOLDTIMEREXPIRED: case ERR_SENDHOLDTIMEREXPIRED: /* Keep forwarding and hope the other side is back soon. */ return 0; case ERR_CEASE: switch (subcode) { case ERR_CEASE_CONN_REJECT: case ERR_CEASE_OTHER_CHANGE: case ERR_CEASE_COLLISION: case ERR_CEASE_RSRC_EXHAUST: /* Per RFC8538 suggestion make these graceful. */ return 0; } break; } return 1; } void session_notification_data(struct peer *p, uint8_t errcode, uint8_t subcode, void *data, size_t datalen) { struct ibuf ibuf; ibuf_from_buffer(&ibuf, data, datalen); session_notification(p, errcode, subcode, &ibuf); } void session_notification(struct peer *p, uint8_t errcode, uint8_t subcode, struct ibuf *ibuf) { struct ibuf *buf; const char *reason = "sending"; int errs = 0, need_hard_reset = 0; size_t datalen = 0; switch (p->state) { case STATE_OPENSENT: case STATE_OPENCONFIRM: case STATE_ESTABLISHED: break; default: /* session not open, no need to send notification */ log_notification(p, errcode, subcode, ibuf, "dropping"); return; } if (p->capa.neg.grestart.grnotification) { if (session_req_hard_reset(errcode, subcode)) { need_hard_reset = 1; datalen += 2; reason = "sending hard-reset"; } else { reason = "sending graceful"; } } log_notification(p, errcode, subcode, ibuf, reason); /* cap to maximum size */ if (ibuf != NULL) { if (ibuf_size(ibuf) > MAX_PKTSIZE - MSGSIZE_NOTIFICATION_MIN - datalen) { log_peer_warnx(&p->conf, "oversized notification, data trunkated"); ibuf_truncate(ibuf, MAX_PKTSIZE - MSGSIZE_NOTIFICATION_MIN - datalen); } datalen += ibuf_size(ibuf); } if ((buf = session_newmsg(BGP_NOTIFICATION, MSGSIZE_NOTIFICATION_MIN + datalen)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } if (need_hard_reset) { errs += ibuf_add_n8(buf, ERR_CEASE); errs += ibuf_add_n8(buf, ERR_CEASE_HARD_RESET); } errs += ibuf_add_n8(buf, errcode); errs += ibuf_add_n8(buf, subcode); if (ibuf != NULL) errs += ibuf_add_ibuf(buf, ibuf); if (errs) { ibuf_free(buf); bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } session_sendmsg(buf, p, BGP_NOTIFICATION); p->stats.msg_sent_notification++; p->stats.last_sent_errcode = errcode; p->stats.last_sent_suberr = subcode; } int session_neighbor_rrefresh(struct peer *p) { uint8_t i; if (!(p->capa.neg.refresh || p->capa.neg.enhanced_rr)) return (-1); for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.mp[i] != 0) session_rrefresh(p, i, ROUTE_REFRESH_REQUEST); } return (0); } void session_rrefresh(struct peer *p, uint8_t aid, uint8_t subtype) { struct ibuf *buf; int errs = 0; uint16_t afi; uint8_t safi; switch (subtype) { case ROUTE_REFRESH_REQUEST: p->stats.refresh_sent_req++; break; case ROUTE_REFRESH_BEGIN_RR: case ROUTE_REFRESH_END_RR: /* requires enhanced route refresh */ if (!p->capa.neg.enhanced_rr) return; if (subtype == ROUTE_REFRESH_BEGIN_RR) p->stats.refresh_sent_borr++; else p->stats.refresh_sent_eorr++; break; default: fatalx("session_rrefresh: bad subtype %d", subtype); } if (aid2afi(aid, &afi, &safi) == -1) fatalx("session_rrefresh: bad afi/safi pair"); if ((buf = session_newmsg(BGP_RREFRESH, MSGSIZE_RREFRESH)) == NULL) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } errs += ibuf_add_n16(buf, afi); errs += ibuf_add_n8(buf, subtype); errs += ibuf_add_n8(buf, safi); if (errs) { ibuf_free(buf); bgp_fsm(p, EVNT_CON_FATAL, NULL); return; } session_sendmsg(buf, p, BGP_RREFRESH); p->stats.msg_sent_rrefresh++; } int session_graceful_restart(struct peer *p) { uint8_t i; uint16_t staletime = conf->staletime; if (p->conf.staletime) staletime = p->conf.staletime; /* RFC 8538: enforce configurable upper bound of the stale timer */ if (staletime > p->capa.neg.grestart.timeout) staletime = p->capa.neg.grestart.timeout; timer_set(&p->timers, Timer_RestartTimeout, staletime); for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.grestart.flags[i] & CAPA_GR_PRESENT) { if (imsg_rde(IMSG_SESSION_STALE, p->conf.id, &i, sizeof(i)) == -1) return (-1); log_peer_warnx(&p->conf, "graceful restart of %s, keeping routes", aid2str(i)); p->capa.neg.grestart.flags[i] |= CAPA_GR_RESTARTING; } else if (p->capa.neg.mp[i]) { if (imsg_rde(IMSG_SESSION_NOGRACE, p->conf.id, &i, sizeof(i)) == -1) return (-1); log_peer_warnx(&p->conf, "graceful restart of %s, flushing routes", aid2str(i)); } } return (0); } int session_graceful_stop(struct peer *p) { uint8_t i; for (i = AID_MIN; i < AID_MAX; i++) { /* * Only flush if the peer is restarting and the timeout fired. * In all other cases the session was already flushed when the * session went down or when the new open message was parsed. */ if (p->capa.neg.grestart.flags[i] & CAPA_GR_RESTARTING) { log_peer_warnx(&p->conf, "graceful restart of %s, " "time-out, flushing", aid2str(i)); if (imsg_rde(IMSG_SESSION_FLUSH, p->conf.id, &i, sizeof(i)) == -1) return (-1); } p->capa.neg.grestart.flags[i] &= ~CAPA_GR_RESTARTING; } return (0); } int session_dispatch_msg(struct pollfd *pfd, struct peer *p) { socklen_t len; int error; if (p->state == STATE_CONNECT) { if (pfd->revents & POLLOUT) { if (pfd->revents & POLLIN) { /* error occurred */ len = sizeof(error); if (getsockopt(pfd->fd, SOL_SOCKET, SO_ERROR, &error, &len) == -1 || error) { if (error) errno = error; if (errno != p->lasterr) { log_peer_warn(&p->conf, "socket error"); p->lasterr = errno; } bgp_fsm(p, EVNT_CON_OPENFAIL, NULL); return (1); } } bgp_fsm(p, EVNT_CON_OPEN, NULL); return (1); } if (pfd->revents & POLLHUP) { bgp_fsm(p, EVNT_CON_OPENFAIL, NULL); return (1); } if (pfd->revents & (POLLERR|POLLNVAL)) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return (1); } return (0); } if (pfd->revents & POLLHUP) { bgp_fsm(p, EVNT_CON_CLOSED, NULL); return (1); } if (pfd->revents & (POLLERR|POLLNVAL)) { bgp_fsm(p, EVNT_CON_FATAL, NULL); return (1); } if (pfd->revents & POLLOUT && msgbuf_queuelen(p->wbuf) > 0) { if (ibuf_write(p->fd, p->wbuf) == -1) { if (errno == EPIPE) log_peer_warnx(&p->conf, "Connection closed"); else log_peer_warn(&p->conf, "write error"); bgp_fsm(p, EVNT_CON_FATAL, NULL); return (1); } p->stats.last_write = getmonotime(); start_timer_sendholdtime(p); if (p->throttled && msgbuf_queuelen(p->wbuf) < SESS_MSG_LOW_MARK) { if (imsg_rde(IMSG_XON, p->conf.id, NULL, 0) == -1) log_peer_warn(&p->conf, "imsg_compose XON"); else p->throttled = 0; } if (!(pfd->revents & POLLIN)) return (1); } if (p->fd != -1 && pfd->revents & POLLIN) { switch (ibuf_read(p->fd, p->wbuf)) { case -1: if (p->state == STATE_IDLE) /* error already handled before */ return (1); log_peer_warn(&p->conf, "read error"); bgp_fsm(p, EVNT_CON_FATAL, NULL); return (1); case 0: bgp_fsm(p, EVNT_CON_CLOSED, NULL); return (1); } p->stats.last_read = getmonotime(); return (1); } return (0); } void session_process_msg(struct peer *p) { struct ibuf *msg; struct mrt *mrt; int processed = 0; uint8_t msgtype; p->rpending = 0; if (p->wbuf == NULL) return; /* * session might drop to IDLE -> all buffers are flushed */ while ((msg = msgbuf_get(p->wbuf)) != NULL) { /* skip msg header and extract type */ if (ibuf_skip(msg, MSGSIZE_HEADER_MARKER) == -1 || ibuf_skip(msg, sizeof(uint16_t)) == -1 || ibuf_get_n8(msg, &msgtype) == -1) { log_peer_warn(&p->conf, "process message failed"); bgp_fsm(p, EVNT_CON_FATAL, NULL); ibuf_free(msg); return; } ibuf_rewind(msg); /* dump to MRT as soon as we have a full packet */ LIST_FOREACH(mrt, &mrthead, entry) { if (!(mrt->type == MRT_ALL_IN || (msgtype == BGP_UPDATE && mrt->type == MRT_UPDATE_IN))) continue; if ((mrt->peer_id == 0 && mrt->group_id == 0) || mrt->peer_id == p->conf.id || (mrt->group_id != 0 && mrt->group_id == p->conf.groupid)) mrt_dump_bgp_msg(mrt, msg, p, msgtype); } ibuf_skip(msg, MSGSIZE_HEADER); switch (msgtype) { case BGP_OPEN: bgp_fsm(p, EVNT_RCVD_OPEN, msg); p->stats.msg_rcvd_open++; break; case BGP_UPDATE: bgp_fsm(p, EVNT_RCVD_UPDATE, msg); p->stats.msg_rcvd_update++; break; case BGP_NOTIFICATION: bgp_fsm(p, EVNT_RCVD_NOTIFICATION, msg); p->stats.msg_rcvd_notification++; break; case BGP_KEEPALIVE: bgp_fsm(p, EVNT_RCVD_KEEPALIVE, msg); p->stats.msg_rcvd_keepalive++; break; case BGP_RREFRESH: parse_rrefresh(p, msg); p->stats.msg_rcvd_rrefresh++; break; default: /* cannot happen */ session_notification_data(p, ERR_HEADER, ERR_HDR_TYPE, &msgtype, 1); log_peer_warnx(&p->conf, "received message with unknown type %u", msgtype); bgp_fsm(p, EVNT_CON_FATAL, NULL); } ibuf_free(msg); if (++processed > MSG_PROCESS_LIMIT) { p->rpending = 1; break; } } } struct ibuf * parse_header(struct ibuf *msg, void *arg, int *fd) { struct peer *peer = arg; struct ibuf *b; u_char m[MSGSIZE_HEADER_MARKER]; uint16_t len, maxlen = MAX_PKTSIZE; uint8_t type; if (ibuf_get(msg, m, sizeof(m)) == -1 || ibuf_get_n16(msg, &len) == -1 || ibuf_get_n8(msg, &type) == -1) return (NULL); /* caller MUST make sure we are getting 19 bytes! */ if (memcmp(m, marker, sizeof(marker))) { log_peer_warnx(&peer->conf, "sync error"); session_notification(peer, ERR_HEADER, ERR_HDR_SYNC, NULL); bgp_fsm(peer, EVNT_CON_FATAL, NULL); errno = EINVAL; return (NULL); } if (peer->capa.ann.ext_msg) maxlen = MAX_EXT_PKTSIZE; if (len < MSGSIZE_HEADER || len > maxlen) { log_peer_warnx(&peer->conf, "received message: illegal length: %u byte", len); goto badlen; } switch (type) { case BGP_OPEN: if (len < MSGSIZE_OPEN_MIN || len > MAX_PKTSIZE) { log_peer_warnx(&peer->conf, "received OPEN: illegal len: %u byte", len); goto badlen; } break; case BGP_NOTIFICATION: if (len < MSGSIZE_NOTIFICATION_MIN) { log_peer_warnx(&peer->conf, "received NOTIFICATION: illegal len: %u byte", len); goto badlen; } break; case BGP_UPDATE: if (len < MSGSIZE_UPDATE_MIN) { log_peer_warnx(&peer->conf, "received UPDATE: illegal len: %u byte", len); goto badlen; } break; case BGP_KEEPALIVE: if (len != MSGSIZE_KEEPALIVE) { log_peer_warnx(&peer->conf, "received KEEPALIVE: illegal len: %u byte", len); goto badlen; } break; case BGP_RREFRESH: if (len < MSGSIZE_RREFRESH_MIN) { log_peer_warnx(&peer->conf, "received RREFRESH: illegal len: %u byte", len); goto badlen; } break; default: log_peer_warnx(&peer->conf, "received msg with unknown type %u", type); session_notification_data(peer, ERR_HEADER, ERR_HDR_TYPE, &type, sizeof(type)); bgp_fsm(peer, EVNT_CON_FATAL, NULL); errno = EINVAL; return (NULL); } if ((b = ibuf_open(len)) == NULL) return (NULL); return (b); badlen: len = htons(len); session_notification_data(peer, ERR_HEADER, ERR_HDR_LEN, &len, sizeof(len)); bgp_fsm(peer, EVNT_CON_FATAL, NULL); errno = ERANGE; return (NULL); } int parse_open(struct peer *peer, struct ibuf *msg) { uint8_t version, rversion; uint16_t short_as; uint16_t holdtime, myholdtime; uint32_t as, bgpid; uint8_t optparamlen; if (ibuf_get_n8(msg, &version) == -1 || ibuf_get_n16(msg, &short_as) == -1 || ibuf_get_n16(msg, &holdtime) == -1 || ibuf_get_n32(msg, &bgpid) == -1 || ibuf_get_n8(msg, &optparamlen) == -1) goto bad_len; if (version != BGP_VERSION) { log_peer_warnx(&peer->conf, "peer wants unrecognized version %u", version); if (version > BGP_VERSION) rversion = version - BGP_VERSION; else rversion = BGP_VERSION; session_notification_data(peer, ERR_OPEN, ERR_OPEN_VERSION, &rversion, sizeof(rversion)); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } as = peer->short_as = short_as; if (as == 0) { log_peer_warnx(&peer->conf, "peer requests unacceptable AS %u", as); session_notification(peer, ERR_OPEN, ERR_OPEN_AS, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } if (holdtime && holdtime < peer->conf.min_holdtime) { log_peer_warnx(&peer->conf, "peer requests unacceptable holdtime %u", holdtime); session_notification(peer, ERR_OPEN, ERR_OPEN_HOLDTIME, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } myholdtime = peer->conf.holdtime; if (!myholdtime) myholdtime = conf->holdtime; if (holdtime < myholdtime) peer->holdtime = holdtime; else peer->holdtime = myholdtime; /* check bgpid for validity - just disallow 0 */ if (bgpid == 0) { log_peer_warnx(&peer->conf, "peer BGPID 0 unacceptable"); session_notification(peer, ERR_OPEN, ERR_OPEN_BGPID, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } peer->remote_bgpid = bgpid; if (optparamlen != 0) { struct ibuf oparams, op; uint8_t ext_type, op_type; uint16_t ext_len, op_len; ibuf_from_ibuf(&oparams, msg); /* check for RFC9072 encoding */ if (ibuf_get_n8(&oparams, &ext_type) == -1) goto bad_len; if (ext_type == OPT_PARAM_EXT_LEN) { if (ibuf_get_n16(&oparams, &ext_len) == -1) goto bad_len; /* skip RFC9072 header */ if (ibuf_skip(msg, 3) == -1) goto bad_len; } else { ext_len = optparamlen; ibuf_rewind(&oparams); } if (ibuf_truncate(&oparams, ext_len) == -1 || ibuf_skip(msg, ext_len) == -1) goto bad_len; while (ibuf_size(&oparams) > 0) { if (ibuf_get_n8(&oparams, &op_type) == -1) goto bad_len; if (ext_type == OPT_PARAM_EXT_LEN) { if (ibuf_get_n16(&oparams, &op_len) == -1) goto bad_len; } else { uint8_t tmp; if (ibuf_get_n8(&oparams, &tmp) == -1) goto bad_len; op_len = tmp; } if (ibuf_get_ibuf(&oparams, op_len, &op) == -1) goto bad_len; switch (op_type) { case OPT_PARAM_CAPABILITIES: /* RFC 3392 */ if (parse_capabilities(peer, &op, &as) == -1) { session_notification(peer, ERR_OPEN, 0, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } break; case OPT_PARAM_AUTH: /* deprecated */ default: /* * unsupported type * the RFCs tell us to leave the data section * empty and notify the peer with ERR_OPEN, * ERR_OPEN_OPT. How the peer should know * _which_ optional parameter we don't support * is beyond me. */ log_peer_warnx(&peer->conf, "received OPEN message with unsupported " "optional parameter: type %u", op_type); session_notification(peer, ERR_OPEN, ERR_OPEN_OPT, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } } } if (ibuf_size(msg) != 0) { bad_len: log_peer_warnx(&peer->conf, "corrupt OPEN message received: length mismatch"); session_notification(peer, ERR_OPEN, 0, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } /* * if remote-as is zero and it's a cloned neighbor, accept any * but only on the first connect, after that the remote-as needs * to remain the same. */ if (peer->template && !peer->conf.remote_as && as != AS_TRANS) { peer->conf.remote_as = as; peer->conf.ebgp = (peer->conf.remote_as != peer->conf.local_as); if (!peer->conf.ebgp) /* force enforce_as off for iBGP sessions */ peer->conf.enforce_as = ENFORCE_AS_OFF; } if (peer->conf.remote_as != as) { log_peer_warnx(&peer->conf, "peer sent wrong AS %s", log_as(as)); session_notification(peer, ERR_OPEN, ERR_OPEN_AS, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } /* on iBGP sessions check for bgpid collision */ if (!peer->conf.ebgp && peer->remote_bgpid == conf->bgpid) { struct in_addr ina; ina.s_addr = htonl(bgpid); log_peer_warnx(&peer->conf, "peer BGPID %s conflicts with ours", inet_ntoa(ina)); session_notification(peer, ERR_OPEN, ERR_OPEN_BGPID, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } if (capa_neg_calc(peer) == -1) { change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } return (0); } int parse_update(struct peer *peer, struct ibuf *msg) { /* * we pass the message verbatim to the rde. * in case of errors the whole session is reset with a * notification anyway, we only need to know the peer */ if (imsg_rde(IMSG_UPDATE, peer->conf.id, ibuf_data(msg), ibuf_size(msg)) == -1) return (-1); return (0); } int parse_rrefresh(struct peer *peer, struct ibuf *msg) { struct route_refresh rr; uint16_t afi, datalen; uint8_t aid, safi, subtype; datalen = ibuf_size(msg) + MSGSIZE_HEADER; if (ibuf_get_n16(msg, &afi) == -1 || ibuf_get_n8(msg, &subtype) == -1 || ibuf_get_n8(msg, &safi) == -1) { /* minimum size checked in session_process_msg() */ fatalx("%s: message too small", __func__); } /* check subtype if peer announced enhanced route refresh */ if (peer->capa.neg.enhanced_rr) { switch (subtype) { case ROUTE_REFRESH_REQUEST: /* no ORF support, so no oversized RREFRESH msgs */ if (datalen != MSGSIZE_RREFRESH) { log_peer_warnx(&peer->conf, "received RREFRESH: illegal len: %u byte", datalen); datalen = htons(datalen); session_notification_data(peer, ERR_HEADER, ERR_HDR_LEN, &datalen, sizeof(datalen)); bgp_fsm(peer, EVNT_CON_FATAL, NULL); return (-1); } peer->stats.refresh_rcvd_req++; break; case ROUTE_REFRESH_BEGIN_RR: case ROUTE_REFRESH_END_RR: /* special handling for RFC7313 */ if (datalen != MSGSIZE_RREFRESH) { log_peer_warnx(&peer->conf, "received RREFRESH: illegal len: %u byte", datalen); ibuf_rewind(msg); session_notification(peer, ERR_RREFRESH, ERR_RR_INV_LEN, msg); bgp_fsm(peer, EVNT_CON_FATAL, NULL); return (-1); } if (subtype == ROUTE_REFRESH_BEGIN_RR) peer->stats.refresh_rcvd_borr++; else peer->stats.refresh_rcvd_eorr++; break; default: log_peer_warnx(&peer->conf, "peer sent bad refresh, " "bad subtype %d", subtype); return (0); } } else { /* force subtype to default */ subtype = ROUTE_REFRESH_REQUEST; peer->stats.refresh_rcvd_req++; } /* afi/safi unchecked - unrecognized values will be ignored anyway */ if (afi2aid(afi, safi, &aid) == -1) { log_peer_warnx(&peer->conf, "peer sent bad refresh, " "invalid afi/safi pair"); return (0); } if (!peer->capa.neg.refresh && !peer->capa.neg.enhanced_rr) { log_peer_warnx(&peer->conf, "peer sent unexpected refresh"); return (0); } rr.aid = aid; rr.subtype = subtype; if (imsg_rde(IMSG_REFRESH, peer->conf.id, &rr, sizeof(rr)) == -1) return (-1); return (0); } void parse_notification(struct peer *peer, struct ibuf *msg) { const char *reason = "received"; uint8_t errcode, subcode; uint8_t reason_len; enum session_events event = EVNT_RCVD_NOTIFICATION; if (ibuf_get_n8(msg, &errcode) == -1 || ibuf_get_n8(msg, &subcode) == -1) { log_peer_warnx(&peer->conf, "received bad notification"); goto done; } /* RFC8538: check for hard-reset or graceful notification */ if (peer->capa.neg.grestart.grnotification) { if (errcode == ERR_CEASE && subcode == ERR_CEASE_HARD_RESET) { if (ibuf_get_n8(msg, &errcode) == -1 || ibuf_get_n8(msg, &subcode) == -1) { log_peer_warnx(&peer->conf, "received bad hard-reset notification"); goto done; } reason = "received hard-reset"; } else { reason = "received graceful"; event = EVNT_RCVD_GRACE_NOTIFICATION; } } peer->errcnt++; peer->stats.last_rcvd_errcode = errcode; peer->stats.last_rcvd_suberr = subcode; log_notification(peer, errcode, subcode, msg, reason); CTASSERT(sizeof(peer->stats.last_reason) > UINT8_MAX); memset(peer->stats.last_reason, 0, sizeof(peer->stats.last_reason)); if (errcode == ERR_CEASE && (subcode == ERR_CEASE_ADMIN_DOWN || subcode == ERR_CEASE_ADMIN_RESET)) { /* check if shutdown reason is included */ if (ibuf_get_n8(msg, &reason_len) != -1 && reason_len != 0) { if (ibuf_get(msg, peer->stats.last_reason, reason_len) == -1) log_peer_warnx(&peer->conf, "received truncated shutdown reason"); } } done: change_state(peer, STATE_IDLE, event); } int parse_capabilities(struct peer *peer, struct ibuf *buf, uint32_t *as) { struct ibuf capabuf; uint16_t afi, nhafi, gr_header; uint8_t capa_code, capa_len; uint8_t safi, aid, role, flags; while (ibuf_size(buf) > 0) { if (ibuf_get_n8(buf, &capa_code) == -1 || ibuf_get_n8(buf, &capa_len) == -1) { log_peer_warnx(&peer->conf, "Bad capabilities attr " "length: too short"); return (-1); } if (ibuf_get_ibuf(buf, capa_len, &capabuf) == -1) { log_peer_warnx(&peer->conf, "Received bad capabilities attr length: " "len %zu smaller than capa_len %u", ibuf_size(buf), capa_len); return (-1); } switch (capa_code) { case CAPA_MP: /* RFC 4760 */ if (capa_len != 4 || ibuf_get_n16(&capabuf, &afi) == -1 || ibuf_skip(&capabuf, 1) == -1 || ibuf_get_n8(&capabuf, &safi) == -1) { log_peer_warnx(&peer->conf, "Received bad multi protocol capability"); break; } if (afi2aid(afi, safi, &aid) == -1) { log_peer_warnx(&peer->conf, "Received multi protocol capability: " " unknown AFI %u, safi %u pair", afi, safi); peer->capa.peer.mp[AID_UNSPEC] = 1; break; } peer->capa.peer.mp[aid] = 1; break; case CAPA_REFRESH: peer->capa.peer.refresh = 1; break; case CAPA_EXT_NEXTHOP: while (ibuf_size(&capabuf) > 0) { uint16_t tmp16; if (ibuf_get_n16(&capabuf, &afi) == -1 || ibuf_get_n16(&capabuf, &tmp16) == -1 || ibuf_get_n16(&capabuf, &nhafi) == -1) { log_peer_warnx(&peer->conf, "Received bad %s capability", log_capability(CAPA_EXT_NEXTHOP)); memset(peer->capa.peer.ext_nh, 0, sizeof(peer->capa.peer.ext_nh)); break; } safi = tmp16; if (afi2aid(afi, safi, &aid) == -1 || !(aid == AID_INET || aid == AID_VPN_IPv4)) { log_peer_warnx(&peer->conf, "Received %s capability: " " unsupported AFI %u, safi %u pair", log_capability(CAPA_EXT_NEXTHOP), afi, safi); continue; } if (nhafi != AFI_IPv6) { log_peer_warnx(&peer->conf, "Received %s capability: " " unsupported nexthop AFI %u", log_capability(CAPA_EXT_NEXTHOP), nhafi); continue; } peer->capa.peer.ext_nh[aid] = 1; } break; case CAPA_EXT_MSG: peer->capa.peer.ext_msg = 1; break; case CAPA_ROLE: if (capa_len != 1 || ibuf_get_n8(&capabuf, &role) == -1) { log_peer_warnx(&peer->conf, "Received bad role capability"); break; } if (!peer->conf.ebgp) { log_peer_warnx(&peer->conf, "Received role capability on iBGP session"); break; } peer->capa.peer.policy = 1; peer->remote_role = capa2role(role); break; case CAPA_RESTART: if (capa_len == 2) { /* peer only supports EoR marker */ peer->capa.peer.grestart.restart = 1; peer->capa.peer.grestart.timeout = 0; break; } else if (capa_len % 4 != 2) { log_peer_warnx(&peer->conf, "Bad graceful restart capability"); peer->capa.peer.grestart.restart = 0; peer->capa.peer.grestart.timeout = 0; break; } if (ibuf_get_n16(&capabuf, &gr_header) == -1) { bad_gr_restart: log_peer_warnx(&peer->conf, "Bad graceful restart capability"); peer->capa.peer.grestart.restart = 0; peer->capa.peer.grestart.timeout = 0; break; } peer->capa.peer.grestart.timeout = gr_header & CAPA_GR_TIMEMASK; if (peer->capa.peer.grestart.timeout == 0) { log_peer_warnx(&peer->conf, "Received " "graceful restart with zero timeout"); peer->capa.peer.grestart.restart = 0; break; } while (ibuf_size(&capabuf) > 0) { if (ibuf_get_n16(&capabuf, &afi) == -1 || ibuf_get_n8(&capabuf, &safi) == -1 || ibuf_get_n8(&capabuf, &flags) == -1) goto bad_gr_restart; if (afi2aid(afi, safi, &aid) == -1) { log_peer_warnx(&peer->conf, "Received graceful restart capa: " " unknown AFI %u, safi %u pair", afi, safi); continue; } peer->capa.peer.grestart.flags[aid] |= CAPA_GR_PRESENT; if (flags & CAPA_GR_F_FLAG) peer->capa.peer.grestart.flags[aid] |= CAPA_GR_FORWARD; if (gr_header & CAPA_GR_R_FLAG) peer->capa.peer.grestart.flags[aid] |= CAPA_GR_RESTART; peer->capa.peer.grestart.restart = 2; } if (gr_header & CAPA_GR_N_FLAG) peer->capa.peer.grestart.grnotification = 1; break; case CAPA_AS4BYTE: if (capa_len != 4 || ibuf_get_n32(&capabuf, as) == -1) { log_peer_warnx(&peer->conf, "Received bad AS4BYTE capability"); peer->capa.peer.as4byte = 0; break; } if (*as == 0) { log_peer_warnx(&peer->conf, "peer requests unacceptable AS %u", *as); session_notification(peer, ERR_OPEN, ERR_OPEN_AS, NULL); change_state(peer, STATE_IDLE, EVNT_RCVD_OPEN); return (-1); } peer->capa.peer.as4byte = 1; break; case CAPA_ADD_PATH: if (capa_len % 4 != 0) { bad_add_path: log_peer_warnx(&peer->conf, "Received bad ADD-PATH capability"); memset(peer->capa.peer.add_path, 0, sizeof(peer->capa.peer.add_path)); break; } while (ibuf_size(&capabuf) > 0) { if (ibuf_get_n16(&capabuf, &afi) == -1 || ibuf_get_n8(&capabuf, &safi) == -1 || ibuf_get_n8(&capabuf, &flags) == -1) goto bad_add_path; if (afi2aid(afi, safi, &aid) == -1) { log_peer_warnx(&peer->conf, "Received ADD-PATH capa: " " unknown AFI %u, safi %u pair", afi, safi); memset(peer->capa.peer.add_path, 0, sizeof(peer->capa.peer.add_path)); break; } if (flags & ~CAPA_AP_BIDIR) { log_peer_warnx(&peer->conf, "Received ADD-PATH capa: " " bad flags %x", flags); memset(peer->capa.peer.add_path, 0, sizeof(peer->capa.peer.add_path)); break; } peer->capa.peer.add_path[aid] = flags; } break; case CAPA_ENHANCED_RR: peer->capa.peer.enhanced_rr = 1; break; default: break; } } return (0); } int capa_neg_calc(struct peer *p) { struct ibuf *ebuf; uint8_t i, hasmp = 0, capa_code, capa_len, capa_aid = 0; /* a capability is accepted only if both sides announced it */ p->capa.neg.refresh = (p->capa.ann.refresh && p->capa.peer.refresh) != 0; p->capa.neg.enhanced_rr = (p->capa.ann.enhanced_rr && p->capa.peer.enhanced_rr) != 0; p->capa.neg.as4byte = (p->capa.ann.as4byte && p->capa.peer.as4byte) != 0; p->capa.neg.ext_msg = (p->capa.ann.ext_msg && p->capa.peer.ext_msg) != 0; /* MP: both side must agree on the AFI,SAFI pair */ if (p->capa.peer.mp[AID_UNSPEC]) hasmp = 1; for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.ann.mp[i] && p->capa.peer.mp[i]) p->capa.neg.mp[i] = 1; else p->capa.neg.mp[i] = 0; if (p->capa.ann.mp[i] || p->capa.peer.mp[i]) hasmp = 1; } /* if no MP capability present default to IPv4 unicast mode */ if (!hasmp) p->capa.neg.mp[AID_INET] = 1; /* * graceful restart: the peer capabilities are of interest here. * It is necessary to compare the new values with the previous ones * and act accordingly. AFI/SAFI that are not part in the MP capability * are treated as not being present. * Also make sure that a flush happens if the session stopped * supporting graceful restart. */ for (i = AID_MIN; i < AID_MAX; i++) { int8_t negflags; /* disable GR if the AFI/SAFI is not present */ if ((p->capa.peer.grestart.flags[i] & CAPA_GR_PRESENT && p->capa.neg.mp[i] == 0)) p->capa.peer.grestart.flags[i] = 0; /* disable */ /* look at current GR state and decide what to do */ negflags = p->capa.neg.grestart.flags[i]; p->capa.neg.grestart.flags[i] = p->capa.peer.grestart.flags[i]; if (negflags & CAPA_GR_RESTARTING) { if (p->capa.ann.grestart.restart != 0 && p->capa.peer.grestart.flags[i] & CAPA_GR_FORWARD) { p->capa.neg.grestart.flags[i] |= CAPA_GR_RESTARTING; } else { if (imsg_rde(IMSG_SESSION_FLUSH, p->conf.id, &i, sizeof(i)) == -1) { log_peer_warnx(&p->conf, "imsg send failed"); return (-1); } log_peer_warnx(&p->conf, "graceful restart of " "%s, not restarted, flushing", aid2str(i)); } } } p->capa.neg.grestart.timeout = p->capa.peer.grestart.timeout; p->capa.neg.grestart.restart = p->capa.peer.grestart.restart; if (p->capa.ann.grestart.restart == 0) p->capa.neg.grestart.restart = 0; /* RFC 8538 graceful notification: both sides need to agree */ p->capa.neg.grestart.grnotification = (p->capa.ann.grestart.grnotification && p->capa.peer.grestart.grnotification) != 0; /* RFC 8950 extended nexthop encoding: both sides need to agree */ memset(p->capa.neg.add_path, 0, sizeof(p->capa.neg.add_path)); for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.mp[i] == 0) continue; if (p->capa.ann.ext_nh[i] && p->capa.peer.ext_nh[i]) { p->capa.neg.ext_nh[i] = 1; } } /* * ADD-PATH: set only those bits where both sides agree. * For this compare our send bit with the recv bit from the peer * and vice versa. * The flags are stored from this systems view point. * At index 0 the flags are set if any per-AID flag is set. */ memset(p->capa.neg.add_path, 0, sizeof(p->capa.neg.add_path)); for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.mp[i] == 0) continue; if ((p->capa.ann.add_path[i] & CAPA_AP_RECV) && (p->capa.peer.add_path[i] & CAPA_AP_SEND)) { p->capa.neg.add_path[i] |= CAPA_AP_RECV; p->capa.neg.add_path[0] |= CAPA_AP_RECV; } if ((p->capa.ann.add_path[i] & CAPA_AP_SEND) && (p->capa.peer.add_path[i] & CAPA_AP_RECV)) { p->capa.neg.add_path[i] |= CAPA_AP_SEND; p->capa.neg.add_path[0] |= CAPA_AP_SEND; } } /* * Open policy: check that the policy is sensible. * * Make sure that the roles match and set the negotiated capability * to the role of the peer. So the RDE can inject the OTC attribute. * See RFC 9234, section 4.2. * These checks should only happen on ebgp sessions. */ if (p->capa.ann.policy != 0 && p->capa.peer.policy != 0 && p->conf.ebgp) { switch (p->conf.role) { case ROLE_PROVIDER: if (p->remote_role != ROLE_CUSTOMER) goto policyfail; break; case ROLE_RS: if (p->remote_role != ROLE_RS_CLIENT) goto policyfail; break; case ROLE_RS_CLIENT: if (p->remote_role != ROLE_RS) goto policyfail; break; case ROLE_CUSTOMER: if (p->remote_role != ROLE_PROVIDER) goto policyfail; break; case ROLE_PEER: if (p->remote_role != ROLE_PEER) goto policyfail; break; default: policyfail: log_peer_warnx(&p->conf, "open policy role mismatch: " "our role %s, their role %s", log_policy(p->conf.role), log_policy(p->remote_role)); session_notification(p, ERR_OPEN, ERR_OPEN_ROLE, NULL); return (-1); } p->capa.neg.policy = 1; } /* enforce presence of open policy role capability */ if (p->capa.ann.policy == 2 && p->capa.peer.policy == 0 && p->conf.ebgp) { log_peer_warnx(&p->conf, "open policy role enforced but " "not present"); session_notification(p, ERR_OPEN, ERR_OPEN_ROLE, NULL); return (-1); } /* enforce presence of other capabilities */ if (p->capa.ann.refresh == 2 && p->capa.neg.refresh == 0) { capa_code = CAPA_REFRESH; capa_len = 0; goto fail; } /* enforce presence of other capabilities */ if (p->capa.ann.ext_msg == 2 && p->capa.neg.ext_msg == 0) { capa_code = CAPA_EXT_MSG; capa_len = 0; goto fail; } if (p->capa.ann.enhanced_rr == 2 && p->capa.neg.enhanced_rr == 0) { capa_code = CAPA_ENHANCED_RR; capa_len = 0; goto fail; } if (p->capa.ann.as4byte == 2 && p->capa.neg.as4byte == 0) { capa_code = CAPA_AS4BYTE; capa_len = 4; goto fail; } if (p->capa.ann.grestart.restart == 2 && p->capa.neg.grestart.restart == 0) { capa_code = CAPA_RESTART; capa_len = 2; goto fail; } for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.ann.mp[i] == 2 && p->capa.neg.mp[i] == 0) { capa_code = CAPA_MP; capa_len = 4; capa_aid = i; goto fail; } } for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.mp[i] == 0) continue; if ((p->capa.ann.add_path[i] & CAPA_AP_RECV_ENFORCE) && (p->capa.neg.add_path[i] & CAPA_AP_RECV) == 0) { capa_code = CAPA_ADD_PATH; capa_len = 4; capa_aid = i; goto fail; } if ((p->capa.ann.add_path[i] & CAPA_AP_SEND_ENFORCE) && (p->capa.neg.add_path[i] & CAPA_AP_SEND) == 0) { capa_code = CAPA_ADD_PATH; capa_len = 4; capa_aid = i; goto fail; } } for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.mp[i] == 0) continue; if (p->capa.ann.ext_nh[i] == 2 && p->capa.neg.ext_nh[i] == 0) { capa_code = CAPA_EXT_NEXTHOP; capa_len = 6; capa_aid = i; goto fail; } } return (0); fail: if ((ebuf = ibuf_dynamic(2, 256)) == NULL) return (-1); /* best effort, no problem if it fails */ session_capa_add(ebuf, capa_code, capa_len); if (capa_code == CAPA_MP) session_capa_add_mp(ebuf, capa_aid); else if (capa_code == CAPA_ADD_PATH) session_capa_add_afi(ebuf, capa_aid, 0); else if (capa_code == CAPA_EXT_NEXTHOP) session_capa_add_ext_nh(ebuf, capa_aid); else if (capa_len > 0) ibuf_add_zero(ebuf, capa_len); session_notification(p, ERR_OPEN, ERR_OPEN_CAPA, ebuf); ibuf_free(ebuf); return (-1); } void session_dispatch_imsg(struct imsgbuf *imsgbuf, int idx, u_int *listener_cnt) { struct imsg imsg; struct ibuf ibuf; struct mrt xmrt; struct route_refresh rr; struct mrt *mrt; struct imsgbuf *i; struct peer *p; struct listen_addr *la, *next, nla; struct session_dependon sdon; struct bgpd_config tconf; uint32_t peerid; int n, fd, depend_ok, restricted; uint16_t t; uint8_t aid, errcode, subcode; while (imsgbuf) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("session_dispatch_imsg: imsg_get error"); if (n == 0) break; peerid = imsg_get_id(&imsg); switch (imsg_get_type(&imsg)) { case IMSG_SOCKET_CONN: case IMSG_SOCKET_CONN_CTL: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); if ((fd = imsg_get_fd(&imsg)) == -1) { log_warnx("expected to receive imsg fd to " "RDE but didn't receive any"); break; } if ((i = malloc(sizeof(struct imsgbuf))) == NULL) fatal(NULL); if (imsgbuf_init(i, fd) == -1 || imsgbuf_set_maxsize(i, MAX_BGPD_IMSGSIZE) == -1) fatal(NULL); if (imsg_get_type(&imsg) == IMSG_SOCKET_CONN) { if (ibuf_rde) { log_warnx("Unexpected imsg connection " "to RDE received"); imsgbuf_clear(ibuf_rde); free(ibuf_rde); } ibuf_rde = i; } else { if (ibuf_rde_ctl) { log_warnx("Unexpected imsg ctl " "connection to RDE received"); imsgbuf_clear(ibuf_rde_ctl); free(ibuf_rde_ctl); } ibuf_rde_ctl = i; } break; case IMSG_RECONF_CONF: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); if (imsg_get_data(&imsg, &tconf, sizeof(tconf)) == -1) fatal("imsg_get_data"); nconf = new_config(); copy_config(nconf, &tconf); pending_reconf = 1; break; case IMSG_RECONF_PEER: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); if ((p = calloc(1, sizeof(struct peer))) == NULL) fatal("new_peer"); if (imsg_get_data(&imsg, &p->conf, sizeof(p->conf)) == -1) fatal("imsg_get_data"); p->state = p->prev_state = STATE_NONE; p->reconf_action = RECONF_REINIT; if (RB_INSERT(peer_head, &nconf->peers, p) != NULL) fatalx("%s: peer tree is corrupt", __func__); break; case IMSG_RECONF_PEER_AUTH: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); if ((p = getpeerbyid(nconf, peerid)) == NULL) { log_warnx("no such peer: id=%u", peerid); break; } if (pfkey_recv_conf(p, &imsg) == -1) fatal("pfkey_recv_conf"); break; case IMSG_RECONF_LISTENER: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); if (nconf == NULL) fatalx("IMSG_RECONF_LISTENER but no config"); if (imsg_get_data(&imsg, &nla, sizeof(nla)) == -1) fatal("imsg_get_data"); TAILQ_FOREACH(la, conf->listen_addrs, entry) if (!la_cmp(la, &nla)) break; if (la == NULL) { if (nla.reconf != RECONF_REINIT) fatalx("king bula sez: " "expected REINIT"); if ((nla.fd = imsg_get_fd(&imsg)) == -1) log_warnx("expected to receive fd for " "%s but didn't receive any", log_sockaddr((struct sockaddr *) &nla.sa, nla.sa_len)); la = calloc(1, sizeof(struct listen_addr)); if (la == NULL) fatal(NULL); memcpy(&la->sa, &nla.sa, sizeof(la->sa)); la->flags = nla.flags; la->fd = nla.fd; la->reconf = RECONF_REINIT; TAILQ_INSERT_TAIL(nconf->listen_addrs, la, entry); } else { if (nla.reconf != RECONF_KEEP) fatalx("king bula sez: expected KEEP"); la->reconf = RECONF_KEEP; } break; case IMSG_RECONF_CTRL: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); if (imsg_get_data(&imsg, &restricted, sizeof(restricted)) == -1) fatal("imsg_get_data"); if ((fd = imsg_get_fd(&imsg)) == -1) { log_warnx("expected to receive fd for control " "socket but didn't receive any"); break; } if (restricted) { control_shutdown(rcsock); rcsock = fd; } else { control_shutdown(csock); csock = fd; } break; case IMSG_RECONF_DRAIN: switch (idx) { case PFD_PIPE_ROUTE: if (nconf != NULL) fatalx("got unexpected %s from RDE", "IMSG_RECONF_DONE"); imsg_compose(ibuf_main, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0); break; case PFD_PIPE_MAIN: if (nconf == NULL) fatalx("got unexpected %s from parent", "IMSG_RECONF_DONE"); imsg_compose(ibuf_main, IMSG_RECONF_DRAIN, 0, 0, -1, NULL, 0); break; default: fatalx("reconf request not from parent or RDE"); } break; case IMSG_RECONF_DONE: if (idx != PFD_PIPE_MAIN) fatalx("reconf request not from parent"); if (nconf == NULL) fatalx("got IMSG_RECONF_DONE but no config"); copy_config(conf, nconf); merge_peers(conf, nconf); /* delete old listeners */ TAILQ_FOREACH_SAFE(la, conf->listen_addrs, entry, next) { if (la->reconf == RECONF_NONE) { log_info("not listening on %s any more", log_sockaddr((struct sockaddr *) &la->sa, la->sa_len)); TAILQ_REMOVE(conf->listen_addrs, la, entry); close(la->fd); free(la); } } /* add new listeners */ TAILQ_CONCAT(conf->listen_addrs, nconf->listen_addrs, entry); setup_listeners(listener_cnt); free_config(nconf); nconf = NULL; pending_reconf = 0; log_info("SE reconfigured"); /* * IMSG_RECONF_DONE is sent when the RDE drained * the peer config sent in merge_peers(). */ break; case IMSG_SESSION_DEPENDON: if (idx != PFD_PIPE_MAIN) fatalx("IFINFO message not from parent"); if (imsg_get_data(&imsg, &sdon, sizeof(sdon)) == -1) fatalx("DEPENDON imsg with wrong len"); depend_ok = sdon.depend_state; RB_FOREACH(p, peer_head, &conf->peers) if (!strcmp(p->conf.if_depend, sdon.ifname)) { if (depend_ok && !p->depend_ok) { p->depend_ok = depend_ok; bgp_fsm(p, EVNT_START, NULL); } else if (!depend_ok && p->depend_ok) { p->depend_ok = depend_ok; session_stop(p, ERR_CEASE_OTHER_CHANGE, NULL); } } break; case IMSG_MRT_OPEN: case IMSG_MRT_REOPEN: if (idx != PFD_PIPE_MAIN) fatalx("mrt request not from parent"); if (imsg_get_data(&imsg, &xmrt, sizeof(xmrt)) == -1) { log_warnx("mrt open, wrong imsg len"); break; } if ((xmrt.fd = imsg_get_fd(&imsg)) == -1) { log_warnx("expected to receive fd for mrt dump " "but didn't receive any"); break; } mrt = mrt_get(&mrthead, &xmrt); if (mrt == NULL) { /* new dump */ mrt = calloc(1, sizeof(struct mrt)); if (mrt == NULL) fatal("session_dispatch_imsg"); memcpy(mrt, &xmrt, sizeof(struct mrt)); if ((mrt->wbuf = msgbuf_new()) == NULL) fatal("session_dispatch_imsg"); LIST_INSERT_HEAD(&mrthead, mrt, entry); } else { /* old dump reopened */ close(mrt->fd); } mrt->fd = xmrt.fd; break; case IMSG_MRT_CLOSE: if (idx != PFD_PIPE_MAIN) fatalx("mrt request not from parent"); if (imsg_get_data(&imsg, &xmrt, sizeof(xmrt)) == -1) { log_warnx("mrt close, wrong imsg len"); break; } mrt = mrt_get(&mrthead, &xmrt); if (mrt != NULL) mrt_done(mrt); break; case IMSG_CTL_KROUTE: case IMSG_CTL_KROUTE_ADDR: case IMSG_CTL_SHOW_NEXTHOP: case IMSG_CTL_SHOW_INTERFACE: case IMSG_CTL_SHOW_FIB_TABLES: case IMSG_CTL_SHOW_RTR: case IMSG_CTL_SHOW_TIMER: if (idx != PFD_PIPE_MAIN) fatalx("ctl kroute request not from parent"); control_imsg_relay(&imsg, NULL); break; case IMSG_CTL_SHOW_NEIGHBOR: if (idx != PFD_PIPE_ROUTE_CTL) fatalx("ctl rib request not from RDE"); p = getpeerbyid(conf, peerid); control_imsg_relay(&imsg, p); break; case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_RIB_PREFIX: case IMSG_CTL_SHOW_RIB_COMMUNITIES: case IMSG_CTL_SHOW_RIB_ATTR: case IMSG_CTL_SHOW_RIB_MEM: case IMSG_CTL_SHOW_NETWORK: case IMSG_CTL_SHOW_FLOWSPEC: case IMSG_CTL_SHOW_SET: if (idx != PFD_PIPE_ROUTE_CTL) fatalx("ctl rib request not from RDE"); control_imsg_relay(&imsg, NULL); break; case IMSG_CTL_END: case IMSG_CTL_RESULT: control_imsg_relay(&imsg, NULL); break; case IMSG_UPDATE: if (idx != PFD_PIPE_ROUTE) fatalx("update request not from RDE"); if (imsg_get_ibuf(&imsg, &ibuf) == -1) log_warn("RDE sent invalid update"); else session_update(peerid, &ibuf); break; case IMSG_UPDATE_ERR: if (idx != PFD_PIPE_ROUTE) fatalx("update request not from RDE"); if ((p = getpeerbyid(conf, peerid)) == NULL) { log_warnx("no such peer: id=%u", peerid); break; } if (imsg_get_ibuf(&imsg, &ibuf) == -1 || ibuf_get_n8(&ibuf, &errcode) == -1 || ibuf_get_n8(&ibuf, &subcode) == -1) { log_warnx("RDE sent invalid notification"); break; } session_notification(p, errcode, subcode, &ibuf); switch (errcode) { case ERR_CEASE: switch (subcode) { case ERR_CEASE_MAX_PREFIX: case ERR_CEASE_MAX_SENT_PREFIX: t = p->conf.max_out_prefix_restart; if (subcode == ERR_CEASE_MAX_PREFIX) t = p->conf.max_prefix_restart; bgp_fsm(p, EVNT_STOP, NULL); if (t) timer_set(&p->timers, Timer_IdleHold, 60 * t); break; default: bgp_fsm(p, EVNT_CON_FATAL, NULL); break; } break; default: bgp_fsm(p, EVNT_CON_FATAL, NULL); break; } break; case IMSG_REFRESH: if (idx != PFD_PIPE_ROUTE) fatalx("route refresh request not from RDE"); if (imsg_get_data(&imsg, &rr, sizeof(rr)) == -1) { log_warnx("RDE sent invalid refresh msg"); break; } if ((p = getpeerbyid(conf, peerid)) == NULL) { log_warnx("no such peer: id=%u", peerid); break; } if (rr.aid < AID_MIN || rr.aid >= AID_MAX) fatalx("IMSG_REFRESH: bad AID"); session_rrefresh(p, rr.aid, rr.subtype); break; case IMSG_SESSION_RESTARTED: if (idx != PFD_PIPE_ROUTE) fatalx("session restart not from RDE"); if (imsg_get_data(&imsg, &aid, sizeof(aid)) == -1) { log_warnx("RDE sent invalid restart msg"); break; } if ((p = getpeerbyid(conf, peerid)) == NULL) { log_warnx("no such peer: id=%u", peerid); break; } if (aid < AID_MIN || aid >= AID_MAX) fatalx("IMSG_SESSION_RESTARTED: bad AID"); if (p->capa.neg.grestart.flags[aid] & CAPA_GR_RESTARTING) { log_peer_warnx(&p->conf, "graceful restart of %s finished", aid2str(aid)); p->capa.neg.grestart.flags[aid] &= ~CAPA_GR_RESTARTING; timer_stop(&p->timers, Timer_RestartTimeout); /* signal back to RDE to cleanup stale routes */ if (imsg_rde(IMSG_SESSION_RESTARTED, peerid, &aid, sizeof(aid)) == -1) fatal("imsg_compose: " "IMSG_SESSION_RESTARTED"); } break; default: break; } imsg_free(&imsg); } } int la_cmp(struct listen_addr *a, struct listen_addr *b) { struct sockaddr_in *in_a, *in_b; struct sockaddr_in6 *in6_a, *in6_b; if (a->sa.ss_family != b->sa.ss_family) return (1); switch (a->sa.ss_family) { case AF_INET: in_a = (struct sockaddr_in *)&a->sa; in_b = (struct sockaddr_in *)&b->sa; if (in_a->sin_addr.s_addr != in_b->sin_addr.s_addr) return (1); if (in_a->sin_port != in_b->sin_port) return (1); break; case AF_INET6: in6_a = (struct sockaddr_in6 *)&a->sa; in6_b = (struct sockaddr_in6 *)&b->sa; if (memcmp(&in6_a->sin6_addr, &in6_b->sin6_addr, sizeof(struct in6_addr))) return (1); if (in6_a->sin6_port != in6_b->sin6_port) return (1); break; default: fatal("king bula sez: unknown address family"); /* NOTREACHED */ } return (0); } struct peer * getpeerbydesc(struct bgpd_config *c, const char *descr) { struct peer *p, *res = NULL; int match = 0; RB_FOREACH(p, peer_head, &c->peers) if (!strcmp(p->conf.descr, descr)) { res = p; match++; } if (match > 1) log_info("neighbor description \"%s\" not unique, request " "aborted", descr); if (match == 1) return (res); else return (NULL); } struct peer * getpeerbyip(struct bgpd_config *c, struct sockaddr *ip) { struct bgpd_addr addr; struct peer *p, *newpeer, *loose = NULL; uint32_t id; sa2addr(ip, &addr, NULL); /* we might want a more effective way to find peers by IP */ RB_FOREACH(p, peer_head, &c->peers) if (!p->conf.template && !memcmp(&addr, &p->conf.remote_addr, sizeof(addr))) return (p); /* try template matching */ RB_FOREACH(p, peer_head, &c->peers) if (p->conf.template && p->conf.remote_addr.aid == addr.aid && session_match_mask(p, &addr)) if (loose == NULL || loose->conf.remote_masklen < p->conf.remote_masklen) loose = p; if (loose != NULL) { /* clone */ if ((newpeer = malloc(sizeof(struct peer))) == NULL) fatal(NULL); memcpy(newpeer, loose, sizeof(struct peer)); for (id = PEER_ID_DYN_MAX; id > PEER_ID_STATIC_MAX; id--) { if (getpeerbyid(c, id) == NULL) /* we found a free id */ break; } newpeer->template = loose; session_template_clone(newpeer, ip, id, 0); newpeer->state = newpeer->prev_state = STATE_NONE; newpeer->reconf_action = RECONF_KEEP; newpeer->rpending = 0; newpeer->wbuf = NULL; init_peer(newpeer); /* start delete timer, it is stopped when session goes up. */ timer_set(&newpeer->timers, Timer_SessionDown, INTERVAL_SESSION_DOWN); bgp_fsm(newpeer, EVNT_START, NULL); if (RB_INSERT(peer_head, &c->peers, newpeer) != NULL) fatalx("%s: peer tree is corrupt", __func__); return (newpeer); } return (NULL); } struct peer * getpeerbyid(struct bgpd_config *c, uint32_t peerid) { static struct peer lookup; lookup.conf.id = peerid; return RB_FIND(peer_head, &c->peers, &lookup); } int peer_matched(struct peer *p, struct ctl_neighbor *n) { char *s; if (n && n->addr.aid) { if (memcmp(&p->conf.remote_addr, &n->addr, sizeof(p->conf.remote_addr))) return 0; } else if (n && n->descr[0]) { s = n->is_group ? p->conf.group : p->conf.descr; /* cannot trust n->descr to be properly terminated */ if (strncmp(s, n->descr, sizeof(n->descr))) return 0; } return 1; } void session_template_clone(struct peer *p, struct sockaddr *ip, uint32_t id, uint32_t as) { struct bgpd_addr remote_addr; if (ip) sa2addr(ip, &remote_addr, NULL); else memcpy(&remote_addr, &p->conf.remote_addr, sizeof(remote_addr)); memcpy(&p->conf, &p->template->conf, sizeof(struct peer_config)); p->conf.id = id; if (as) { p->conf.remote_as = as; p->conf.ebgp = (p->conf.remote_as != p->conf.local_as); if (!p->conf.ebgp) /* force enforce_as off for iBGP sessions */ p->conf.enforce_as = ENFORCE_AS_OFF; } memcpy(&p->conf.remote_addr, &remote_addr, sizeof(remote_addr)); switch (p->conf.remote_addr.aid) { case AID_INET: p->conf.remote_masklen = 32; break; case AID_INET6: p->conf.remote_masklen = 128; break; } p->conf.template = 0; } int session_match_mask(struct peer *p, struct bgpd_addr *a) { struct bgpd_addr masked; applymask(&masked, a, p->conf.remote_masklen); if (memcmp(&masked, &p->conf.remote_addr, sizeof(masked)) == 0) return (1); return (0); } void session_down(struct peer *peer) { memset(&peer->capa.neg, 0, sizeof(peer->capa.neg)); peer->stats.last_updown = getmonotime(); timer_set(&peer->timers, Timer_SessionDown, INTERVAL_SESSION_DOWN); /* * session_down is called in the exit code path so check * if the RDE is still around, if not there is no need to * send the message. */ if (ibuf_rde == NULL) return; if (imsg_rde(IMSG_SESSION_DOWN, peer->conf.id, NULL, 0) == -1) fatalx("imsg_compose error"); } void session_up(struct peer *p) { struct session_up sup; /* clear last errors, now that the session is up */ p->stats.last_sent_errcode = 0; p->stats.last_sent_suberr = 0; p->stats.last_rcvd_errcode = 0; p->stats.last_rcvd_suberr = 0; memset(p->stats.last_reason, 0, sizeof(p->stats.last_reason)); timer_stop(&p->timers, Timer_SessionDown); if (!p->rdesession) { /* inform rde about new peer */ if (imsg_rde(IMSG_SESSION_ADD, p->conf.id, &p->conf, sizeof(p->conf)) == -1) fatalx("imsg_compose error"); p->rdesession = 1; } if (p->local.aid == AID_INET) { sup.local_v4_addr = p->local; sup.local_v6_addr = p->local_alt; } else { sup.local_v6_addr = p->local; sup.local_v4_addr = p->local_alt; } sup.remote_addr = p->remote; sup.if_scope = p->if_scope; sup.remote_bgpid = p->remote_bgpid; sup.short_as = p->short_as; memcpy(&sup.capa, &p->capa.neg, sizeof(sup.capa)); p->stats.last_updown = getmonotime(); if (imsg_rde(IMSG_SESSION_UP, p->conf.id, &sup, sizeof(sup)) == -1) fatalx("imsg_compose error"); } int imsg_ctl_parent(struct imsg *imsg) { return imsg_forward(ibuf_main, imsg); } int imsg_ctl_rde(struct imsg *imsg) { if (ibuf_rde_ctl == NULL) return (0); /* * Use control socket to talk to RDE to bypass the queue of the * regular imsg socket. */ return imsg_forward(ibuf_rde_ctl, imsg); } int imsg_ctl_rde_msg(int type, uint32_t peerid, pid_t pid) { if (ibuf_rde_ctl == NULL) return (0); /* * Use control socket to talk to RDE to bypass the queue of the * regular imsg socket. */ return imsg_compose(ibuf_rde_ctl, type, peerid, pid, -1, NULL, 0); } int imsg_rde(int type, uint32_t peerid, void *data, uint16_t datalen) { if (ibuf_rde == NULL) return (0); return imsg_compose(ibuf_rde, type, peerid, 0, -1, data, datalen); } void session_demote(struct peer *p, int level) { struct demote_msg msg; strlcpy(msg.demote_group, p->conf.demote_group, sizeof(msg.demote_group)); msg.level = level; if (imsg_compose(ibuf_main, IMSG_DEMOTE, p->conf.id, 0, -1, &msg, sizeof(msg)) == -1) fatalx("imsg_compose error"); p->demoted += level; } void session_stop(struct peer *peer, uint8_t subcode, const char *reason) { struct ibuf *ibuf; if (reason != NULL) strlcpy(peer->conf.reason, reason, sizeof(peer->conf.reason)); ibuf = ibuf_dynamic(0, REASON_LEN); if ((subcode == ERR_CEASE_ADMIN_DOWN || subcode == ERR_CEASE_ADMIN_RESET) && reason != NULL && *reason != '\0' && ibuf != NULL) { if (ibuf_add_n8(ibuf, strlen(reason)) == -1 || ibuf_add(ibuf, reason, strlen(reason))) { log_peer_warnx(&peer->conf, "trying to send overly long shutdown reason"); ibuf_free(ibuf); ibuf = NULL; } } switch (peer->state) { case STATE_OPENSENT: case STATE_OPENCONFIRM: case STATE_ESTABLISHED: session_notification(peer, ERR_CEASE, subcode, ibuf); break; default: /* session not open, no need to send notification */ if (subcode >= sizeof(suberr_cease_names) / sizeof(char *) || suberr_cease_names[subcode] == NULL) log_peer_warnx(&peer->conf, "session stop: %s, " "unknown subcode %u", errnames[ERR_CEASE], subcode); else log_peer_warnx(&peer->conf, "session stop: %s, %s", errnames[ERR_CEASE], suberr_cease_names[subcode]); break; } ibuf_free(ibuf); bgp_fsm(peer, EVNT_STOP, NULL); } struct bgpd_addr * session_localaddr(struct peer *p) { switch (p->conf.remote_addr.aid) { case AID_INET: return &p->conf.local_addr_v4; case AID_INET6: return &p->conf.local_addr_v6; } fatalx("Unknown AID in %s", __func__); } void merge_peers(struct bgpd_config *c, struct bgpd_config *nc) { struct peer *p, *np, *next; RB_FOREACH(p, peer_head, &c->peers) { /* templates are handled specially */ if (p->template != NULL) continue; np = getpeerbyid(nc, p->conf.id); if (np == NULL) { p->reconf_action = RECONF_DELETE; continue; } /* peer no longer uses TCP MD5SIG so deconfigure */ if (p->auth_conf.method == AUTH_MD5SIG && np->auth_conf.method != AUTH_MD5SIG) tcp_md5_del_listener(c, p); else if (np->auth_conf.method == AUTH_MD5SIG) tcp_md5_add_listener(c, np); memcpy(&p->conf, &np->conf, sizeof(p->conf)); memcpy(&p->auth_conf, &np->auth_conf, sizeof(p->auth_conf)); RB_REMOVE(peer_head, &nc->peers, np); free(np); p->reconf_action = RECONF_KEEP; /* had demotion, is demoted, demote removed? */ if (p->demoted && !p->conf.demote_group[0]) session_demote(p, -1); /* if session is not open then refresh pfkey data */ if (p->state < STATE_OPENSENT && !p->template) imsg_compose(ibuf_main, IMSG_PFKEY_RELOAD, p->conf.id, 0, -1, NULL, 0); /* * If the session is established or the SessionDown timer is * running sync with the RDE */ if (p->rdesession) { if (imsg_rde(IMSG_SESSION_ADD, p->conf.id, &p->conf, sizeof(struct peer_config)) == -1) fatalx("imsg_compose error"); } /* apply the config to all clones of a template */ if (p->conf.template) { struct peer *xp; RB_FOREACH(xp, peer_head, &c->peers) { if (xp->template != p) continue; session_template_clone(xp, NULL, xp->conf.id, xp->conf.remote_as); if (p->rdesession) { if (imsg_rde(IMSG_SESSION_ADD, xp->conf.id, &xp->conf, sizeof(xp->conf)) == -1) fatalx("imsg_compose error"); } } } } if (imsg_rde(IMSG_RECONF_DRAIN, 0, NULL, 0) == -1) fatalx("imsg_compose error"); /* pfkeys of new peers already loaded by the parent process */ RB_FOREACH_SAFE(np, peer_head, &nc->peers, next) { RB_REMOVE(peer_head, &nc->peers, np); if (RB_INSERT(peer_head, &c->peers, np) != NULL) fatalx("%s: peer tree is corrupt", __func__); if (np->auth_conf.method == AUTH_MD5SIG) tcp_md5_add_listener(c, np); } } openbgpd-8.8/src/bgpd/log.c100644 001750 001750 00000006734 13430764165 0011344/* $OpenBSD: log.c,v 1.64 2017/03/21 12:06:55 bluhm Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include "log.h" static int debug; static int verbose; static const char *log_procname; void log_init(int n_debug, int facility) { extern char *__progname; debug = n_debug; verbose = n_debug; log_procinit(__progname); if (!debug) openlog(__progname, LOG_PID | LOG_NDELAY, facility); tzset(); } void log_procinit(const char *procname) { if (procname != NULL) log_procname = procname; } void log_setverbose(int v) { verbose = v; } int log_getverbose(void) { return (verbose); } void logit(int pri, const char *fmt, ...) { va_list ap; va_start(ap, fmt); vlog(pri, fmt, ap); va_end(ap); } void vlog(int pri, const char *fmt, va_list ap) { char *nfmt; int saved_errno = errno; if (debug) { /* best effort in out of mem situations */ if (asprintf(&nfmt, "%s\n", fmt) == -1) { vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); } else { vfprintf(stderr, nfmt, ap); free(nfmt); } fflush(stderr); } else vsyslog(pri, fmt, ap); errno = saved_errno; } void log_warn(const char *emsg, ...) { char *nfmt; va_list ap; int saved_errno = errno; /* best effort to even work in out of memory situations */ if (emsg == NULL) logit(LOG_ERR, "%s", strerror(saved_errno)); else { va_start(ap, emsg); if (asprintf(&nfmt, "%s: %s", emsg, strerror(saved_errno)) == -1) { /* we tried it... */ vlog(LOG_ERR, emsg, ap); logit(LOG_ERR, "%s", strerror(saved_errno)); } else { vlog(LOG_ERR, nfmt, ap); free(nfmt); } va_end(ap); } errno = saved_errno; } void log_warnx(const char *emsg, ...) { va_list ap; va_start(ap, emsg); vlog(LOG_ERR, emsg, ap); va_end(ap); } void log_info(const char *emsg, ...) { va_list ap; va_start(ap, emsg); vlog(LOG_INFO, emsg, ap); va_end(ap); } void log_debug(const char *emsg, ...) { va_list ap; if (verbose) { va_start(ap, emsg); vlog(LOG_DEBUG, emsg, ap); va_end(ap); } } static void vfatalc(int code, const char *emsg, va_list ap) { static char s[BUFSIZ]; const char *sep; if (emsg != NULL) { (void)vsnprintf(s, sizeof(s), emsg, ap); sep = ": "; } else { s[0] = '\0'; sep = ""; } if (code) logit(LOG_CRIT, "fatal in %s: %s%s%s", log_procname, s, sep, strerror(code)); else logit(LOG_CRIT, "fatal in %s%s%s", log_procname, sep, s); } void fatal(const char *emsg, ...) { va_list ap; va_start(ap, emsg); vfatalc(errno, emsg, ap); va_end(ap); exit(1); } void fatalx(const char *emsg, ...) { va_list ap; va_start(ap, emsg); vfatalc(0, emsg, ap); va_end(ap); exit(1); } openbgpd-8.8/src/bgpd/logmsg.c100644 001750 001750 00000015117 14636734710 0012050/* $OpenBSD: logmsg.c,v 1.14 2024/05/20 10:00:00 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" char * log_fmt_peer(const struct peer_config *peer) { const char *ip; char *pfmt, *p; ip = log_addr(&peer->remote_addr); if ((peer->remote_addr.aid == AID_INET && peer->remote_masklen != 32) || (peer->remote_addr.aid == AID_INET6 && peer->remote_masklen != 128)) { if (asprintf(&p, "%s/%u", ip, peer->remote_masklen) == -1) fatal(NULL); } else { if ((p = strdup(ip)) == NULL) fatal(NULL); } if (peer->descr[0]) { if (asprintf(&pfmt, "neighbor %s (%s)", p, peer->descr) == -1) fatal(NULL); } else { if (asprintf(&pfmt, "neighbor %s", p) == -1) fatal(NULL); } free(p); return (pfmt); } void log_peer_info(const struct peer_config *peer, const char *emsg, ...) { char *p, *msg; va_list ap; p = log_fmt_peer(peer); va_start(ap, emsg); if (vasprintf(&msg, emsg, ap) == -1) fatal(NULL); va_end(ap); logit(LOG_INFO, "%s: %s", p, msg); free(msg); free(p); } void log_peer_warn(const struct peer_config *peer, const char *emsg, ...) { char *p, *msg; va_list ap; int saved_errno = errno; p = log_fmt_peer(peer); if (emsg == NULL) { logit(LOG_ERR, "%s: %s", p, strerror(saved_errno)); } else { va_start(ap, emsg); if (vasprintf(&msg, emsg, ap) == -1) fatal(NULL); va_end(ap); logit(LOG_ERR, "%s: %s: %s", p, msg, strerror(saved_errno)); free(msg); } free(p); } void log_peer_warnx(const struct peer_config *peer, const char *emsg, ...) { char *p, *msg; va_list ap; p = log_fmt_peer(peer); va_start(ap, emsg); if (vasprintf(&msg, emsg, ap) == -1) fatal(NULL); va_end(ap); logit(LOG_ERR, "%s: %s", p, msg); free(msg); free(p); } void log_statechange(struct peer *peer, enum session_state nstate, enum session_events event) { char *p; /* don't clutter the logs with constant Connect -> Active -> Connect */ if (nstate == STATE_CONNECT && peer->state == STATE_ACTIVE && peer->prev_state == STATE_CONNECT) return; if (nstate == STATE_ACTIVE && peer->state == STATE_CONNECT && peer->prev_state == STATE_ACTIVE) return; peer->lasterr = 0; p = log_fmt_peer(&peer->conf); logit(LOG_INFO, "%s: state change %s -> %s, reason: %s", p, statenames[peer->state], statenames[nstate], eventnames[event]); free(p); } void log_notification(const struct peer *peer, uint8_t errcode, uint8_t subcode, const struct ibuf *data, const char *dir) { struct ibuf ibuf; char *p; const char *suberrname = NULL; int uk = 0; if (data != NULL) ibuf_from_ibuf(&ibuf, data); else ibuf_from_buffer(&ibuf, NULL, 0); p = log_fmt_peer(&peer->conf); switch (errcode) { case ERR_HEADER: if (subcode >= sizeof(suberr_header_names) / sizeof(char *) || suberr_header_names[subcode] == NULL) uk = 1; else suberrname = suberr_header_names[subcode]; break; case ERR_OPEN: if (subcode >= sizeof(suberr_open_names) / sizeof(char *) || suberr_open_names[subcode] == NULL) uk = 1; else suberrname = suberr_open_names[subcode]; if (errcode == ERR_OPEN && subcode == ERR_OPEN_CAPA) { uint8_t capa_code; if (ibuf_get_n8(&ibuf, &capa_code) == -1) break; logit(LOG_ERR, "%s: %s notification: %s, %s: %s", p, dir, errnames[errcode], suberrname, log_capability(capa_code)); free(p); return; } break; case ERR_UPDATE: if (subcode >= sizeof(suberr_update_names) / sizeof(char *) || suberr_update_names[subcode] == NULL) uk = 1; else suberrname = suberr_update_names[subcode]; break; case ERR_CEASE: if (subcode >= sizeof(suberr_cease_names) / sizeof(char *) || suberr_cease_names[subcode] == NULL) uk = 1; else suberrname = suberr_cease_names[subcode]; if (subcode == ERR_CEASE_ADMIN_DOWN || subcode == ERR_CEASE_ADMIN_RESET) { uint8_t len; /* check if shutdown reason is included */ if (ibuf_get_n8(&ibuf, &len) != -1 && len != 0) { char *s; if ((s = ibuf_get_string(&ibuf, len)) != NULL) { logit(LOG_ERR, "%s: %s notification: " "%s, %s: reason \"%s\"", p, dir, errnames[errcode], suberrname, log_reason(s)); free(s); free(p); return; } } } break; case ERR_HOLDTIMEREXPIRED: if (subcode != 0) uk = 1; break; case ERR_FSM: if (subcode >= sizeof(suberr_fsm_names) / sizeof(char *) || suberr_fsm_names[subcode] == NULL) uk = 1; else suberrname = suberr_fsm_names[subcode]; break; case ERR_RREFRESH: if (subcode >= sizeof(suberr_rrefresh_names) / sizeof(char *) || suberr_rrefresh_names[subcode] == NULL) uk = 1; else suberrname = suberr_rrefresh_names[subcode]; break; default: logit(LOG_ERR, "%s: %s notification, unknown errcode " "%u, subcode %u", p, dir, errcode, subcode); free(p); return; } if (uk) logit(LOG_ERR, "%s: %s notification: %s, unknown subcode %u", p, dir, errnames[errcode], subcode); else { if (suberrname == NULL) logit(LOG_ERR, "%s: %s notification: %s", p, dir, errnames[errcode]); else logit(LOG_ERR, "%s: %s notification: %s, %s", p, dir, errnames[errcode], suberrname); } free(p); } void log_conn_attempt(const struct peer *peer, struct sockaddr *sa, socklen_t len) { char *p; if (peer == NULL) { /* connection from non-peer, drop */ if (log_getverbose()) logit(LOG_INFO, "connection from non-peer %s refused", log_sockaddr(sa, len)); } else { /* only log if there is a chance that the session may come up */ if (peer->conf.down && peer->state == STATE_IDLE) return; p = log_fmt_peer(&peer->conf); logit(LOG_INFO, "Connection attempt from %s while session is " "in state %s", p, statenames[peer->state]); free(p); } } openbgpd-8.8/src/bgpd/parse.y100644 001750 001750 00000416641 14751151130 0011712/* $OpenBSD: parse.y,v 1.479 2025/02/04 18:16:56 denis Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer * Copyright (c) 2001 Markus Friedl. All rights reserved. * Copyright (c) 2001 Daniel Hartmeier. All rights reserved. * Copyright (c) 2001 Theo de Raadt. All rights reserved. * Copyright (c) 2016, 2017 Job Snijders * Copyright (c) 2016 Peter Hessler * Copyright (c) 2017, 2018 Sebastian Benoit * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ %{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "log.h" #ifndef nitems #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) #endif #define MACRO_NAME_LEN 128 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files); static struct file { TAILQ_ENTRY(file) entry; FILE *stream; char *name; size_t ungetpos; size_t ungetsize; u_char *ungetbuf; int eof_reached; int lineno; int errors; } *file, *topfile; struct file *pushfile(const char *, int); int popfile(void); int check_file_secrecy(int, const char *); int yyparse(void); int yylex(void); int yyerror(const char *, ...) __attribute__((__format__ (printf, 1, 2))) __attribute__((__nonnull__ (1))); int kw_cmp(const void *, const void *); int lookup(char *); int igetc(void); int lgetc(int); void lungetc(int); int findeol(void); int expand_macro(void); TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead); struct sym { TAILQ_ENTRY(sym) entry; int used; int persist; char *nam; char *val; }; int symset(const char *, const char *, int); char *symget(const char *); struct filter_rib_l { struct filter_rib_l *next; char name[PEER_DESCR_LEN]; }; struct filter_peers_l { struct filter_peers_l *next; struct filter_peers p; }; struct filter_prefix_l { struct filter_prefix_l *next; struct filter_prefix p; }; struct filter_prefixlen { enum comp_ops op; int len_min; int len_max; }; struct filter_as_l { struct filter_as_l *next; struct filter_as a; }; struct filter_match_l { struct filter_match m; struct filter_prefix_l *prefix_l; struct filter_as_l *as_l; struct filter_prefixset *prefixset; } fmopts; struct aspa_tas_l { struct aspa_tas_l *next; uint32_t as; uint32_t num; }; struct flowspec_context { uint8_t *components[FLOWSPEC_TYPE_MAX]; uint16_t complen[FLOWSPEC_TYPE_MAX]; uint8_t aid; uint8_t type; uint8_t addr_type; }; struct peer *alloc_peer(void); struct peer *new_peer(void); struct peer *new_group(void); int add_mrtconfig(enum mrt_type, char *, int, struct peer *, char *); struct rde_rib *add_rib(char *); struct rde_rib *find_rib(char *); int rib_add_fib(struct rde_rib *, u_int); int get_id(struct peer *); int merge_prefixspec(struct filter_prefix *, struct filter_prefixlen *); int expand_rule(struct filter_rule *, struct filter_rib_l *, struct filter_peers_l *, struct filter_match_l *, struct filter_set_head *); int str2key(char *, char *, size_t); int neighbor_consistent(struct peer *); int merge_filterset(struct filter_set_head *, struct filter_set *); void optimize_filters(struct filter_head *); struct filter_rule *get_rule(enum action_types); int parsecommunity(struct community *, int, char *); int parseextcommunity(struct community *, char *, char *); static int new_as_set(char *); static void add_as_set(uint32_t); static void done_as_set(void); static struct prefixset *new_prefix_set(char *, int); static void add_roa_set(struct prefixset_item *, uint32_t, uint8_t, time_t); static struct rtr_config *get_rtr(struct bgpd_addr *); static int insert_rtr(struct rtr_config *); static int merge_aspa_set(uint32_t, struct aspa_tas_l *, time_t); static int map_tos(char *, int *); static int getservice(char *); static int parse_flags(char *); static struct flowspec_config *flow_to_flowspec(struct flowspec_context *); static void flow_free(struct flowspec_context *); static int push_prefix(struct bgpd_addr *, uint8_t); static int push_binop(uint8_t, long long); static int push_unary_numop(enum comp_ops, long long); static int push_binary_numop(enum comp_ops, long long, long long); static int geticmptypebyname(char *, uint8_t); static int geticmpcodebyname(u_long, char *, uint8_t); static int merge_auth_conf(struct auth_config *, struct auth_config *); static struct bgpd_config *conf; static struct network_head *netconf; static struct peer_head *new_peers, *cur_peers; static struct rtr_config_head *cur_rtrs; static struct peer *curpeer; static struct peer *curgroup; static struct rde_rib *currib; static struct l3vpn *curvpn; static struct prefixset *curpset, *curoset; static struct roa_tree *curroatree; static struct rtr_config *currtr; static struct filter_head *filter_l; static struct filter_head *peerfilter_l; static struct filter_head *groupfilter_l; static struct filter_rule *curpeer_filter[2]; static struct filter_rule *curgroup_filter[2]; static struct flowspec_context *curflow; static int noexpires; typedef struct { union { long long number; char *string; struct bgpd_addr addr; uint8_t u8; struct filter_rib_l *filter_rib; struct filter_peers_l *filter_peers; struct filter_match_l filter_match; struct filter_prefixset *filter_prefixset; struct filter_prefix_l *filter_prefix; struct filter_as_l *filter_as; struct filter_set *filter_set; struct filter_set_head *filter_set_head; struct aspa_tas_l *aspa_elm; struct { struct bgpd_addr prefix; uint8_t len; } prefix; struct filter_prefixlen prefixlen; struct prefixset_item *prefixset_item; struct auth_config authconf; struct { enum auth_enc_alg enc_alg; uint8_t enc_key_len; char enc_key[IPSEC_ENC_KEY_LEN]; } encspec; } v; int lineno; } YYSTYPE; %} %token AS ROUTERID HOLDTIME YMIN LISTEN ON FIBUPDATE FIBPRIORITY RTABLE %token NONE UNICAST VPN RD EXPORT EXPORTTRGT IMPORTTRGT DEFAULTROUTE %token RDE RIB EVALUATE IGNORE COMPARE RTR PORT MINVERSION STALETIME %token GROUP NEIGHBOR NETWORK %token EBGP IBGP %token FLOWSPEC PROTO FLAGS FRAGMENT TOS LENGTH ICMPTYPE CODE %token LOCALAS REMOTEAS DESCR LOCALADDR MULTIHOP PASSIVE MAXPREFIX RESTART %token ANNOUNCE REFRESH AS4BYTE CONNECTRETRY ENHANCED ADDPATH EXTENDED %token SEND RECV PLUS POLICY ROLE GRACEFUL NOTIFICATION MESSAGE %token DEMOTE ENFORCE NEIGHBORAS ASOVERRIDE REFLECTOR DEPEND DOWN %token DUMP IN OUT SOCKET RESTRICTED %token LOG TRANSPARENT FILTERED %token TCP MD5SIG PASSWORD KEY TTLSECURITY %token ALLOW DENY MATCH %token QUICK %token FROM TO ANY %token CONNECTED STATIC %token COMMUNITY EXTCOMMUNITY LARGECOMMUNITY DELETE %token MAXCOMMUNITIES MAXEXTCOMMUNITIES MAXLARGECOMMUNITIES %token PREFIX PREFIXLEN PREFIXSET %token ASPASET ROASET ORIGINSET OVS AVS EXPIRES %token ASSET SOURCEAS TRANSITAS PEERAS PROVIDERAS CUSTOMERAS MAXASLEN MAXASSEQ %token SET LOCALPREF MED METRIC NEXTHOP REJECT BLACKHOLE NOMODIFY SELF %token PREPEND_SELF PREPEND_PEER PFTABLE WEIGHT RTLABEL ORIGIN PRIORITY %token ERROR INCLUDE %token IPSEC ESP AH SPI IKE %token IPV4 IPV6 EVPN %token QUALIFY VIA %token NE LE GE XRANGE LONGER MAXLEN MAX %token STRING %token NUMBER %type asnumber as4number as4number_any optnumber %type espah af safi restart origincode nettype %type yesno inout restricted expires %type yesnoenforce enforce %type validity aspa_validity %type addpathextra addpathmax %type port proto_item tos length flag icmptype %type string %type address %type prefix addrspec %type prefixset_item %type action quick direction delete community %type filter_rib_h filter_rib_l filter_rib %type filter_peer filter_peer_l filter_peer_h %type filter_match filter_elm filter_match_h %type filter_as filter_as_l filter_as_h %type filter_as_t filter_as_t_l filter_as_l_h %type prefixlenop %type filter_set_opt %type filter_set filter_set_l %type filter_prefix filter_prefix_l filter_prefix_h %type filter_prefix_m %type unaryop equalityop binaryop filter_as_type %type authconf %type encspec %type aspa_tas aspa_tas_l %% grammar : /* empty */ | grammar '\n' | grammar varset '\n' | grammar include '\n' | grammar as_set '\n' | grammar prefixset '\n' | grammar roa_set '\n' | grammar aspa_set '\n' | grammar origin_set '\n' | grammar rtr '\n' | grammar rib '\n' | grammar network '\n' | grammar flowspec '\n' | grammar mrtdump '\n' | grammar conf_main '\n' | grammar l3vpn '\n' | grammar neighbor '\n' | grammar group '\n' | grammar filterrule '\n' | grammar error '\n' { file->errors++; } ; asnumber : NUMBER { /* * According to iana 65535 and 4294967295 are reserved * but enforcing this is not duty of the parser. */ if ($1 < 0 || $1 > UINT_MAX) { yyerror("AS too big: max %u", UINT_MAX); YYERROR; } } as4number : STRING { const char *errstr; char *dot; uint32_t uvalh = 0, uval; if ((dot = strchr($1,'.')) != NULL) { *dot++ = '\0'; uvalh = strtonum($1, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", $1, errstr); free($1); YYERROR; } uval = strtonum(dot, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", dot, errstr); free($1); YYERROR; } free($1); } else { yyerror("AS %s is bad", $1); free($1); YYERROR; } if (uvalh == 0 && (uval == AS_TRANS || uval == 0)) { yyerror("AS %u is reserved and may not be used", uval); YYERROR; } $$ = uval | (uvalh << 16); } | asnumber { if ($1 == AS_TRANS || $1 == 0) { yyerror("AS %u is reserved and may not be used", (uint32_t)$1); YYERROR; } $$ = $1; } ; as4number_any : STRING { const char *errstr; char *dot; uint32_t uvalh = 0, uval; if ((dot = strchr($1,'.')) != NULL) { *dot++ = '\0'; uvalh = strtonum($1, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", $1, errstr); free($1); YYERROR; } uval = strtonum(dot, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("number %s is %s", dot, errstr); free($1); YYERROR; } free($1); } else { yyerror("AS %s is bad", $1); free($1); YYERROR; } $$ = uval | (uvalh << 16); } | asnumber { $$ = $1; } ; string : string STRING { if (asprintf(&$$, "%s %s", $1, $2) == -1) fatal("string: asprintf"); free($1); free($2); } | STRING ; yesno : STRING { if (!strcmp($1, "yes")) $$ = 1; else if (!strcmp($1, "no")) $$ = 0; else { yyerror("syntax error, " "either yes or no expected"); free($1); YYERROR; } free($1); } ; varset : STRING '=' string { char *s = $1; if (strlen($1) >= MACRO_NAME_LEN) { yyerror("macro name to long, max %d characters", MACRO_NAME_LEN - 1); free($1); free($3); YYERROR; } do { if (isalnum((unsigned char)*s) || *s == '_') continue; yyerror("macro name can only contain " "alphanumerics and '_'"); free($1); free($3); YYERROR; } while (*++s); if (cmd_opts & BGPD_OPT_VERBOSE) printf("%s = \"%s\"\n", $1, $3); if (symset($1, $3, 0) == -1) fatal("cannot store variable"); free($1); free($3); } ; include : INCLUDE STRING { struct file *nfile; if ((nfile = pushfile($2, 1)) == NULL) { yyerror("failed to include file %s", $2); free($2); YYERROR; } free($2); file = nfile; lungetc('\n'); } ; as_set : ASSET STRING '{' optnl { if (strlen($2) >= SET_NAME_LEN) { yyerror("as-set name %s too long", $2); free($2); YYERROR; } if (new_as_set($2) != 0) { free($2); YYERROR; } free($2); } as_set_l optnl '}' { done_as_set(); } | ASSET STRING '{' optnl '}' { if (new_as_set($2) != 0) { free($2); YYERROR; } free($2); } as_set_l : as4number_any { add_as_set($1); } | as_set_l comma as4number_any { add_as_set($3); } prefixset : PREFIXSET STRING '{' optnl { if ((curpset = new_prefix_set($2, 0)) == NULL) { free($2); YYERROR; } free($2); } prefixset_l optnl '}' { SIMPLEQ_INSERT_TAIL(&conf->prefixsets, curpset, entry); curpset = NULL; } | PREFIXSET STRING '{' optnl '}' { if ((curpset = new_prefix_set($2, 0)) == NULL) { free($2); YYERROR; } free($2); SIMPLEQ_INSERT_TAIL(&conf->prefixsets, curpset, entry); curpset = NULL; } prefixset_l : prefixset_item { struct prefixset_item *psi; if ($1->p.op != OP_NONE) curpset->sflags |= PREFIXSET_FLAG_OPS; psi = RB_INSERT(prefixset_tree, &curpset->psitems, $1); if (psi != NULL) { if (cmd_opts & BGPD_OPT_VERBOSE2) log_warnx("warning: duplicate entry in " "prefixset \"%s\" for %s/%u", curpset->name, log_addr(&$1->p.addr), $1->p.len); free($1); } } | prefixset_l comma prefixset_item { struct prefixset_item *psi; if ($3->p.op != OP_NONE) curpset->sflags |= PREFIXSET_FLAG_OPS; psi = RB_INSERT(prefixset_tree, &curpset->psitems, $3); if (psi != NULL) { if (cmd_opts & BGPD_OPT_VERBOSE2) log_warnx("warning: duplicate entry in " "prefixset \"%s\" for %s/%u", curpset->name, log_addr(&$3->p.addr), $3->p.len); free($3); } } ; prefixset_item : prefix prefixlenop { if ($2.op != OP_NONE && $2.op != OP_RANGE) { yyerror("unsupported prefixlen operation in " "prefix-set"); YYERROR; } if (($$ = calloc(1, sizeof(*$$))) == NULL) fatal(NULL); memcpy(&$$->p.addr, &$1.prefix, sizeof($$->p.addr)); $$->p.len = $1.len; if (merge_prefixspec(&$$->p, &$2) == -1) { free($$); YYERROR; } } ; roa_set : ROASET '{' optnl { curroatree = &conf->roa; } roa_set_l optnl '}' { curroatree = NULL; } | ROASET '{' optnl '}' /* nothing */ ; origin_set : ORIGINSET STRING '{' optnl { if ((curoset = new_prefix_set($2, 1)) == NULL) { free($2); YYERROR; } curroatree = &curoset->roaitems; noexpires = 1; free($2); } roa_set_l optnl '}' { SIMPLEQ_INSERT_TAIL(&conf->originsets, curoset, entry); curoset = NULL; curroatree = NULL; noexpires = 0; } | ORIGINSET STRING '{' optnl '}' { if ((curoset = new_prefix_set($2, 1)) == NULL) { free($2); YYERROR; } free($2); SIMPLEQ_INSERT_TAIL(&conf->originsets, curoset, entry); curoset = NULL; curroatree = NULL; } ; expires : /* empty */ { $$ = 0; } | EXPIRES NUMBER { if (noexpires) { yyerror("syntax error, expires not allowed"); YYERROR; } $$ = $2; } roa_set_l : prefixset_item SOURCEAS as4number_any expires { if ($1->p.len_min != $1->p.len) { yyerror("unsupported prefixlen operation in " "roa-set"); free($1); YYERROR; } add_roa_set($1, $3, $1->p.len_max, $4); free($1); } | roa_set_l comma prefixset_item SOURCEAS as4number_any expires { if ($3->p.len_min != $3->p.len) { yyerror("unsupported prefixlen operation in " "roa-set"); free($3); YYERROR; } add_roa_set($3, $5, $3->p.len_max, $6); free($3); } ; aspa_set : ASPASET '{' optnl aspa_set_l optnl '}' | ASPASET '{' optnl '}' ; aspa_set_l : aspa_elm | aspa_set_l comma aspa_elm ; aspa_elm : CUSTOMERAS as4number expires PROVIDERAS '{' optnl aspa_tas_l optnl '}' { int rv; struct aspa_tas_l *a, *n; rv = merge_aspa_set($2, $7, $3); for (a = $7; a != NULL; a = n) { n = a->next; free(a); } if (rv == -1) YYERROR; } ; aspa_tas_l : aspa_tas { $$ = $1; } | aspa_tas_l comma aspa_tas { $3->next = $1; $3->num = $1->num + 1; $$ = $3; } ; aspa_tas : as4number_any { if (($$ = calloc(1, sizeof(*$$))) == NULL) fatal(NULL); $$->as = $1; $$->num = 1; } | as4number_any af { if (($$ = calloc(1, sizeof(*$$))) == NULL) fatal(NULL); $$->as = $1; $$->num = 1; } ; rtr : RTR address { currtr = get_rtr(&$2); currtr->remote_port = RTR_PORT; if (insert_rtr(currtr) == -1) { free(currtr); YYERROR; } currtr = NULL; } | RTR address { currtr = get_rtr(&$2); currtr->remote_port = RTR_PORT; } '{' optnl rtropt_l optnl '}' { if (insert_rtr(currtr) == -1) { free(currtr); YYERROR; } currtr = NULL; } ; rtropt_l : rtropt | rtropt_l optnl rtropt ; rtropt : DESCR STRING { if (strlcpy(currtr->descr, $2, sizeof(currtr->descr)) >= sizeof(currtr->descr)) { yyerror("descr \"%s\" too long: max %zu", $2, sizeof(currtr->descr) - 1); free($2); YYERROR; } free($2); } | LOCALADDR address { if ($2.aid != currtr->remote_addr.aid) { yyerror("Bad address family %s for " "local-addr", aid2str($2.aid)); YYERROR; } currtr->local_addr = $2; } | PORT port { currtr->remote_port = $2; } | MINVERSION NUMBER { if ($2 < 0 || $2 > RTR_MAX_VERSION) { yyerror("min-version must be between %u and %u", 0, RTR_MAX_VERSION); YYERROR; } currtr->min_version = $2; } | authconf { if (merge_auth_conf(&currtr->auth, &$1) == 0) YYERROR; } ; conf_main : AS as4number { conf->as = $2; if ($2 > USHRT_MAX) conf->short_as = AS_TRANS; else conf->short_as = $2; } | AS as4number asnumber { conf->as = $2; conf->short_as = $3; } | ROUTERID address { if ($2.aid != AID_INET) { yyerror("router-id must be an IPv4 address"); YYERROR; } conf->bgpid = ntohl($2.v4.s_addr); } | HOLDTIME NUMBER { if ($2 < MIN_HOLDTIME || $2 > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } conf->holdtime = $2; } | HOLDTIME YMIN NUMBER { if ($3 < MIN_HOLDTIME || $3 > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } conf->min_holdtime = $3; } | STALETIME NUMBER { if ($2 < MIN_HOLDTIME || $2 > USHRT_MAX) { yyerror("staletime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } conf->staletime = $2; } | LISTEN ON address { struct listen_addr *la; struct sockaddr *sa; if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("parse conf_main listen on calloc"); la->fd = -1; la->reconf = RECONF_REINIT; sa = addr2sa(&$3, BGP_PORT, &la->sa_len); memcpy(&la->sa, sa, la->sa_len); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); } | LISTEN ON address PORT port { struct listen_addr *la; struct sockaddr *sa; if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("parse conf_main listen on calloc"); la->fd = -1; la->reconf = RECONF_REINIT; sa = addr2sa(&$3, $5, &la->sa_len); memcpy(&la->sa, sa, la->sa_len); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); } | FIBPRIORITY NUMBER { if (!kr_check_prio($2)) { yyerror("fib-priority %lld out of range", $2); YYERROR; } conf->fib_priority = $2; } | FIBUPDATE yesno { struct rde_rib *rr; rr = find_rib("Loc-RIB"); if (rr == NULL) fatalx("RTABLE cannot find the main RIB!"); if ($2 == 0) rr->flags |= F_RIB_NOFIBSYNC; else rr->flags &= ~F_RIB_NOFIBSYNC; } | TRANSPARENT yesno { if ($2 == 1) conf->flags |= BGPD_FLAG_DECISION_TRANS_AS; else conf->flags &= ~BGPD_FLAG_DECISION_TRANS_AS; } | REJECT ASSET yesno { if ($3 == 1) conf->flags &= ~BGPD_FLAG_PERMIT_AS_SET; else conf->flags |= BGPD_FLAG_PERMIT_AS_SET; } | LOG STRING { if (!strcmp($2, "updates")) conf->log |= BGPD_LOG_UPDATES; else { free($2); YYERROR; } free($2); } | DUMP STRING STRING optnumber { int action; if ($4 < 0 || $4 > INT_MAX) { yyerror("bad timeout"); free($2); free($3); YYERROR; } if (!strcmp($2, "table")) action = MRT_TABLE_DUMP; else if (!strcmp($2, "table-mp")) action = MRT_TABLE_DUMP_MP; else if (!strcmp($2, "table-v2")) action = MRT_TABLE_DUMP_V2; else { yyerror("unknown mrt dump type"); free($2); free($3); YYERROR; } free($2); if (add_mrtconfig(action, $3, $4, NULL, NULL) == -1) { free($3); YYERROR; } free($3); } | DUMP RIB STRING STRING STRING optnumber { int action; if ($6 < 0 || $6 > INT_MAX) { yyerror("bad timeout"); free($3); free($4); free($5); YYERROR; } if (!strcmp($4, "table")) action = MRT_TABLE_DUMP; else if (!strcmp($4, "table-mp")) action = MRT_TABLE_DUMP_MP; else if (!strcmp($4, "table-v2")) action = MRT_TABLE_DUMP_V2; else { yyerror("unknown mrt dump type"); free($3); free($4); free($5); YYERROR; } free($4); if (add_mrtconfig(action, $5, $6, NULL, $3) == -1) { free($3); free($5); YYERROR; } free($3); free($5); } | RDE STRING EVALUATE { if (!strcmp($2, "route-age")) conf->flags |= BGPD_FLAG_DECISION_ROUTEAGE; else { yyerror("unknown route decision type"); free($2); YYERROR; } free($2); } | RDE STRING IGNORE { if (!strcmp($2, "route-age")) conf->flags &= ~BGPD_FLAG_DECISION_ROUTEAGE; else { yyerror("unknown route decision type"); free($2); YYERROR; } free($2); } | RDE MED COMPARE STRING { if (!strcmp($4, "always")) conf->flags |= BGPD_FLAG_DECISION_MED_ALWAYS; else if (!strcmp($4, "strict")) conf->flags &= ~BGPD_FLAG_DECISION_MED_ALWAYS; else { yyerror("rde med compare: " "unknown setting \"%s\"", $4); free($4); YYERROR; } free($4); } | RDE EVALUATE STRING { if (!strcmp($3, "all")) conf->flags |= BGPD_FLAG_DECISION_ALL_PATHS; else if (!strcmp($3, "default")) conf->flags &= ~BGPD_FLAG_DECISION_ALL_PATHS; else { yyerror("rde evaluate: " "unknown setting \"%s\"", $3); free($3); YYERROR; } free($3); } | RDE RIB STRING INCLUDE FILTERED { if (strcmp($3, "Loc-RIB") != 0) { yyerror("include filtered only supported in " "Loc-RIB"); YYERROR; } conf->filtered_in_locrib = 1; } | NEXTHOP QUALIFY VIA STRING { if (!strcmp($4, "bgp")) conf->flags |= BGPD_FLAG_NEXTHOP_BGP; else if (!strcmp($4, "default")) conf->flags |= BGPD_FLAG_NEXTHOP_DEFAULT; else { yyerror("nexthop depend on: " "unknown setting \"%s\"", $4); free($4); YYERROR; } free($4); } | RTABLE NUMBER { struct rde_rib *rr; if ($2 > RT_TABLEID_MAX) { yyerror("rtable %llu too big: max %u", $2, RT_TABLEID_MAX); YYERROR; } if (!ktable_exists($2, NULL)) { yyerror("rtable id %lld does not exist", $2); YYERROR; } rr = find_rib("Loc-RIB"); if (rr == NULL) fatalx("RTABLE cannot find the main RIB!"); rr->rtableid = $2; } | CONNECTRETRY NUMBER { if ($2 > USHRT_MAX || $2 < 1) { yyerror("invalid connect-retry"); YYERROR; } conf->connectretry = $2; } | SOCKET STRING restricted { if (strlen($2) >= sizeof(((struct sockaddr_un *)0)->sun_path)) { yyerror("socket path too long"); YYERROR; } if ($3) { free(conf->rcsock); conf->rcsock = $2; } else { free(conf->csock); conf->csock = $2; } } ; rib : RDE RIB STRING { if ((currib = add_rib($3)) == NULL) { free($3); YYERROR; } free($3); } ribopts { currib = NULL; } ribopts : fibupdate | RTABLE NUMBER fibupdate { if ($2 > RT_TABLEID_MAX) { yyerror("rtable %llu too big: max %u", $2, RT_TABLEID_MAX); YYERROR; } if (rib_add_fib(currib, $2) == -1) YYERROR; } | yesno EVALUATE { if ($1) { yyerror("bad rde rib definition"); YYERROR; } currib->flags |= F_RIB_NOEVALUATE; } ; fibupdate : /* empty */ | FIBUPDATE yesno { if ($2 == 0) currib->flags |= F_RIB_NOFIBSYNC; else currib->flags &= ~F_RIB_NOFIBSYNC; } ; mrtdump : DUMP STRING inout STRING optnumber { int action; if ($5 < 0 || $5 > INT_MAX) { yyerror("bad timeout"); free($2); free($4); YYERROR; } if (!strcmp($2, "all")) action = $3 ? MRT_ALL_IN : MRT_ALL_OUT; else if (!strcmp($2, "updates")) action = $3 ? MRT_UPDATE_IN : MRT_UPDATE_OUT; else { yyerror("unknown mrt msg dump type"); free($2); free($4); YYERROR; } if (add_mrtconfig(action, $4, $5, curpeer, NULL) == -1) { free($2); free($4); YYERROR; } free($2); free($4); } ; network : NETWORK prefix filter_set { struct network *n, *m; if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); memcpy(&n->net.prefix, &$2.prefix, sizeof(n->net.prefix)); n->net.prefixlen = $2.len; filterset_move($3, &n->net.attrset); free($3); TAILQ_FOREACH(m, netconf, entry) { if (n->net.type == m->net.type && n->net.prefixlen == m->net.prefixlen && prefix_compare(&n->net.prefix, &m->net.prefix, n->net.prefixlen) == 0) yyerror("duplicate prefix " "in network statement"); } TAILQ_INSERT_TAIL(netconf, n, entry); } | NETWORK PREFIXSET STRING filter_set { struct prefixset *ps; struct network *n; if ((ps = find_prefixset($3, &conf->prefixsets)) == NULL) { yyerror("prefix-set '%s' not defined", $3); free($3); filterset_free($4); free($4); YYERROR; } if (ps->sflags & PREFIXSET_FLAG_OPS) { yyerror("prefix-set %s has prefixlen operators " "and cannot be used in network statements.", ps->name); free($3); filterset_free($4); free($4); YYERROR; } if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); strlcpy(n->net.psname, ps->name, sizeof(n->net.psname)); filterset_move($4, &n->net.attrset); n->net.type = NETWORK_PREFIXSET; TAILQ_INSERT_TAIL(netconf, n, entry); free($3); free($4); } | NETWORK af RTLABEL STRING filter_set { struct network *n; if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); if (afi2aid($2, SAFI_UNICAST, &n->net.prefix.aid) == -1) { yyerror("unknown address family"); filterset_free($5); free($5); YYERROR; } n->net.type = NETWORK_RTLABEL; n->net.rtlabel = rtlabel_name2id($4); filterset_move($5, &n->net.attrset); free($5); TAILQ_INSERT_TAIL(netconf, n, entry); } | NETWORK af PRIORITY NUMBER filter_set { struct network *n; if (!kr_check_prio($4)) { yyerror("priority %lld out of range", $4); YYERROR; } if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); if (afi2aid($2, SAFI_UNICAST, &n->net.prefix.aid) == -1) { yyerror("unknown address family"); filterset_free($5); free($5); YYERROR; } n->net.type = NETWORK_PRIORITY; n->net.priority = $4; filterset_move($5, &n->net.attrset); free($5); TAILQ_INSERT_TAIL(netconf, n, entry); } | NETWORK af nettype filter_set { struct network *n; if ((n = calloc(1, sizeof(struct network))) == NULL) fatal("new_network"); if (afi2aid($2, SAFI_UNICAST, &n->net.prefix.aid) == -1) { yyerror("unknown address family"); filterset_free($4); free($4); YYERROR; } n->net.type = $3 ? NETWORK_STATIC : NETWORK_CONNECTED; filterset_move($4, &n->net.attrset); free($4); TAILQ_INSERT_TAIL(netconf, n, entry); } ; flowspec : FLOWSPEC af { if ((curflow = calloc(1, sizeof(*curflow))) == NULL) fatal("new_flowspec"); curflow->aid = $2; } flow_rules filter_set { struct flowspec_config *f; f = flow_to_flowspec(curflow); if (f == NULL) { yyerror("out of memory"); free($5); flow_free(curflow); curflow = NULL; YYERROR; } filterset_move($5, &f->attrset); free($5); flow_free(curflow); curflow = NULL; if (RB_INSERT(flowspec_tree, &conf->flowspecs, f) != NULL) { yyerror("duplicate flowspec definition"); flowspec_free(f); YYERROR; } } ; proto : PROTO proto_item | PROTO '{' optnl proto_list optnl '}' ; proto_list : proto_item { curflow->type = FLOWSPEC_TYPE_PROTO; if (push_unary_numop(OP_EQ, $1) == -1) YYERROR; } | proto_list comma proto_item { curflow->type = FLOWSPEC_TYPE_PROTO; if (push_unary_numop(OP_EQ, $3) == -1) YYERROR; } ; proto_item : STRING { struct protoent *p; p = getprotobyname($1); if (p == NULL) { yyerror("unknown protocol %s", $1); free($1); YYERROR; } $$ = p->p_proto; free($1); } | NUMBER { if ($1 < 0 || $1 > 255) { yyerror("protocol outside range"); YYERROR; } $$ = $1; } ; from : FROM { curflow->type = FLOWSPEC_TYPE_SRC_PORT; curflow->addr_type = FLOWSPEC_TYPE_SOURCE; } ipportspec ; to : TO { curflow->type = FLOWSPEC_TYPE_DST_PORT; curflow->addr_type = FLOWSPEC_TYPE_DEST; } ipportspec ; ipportspec : ipspec | ipspec PORT portspec | PORT portspec ; ipspec : ANY | prefix { if (push_prefix(&$1.prefix, $1.len) == -1) YYERROR; } ; portspec : port_item | '{' optnl port_list optnl '}' ; port_list : port_item | port_list comma port_item ; port_item : port { if (push_unary_numop(OP_EQ, $1) == -1) YYERROR; } | unaryop port { if (push_unary_numop($1, $2) == -1) YYERROR; } | port binaryop port { if (push_binary_numop($2, $1, $3)) YYERROR; } ; port : NUMBER { if ($1 < 1 || $1 > USHRT_MAX) { yyerror("port must be between %u and %u", 1, USHRT_MAX); YYERROR; } $$ = $1; } | STRING { if (($$ = getservice($1)) == -1) { yyerror("unknown port '%s'", $1); free($1); YYERROR; } free($1); } ; flow_rules : /* empty */ | flow_rules_l ; flow_rules_l : flowrule | flow_rules_l flowrule ; flowrule : from | to | FLAGS { curflow->type = FLOWSPEC_TYPE_TCP_FLAGS; } flags | FRAGMENT { curflow->type = FLOWSPEC_TYPE_FRAG; } flags; | icmpspec | LENGTH lengthspec { curflow->type = FLOWSPEC_TYPE_PKT_LEN; } | proto | TOS tos { curflow->type = FLOWSPEC_TYPE_DSCP; if (push_unary_numop(OP_EQ, $2 >> 2) == -1) YYERROR; } ; flags : flag '/' flag { if (($1 & $3) != $1) { yyerror("bad flag combination, " "check bit not in mask"); YYERROR; } if (push_binop(FLOWSPEC_OP_BIT_MATCH, $1) == -1) YYERROR; /* check if extra mask op is needed */ if ($3 & ~$1) { if (push_binop(FLOWSPEC_OP_BIT_NOT | FLOWSPEC_OP_AND, $3 & ~$1) == -1) YYERROR; } } | '/' flag { if (push_binop(FLOWSPEC_OP_BIT_NOT, $2) == -1) YYERROR; } | flag { if (push_binop(0, $1) == -1) YYERROR; } | ANY /* nothing */ ; flag : STRING { if (($$ = parse_flags($1)) < 0) { yyerror("bad flags %s", $1); free($1); YYERROR; } free($1); } ; icmpspec : ICMPTYPE icmp_item | ICMPTYPE '{' optnl icmp_list optnl '}' ; icmp_list : icmp_item | icmp_list comma icmp_item ; icmp_item : icmptype { curflow->type = FLOWSPEC_TYPE_ICMP_TYPE; if (push_unary_numop(OP_EQ, $1) == -1) YYERROR; } | icmptype CODE STRING { int code; if ((code = geticmpcodebyname($1, $3, curflow->aid)) == -1) { yyerror("unknown icmp-code %s", $3); free($3); YYERROR; } free($3); curflow->type = FLOWSPEC_TYPE_ICMP_TYPE; if (push_unary_numop(OP_EQ, $1) == -1) YYERROR; curflow->type = FLOWSPEC_TYPE_ICMP_CODE; if (push_unary_numop(OP_EQ, code) == -1) YYERROR; } | icmptype CODE NUMBER { if ($3 < 0 || $3 > 255) { yyerror("illegal icmp-code %lld", $3); YYERROR; } curflow->type = FLOWSPEC_TYPE_ICMP_TYPE; if (push_unary_numop(OP_EQ, $1) == -1) YYERROR; curflow->type = FLOWSPEC_TYPE_ICMP_CODE; if (push_unary_numop(OP_EQ, $3) == -1) YYERROR; } ; icmptype : STRING { int type; if ((type = geticmptypebyname($1, curflow->aid)) == -1) { yyerror("unknown icmp-type %s", $1); free($1); YYERROR; } $$ = type; free($1); } | NUMBER { if ($1 < 0 || $1 > 255) { yyerror("illegal icmp-type %lld", $1); YYERROR; } $$ = $1; } ; tos : STRING { int val; char *end; if (map_tos($1, &val)) $$ = val; else if ($1[0] == '0' && $1[1] == 'x') { errno = 0; $$ = strtoul($1, &end, 16); if (errno || *end != '\0') $$ = 256; } else $$ = 256; if ($$ < 0 || $$ > 255) { yyerror("illegal tos value %s", $1); free($1); YYERROR; } free($1); } | NUMBER { if ($$ < 0 || $$ > 255) { yyerror("illegal tos value %lld", $1); YYERROR; } $$ = $1; } ; lengthspec : length_item | '{' optnl length_list optnl '}' ; length_list : length_item | length_list comma length_item ; length_item : length { if (push_unary_numop(OP_EQ, $1) == -1) YYERROR; } | unaryop length { if (push_unary_numop($1, $2) == -1) YYERROR; } | length binaryop length { if (push_binary_numop($2, $1, $3) == -1) YYERROR; } ; length : NUMBER { if ($$ < 0 || $$ > USHRT_MAX) { yyerror("illegal ptk length value %lld", $1); YYERROR; } $$ = $1; } inout : IN { $$ = 1; } | OUT { $$ = 0; } ; restricted : /* empty */ { $$ = 0; } | RESTRICTED { $$ = 1; } ; address : STRING { uint8_t len; if (!host($1, &$$, &len)) { yyerror("could not parse address spec \"%s\"", $1); free($1); YYERROR; } free($1); if (($$.aid == AID_INET && len != 32) || ($$.aid == AID_INET6 && len != 128)) { /* unreachable */ yyerror("got prefixlen %u, expected %u", len, $$.aid == AID_INET ? 32 : 128); YYERROR; } } ; prefix : STRING '/' NUMBER { char *s; if ($3 < 0 || $3 > 128) { yyerror("bad prefixlen %lld", $3); free($1); YYERROR; } if (asprintf(&s, "%s/%lld", $1, $3) == -1) fatal(NULL); free($1); if (!host(s, &$$.prefix, &$$.len)) { yyerror("could not parse address \"%s\"", s); free(s); YYERROR; } free(s); } | NUMBER '/' NUMBER { char *s; /* does not match IPv6 */ if ($1 < 0 || $1 > 255 || $3 < 0 || $3 > 32) { yyerror("bad prefix %lld/%lld", $1, $3); YYERROR; } if (asprintf(&s, "%lld/%lld", $1, $3) == -1) fatal(NULL); if (!host(s, &$$.prefix, &$$.len)) { yyerror("could not parse address \"%s\"", s); free(s); YYERROR; } free(s); } ; addrspec : address { memcpy(&$$.prefix, &$1, sizeof(struct bgpd_addr)); if ($$.prefix.aid == AID_INET) $$.len = 32; else $$.len = 128; } | prefix ; optnumber : /* empty */ { $$ = 0; } | NUMBER ; l3vpn : VPN STRING ON STRING { u_int rdomain, label; if (get_mpe_config($4, &rdomain, &label) == -1) { if ((cmd_opts & BGPD_OPT_NOACTION) == 0) { yyerror("troubles getting config of %s", $4); free($4); free($2); YYERROR; } } if (!(curvpn = calloc(1, sizeof(struct l3vpn)))) fatal(NULL); strlcpy(curvpn->ifmpe, $4, IFNAMSIZ); if (strlcpy(curvpn->descr, $2, sizeof(curvpn->descr)) >= sizeof(curvpn->descr)) { yyerror("descr \"%s\" too long: max %zu", $2, sizeof(curvpn->descr) - 1); free($2); free($4); free(curvpn); curvpn = NULL; YYERROR; } free($2); free($4); TAILQ_INIT(&curvpn->import); TAILQ_INIT(&curvpn->export); TAILQ_INIT(&curvpn->net_l); curvpn->label = label; curvpn->rtableid = rdomain; netconf = &curvpn->net_l; } '{' l3vpnopts_l '}' { /* insert into list */ SIMPLEQ_INSERT_TAIL(&conf->l3vpns, curvpn, entry); curvpn = NULL; netconf = &conf->networks; } ; l3vpnopts_l : /* empty */ | l3vpnopts_l '\n' | l3vpnopts_l l3vpnopts '\n' | l3vpnopts_l error '\n' ; l3vpnopts : RD STRING { struct community ext; memset(&ext, 0, sizeof(ext)); if (parseextcommunity(&ext, "rt", $2) == -1) { free($2); YYERROR; } free($2); /* * RD is almost encoded like an ext-community, * but only almost so convert here. */ if (community_to_rd(&ext, &curvpn->rd) == -1) { yyerror("bad encoding of rd"); YYERROR; } } | EXPORTTRGT STRING STRING { struct filter_set *set; if ((set = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); set->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&set->action.community, $2, $3) == -1) { free($3); free($2); free(set); YYERROR; } free($3); free($2); TAILQ_INSERT_TAIL(&curvpn->export, set, entry); } | IMPORTTRGT STRING STRING { struct filter_set *set; if ((set = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); set->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&set->action.community, $2, $3) == -1) { free($3); free($2); free(set); YYERROR; } free($3); free($2); TAILQ_INSERT_TAIL(&curvpn->import, set, entry); } | FIBUPDATE yesno { if ($2 == 0) curvpn->flags |= F_RIB_NOFIBSYNC; else curvpn->flags &= ~F_RIB_NOFIBSYNC; } | network ; neighbor : { curpeer = new_peer(); } NEIGHBOR addrspec { memcpy(&curpeer->conf.remote_addr, &$3.prefix, sizeof(curpeer->conf.remote_addr)); curpeer->conf.remote_masklen = $3.len; if (($3.prefix.aid == AID_INET && $3.len != 32) || ($3.prefix.aid == AID_INET6 && $3.len != 128)) curpeer->conf.template = 1; if (get_id(curpeer)) { yyerror("get_id failed"); YYERROR; } } peeropts_h { uint8_t aid; if (curpeer_filter[0] != NULL) TAILQ_INSERT_TAIL(peerfilter_l, curpeer_filter[0], entry); if (curpeer_filter[1] != NULL) TAILQ_INSERT_TAIL(peerfilter_l, curpeer_filter[1], entry); curpeer_filter[0] = NULL; curpeer_filter[1] = NULL; /* * Check if any MP capa is set, if none is set and * and the default AID was not disabled via none then * enable it. Finally fixup the disabled AID. */ for (aid = AID_MIN; aid < AID_MAX; aid++) { if (curpeer->conf.capabilities.mp[aid] > 0) break; } if (aid == AID_MAX && curpeer->conf.capabilities.mp[ curpeer->conf.remote_addr.aid] != -1) curpeer->conf.capabilities.mp[ curpeer->conf.remote_addr.aid] = 1; for (aid = AID_MIN; aid < AID_MAX; aid++) { if (curpeer->conf.capabilities.mp[aid] == -1) curpeer->conf.capabilities.mp[aid] = 0; } if (neighbor_consistent(curpeer) == -1) { free(curpeer); YYERROR; } if (RB_INSERT(peer_head, new_peers, curpeer) != NULL) fatalx("%s: peer tree is corrupt", __func__); curpeer = curgroup; } ; group : GROUP string { curgroup = curpeer = new_group(); if (strlcpy(curgroup->conf.group, $2, sizeof(curgroup->conf.group)) >= sizeof(curgroup->conf.group)) { yyerror("group name \"%s\" too long: max %zu", $2, sizeof(curgroup->conf.group) - 1); free($2); free(curgroup); YYERROR; } free($2); if (get_id(curgroup)) { yyerror("get_id failed"); free(curgroup); YYERROR; } } '{' groupopts_l '}' { if (curgroup_filter[0] != NULL) TAILQ_INSERT_TAIL(groupfilter_l, curgroup_filter[0], entry); if (curgroup_filter[1] != NULL) TAILQ_INSERT_TAIL(groupfilter_l, curgroup_filter[1], entry); curgroup_filter[0] = NULL; curgroup_filter[1] = NULL; free(curgroup); curgroup = NULL; } ; groupopts_l : /* empty */ | groupopts_l '\n' | groupopts_l peeropts '\n' | groupopts_l neighbor '\n' | groupopts_l error '\n' ; addpathextra : /* empty */ { $$ = 0; } | PLUS NUMBER { if ($2 < 1 || $2 > USHRT_MAX) { yyerror("additional paths must be between " "%u and %u", 1, USHRT_MAX); YYERROR; } $$ = $2; } ; addpathmax : /* empty */ { $$ = 0; } | MAX NUMBER { if ($2 < 1 || $2 > USHRT_MAX) { yyerror("maximum additional paths must be " "between %u and %u", 1, USHRT_MAX); YYERROR; } $$ = $2; } ; peeropts_h : '{' '\n' peeropts_l '}' | '{' peeropts '}' | /* empty */ ; peeropts_l : /* empty */ | peeropts_l '\n' | peeropts_l peeropts '\n' | peeropts_l error '\n' ; peeropts : REMOTEAS as4number { curpeer->conf.remote_as = $2; } | LOCALAS as4number { curpeer->conf.local_as = $2; if ($2 > USHRT_MAX) curpeer->conf.local_short_as = AS_TRANS; else curpeer->conf.local_short_as = $2; } | LOCALAS as4number asnumber { curpeer->conf.local_as = $2; curpeer->conf.local_short_as = $3; } | DESCR string { if (strlcpy(curpeer->conf.descr, $2, sizeof(curpeer->conf.descr)) >= sizeof(curpeer->conf.descr)) { yyerror("descr \"%s\" too long: max %zu", $2, sizeof(curpeer->conf.descr) - 1); free($2); YYERROR; } free($2); } | LOCALADDR address { if ($2.aid == AID_INET) memcpy(&curpeer->conf.local_addr_v4, &$2, sizeof(curpeer->conf.local_addr_v4)); else if ($2.aid == AID_INET6) memcpy(&curpeer->conf.local_addr_v6, &$2, sizeof(curpeer->conf.local_addr_v6)); else { yyerror("Unsupported address family %s for " "local-addr", aid2str($2.aid)); YYERROR; } } | yesno LOCALADDR { if ($1) { yyerror("bad local-address definition"); YYERROR; } memset(&curpeer->conf.local_addr_v4, 0, sizeof(curpeer->conf.local_addr_v4)); memset(&curpeer->conf.local_addr_v6, 0, sizeof(curpeer->conf.local_addr_v6)); } | MULTIHOP NUMBER { if ($2 < 2 || $2 > 255) { yyerror("invalid multihop distance %lld", $2); YYERROR; } curpeer->conf.distance = $2; } | PASSIVE { curpeer->conf.passive = 1; } | DOWN { curpeer->conf.down = 1; } | DOWN STRING { curpeer->conf.down = 1; if (strlcpy(curpeer->conf.reason, $2, sizeof(curpeer->conf.reason)) >= sizeof(curpeer->conf.reason)) { yyerror("shutdown reason too long"); free($2); YYERROR; } free($2); } | RIB STRING { if (!find_rib($2)) { yyerror("rib \"%s\" does not exist.", $2); free($2); YYERROR; } if (strlcpy(curpeer->conf.rib, $2, sizeof(curpeer->conf.rib)) >= sizeof(curpeer->conf.rib)) { yyerror("rib name \"%s\" too long: max %zu", $2, sizeof(curpeer->conf.rib) - 1); free($2); YYERROR; } free($2); } | HOLDTIME NUMBER { if ($2 < MIN_HOLDTIME || $2 > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } curpeer->conf.holdtime = $2; } | HOLDTIME YMIN NUMBER { if ($3 < MIN_HOLDTIME || $3 > USHRT_MAX) { yyerror("holdtime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } curpeer->conf.min_holdtime = $3; } | STALETIME NUMBER { if ($2 < MIN_HOLDTIME || $2 > USHRT_MAX) { yyerror("staletime must be between %u and %u", MIN_HOLDTIME, USHRT_MAX); YYERROR; } curpeer->conf.staletime = $2; } | ANNOUNCE af safi enforce { uint8_t aid, safi; uint16_t afi; if ($3 == SAFI_NONE) { for (aid = AID_MIN; aid < AID_MAX; aid++) { if (aid2afi(aid, &afi, &safi) == -1 || afi != $2) continue; curpeer->conf.capabilities.mp[aid] = -1; } } else { if (afi2aid($2, $3, &aid) == -1) { yyerror("unknown AFI/SAFI pair"); YYERROR; } if ($4) curpeer->conf.capabilities.mp[aid] = 2; else curpeer->conf.capabilities.mp[aid] = 1; } } | ANNOUNCE EVPN enforce { if ($3) curpeer->conf.capabilities.mp[AID_EVPN] = 2; else curpeer->conf.capabilities.mp[AID_EVPN] = 1; } | ANNOUNCE REFRESH yesnoenforce { curpeer->conf.capabilities.refresh = $3; } | ANNOUNCE ENHANCED REFRESH yesnoenforce { curpeer->conf.capabilities.enhanced_rr = $4; } | ANNOUNCE RESTART yesnoenforce { curpeer->conf.capabilities.grestart.restart = $3; } | ANNOUNCE GRACEFUL NOTIFICATION yesno { curpeer->conf.capabilities.grestart.grnotification = $4; } | ANNOUNCE AS4BYTE yesnoenforce { curpeer->conf.capabilities.as4byte = $3; } | ANNOUNCE ADDPATH RECV yesnoenforce { int8_t *ap = curpeer->conf.capabilities.add_path; uint8_t i; for (i = AID_MIN; i < AID_MAX; i++) { if ($4) { if ($4 == 2) ap[i] |= CAPA_AP_RECV_ENFORCE; ap[i] |= CAPA_AP_RECV; } else ap[i] &= ~CAPA_AP_RECV; } } | ANNOUNCE ADDPATH SEND STRING addpathextra addpathmax enforce { int8_t *ap = curpeer->conf.capabilities.add_path; enum addpath_mode mode; u_int8_t i; if (!strcmp($4, "no")) { free($4); if ($5 != 0 || $6 != 0 || $7 != 0) { yyerror("no additional option allowed " "for 'add-path send no'"); YYERROR; } mode = ADDPATH_EVAL_NONE; } else if (!strcmp($4, "all")) { free($4); if ($5 != 0 || $6 != 0) { yyerror("no additional option allowed " "for 'add-path send all'"); YYERROR; } mode = ADDPATH_EVAL_ALL; } else if (!strcmp($4, "best")) { free($4); mode = ADDPATH_EVAL_BEST; } else if (!strcmp($4, "ecmp")) { free($4); mode = ADDPATH_EVAL_ECMP; } else if (!strcmp($4, "as-wide-best")) { free($4); mode = ADDPATH_EVAL_AS_WIDE; } else { yyerror("announce add-path send: " "unknown mode \"%s\"", $4); free($4); YYERROR; } for (i = AID_MIN; i < AID_MAX; i++) { if (mode != ADDPATH_EVAL_NONE) { if ($7) ap[i] |= CAPA_AP_SEND_ENFORCE; ap[i] |= CAPA_AP_SEND; } else ap[i] &= ~CAPA_AP_SEND; } curpeer->conf.eval.mode = mode; curpeer->conf.eval.extrapaths = $5; curpeer->conf.eval.maxpaths = $6; } | ANNOUNCE POLICY yesnoenforce { curpeer->conf.capabilities.policy = $3; } | ANNOUNCE EXTENDED MESSAGE yesnoenforce { curpeer->conf.capabilities.ext_msg = $4; } | ANNOUNCE EXTENDED NEXTHOP yesnoenforce { curpeer->conf.capabilities.ext_nh[AID_VPN_IPv4] = curpeer->conf.capabilities.ext_nh[AID_INET] = $4; } | ROLE STRING { if (strcmp($2, "provider") == 0) { curpeer->conf.role = ROLE_PROVIDER; } else if (strcmp($2, "rs") == 0) { curpeer->conf.role = ROLE_RS; } else if (strcmp($2, "rs-client") == 0) { curpeer->conf.role = ROLE_RS_CLIENT; } else if (strcmp($2, "customer") == 0) { curpeer->conf.role = ROLE_CUSTOMER; } else if (strcmp($2, "peer") == 0) { curpeer->conf.role = ROLE_PEER; } else { yyerror("syntax error, one of none, provider, " "rs, rs-client, customer, peer expected"); free($2); YYERROR; } free($2); } | ROLE NONE { curpeer->conf.role = ROLE_NONE; } | EXPORT NONE { curpeer->conf.export_type = EXPORT_NONE; } | EXPORT DEFAULTROUTE { curpeer->conf.export_type = EXPORT_DEFAULT_ROUTE; } | ENFORCE NEIGHBORAS yesno { if ($3) curpeer->conf.enforce_as = ENFORCE_AS_ON; else curpeer->conf.enforce_as = ENFORCE_AS_OFF; } | ENFORCE LOCALAS yesno { if ($3) curpeer->conf.enforce_local_as = ENFORCE_AS_ON; else curpeer->conf.enforce_local_as = ENFORCE_AS_OFF; } | ASOVERRIDE yesno { if ($2) { struct filter_rule *r; struct filter_set *s; if ((s = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); s->type = ACTION_SET_AS_OVERRIDE; r = get_rule(s->type); if (merge_filterset(&r->set, s) == -1) YYERROR; } } | MAXPREFIX NUMBER restart { if ($2 < 0 || $2 > UINT_MAX) { yyerror("bad maximum number of prefixes"); YYERROR; } curpeer->conf.max_prefix = $2; curpeer->conf.max_prefix_restart = $3; } | MAXPREFIX NUMBER OUT restart { if ($2 < 0 || $2 > UINT_MAX) { yyerror("bad maximum number of prefixes"); YYERROR; } curpeer->conf.max_out_prefix = $2; curpeer->conf.max_out_prefix_restart = $4; } | authconf { if (merge_auth_conf(&curpeer->auth_conf, &$1) == 0) YYERROR; } | TTLSECURITY yesno { curpeer->conf.ttlsec = $2; } | SET filter_set_opt { struct filter_rule *r; r = get_rule($2->type); if (merge_filterset(&r->set, $2) == -1) YYERROR; } | SET '{' optnl filter_set_l optnl '}' { struct filter_rule *r; struct filter_set *s; while ((s = TAILQ_FIRST($4)) != NULL) { TAILQ_REMOVE($4, s, entry); r = get_rule(s->type); if (merge_filterset(&r->set, s) == -1) YYERROR; } free($4); } | mrtdump | REFLECTOR { if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid != 0) { yyerror("only one route reflector " "cluster allowed"); YYERROR; } conf->flags |= BGPD_FLAG_REFLECTOR; curpeer->conf.reflector_client = 1; } | REFLECTOR address { if ($2.aid != AID_INET) { yyerror("route reflector cluster-id must be " "an IPv4 address"); YYERROR; } if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid != ntohl($2.v4.s_addr)) { yyerror("only one route reflector " "cluster allowed"); YYERROR; } conf->flags |= BGPD_FLAG_REFLECTOR; curpeer->conf.reflector_client = 1; conf->clusterid = ntohl($2.v4.s_addr); } | DEPEND ON STRING { if (strlcpy(curpeer->conf.if_depend, $3, sizeof(curpeer->conf.if_depend)) >= sizeof(curpeer->conf.if_depend)) { yyerror("interface name \"%s\" too long: " "max %zu", $3, sizeof(curpeer->conf.if_depend) - 1); free($3); YYERROR; } free($3); } | DEMOTE STRING { #ifdef HAVE_CARP if (strlcpy(curpeer->conf.demote_group, $2, sizeof(curpeer->conf.demote_group)) >= sizeof(curpeer->conf.demote_group)) { yyerror("demote group name \"%s\" too long: " "max %zu", $2, sizeof(curpeer->conf.demote_group) - 1); free($2); YYERROR; } free($2); if (carp_demote_init(curpeer->conf.demote_group, cmd_opts & BGPD_OPT_FORCE_DEMOTE) == -1) { yyerror("error initializing group \"%s\"", curpeer->conf.demote_group); YYERROR; } #else yyerror("carp demote not supported"); free($2); YYERROR; #endif } | TRANSPARENT yesno { if ($2 == 1) curpeer->conf.flags |= PEERFLAG_TRANS_AS; else curpeer->conf.flags &= ~PEERFLAG_TRANS_AS; } | LOG STRING { if (!strcmp($2, "updates")) curpeer->conf.flags |= PEERFLAG_LOG_UPDATES; else if (!strcmp($2, "no")) curpeer->conf.flags &= ~PEERFLAG_LOG_UPDATES; else { free($2); YYERROR; } free($2); } | REJECT ASSET yesno { if ($3 == 1) curpeer->conf.flags &= ~PEERFLAG_PERMIT_AS_SET; else curpeer->conf.flags |= PEERFLAG_PERMIT_AS_SET; } | PORT port { curpeer->conf.remote_port = $2; } | RDE EVALUATE STRING { if (!strcmp($3, "all")) curpeer->conf.flags |= PEERFLAG_EVALUATE_ALL; else if (!strcmp($3, "default")) curpeer->conf.flags &= ~PEERFLAG_EVALUATE_ALL; else { yyerror("rde evaluate: " "unknown setting \"%s\"", $3); free($3); YYERROR; } free($3); } ; restart : /* nada */ { $$ = 0; } | RESTART NUMBER { if ($2 < 1 || $2 > USHRT_MAX) { yyerror("restart out of range. 1 to %u minutes", USHRT_MAX); YYERROR; } $$ = $2; } ; af : IPV4 { $$ = AFI_IPv4; } | IPV6 { $$ = AFI_IPv6; } ; safi : NONE { $$ = SAFI_NONE; } | UNICAST { $$ = SAFI_UNICAST; } | VPN { $$ = SAFI_MPLSVPN; } | FLOWSPEC { $$ = SAFI_FLOWSPEC; } ; nettype : STATIC { $$ = 1; } | CONNECTED { $$ = 0; } ; authconf : TCP MD5SIG PASSWORD string { memset(&$$, 0, sizeof($$)); if (strlcpy($$.md5key, $4, sizeof($$.md5key)) >= sizeof($$.md5key)) { yyerror("tcp md5sig password too long: max %zu", sizeof($$.md5key) - 1); free($4); YYERROR; } $$.method = AUTH_MD5SIG; $$.md5key_len = strlen($4); free($4); } | TCP MD5SIG KEY string { memset(&$$, 0, sizeof($$)); if (str2key($4, $$.md5key, sizeof($$.md5key)) == -1) { free($4); YYERROR; } $$.method = AUTH_MD5SIG; $$.md5key_len = strlen($4) / 2; free($4); } | IPSEC espah IKE { memset(&$$, 0, sizeof($$)); if ($2) $$.method = AUTH_IPSEC_IKE_ESP; else $$.method = AUTH_IPSEC_IKE_AH; } | IPSEC espah inout SPI NUMBER STRING STRING encspec { enum auth_alg auth_alg; uint8_t keylen; memset(&$$, 0, sizeof($$)); if (!strcmp($6, "sha1")) { auth_alg = AUTH_AALG_SHA1HMAC; keylen = 20; } else if (!strcmp($6, "md5")) { auth_alg = AUTH_AALG_MD5HMAC; keylen = 16; } else { yyerror("unknown auth algorithm \"%s\"", $6); free($6); free($7); YYERROR; } free($6); if (strlen($7) / 2 != keylen) { yyerror("auth key len: must be %u bytes, " "is %zu bytes", keylen, strlen($7) / 2); free($7); YYERROR; } if ($2) $$.method = AUTH_IPSEC_MANUAL_ESP; else { if ($8.enc_alg) { yyerror("\"ipsec ah\" doesn't take " "encryption keys"); free($7); YYERROR; } $$.method = AUTH_IPSEC_MANUAL_AH; } if ($5 <= SPI_RESERVED_MAX || $5 > UINT_MAX) { yyerror("bad spi number %lld", $5); free($7); YYERROR; } if ($3 == 1) { if (str2key($7, $$.auth_key_in, sizeof($$.auth_key_in)) == -1) { free($7); YYERROR; } $$.spi_in = $5; $$.auth_alg_in = auth_alg; $$.enc_alg_in = $8.enc_alg; memcpy(&$$.enc_key_in, &$8.enc_key, sizeof($$.enc_key_in)); $$.enc_keylen_in = $8.enc_key_len; $$.auth_keylen_in = keylen; } else { if (str2key($7, $$.auth_key_out, sizeof($$.auth_key_out)) == -1) { free($7); YYERROR; } $$.spi_out = $5; $$.auth_alg_out = auth_alg; $$.enc_alg_out = $8.enc_alg; memcpy(&$$.enc_key_out, &$8.enc_key, sizeof($$.enc_key_out)); $$.enc_keylen_out = $8.enc_key_len; $$.auth_keylen_out = keylen; } free($7); } ; espah : ESP { $$ = 1; } | AH { $$ = 0; } ; encspec : /* nada */ { memset(&$$, 0, sizeof($$)); } | STRING STRING { memset(&$$, 0, sizeof($$)); if (!strcmp($1, "3des") || !strcmp($1, "3des-cbc")) { $$.enc_alg = AUTH_EALG_3DESCBC; $$.enc_key_len = 21; /* XXX verify */ } else if (!strcmp($1, "aes") || !strcmp($1, "aes-128-cbc")) { $$.enc_alg = AUTH_EALG_AES; $$.enc_key_len = 16; } else { yyerror("unknown enc algorithm \"%s\"", $1); free($1); free($2); YYERROR; } free($1); if (strlen($2) / 2 != $$.enc_key_len) { yyerror("enc key length wrong: should be %u " "bytes, is %zu bytes", $$.enc_key_len * 2, strlen($2)); free($2); YYERROR; } if (str2key($2, $$.enc_key, sizeof($$.enc_key)) == -1) { free($2); YYERROR; } free($2); } ; filterrule : action quick filter_rib_h direction filter_peer_h filter_match_h filter_set { struct filter_rule r; struct filter_rib_l *rb, *rbnext; memset(&r, 0, sizeof(r)); r.action = $1; r.quick = $2; r.dir = $4; if ($3) { if (r.dir != DIR_IN) { yyerror("rib only allowed on \"from\" " "rules."); for (rb = $3; rb != NULL; rb = rbnext) { rbnext = rb->next; free(rb); } YYERROR; } } if (expand_rule(&r, $3, $5, &$6, $7) == -1) YYERROR; } ; action : ALLOW { $$ = ACTION_ALLOW; } | DENY { $$ = ACTION_DENY; } | MATCH { $$ = ACTION_NONE; } ; quick : /* empty */ { $$ = 0; } | QUICK { $$ = 1; } ; direction : FROM { $$ = DIR_IN; } | TO { $$ = DIR_OUT; } ; filter_rib_h : /* empty */ { $$ = NULL; } | RIB filter_rib { $$ = $2; } | RIB '{' optnl filter_rib_l optnl '}' { $$ = $4; } filter_rib_l : filter_rib { $$ = $1; } | filter_rib_l comma filter_rib { $3->next = $1; $$ = $3; } ; filter_rib : STRING { if (!find_rib($1)) { yyerror("rib \"%s\" does not exist.", $1); free($1); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_rib_l))) == NULL) fatal(NULL); $$->next = NULL; if (strlcpy($$->name, $1, sizeof($$->name)) >= sizeof($$->name)) { yyerror("rib name \"%s\" too long: " "max %zu", $1, sizeof($$->name) - 1); free($1); free($$); YYERROR; } free($1); } ; filter_peer_h : filter_peer | '{' optnl filter_peer_l optnl '}' { $$ = $3; } ; filter_peer_l : filter_peer { $$ = $1; } | filter_peer_l comma filter_peer { $3->next = $1; $$ = $3; } ; filter_peer : ANY { if (($$ = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); $$->p.peerid = $$->p.groupid = 0; $$->next = NULL; } | address { struct peer *p; if (($$ = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); $$->p.remote_as = $$->p.groupid = $$->p.peerid = 0; $$->next = NULL; RB_FOREACH(p, peer_head, new_peers) if (!memcmp(&p->conf.remote_addr, &$1, sizeof(p->conf.remote_addr))) { $$->p.peerid = p->conf.id; break; } if ($$->p.peerid == 0) { yyerror("no such peer: %s", log_addr(&$1)); free($$); YYERROR; } } | AS as4number { if (($$ = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); $$->p.groupid = $$->p.peerid = 0; $$->p.remote_as = $2; } | GROUP STRING { struct peer *p; if (($$ = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); $$->p.remote_as = $$->p.peerid = 0; $$->next = NULL; RB_FOREACH(p, peer_head, new_peers) if (!strcmp(p->conf.group, $2)) { $$->p.groupid = p->conf.groupid; break; } if ($$->p.groupid == 0) { yyerror("no such group: \"%s\"", $2); free($2); free($$); YYERROR; } free($2); } | EBGP { if (($$ = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); $$->p.ebgp = 1; } | IBGP { if (($$ = calloc(1, sizeof(struct filter_peers_l))) == NULL) fatal(NULL); $$->p.ibgp = 1; } ; filter_prefix_h : IPV4 prefixlenop { if ($2.op == OP_NONE) { $2.op = OP_RANGE; $2.len_min = 0; $2.len_max = -1; } if (($$ = calloc(1, sizeof(struct filter_prefix_l))) == NULL) fatal(NULL); $$->p.addr.aid = AID_INET; if (merge_prefixspec(&$$->p, &$2) == -1) { free($$); YYERROR; } } | IPV6 prefixlenop { if ($2.op == OP_NONE) { $2.op = OP_RANGE; $2.len_min = 0; $2.len_max = -1; } if (($$ = calloc(1, sizeof(struct filter_prefix_l))) == NULL) fatal(NULL); $$->p.addr.aid = AID_INET6; if (merge_prefixspec(&$$->p, &$2) == -1) { free($$); YYERROR; } } | PREFIX filter_prefix { $$ = $2; } | PREFIX '{' filter_prefix_m '}' { $$ = $3; } ; filter_prefix_m : filter_prefix_l | '{' filter_prefix_l '}' { $$ = $2; } | '{' filter_prefix_l '}' filter_prefix_m { struct filter_prefix_l *p; /* merge, both can be lists */ for (p = $2; p != NULL && p->next != NULL; p = p->next) ; /* nothing */ if (p != NULL) p->next = $4; $$ = $2; } filter_prefix_l : filter_prefix { $$ = $1; } | filter_prefix_l comma filter_prefix { $3->next = $1; $$ = $3; } ; filter_prefix : prefix prefixlenop { if (($$ = calloc(1, sizeof(struct filter_prefix_l))) == NULL) fatal(NULL); memcpy(&$$->p.addr, &$1.prefix, sizeof($$->p.addr)); $$->p.len = $1.len; if (merge_prefixspec(&$$->p, &$2) == -1) { free($$); YYERROR; } } ; filter_as_h : filter_as_t | '{' filter_as_t_l '}' { $$ = $2; } ; filter_as_t_l : filter_as_t | filter_as_t_l comma filter_as_t { struct filter_as_l *a; /* merge, both can be lists */ for (a = $1; a != NULL && a->next != NULL; a = a->next) ; /* nothing */ if (a != NULL) a->next = $3; $$ = $1; } ; filter_as_t : filter_as_type filter_as { $$ = $2; $$->a.type = $1; } | filter_as_type '{' filter_as_l_h '}' { struct filter_as_l *a; $$ = $3; for (a = $$; a != NULL; a = a->next) a->a.type = $1; } | filter_as_type ASSET STRING { if (as_sets_lookup(&conf->as_sets, $3) == NULL) { yyerror("as-set \"%s\" not defined", $3); free($3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); $$->a.type = $1; $$->a.flags = AS_FLAG_AS_SET_NAME; if (strlcpy($$->a.name, $3, sizeof($$->a.name)) >= sizeof($$->a.name)) { yyerror("as-set name \"%s\" too long: " "max %zu", $3, sizeof($$->a.name) - 1); free($3); free($$); YYERROR; } free($3); } ; filter_as_l_h : filter_as_l | '{' filter_as_l '}' { $$ = $2; } | '{' filter_as_l '}' filter_as_l_h { struct filter_as_l *a; /* merge, both can be lists */ for (a = $2; a != NULL && a->next != NULL; a = a->next) ; /* nothing */ if (a != NULL) a->next = $4; $$ = $2; } ; filter_as_l : filter_as | filter_as_l comma filter_as { $3->next = $1; $$ = $3; } ; filter_as : as4number_any { if (($$ = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); $$->a.as_min = $1; $$->a.as_max = $1; $$->a.op = OP_EQ; } | NEIGHBORAS { if (($$ = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); $$->a.flags = AS_FLAG_NEIGHBORAS; } | equalityop as4number_any { if (($$ = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); $$->a.op = $1; $$->a.as_min = $2; $$->a.as_max = $2; } | as4number_any binaryop as4number_any { if (($$ = calloc(1, sizeof(struct filter_as_l))) == NULL) fatal(NULL); if ($1 >= $3) { yyerror("start AS is bigger than end"); YYERROR; } $$->a.op = $2; $$->a.as_min = $1; $$->a.as_max = $3; } ; filter_match_h : /* empty */ { memset(&$$, 0, sizeof($$)); } | { memset(&fmopts, 0, sizeof(fmopts)); } filter_match { memcpy(&$$, &fmopts, sizeof($$)); } ; filter_match : filter_elm | filter_match filter_elm ; filter_elm : filter_prefix_h { if (fmopts.prefix_l != NULL) { yyerror("\"prefix\" already specified"); YYERROR; } if (fmopts.m.prefixset.name[0] != '\0') { yyerror("\"prefix-set\" already specified, " "cannot be used with \"prefix\" in the " "same filter rule"); YYERROR; } fmopts.prefix_l = $1; } | filter_as_h { if (fmopts.as_l != NULL) { yyerror("AS filters already specified"); YYERROR; } fmopts.as_l = $1; } | MAXASLEN NUMBER { if (fmopts.m.aslen.type != ASLEN_NONE) { yyerror("AS length filters already specified"); YYERROR; } if ($2 < 0 || $2 > UINT_MAX) { yyerror("bad max-as-len %lld", $2); YYERROR; } fmopts.m.aslen.type = ASLEN_MAX; fmopts.m.aslen.aslen = $2; } | MAXASSEQ NUMBER { if (fmopts.m.aslen.type != ASLEN_NONE) { yyerror("AS length filters already specified"); YYERROR; } if ($2 < 0 || $2 > UINT_MAX) { yyerror("bad max-as-seq %lld", $2); YYERROR; } fmopts.m.aslen.type = ASLEN_SEQ; fmopts.m.aslen.aslen = $2; } | community STRING { int i; for (i = 0; i < MAX_COMM_MATCH; i++) { if (fmopts.m.community[i].flags == 0) break; } if (i >= MAX_COMM_MATCH) { yyerror("too many \"community\" filters " "specified"); free($2); YYERROR; } if (parsecommunity(&fmopts.m.community[i], $1, $2) == -1) { free($2); YYERROR; } free($2); } | EXTCOMMUNITY STRING STRING { int i; for (i = 0; i < MAX_COMM_MATCH; i++) { if (fmopts.m.community[i].flags == 0) break; } if (i >= MAX_COMM_MATCH) { yyerror("too many \"community\" filters " "specified"); free($2); free($3); YYERROR; } if (parseextcommunity(&fmopts.m.community[i], $2, $3) == -1) { free($2); free($3); YYERROR; } free($2); free($3); } | EXTCOMMUNITY OVS STRING { int i; for (i = 0; i < MAX_COMM_MATCH; i++) { if (fmopts.m.community[i].flags == 0) break; } if (i >= MAX_COMM_MATCH) { yyerror("too many \"community\" filters " "specified"); free($3); YYERROR; } if (parseextcommunity(&fmopts.m.community[i], "ovs", $3) == -1) { free($3); YYERROR; } free($3); } | MAXCOMMUNITIES NUMBER { if ($2 < 0 || $2 > INT16_MAX) { yyerror("bad max-comunities %lld", $2); YYERROR; } if (fmopts.m.maxcomm != 0) { yyerror("%s already specified", "max-communities"); YYERROR; } /* * Offset by 1 since 0 means not used. * The match function then uses >= to compensate. */ fmopts.m.maxcomm = $2 + 1; } | MAXEXTCOMMUNITIES NUMBER { if ($2 < 0 || $2 > INT16_MAX) { yyerror("bad max-ext-communities %lld", $2); YYERROR; } if (fmopts.m.maxextcomm != 0) { yyerror("%s already specified", "max-ext-communities"); YYERROR; } fmopts.m.maxextcomm = $2 + 1; } | MAXLARGECOMMUNITIES NUMBER { if ($2 < 0 || $2 > INT16_MAX) { yyerror("bad max-large-communities %lld", $2); YYERROR; } if (fmopts.m.maxlargecomm != 0) { yyerror("%s already specified", "max-large-communities"); YYERROR; } fmopts.m.maxlargecomm = $2 + 1; } | NEXTHOP address { if (fmopts.m.nexthop.flags) { yyerror("nexthop already specified"); YYERROR; } fmopts.m.nexthop.addr = $2; fmopts.m.nexthop.flags = FILTER_NEXTHOP_ADDR; } | NEXTHOP NEIGHBOR { if (fmopts.m.nexthop.flags) { yyerror("nexthop already specified"); YYERROR; } fmopts.m.nexthop.flags = FILTER_NEXTHOP_NEIGHBOR; } | PREFIXSET STRING prefixlenop { struct prefixset *ps; if (fmopts.prefix_l != NULL) { yyerror("\"prefix\" already specified, cannot " "be used with \"prefix-set\" in the same " "filter rule"); free($2); YYERROR; } if (fmopts.m.prefixset.name[0] != '\0') { yyerror("prefix-set filter already specified"); free($2); YYERROR; } if ((ps = find_prefixset($2, &conf->prefixsets)) == NULL) { yyerror("prefix-set '%s' not defined", $2); free($2); YYERROR; } if (strlcpy(fmopts.m.prefixset.name, $2, sizeof(fmopts.m.prefixset.name)) >= sizeof(fmopts.m.prefixset.name)) { yyerror("prefix-set name too long"); free($2); YYERROR; } if (!($3.op == OP_NONE || ($3.op == OP_RANGE && $3.len_min == -1 && $3.len_max == -1))) { yyerror("prefix-sets can only use option " "or-longer"); free($2); YYERROR; } if ($3.op == OP_RANGE && ps->sflags & PREFIXSET_FLAG_OPS) { yyerror("prefix-set %s contains prefixlen " "operators and cannot be used with an " "or-longer filter", $2); free($2); YYERROR; } if ($3.op == OP_RANGE && $3.len_min == -1 && $3.len_min == -1) fmopts.m.prefixset.flags |= PREFIXSET_FLAG_LONGER; fmopts.m.prefixset.flags |= PREFIXSET_FLAG_FILTER; free($2); } | ORIGINSET STRING { if (fmopts.m.originset.name[0] != '\0') { yyerror("origin-set filter already specified"); free($2); YYERROR; } if (find_prefixset($2, &conf->originsets) == NULL) { yyerror("origin-set '%s' not defined", $2); free($2); YYERROR; } if (strlcpy(fmopts.m.originset.name, $2, sizeof(fmopts.m.originset.name)) >= sizeof(fmopts.m.originset.name)) { yyerror("origin-set name too long"); free($2); YYERROR; } free($2); } | OVS validity { if (fmopts.m.ovs.is_set) { yyerror("ovs filter already specified"); YYERROR; } fmopts.m.ovs.validity = $2; fmopts.m.ovs.is_set = 1; } | AVS aspa_validity { if (fmopts.m.avs.is_set) { yyerror("avs filter already specified"); YYERROR; } fmopts.m.avs.validity = $2; fmopts.m.avs.is_set = 1; } ; prefixlenop : /* empty */ { memset(&$$, 0, sizeof($$)); } | LONGER { memset(&$$, 0, sizeof($$)); $$.op = OP_RANGE; $$.len_min = -1; $$.len_max = -1; } | MAXLEN NUMBER { memset(&$$, 0, sizeof($$)); if ($2 < 0 || $2 > 128) { yyerror("prefixlen must be >= 0 and <= 128"); YYERROR; } $$.op = OP_RANGE; $$.len_min = -1; $$.len_max = $2; } | PREFIXLEN unaryop NUMBER { int min, max; memset(&$$, 0, sizeof($$)); if ($3 < 0 || $3 > 128) { yyerror("prefixlen must be >= 0 and <= 128"); YYERROR; } /* * convert the unary operation into the equivalent * range check */ $$.op = OP_RANGE; switch ($2) { case OP_NE: $$.op = $2; case OP_EQ: min = max = $3; break; case OP_LT: if ($3 == 0) { yyerror("prefixlen must be > 0"); YYERROR; } $3 -= 1; case OP_LE: min = -1; max = $3; break; case OP_GT: $3 += 1; case OP_GE: min = $3; max = -1; break; default: yyerror("unknown prefixlen operation"); YYERROR; } $$.len_min = min; $$.len_max = max; } | PREFIXLEN NUMBER binaryop NUMBER { memset(&$$, 0, sizeof($$)); if ($2 < 0 || $2 > 128 || $4 < 0 || $4 > 128) { yyerror("prefixlen must be < 128"); YYERROR; } if ($2 > $4) { yyerror("start prefixlen is bigger than end"); YYERROR; } $$.op = $3; $$.len_min = $2; $$.len_max = $4; } ; filter_as_type : AS { $$ = AS_ALL; } | SOURCEAS { $$ = AS_SOURCE; } | TRANSITAS { $$ = AS_TRANSIT; } | PEERAS { $$ = AS_PEER; } ; filter_set : /* empty */ { $$ = NULL; } | SET filter_set_opt { if (($$ = calloc(1, sizeof(struct filter_set_head))) == NULL) fatal(NULL); TAILQ_INIT($$); TAILQ_INSERT_TAIL($$, $2, entry); } | SET '{' optnl filter_set_l optnl '}' { $$ = $4; } ; filter_set_l : filter_set_l comma filter_set_opt { $$ = $1; if (merge_filterset($$, $3) == 1) YYERROR; } | filter_set_opt { if (($$ = calloc(1, sizeof(struct filter_set_head))) == NULL) fatal(NULL); TAILQ_INIT($$); TAILQ_INSERT_TAIL($$, $1, entry); } ; community : COMMUNITY { $$ = COMMUNITY_TYPE_BASIC; } | LARGECOMMUNITY { $$ = COMMUNITY_TYPE_LARGE; } ; delete : /* empty */ { $$ = 0; } | DELETE { $$ = 1; } ; enforce : /* empty */ { $$ = 0; } | ENFORCE { $$ = 2; } ; yesnoenforce : yesno { $$ = $1; } | ENFORCE { $$ = 2; } ; filter_set_opt : LOCALPREF NUMBER { if ($2 < -INT_MAX || $2 > UINT_MAX) { yyerror("bad localpref %lld", $2); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ($2 >= 0) { $$->type = ACTION_SET_LOCALPREF; $$->action.metric = $2; } else { $$->type = ACTION_SET_RELATIVE_LOCALPREF; $$->action.relative = $2; } } | LOCALPREF '+' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad localpref +%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_LOCALPREF; $$->action.relative = $3; } | LOCALPREF '-' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad localpref -%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_LOCALPREF; $$->action.relative = -$3; } | MED NUMBER { if ($2 < -INT_MAX || $2 > UINT_MAX) { yyerror("bad metric %lld", $2); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ($2 >= 0) { $$->type = ACTION_SET_MED; $$->action.metric = $2; } else { $$->type = ACTION_SET_RELATIVE_MED; $$->action.relative = $2; } } | MED '+' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad metric +%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_MED; $$->action.relative = $3; } | MED '-' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad metric -%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_MED; $$->action.relative = -$3; } | METRIC NUMBER { /* alias for MED */ if ($2 < -INT_MAX || $2 > UINT_MAX) { yyerror("bad metric %lld", $2); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ($2 >= 0) { $$->type = ACTION_SET_MED; $$->action.metric = $2; } else { $$->type = ACTION_SET_RELATIVE_MED; $$->action.relative = $2; } } | METRIC '+' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad metric +%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_MED; $$->action.metric = $3; } | METRIC '-' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad metric -%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_MED; $$->action.relative = -$3; } | WEIGHT NUMBER { if ($2 < -INT_MAX || $2 > UINT_MAX) { yyerror("bad weight %lld", $2); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ($2 > 0) { $$->type = ACTION_SET_WEIGHT; $$->action.metric = $2; } else { $$->type = ACTION_SET_RELATIVE_WEIGHT; $$->action.relative = $2; } } | WEIGHT '+' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad weight +%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_WEIGHT; $$->action.relative = $3; } | WEIGHT '-' NUMBER { if ($3 < 0 || $3 > INT_MAX) { yyerror("bad weight -%lld", $3); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_RELATIVE_WEIGHT; $$->action.relative = -$3; } | NEXTHOP address { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_NEXTHOP; memcpy(&$$->action.nexthop, &$2, sizeof($$->action.nexthop)); } | NEXTHOP BLACKHOLE { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_NEXTHOP_BLACKHOLE; } | NEXTHOP REJECT { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_NEXTHOP_REJECT; } | NEXTHOP NOMODIFY { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_NEXTHOP_NOMODIFY; } | NEXTHOP SELF { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_NEXTHOP_SELF; } | PREPEND_SELF NUMBER { if ($2 < 0 || $2 > 128) { yyerror("bad number of prepends"); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_PREPEND_SELF; $$->action.prepend = $2; } | PREPEND_PEER NUMBER { if ($2 < 0 || $2 > 128) { yyerror("bad number of prepends"); YYERROR; } if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_PREPEND_PEER; $$->action.prepend = $2; } | ASOVERRIDE { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_AS_OVERRIDE; } | PFTABLE STRING { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_PFTABLE; if (!(cmd_opts & BGPD_OPT_NOACTION) && pftable_exists($2) != 0) { yyerror("pftable name does not exist"); free($2); free($$); YYERROR; } if (strlcpy($$->action.pftable, $2, sizeof($$->action.pftable)) >= sizeof($$->action.pftable)) { yyerror("pftable name too long"); free($2); free($$); YYERROR; } if (pftable_add($2) != 0) { yyerror("Couldn't register table"); free($2); free($$); YYERROR; } free($2); } | RTLABEL STRING { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_RTLABEL; if (strlcpy($$->action.rtlabel, $2, sizeof($$->action.rtlabel)) >= sizeof($$->action.rtlabel)) { yyerror("rtlabel name too long"); free($2); free($$); YYERROR; } free($2); } | community delete STRING { uint8_t f1, f2, f3; if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ($2) $$->type = ACTION_DEL_COMMUNITY; else $$->type = ACTION_SET_COMMUNITY; if (parsecommunity(&$$->action.community, $1, $3) == -1) { free($3); free($$); YYERROR; } free($3); /* Don't allow setting of any match */ f1 = $$->action.community.flags >> 8; f2 = $$->action.community.flags >> 16; f3 = $$->action.community.flags >> 24; if (!$2 && (f1 == COMMUNITY_ANY || f2 == COMMUNITY_ANY || f3 == COMMUNITY_ANY)) { yyerror("'*' is not allowed in set community"); free($$); YYERROR; } } | EXTCOMMUNITY delete STRING STRING { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ($2) $$->type = ACTION_DEL_COMMUNITY; else $$->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&$$->action.community, $3, $4) == -1) { free($3); free($4); free($$); YYERROR; } free($3); free($4); } | EXTCOMMUNITY delete OVS STRING { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); if ($2) $$->type = ACTION_DEL_COMMUNITY; else $$->type = ACTION_SET_COMMUNITY; if (parseextcommunity(&$$->action.community, "ovs", $4) == -1) { free($4); free($$); YYERROR; } free($4); } | ORIGIN origincode { if (($$ = calloc(1, sizeof(struct filter_set))) == NULL) fatal(NULL); $$->type = ACTION_SET_ORIGIN; $$->action.origin = $2; } ; origincode : STRING { if (!strcmp($1, "egp")) $$ = ORIGIN_EGP; else if (!strcmp($1, "igp")) $$ = ORIGIN_IGP; else if (!strcmp($1, "incomplete")) $$ = ORIGIN_INCOMPLETE; else { yyerror("unknown origin \"%s\"", $1); free($1); YYERROR; } free($1); }; validity : STRING { if (!strcmp($1, "not-found")) $$ = ROA_NOTFOUND; else if (!strcmp($1, "invalid")) $$ = ROA_INVALID; else if (!strcmp($1, "valid")) $$ = ROA_VALID; else { yyerror("unknown roa validity \"%s\"", $1); free($1); YYERROR; } free($1); }; aspa_validity : STRING { if (!strcmp($1, "unknown")) $$ = ASPA_UNKNOWN; else if (!strcmp($1, "invalid")) $$ = ASPA_INVALID; else if (!strcmp($1, "valid")) $$ = ASPA_VALID; else { yyerror("unknown aspa validity \"%s\"", $1); free($1); YYERROR; } free($1); }; optnl : /* empty */ | '\n' optnl ; comma : /* empty */ | ',' | '\n' optnl | ',' '\n' optnl ; unaryop : '=' { $$ = OP_EQ; } | NE { $$ = OP_NE; } | LE { $$ = OP_LE; } | '<' { $$ = OP_LT; } | GE { $$ = OP_GE; } | '>' { $$ = OP_GT; } ; equalityop : '=' { $$ = OP_EQ; } | NE { $$ = OP_NE; } ; binaryop : '-' { $$ = OP_RANGE; } | XRANGE { $$ = OP_XRANGE; } ; %% struct keywords { const char *k_name; int k_val; }; int yyerror(const char *fmt, ...) { va_list ap; char *msg; file->errors++; va_start(ap, fmt); if (vasprintf(&msg, fmt, ap) == -1) fatalx("yyerror vasprintf"); va_end(ap); logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg); free(msg); return (0); } int kw_cmp(const void *k, const void *e) { return (strcmp(k, ((const struct keywords *)e)->k_name)); } int lookup(char *s) { /* this has to be sorted always */ static const struct keywords keywords[] = { { "AS", AS }, { "EVPN", EVPN }, { "IPv4", IPV4 }, { "IPv6", IPV6 }, { "add-path", ADDPATH }, { "ah", AH }, { "allow", ALLOW }, { "announce", ANNOUNCE }, { "any", ANY }, { "as-4byte", AS4BYTE }, { "as-override", ASOVERRIDE }, { "as-set", ASSET }, { "aspa-set", ASPASET }, { "avs", AVS }, { "blackhole", BLACKHOLE }, { "community", COMMUNITY }, { "compare", COMPARE }, { "connect-retry", CONNECTRETRY }, { "connected", CONNECTED }, { "customer-as", CUSTOMERAS }, { "default-route", DEFAULTROUTE }, { "delete", DELETE }, { "demote", DEMOTE }, { "deny", DENY }, { "depend", DEPEND }, { "descr", DESCR }, { "down", DOWN }, { "dump", DUMP }, { "ebgp", EBGP }, { "enforce", ENFORCE }, { "enhanced", ENHANCED }, { "esp", ESP }, { "evaluate", EVALUATE }, { "expires", EXPIRES }, { "export", EXPORT }, { "export-target", EXPORTTRGT }, { "ext-community", EXTCOMMUNITY }, { "extended", EXTENDED }, { "fib-priority", FIBPRIORITY }, { "fib-update", FIBUPDATE }, { "filtered", FILTERED }, { "flags", FLAGS }, { "flowspec", FLOWSPEC }, { "fragment", FRAGMENT }, { "from", FROM }, { "graceful", GRACEFUL }, { "group", GROUP }, { "holdtime", HOLDTIME }, { "ibgp", IBGP }, { "ignore", IGNORE }, { "ike", IKE }, { "import-target", IMPORTTRGT }, { "in", IN }, { "include", INCLUDE }, { "inet", IPV4 }, { "inet6", IPV6 }, { "ipsec", IPSEC }, { "key", KEY }, { "large-community", LARGECOMMUNITY }, { "listen", LISTEN }, { "local-address", LOCALADDR }, { "local-as", LOCALAS }, { "localpref", LOCALPREF }, { "log", LOG }, { "match", MATCH }, { "max", MAX }, { "max-as-len", MAXASLEN }, { "max-as-seq", MAXASSEQ }, { "max-communities", MAXCOMMUNITIES }, { "max-ext-communities", MAXEXTCOMMUNITIES }, { "max-large-communities", MAXLARGECOMMUNITIES }, { "max-prefix", MAXPREFIX }, { "maxlen", MAXLEN }, { "md5sig", MD5SIG }, { "med", MED }, { "message", MESSAGE }, { "metric", METRIC }, { "min", YMIN }, { "min-version", MINVERSION }, { "multihop", MULTIHOP }, { "neighbor", NEIGHBOR }, { "neighbor-as", NEIGHBORAS }, { "network", NETWORK }, { "nexthop", NEXTHOP }, { "no-modify", NOMODIFY }, { "none", NONE }, { "notification", NOTIFICATION }, { "on", ON }, { "or-longer", LONGER }, { "origin", ORIGIN }, { "origin-set", ORIGINSET }, { "out", OUT }, { "ovs", OVS }, { "passive", PASSIVE }, { "password", PASSWORD }, { "peer-as", PEERAS }, { "pftable", PFTABLE }, { "plus", PLUS }, { "policy", POLICY }, { "port", PORT }, { "prefix", PREFIX }, { "prefix-set", PREFIXSET }, { "prefixlen", PREFIXLEN }, { "prepend-neighbor", PREPEND_PEER }, { "prepend-self", PREPEND_SELF }, { "priority", PRIORITY }, { "proto", PROTO }, { "provider-as", PROVIDERAS }, { "qualify", QUALIFY }, { "quick", QUICK }, { "rd", RD }, { "rde", RDE }, { "recv", RECV }, { "refresh", REFRESH }, { "reject", REJECT }, { "remote-as", REMOTEAS }, { "restart", RESTART }, { "restricted", RESTRICTED }, { "rib", RIB }, { "roa-set", ROASET }, { "role", ROLE }, { "route-reflector", REFLECTOR }, { "router-id", ROUTERID }, { "rtable", RTABLE }, { "rtlabel", RTLABEL }, { "rtr", RTR }, { "self", SELF }, { "send", SEND }, { "set", SET }, { "socket", SOCKET }, { "source-as", SOURCEAS }, { "spi", SPI }, { "staletime", STALETIME }, { "static", STATIC }, { "tcp", TCP }, { "to", TO }, { "tos", TOS }, { "transit-as", TRANSITAS }, { "transparent-as", TRANSPARENT }, { "ttl-security", TTLSECURITY }, { "unicast", UNICAST }, { "via", VIA }, { "vpn", VPN }, { "weight", WEIGHT }, }; const struct keywords *p; p = bsearch(s, keywords, nitems(keywords), sizeof(keywords[0]), kw_cmp); if (p) return (p->k_val); else return (STRING); } #define START_EXPAND 1 #define DONE_EXPAND 2 static int expanding; int igetc(void) { int c; while (1) { if (file->ungetpos > 0) c = file->ungetbuf[--file->ungetpos]; else c = getc(file->stream); if (c == START_EXPAND) expanding = 1; else if (c == DONE_EXPAND) expanding = 0; else break; } return (c); } int lgetc(int quotec) { int c, next; if (quotec) { if ((c = igetc()) == EOF) { yyerror("reached end of file while parsing " "quoted string"); if (file == topfile || popfile() == EOF) return (EOF); return (quotec); } return (c); } while ((c = igetc()) == '\\') { next = igetc(); if (next != '\n') { c = next; break; } yylval.lineno = file->lineno; file->lineno++; } if (c == EOF) { /* * Fake EOL when hit EOF for the first time. This gets line * count right if last line in included file is syntactically * invalid and has no newline. */ if (file->eof_reached == 0) { file->eof_reached = 1; return ('\n'); } while (c == EOF) { if (file == topfile || popfile() == EOF) return (EOF); c = igetc(); } } return (c); } void lungetc(int c) { if (c == EOF) return; if (file->ungetpos >= file->ungetsize) { void *p = reallocarray(file->ungetbuf, file->ungetsize, 2); if (p == NULL) err(1, "lungetc"); file->ungetbuf = p; file->ungetsize *= 2; } file->ungetbuf[file->ungetpos++] = c; } int findeol(void) { int c; /* skip to either EOF or the first real EOL */ while (1) { c = lgetc(0); if (c == '\n') { file->lineno++; break; } if (c == EOF) break; } return (ERROR); } int expand_macro(void) { char buf[MACRO_NAME_LEN]; char *p, *val; int c; p = buf; while (1) { if ((c = lgetc('$')) == EOF) return (ERROR); if (p + 1 >= buf + sizeof(buf) - 1) { yyerror("macro name too long"); return (ERROR); } if (isalnum(c) || c == '_') { *p++ = c; continue; } *p = '\0'; lungetc(c); break; } val = symget(buf); if (val == NULL) { yyerror("macro '%s' not defined", buf); return (ERROR); } p = val + strlen(val) - 1; lungetc(DONE_EXPAND); while (p >= val) { lungetc((unsigned char)*p); p--; } lungetc(START_EXPAND); return (0); } int yylex(void) { char buf[8096]; char *p; int quotec, next, c; int token; top: p = buf; while ((c = lgetc(0)) == ' ' || c == '\t') ; /* nothing */ yylval.lineno = file->lineno; if (c == '#') while ((c = lgetc(0)) != '\n' && c != EOF) ; /* nothing */ if (c == '$' && !expanding) { c = expand_macro(); if (c != 0) return (c); goto top; } switch (c) { case '\'': case '"': quotec = c; while (1) { if ((c = lgetc(quotec)) == EOF) return (0); if (c == '\n') { file->lineno++; continue; } else if (c == '\\') { if ((next = lgetc(quotec)) == EOF) return (0); if (next == quotec || next == ' ' || next == '\t') c = next; else if (next == '\n') { file->lineno++; continue; } else lungetc(next); } else if (c == quotec) { *p = '\0'; break; } else if (c == '\0') { yyerror("syntax error: unterminated quote"); return (findeol()); } if (p + 1 >= buf + sizeof(buf) - 1) { yyerror("string too long"); return (findeol()); } *p++ = c; } yylval.v.string = strdup(buf); if (yylval.v.string == NULL) fatal("yylex: strdup"); return (STRING); case '!': next = lgetc(0); if (next == '=') return (NE); lungetc(next); break; case '<': next = lgetc(0); if (next == '=') return (LE); lungetc(next); break; case '>': next = lgetc(0); if (next == '<') return (XRANGE); else if (next == '=') return (GE); lungetc(next); break; } #define allowed_to_end_number(x) \ (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=') if (c == '-' || isdigit(c)) { do { *p++ = c; if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } } while ((c = lgetc(0)) != EOF && isdigit(c)); lungetc(c); if (p == buf + 1 && buf[0] == '-') goto nodigits; if (c == EOF || allowed_to_end_number(c)) { const char *errstr = NULL; *p = '\0'; yylval.v.number = strtonum(buf, LLONG_MIN, LLONG_MAX, &errstr); if (errstr) { yyerror("\"%s\" invalid number: %s", buf, errstr); return (findeol()); } return (NUMBER); } else { nodigits: while (p > buf + 1) lungetc((unsigned char)*--p); c = (unsigned char)*--p; if (c == '-') return (c); } } #define allowed_in_string(x) \ (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \ x != '{' && x != '}' && x != '<' && x != '>' && \ x != '!' && x != '=' && x != '/' && x != '#' && \ x != ',')) if (isalnum(c) || c == ':' || c == '_' || c == '*') { do { if (c == '$' && !expanding) { c = expand_macro(); if (c != 0) return (c); } else *p++ = c; if ((size_t)(p-buf) >= sizeof(buf)) { yyerror("string too long"); return (findeol()); } } while ((c = lgetc(0)) != EOF && (allowed_in_string(c))); lungetc(c); *p = '\0'; if ((token = lookup(buf)) == STRING) if ((yylval.v.string = strdup(buf)) == NULL) fatal("yylex: strdup"); return (token); } if (c == '\n') { yylval.lineno = file->lineno; file->lineno++; } if (c == EOF) return (0); return (c); } int check_file_secrecy(int fd, const char *fname) { struct stat st; if (fstat(fd, &st)) { log_warn("cannot stat %s", fname); return (-1); } return (0); } struct file * pushfile(const char *name, int secret) { struct file *nfile; if ((nfile = calloc(1, sizeof(struct file))) == NULL) { log_warn("%s", __func__); return (NULL); } if ((nfile->name = strdup(name)) == NULL) { log_warn("%s", __func__); free(nfile); return (NULL); } if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { log_warn("%s: %s", __func__, nfile->name); free(nfile->name); free(nfile); return (NULL); } if (secret && check_file_secrecy(fileno(nfile->stream), nfile->name)) { fclose(nfile->stream); free(nfile->name); free(nfile); return (NULL); } nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0; nfile->ungetsize = 16; nfile->ungetbuf = malloc(nfile->ungetsize); if (nfile->ungetbuf == NULL) { log_warn("%s", __func__); fclose(nfile->stream); free(nfile->name); free(nfile); return (NULL); } TAILQ_INSERT_TAIL(&files, nfile, entry); return (nfile); } int popfile(void) { struct file *prev; if ((prev = TAILQ_PREV(file, files, entry)) != NULL) prev->errors += file->errors; TAILQ_REMOVE(&files, file, entry); fclose(file->stream); free(file->name); free(file->ungetbuf); free(file); file = prev; return (file ? 0 : EOF); } static void init_config(struct bgpd_config *c) { u_int rdomid; c->min_holdtime = MIN_HOLDTIME; c->holdtime = INTERVAL_HOLD; c->staletime = INTERVAL_STALE; c->connectretry = INTERVAL_CONNECTRETRY; c->bgpid = get_bgpid(); c->fib_priority = kr_default_prio(); c->default_tableid = getrtable(); if (!ktable_exists(c->default_tableid, &rdomid)) fatalx("current routing table %u does not exist", c->default_tableid); if (rdomid != c->default_tableid) fatalx("current routing table %u is not a routing domain", c->default_tableid); if (asprintf(&c->csock, "%s.%d", SOCKET_NAME, c->default_tableid) == -1) fatal(NULL); } struct bgpd_config * parse_config(char *filename, struct peer_head *ph, struct rtr_config_head *rh) { struct sym *sym, *next; struct rde_rib *rr; struct network *n; int errors = 0; conf = new_config(); init_config(conf); if ((filter_l = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); if ((peerfilter_l = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); if ((groupfilter_l = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); TAILQ_INIT(filter_l); TAILQ_INIT(peerfilter_l); TAILQ_INIT(groupfilter_l); curpeer = NULL; curgroup = NULL; cur_peers = ph; cur_rtrs = rh; new_peers = &conf->peers; netconf = &conf->networks; if ((rr = add_rib("Adj-RIB-In")) == NULL) fatal("add_rib failed"); rr->flags = F_RIB_NOFIB | F_RIB_NOEVALUATE; if ((rr = add_rib("Loc-RIB")) == NULL) fatal("add_rib failed"); rib_add_fib(rr, conf->default_tableid); rr->flags = F_RIB_LOCAL; if ((file = pushfile(filename, 1)) == NULL) goto errors; topfile = file; yyparse(); errors = file->errors; popfile(); /* check that we dont try to announce our own routes */ TAILQ_FOREACH(n, netconf, entry) if (n->net.priority == conf->fib_priority) { errors++; logit(LOG_CRIT, "network priority %d == fib-priority " "%d is not allowed.", n->net.priority, conf->fib_priority); } /* Free macros and check which have not been used. */ TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) { if ((cmd_opts & BGPD_OPT_VERBOSE2) && !sym->used) fprintf(stderr, "warning: macro \"%s\" not " "used\n", sym->nam); if (!sym->persist) { free(sym->nam); free(sym->val); TAILQ_REMOVE(&symhead, sym, entry); free(sym); } } if (!conf->as) { log_warnx("configuration error: AS not given"); errors++; } /* clear the globals */ curpeer = NULL; curgroup = NULL; cur_peers = NULL; new_peers = NULL; netconf = NULL; curflow = NULL; if (errors) { errors: while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) { SIMPLEQ_REMOVE_HEAD(&ribnames, entry); free(rr); } filterlist_free(filter_l); filterlist_free(peerfilter_l); filterlist_free(groupfilter_l); free_config(conf); return (NULL); } /* Create default listeners if none where specified. */ if (TAILQ_EMPTY(conf->listen_addrs)) { struct listen_addr *la; if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("setup_listeners calloc"); la->fd = -1; la->flags = DEFAULT_LISTENER; la->reconf = RECONF_REINIT; la->sa_len = sizeof(struct sockaddr_in); ((struct sockaddr_in *)&la->sa)->sin_family = AF_INET; ((struct sockaddr_in *)&la->sa)->sin_addr.s_addr = htonl(INADDR_ANY); ((struct sockaddr_in *)&la->sa)->sin_port = htons(BGP_PORT); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); if ((la = calloc(1, sizeof(struct listen_addr))) == NULL) fatal("setup_listeners calloc"); la->fd = -1; la->flags = DEFAULT_LISTENER; la->reconf = RECONF_REINIT; la->sa_len = sizeof(struct sockaddr_in6); ((struct sockaddr_in6 *)&la->sa)->sin6_family = AF_INET6; ((struct sockaddr_in6 *)&la->sa)->sin6_port = htons(BGP_PORT); TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry); } /* update clusterid in case it was not set explicitly */ if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid == 0) conf->clusterid = conf->bgpid; /* * Concatenate filter list and static group and peer filtersets * together. Static group sets come first then peer sets * last normal filter rules. */ TAILQ_CONCAT(conf->filters, groupfilter_l, entry); TAILQ_CONCAT(conf->filters, peerfilter_l, entry); TAILQ_CONCAT(conf->filters, filter_l, entry); optimize_filters(conf->filters); free(filter_l); free(peerfilter_l); free(groupfilter_l); return (conf); } int symset(const char *nam, const char *val, int persist) { struct sym *sym; TAILQ_FOREACH(sym, &symhead, entry) { if (strcmp(nam, sym->nam) == 0) break; } if (sym != NULL) { if (sym->persist == 1) return (0); else { free(sym->nam); free(sym->val); TAILQ_REMOVE(&symhead, sym, entry); free(sym); } } if ((sym = calloc(1, sizeof(*sym))) == NULL) return (-1); sym->nam = strdup(nam); if (sym->nam == NULL) { free(sym); return (-1); } sym->val = strdup(val); if (sym->val == NULL) { free(sym->nam); free(sym); return (-1); } sym->used = 0; sym->persist = persist; TAILQ_INSERT_TAIL(&symhead, sym, entry); return (0); } int cmdline_symset(char *s) { char *sym, *val; int ret; if ((val = strrchr(s, '=')) == NULL) return (-1); sym = strndup(s, val - s); if (sym == NULL) fatal("%s: strndup", __func__); ret = symset(sym, val + 1, 1); free(sym); return (ret); } char * symget(const char *nam) { struct sym *sym; TAILQ_FOREACH(sym, &symhead, entry) { if (strcmp(nam, sym->nam) == 0) { sym->used = 1; return (sym->val); } } return (NULL); } static int cmpcommunity(struct community *a, struct community *b) { if (a->flags > b->flags) return 1; if (a->flags < b->flags) return -1; if (a->data1 > b->data1) return 1; if (a->data1 < b->data1) return -1; if (a->data2 > b->data2) return 1; if (a->data2 < b->data2) return -1; if (a->data3 > b->data3) return 1; if (a->data3 < b->data3) return -1; return 0; } static int getcommunity(char *s, int large, uint32_t *val, uint32_t *flag) { long long max = USHRT_MAX; const char *errstr; *flag = 0; *val = 0; if (strcmp(s, "*") == 0) { *flag = COMMUNITY_ANY; return 0; } else if (strcmp(s, "neighbor-as") == 0) { *flag = COMMUNITY_NEIGHBOR_AS; return 0; } else if (strcmp(s, "local-as") == 0) { *flag = COMMUNITY_LOCAL_AS; return 0; } if (large) max = UINT_MAX; *val = strtonum(s, 0, max, &errstr); if (errstr) { yyerror("Community %s is %s (max: %lld)", s, errstr, max); return -1; } return 0; } static void setcommunity(struct community *c, uint32_t as, uint32_t data, uint32_t asflag, uint32_t dataflag) { c->flags = COMMUNITY_TYPE_BASIC; c->flags |= asflag << 8; c->flags |= dataflag << 16; c->data1 = as; c->data2 = data; c->data3 = 0; } static int parselargecommunity(struct community *c, char *s) { char *p, *q; uint32_t dflag1, dflag2, dflag3; if ((p = strchr(s, ':')) == NULL) { yyerror("Bad community syntax"); return (-1); } *p++ = 0; if ((q = strchr(p, ':')) == NULL) { yyerror("Bad community syntax"); return (-1); } *q++ = 0; if (getcommunity(s, 1, &c->data1, &dflag1) == -1 || getcommunity(p, 1, &c->data2, &dflag2) == -1 || getcommunity(q, 1, &c->data3, &dflag3) == -1) return (-1); c->flags = COMMUNITY_TYPE_LARGE; c->flags |= dflag1 << 8; c->flags |= dflag2 << 16; c->flags |= dflag3 << 24; return (0); } int parsecommunity(struct community *c, int type, char *s) { char *p; uint32_t as, data, asflag, dataflag; if (type == COMMUNITY_TYPE_LARGE) return parselargecommunity(c, s); /* Well-known communities */ if (strcasecmp(s, "GRACEFUL_SHUTDOWN") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_GRACEFUL_SHUTDOWN, 0, 0); return (0); } else if (strcasecmp(s, "NO_EXPORT") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPORT, 0, 0); return (0); } else if (strcasecmp(s, "NO_ADVERTISE") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_ADVERTISE, 0, 0); return (0); } else if (strcasecmp(s, "NO_EXPORT_SUBCONFED") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPSUBCONFED, 0, 0); return (0); } else if (strcasecmp(s, "NO_PEER") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_PEER, 0, 0); return (0); } else if (strcasecmp(s, "BLACKHOLE") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_BLACKHOLE, 0, 0); return (0); } if ((p = strchr(s, ':')) == NULL) { yyerror("Bad community syntax"); return (-1); } *p++ = 0; if (getcommunity(s, 0, &as, &asflag) == -1 || getcommunity(p, 0, &data, &dataflag) == -1) return (-1); setcommunity(c, as, data, asflag, dataflag); return (0); } static int parsesubtype(char *name, int *type, int *subtype) { const struct ext_comm_pairs *cp; int found = 0; for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if (strcmp(name, cp->subname) == 0) { if (found == 0) { *type = cp->type; *subtype = cp->subtype; } found++; } } if (found > 1) *type = -1; return (found); } static int parseextvalue(int type, char *s, uint32_t *v, uint32_t *flag) { const char *errstr; char *p; struct in_addr ip; uint32_t uvalh, uval; if (type != -1) { /* nothing */ } else if (strcmp(s, "neighbor-as") == 0) { *flag = COMMUNITY_NEIGHBOR_AS; *v = 0; return EXT_COMMUNITY_TRANS_TWO_AS; } else if (strcmp(s, "local-as") == 0) { *flag = COMMUNITY_LOCAL_AS; *v = 0; return EXT_COMMUNITY_TRANS_TWO_AS; } else if ((p = strchr(s, '.')) == NULL) { /* AS_PLAIN number (4 or 2 byte) */ strtonum(s, 0, USHRT_MAX, &errstr); if (errstr == NULL) type = EXT_COMMUNITY_TRANS_TWO_AS; else type = EXT_COMMUNITY_TRANS_FOUR_AS; } else if (strchr(p + 1, '.') == NULL) { /* AS_DOT number (4-byte) */ type = EXT_COMMUNITY_TRANS_FOUR_AS; } else { /* more than one dot -> IP address */ type = EXT_COMMUNITY_TRANS_IPV4; } switch (type & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: uval = strtonum(s, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", s, errstr); return (-1); } *v = uval; break; case EXT_COMMUNITY_TRANS_FOUR_AS: if ((p = strchr(s, '.')) == NULL) { uval = strtonum(s, 0, UINT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", s, errstr); return (-1); } *v = uval; break; } *p++ = '\0'; uvalh = strtonum(s, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", s, errstr); return (-1); } uval = strtonum(p, 0, USHRT_MAX, &errstr); if (errstr) { yyerror("Bad ext-community %s is %s", p, errstr); return (-1); } *v = uval | (uvalh << 16); break; case EXT_COMMUNITY_TRANS_IPV4: if (inet_pton(AF_INET, s, &ip) != 1) { yyerror("Bad ext-community %s not parseable", s); return (-1); } *v = ntohl(ip.s_addr); break; default: fatalx("%s: unexpected type %d", __func__, type); } return (type); } int parseextcommunity(struct community *c, char *t, char *s) { const struct ext_comm_pairs *cp; char *p, *ep; uint64_t ullval; uint32_t uval, uval2, dflag1 = 0, dflag2 = 0; int type = 0, subtype = 0; if (strcmp(t, "*") == 0 && strcmp(s, "*") == 0) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= COMMUNITY_ANY << 24; return (0); } if (parsesubtype(t, &type, &subtype) == 0) { yyerror("Bad ext-community unknown type"); return (-1); } switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_GEN_TWO_AS: case EXT_COMMUNITY_GEN_FOUR_AS: case EXT_COMMUNITY_GEN_IPV4: case -1: if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } if ((p = strchr(s, ':')) == NULL) { yyerror("Bad ext-community %s", s); return (-1); } *p++ = '\0'; if ((type = parseextvalue(type, s, &uval, &dflag1)) == -1) return (-1); switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_GEN_TWO_AS: if (getcommunity(p, 1, &uval2, &dflag2) == -1) return (-1); break; case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_GEN_IPV4: case EXT_COMMUNITY_GEN_FOUR_AS: if (getcommunity(p, 0, &uval2, &dflag2) == -1) return (-1); break; default: fatalx("parseextcommunity: unexpected result"); } c->data1 = uval; c->data2 = uval2; break; case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } errno = 0; ullval = strtoull(s, &ep, 0); if (s[0] == '\0' || *ep != '\0') { yyerror("Bad ext-community bad value"); return (-1); } if (errno == ERANGE && ullval > EXT_COMMUNITY_OPAQUE_MAX) { yyerror("Bad ext-community value too big"); return (-1); } c->data1 = ullval >> 32; c->data2 = ullval; break; case EXT_COMMUNITY_NON_TRANS_OPAQUE: if (subtype == EXT_COMMUNITY_SUBTYPE_OVS) { if (strcmp(s, "valid") == 0) { c->data2 = EXT_COMMUNITY_OVS_VALID; break; } else if (strcmp(s, "invalid") == 0) { c->data2 = EXT_COMMUNITY_OVS_INVALID; break; } else if (strcmp(s, "not-found") == 0) { c->data2 = EXT_COMMUNITY_OVS_NOTFOUND; break; } else if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } } yyerror("Bad ext-community %s", s); return (-1); } c->data3 = type << 8 | subtype; /* special handling of ext-community rt * since type is not known */ if (dflag1 == COMMUNITY_ANY && type == -1) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= dflag1 << 8; return (0); } /* verify type/subtype combo */ for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if (cp->type == type && cp->subtype == subtype) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= dflag1 << 8; c->flags |= dflag2 << 16; return (0); } } yyerror("Bad ext-community bad format for type"); return (-1); } struct peer * alloc_peer(void) { struct peer *p; if ((p = calloc(1, sizeof(struct peer))) == NULL) fatal("new_peer"); /* some sane defaults */ p->state = STATE_NONE; p->reconf_action = RECONF_REINIT; p->conf.distance = 1; p->conf.export_type = EXPORT_UNSET; p->conf.capabilities.refresh = 1; p->conf.capabilities.grestart.restart = 1; p->conf.capabilities.as4byte = 1; p->conf.capabilities.policy = 1; p->conf.local_as = conf->as; p->conf.local_short_as = conf->short_as; p->conf.remote_port = BGP_PORT; if (conf->flags & BGPD_FLAG_DECISION_TRANS_AS) p->conf.flags |= PEERFLAG_TRANS_AS; if (conf->flags & BGPD_FLAG_DECISION_ALL_PATHS) p->conf.flags |= PEERFLAG_EVALUATE_ALL; if (conf->flags & BGPD_FLAG_PERMIT_AS_SET) p->conf.flags |= PEERFLAG_PERMIT_AS_SET; return (p); } struct peer * new_peer(void) { struct peer *p; p = alloc_peer(); if (curgroup != NULL) { p->conf = curgroup->conf; p->auth_conf = curgroup->auth_conf; p->conf.groupid = curgroup->conf.id; } return (p); } struct peer * new_group(void) { return (alloc_peer()); } int add_mrtconfig(enum mrt_type type, char *name, int timeout, struct peer *p, char *rib) { struct mrt *m, *n; LIST_FOREACH(m, conf->mrt, entry) { if ((rib && strcmp(rib, m->rib)) || (!rib && *m->rib)) continue; if (p == NULL) { if (m->peer_id != 0 || m->group_id != 0) continue; } else { if (m->peer_id != p->conf.id || m->group_id != p->conf.groupid) continue; } if (m->type == type) { yyerror("only one mrtdump per type allowed."); return (-1); } } if ((n = calloc(1, sizeof(struct mrt_config))) == NULL) fatal("add_mrtconfig"); n->type = type; n->state = MRT_STATE_OPEN; if (strlcpy(MRT2MC(n)->name, name, sizeof(MRT2MC(n)->name)) >= sizeof(MRT2MC(n)->name)) { yyerror("filename \"%s\" too long: max %zu", name, sizeof(MRT2MC(n)->name) - 1); free(n); return (-1); } MRT2MC(n)->ReopenTimerInterval = timeout; if (p != NULL) { if (curgroup == p) { n->peer_id = 0; n->group_id = p->conf.id; } else { n->peer_id = p->conf.id; n->group_id = p->conf.groupid; } } if (rib) { if (!find_rib(rib)) { yyerror("rib \"%s\" does not exist.", rib); free(n); return (-1); } if (strlcpy(n->rib, rib, sizeof(n->rib)) >= sizeof(n->rib)) { yyerror("rib name \"%s\" too long: max %zu", name, sizeof(n->rib) - 1); free(n); return (-1); } } LIST_INSERT_HEAD(conf->mrt, n, entry); return (0); } struct rde_rib * add_rib(char *name) { struct rde_rib *rr; if ((rr = find_rib(name)) == NULL) { if ((rr = calloc(1, sizeof(*rr))) == NULL) { log_warn("add_rib"); return (NULL); } if (strlcpy(rr->name, name, sizeof(rr->name)) >= sizeof(rr->name)) { yyerror("rib name \"%s\" too long: max %zu", name, sizeof(rr->name) - 1); free(rr); return (NULL); } rr->flags = F_RIB_NOFIB; SIMPLEQ_INSERT_TAIL(&ribnames, rr, entry); } return (rr); } struct rde_rib * find_rib(char *name) { struct rde_rib *rr; SIMPLEQ_FOREACH(rr, &ribnames, entry) { if (!strcmp(rr->name, name)) return (rr); } return (NULL); } int rib_add_fib(struct rde_rib *rr, u_int rtableid) { u_int rdom; if (!ktable_exists(rtableid, &rdom)) { yyerror("rtable id %u does not exist", rtableid); return (-1); } /* * conf->default_tableid is also a rdomain because that is checked * in init_config() */ if (rdom != conf->default_tableid) { log_warnx("rtable %u does not belong to rdomain %u", rtableid, conf->default_tableid); return (-1); } rr->rtableid = rtableid; rr->flags &= ~F_RIB_NOFIB; return (0); } struct prefixset * find_prefixset(char *name, struct prefixset_head *p) { struct prefixset *ps; SIMPLEQ_FOREACH(ps, p, entry) { if (!strcmp(ps->name, name)) return (ps); } return (NULL); } int get_id(struct peer *newpeer) { static uint32_t id = PEER_ID_STATIC_MIN; struct peer *p = NULL; /* check if the peer already existed before */ if (newpeer->conf.remote_addr.aid) { /* neighbor */ if (cur_peers) RB_FOREACH(p, peer_head, cur_peers) if (p->conf.remote_masklen == newpeer->conf.remote_masklen && memcmp(&p->conf.remote_addr, &newpeer->conf.remote_addr, sizeof(p->conf.remote_addr)) == 0) break; if (p) { newpeer->conf.id = p->conf.id; return (0); } } else { /* group */ if (cur_peers) RB_FOREACH(p, peer_head, cur_peers) if (strcmp(p->conf.group, newpeer->conf.group) == 0) break; if (p) { newpeer->conf.id = p->conf.groupid; return (0); } } /* else new one */ if (id < PEER_ID_STATIC_MAX) { newpeer->conf.id = id++; return (0); } return (-1); } int merge_prefixspec(struct filter_prefix *p, struct filter_prefixlen *pl) { uint8_t max_len = 0; switch (p->addr.aid) { case AID_INET: case AID_VPN_IPv4: max_len = 32; break; case AID_INET6: case AID_VPN_IPv6: max_len = 128; break; } if (pl->op == OP_NONE) { p->len_min = p->len_max = p->len; return (0); } if (pl->len_min == -1) pl->len_min = p->len; if (pl->len_max == -1) pl->len_max = max_len; if (pl->len_max > max_len) { yyerror("prefixlen %d too big, limit %d", pl->len_max, max_len); return (-1); } if (pl->len_min > pl->len_max) { yyerror("prefixlen %d too big, limit %d", pl->len_min, pl->len_max); return (-1); } if (pl->len_min < p->len) { yyerror("prefixlen %d smaller than prefix, limit %d", pl->len_min, p->len); return (-1); } p->op = pl->op; p->len_min = pl->len_min; p->len_max = pl->len_max; return (0); } int expand_rule(struct filter_rule *rule, struct filter_rib_l *rib, struct filter_peers_l *peer, struct filter_match_l *match, struct filter_set_head *set) { struct filter_rule *r; struct filter_rib_l *rb, *rbnext; struct filter_peers_l *p, *pnext; struct filter_prefix_l *prefix, *prefix_next; struct filter_as_l *a, *anext; struct filter_set *s; rb = rib; do { p = peer; do { a = match->as_l; do { prefix = match->prefix_l; do { if ((r = calloc(1, sizeof(struct filter_rule))) == NULL) { log_warn("expand_rule"); return (-1); } memcpy(r, rule, sizeof(struct filter_rule)); memcpy(&r->match, match, sizeof(struct filter_match)); filterset_copy(set, &r->set); if (rb != NULL) strlcpy(r->rib, rb->name, sizeof(r->rib)); if (p != NULL) memcpy(&r->peer, &p->p, sizeof(struct filter_peers)); if (prefix != NULL) memcpy(&r->match.prefix, &prefix->p, sizeof(r->match.prefix)); if (a != NULL) memcpy(&r->match.as, &a->a, sizeof(struct filter_as)); TAILQ_INSERT_TAIL(filter_l, r, entry); if (prefix != NULL) prefix = prefix->next; } while (prefix != NULL); if (a != NULL) a = a->next; } while (a != NULL); if (p != NULL) p = p->next; } while (p != NULL); if (rb != NULL) rb = rb->next; } while (rb != NULL); for (rb = rib; rb != NULL; rb = rbnext) { rbnext = rb->next; free(rb); } for (p = peer; p != NULL; p = pnext) { pnext = p->next; free(p); } for (a = match->as_l; a != NULL; a = anext) { anext = a->next; free(a); } for (prefix = match->prefix_l; prefix != NULL; prefix = prefix_next) { prefix_next = prefix->next; free(prefix); } if (set != NULL) { while ((s = TAILQ_FIRST(set)) != NULL) { TAILQ_REMOVE(set, s, entry); free(s); } free(set); } return (0); } static int h2i(char c) { if (c >= '0' && c <= '9') return c - '0'; else if (c >= 'a' && c <= 'f') return c - 'a' + 10; else if (c >= 'A' && c <= 'F') return c - 'A' + 10; else return -1; } int str2key(char *s, char *dest, size_t max_len) { size_t i; if (strlen(s) / 2 > max_len) { yyerror("key too long"); return (-1); } if (strlen(s) % 2) { yyerror("key must be of even length"); return (-1); } for (i = 0; i < strlen(s) / 2; i++) { int hi, lo; hi = h2i(s[2 * i]); lo = h2i(s[2 * i + 1]); if (hi == -1 || lo == -1) { yyerror("key must be specified in hex"); return (-1); } dest[i] = (hi << 4) | lo; } return (0); } int neighbor_consistent(struct peer *p) { struct bgpd_addr *local_addr; struct peer *xp; switch (p->conf.remote_addr.aid) { case AID_INET: local_addr = &p->conf.local_addr_v4; break; case AID_INET6: local_addr = &p->conf.local_addr_v6; break; default: yyerror("Bad address family for remote-addr"); return (-1); } /* with any form of ipsec local-address is required */ if ((p->auth_conf.method == AUTH_IPSEC_IKE_ESP || p->auth_conf.method == AUTH_IPSEC_IKE_AH || p->auth_conf.method == AUTH_IPSEC_MANUAL_ESP || p->auth_conf.method == AUTH_IPSEC_MANUAL_AH) && local_addr->aid == AID_UNSPEC) { yyerror("neighbors with any form of IPsec configured " "need local-address to be specified"); return (-1); } /* with static keying we need both directions */ if ((p->auth_conf.method == AUTH_IPSEC_MANUAL_ESP || p->auth_conf.method == AUTH_IPSEC_MANUAL_AH) && (!p->auth_conf.spi_in || !p->auth_conf.spi_out)) { yyerror("with manual keyed IPsec, SPIs and keys " "for both directions are required"); return (-1); } if (!conf->as) { yyerror("AS needs to be given before neighbor definitions"); return (-1); } /* set default values if they where undefined */ p->conf.ebgp = (p->conf.remote_as != conf->as); if (p->conf.enforce_as == ENFORCE_AS_UNDEF) p->conf.enforce_as = p->conf.ebgp ? ENFORCE_AS_ON : ENFORCE_AS_OFF; if (p->conf.enforce_local_as == ENFORCE_AS_UNDEF) p->conf.enforce_local_as = ENFORCE_AS_ON; if (p->conf.remote_as == 0 && !p->conf.template) { yyerror("peer AS may not be zero"); return (-1); } /* EBGP neighbors are not allowed in route reflector clusters */ if (p->conf.reflector_client && p->conf.ebgp) { yyerror("EBGP neighbors are not allowed in route " "reflector clusters"); return (-1); } /* BGP role and RFC 9234 role are only valid for EBGP neighbors */ if (!p->conf.ebgp) { p->conf.role = ROLE_NONE; p->conf.capabilities.policy = 0; } else if (p->conf.role == ROLE_NONE) { /* no role, no policy capability */ p->conf.capabilities.policy = 0; } /* check for duplicate peer definitions */ RB_FOREACH(xp, peer_head, new_peers) if (xp->conf.remote_masklen == p->conf.remote_masklen && memcmp(&xp->conf.remote_addr, &p->conf.remote_addr, sizeof(p->conf.remote_addr)) == 0) break; if (xp != NULL) { char *descr = log_fmt_peer(&p->conf); yyerror("duplicate %s", descr); free(descr); return (-1); } return (0); } static void filterset_add(struct filter_set_head *sh, struct filter_set *s) { struct filter_set *t; TAILQ_FOREACH(t, sh, entry) { if (s->type < t->type) { TAILQ_INSERT_BEFORE(t, s, entry); return; } if (s->type == t->type) { switch (s->type) { case ACTION_SET_COMMUNITY: case ACTION_DEL_COMMUNITY: switch (cmpcommunity(&s->action.community, &t->action.community)) { case -1: TAILQ_INSERT_BEFORE(t, s, entry); return; case 0: break; case 1: continue; } break; case ACTION_SET_NEXTHOP: /* only last nexthop per AF matters */ if (s->action.nexthop.aid < t->action.nexthop.aid) { TAILQ_INSERT_BEFORE(t, s, entry); return; } else if (s->action.nexthop.aid == t->action.nexthop.aid) { t->action.nexthop = s->action.nexthop; break; } continue; case ACTION_SET_NEXTHOP_BLACKHOLE: case ACTION_SET_NEXTHOP_REJECT: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: /* set it only once */ break; case ACTION_SET_LOCALPREF: case ACTION_SET_MED: case ACTION_SET_WEIGHT: /* only last set matters */ t->action.metric = s->action.metric; break; case ACTION_SET_RELATIVE_LOCALPREF: case ACTION_SET_RELATIVE_MED: case ACTION_SET_RELATIVE_WEIGHT: /* sum all relative numbers */ t->action.relative += s->action.relative; break; case ACTION_SET_ORIGIN: /* only last set matters */ t->action.origin = s->action.origin; break; case ACTION_PFTABLE: /* only last set matters */ strlcpy(t->action.pftable, s->action.pftable, sizeof(t->action.pftable)); break; case ACTION_RTLABEL: /* only last set matters */ strlcpy(t->action.rtlabel, s->action.rtlabel, sizeof(t->action.rtlabel)); break; default: break; } free(s); return; } } TAILQ_INSERT_TAIL(sh, s, entry); } int merge_filterset(struct filter_set_head *sh, struct filter_set *s) { struct filter_set *t; TAILQ_FOREACH(t, sh, entry) { /* * need to cycle across the full list because even * if types are not equal filterset_cmp() may return 0. */ if (filterset_cmp(s, t) == 0) { if (s->type == ACTION_SET_COMMUNITY) yyerror("community is already set"); else if (s->type == ACTION_DEL_COMMUNITY) yyerror("community will already be deleted"); else yyerror("redefining set parameter %s", filterset_name(s->type)); return (-1); } } filterset_add(sh, s); return (0); } static int filter_equal(struct filter_rule *fa, struct filter_rule *fb) { if (fa == NULL || fb == NULL) return 0; if (fa->action != fb->action || fa->quick != fb->quick || fa->dir != fb->dir) return 0; if (memcmp(&fa->peer, &fb->peer, sizeof(fa->peer))) return 0; if (memcmp(&fa->match, &fb->match, sizeof(fa->match))) return 0; return 1; } /* do a basic optimization by folding equal rules together */ void optimize_filters(struct filter_head *fh) { struct filter_rule *r, *nr; TAILQ_FOREACH_SAFE(r, fh, entry, nr) { while (filter_equal(r, nr)) { struct filter_set *t; while ((t = TAILQ_FIRST(&nr->set)) != NULL) { TAILQ_REMOVE(&nr->set, t, entry); filterset_add(&r->set, t); } TAILQ_REMOVE(fh, nr, entry); free(nr); nr = TAILQ_NEXT(r, entry); } } } struct filter_rule * get_rule(enum action_types type) { struct filter_rule *r; int out; switch (type) { case ACTION_SET_PREPEND_SELF: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: out = 1; break; default: out = 0; break; } r = (curpeer == curgroup) ? curgroup_filter[out] : curpeer_filter[out]; if (r == NULL) { if ((r = calloc(1, sizeof(struct filter_rule))) == NULL) fatal(NULL); r->quick = 0; r->dir = out ? DIR_OUT : DIR_IN; r->action = ACTION_NONE; TAILQ_INIT(&r->set); if (curpeer == curgroup) { /* group */ r->peer.groupid = curgroup->conf.id; curgroup_filter[out] = r; } else { /* peer */ r->peer.peerid = curpeer->conf.id; curpeer_filter[out] = r; } } return (r); } struct set_table *curset; static int new_as_set(char *name) { struct as_set *aset; if (as_sets_lookup(&conf->as_sets, name) != NULL) { yyerror("as-set \"%s\" already exists", name); return -1; } aset = as_sets_new(&conf->as_sets, name, 0, sizeof(uint32_t)); if (aset == NULL) fatal(NULL); curset = aset->set; return 0; } static void add_as_set(uint32_t as) { if (curset == NULL) fatalx("%s: bad mojo jojo", __func__); if (set_add(curset, &as, 1) != 0) fatal(NULL); } static void done_as_set(void) { curset = NULL; } static struct prefixset * new_prefix_set(char *name, int is_roa) { const char *type = "prefix-set"; struct prefixset_head *sets = &conf->prefixsets; struct prefixset *pset; if (is_roa) { type = "origin-set"; sets = &conf->originsets; } if (find_prefixset(name, sets) != NULL) { yyerror("%s \"%s\" already exists", type, name); return NULL; } if ((pset = calloc(1, sizeof(*pset))) == NULL) fatal("prefixset"); if (strlcpy(pset->name, name, sizeof(pset->name)) >= sizeof(pset->name)) { yyerror("%s \"%s\" too long: max %zu", type, name, sizeof(pset->name) - 1); free(pset); return NULL; } RB_INIT(&pset->psitems); RB_INIT(&pset->roaitems); return pset; } static void add_roa_set(struct prefixset_item *npsi, uint32_t as, uint8_t max, time_t expires) { struct roa *roa, *r; if ((roa = calloc(1, sizeof(*roa))) == NULL) fatal("add_roa_set"); roa->aid = npsi->p.addr.aid; roa->prefixlen = npsi->p.len; roa->maxlen = max; roa->asnum = as; roa->expires = expires; switch (roa->aid) { case AID_INET: roa->prefix.inet = npsi->p.addr.v4; break; case AID_INET6: roa->prefix.inet6 = npsi->p.addr.v6; break; default: fatalx("Bad address family for roa_set address"); } r = RB_INSERT(roa_tree, curroatree, roa); if (r != NULL) { /* just ignore duplicates */ if (r->expires != 0 && expires != 0 && expires > r->expires) r->expires = expires; free(roa); } } static struct rtr_config * get_rtr(struct bgpd_addr *addr) { struct rtr_config *n; n = calloc(1, sizeof(*n)); if (n == NULL) { yyerror("out of memory"); return NULL; } n->remote_addr = *addr; strlcpy(n->descr, log_addr(addr), sizeof(currtr->descr)); return n; } static int insert_rtr(struct rtr_config *new) { static uint32_t id; struct rtr_config *r; if (id == UINT32_MAX) { yyerror("out of rtr session IDs"); return -1; } SIMPLEQ_FOREACH(r, &conf->rtrs, entry) if (memcmp(&r->remote_addr, &new->remote_addr, sizeof(r->remote_addr)) == 0 && r->remote_port == new->remote_port) { yyerror("duplicate rtr session to %s:%u", log_addr(&new->remote_addr), new->remote_port); return -1; } if (cur_rtrs) SIMPLEQ_FOREACH(r, cur_rtrs, entry) if (memcmp(&r->remote_addr, &new->remote_addr, sizeof(r->remote_addr)) == 0 && r->remote_port == new->remote_port) { new->id = r->id; break; } if (new->id == 0) new->id = ++id; SIMPLEQ_INSERT_TAIL(&conf->rtrs, currtr, entry); return 0; } static int merge_aspa_set(uint32_t as, struct aspa_tas_l *tas, time_t expires) { struct aspa_set *aspa, needle = { .as = as }; uint32_t i, num, *newtas; aspa = RB_FIND(aspa_tree, &conf->aspa, &needle); if (aspa == NULL) { if ((aspa = calloc(1, sizeof(*aspa))) == NULL) { yyerror("out of memory"); return -1; } aspa->as = as; aspa->expires = expires; RB_INSERT(aspa_tree, &conf->aspa, aspa); } if (MAX_ASPA_SPAS_COUNT - aspa->num <= tas->num) { yyerror("too many providers for customer-as %u", as); return -1; } num = aspa->num + tas->num; newtas = recallocarray(aspa->tas, aspa->num, num, sizeof(uint32_t)); if (newtas == NULL) { yyerror("out of memory"); return -1; } /* fill starting at the end since the tas list is reversed */ if (num > 0) { for (i = num - 1; tas; tas = tas->next, i--) newtas[i] = tas->as; } aspa->num = num; aspa->tas = newtas; /* take the longest expiry time, same logic as for ROA entries */ if (aspa->expires != 0 && expires != 0 && expires > aspa->expires) aspa->expires = expires; return 0; } static int kw_casecmp(const void *k, const void *e) { return (strcasecmp(k, ((const struct keywords *)e)->k_name)); } static int map_tos(char *s, int *val) { /* DiffServ Codepoints and other TOS mappings */ const struct keywords toswords[] = { { "af11", IPTOS_DSCP_AF11 }, { "af12", IPTOS_DSCP_AF12 }, { "af13", IPTOS_DSCP_AF13 }, { "af21", IPTOS_DSCP_AF21 }, { "af22", IPTOS_DSCP_AF22 }, { "af23", IPTOS_DSCP_AF23 }, { "af31", IPTOS_DSCP_AF31 }, { "af32", IPTOS_DSCP_AF32 }, { "af33", IPTOS_DSCP_AF33 }, { "af41", IPTOS_DSCP_AF41 }, { "af42", IPTOS_DSCP_AF42 }, { "af43", IPTOS_DSCP_AF43 }, { "critical", IPTOS_PREC_CRITIC_ECP }, { "cs0", IPTOS_DSCP_CS0 }, { "cs1", IPTOS_DSCP_CS1 }, { "cs2", IPTOS_DSCP_CS2 }, { "cs3", IPTOS_DSCP_CS3 }, { "cs4", IPTOS_DSCP_CS4 }, { "cs5", IPTOS_DSCP_CS5 }, { "cs6", IPTOS_DSCP_CS6 }, { "cs7", IPTOS_DSCP_CS7 }, { "ef", IPTOS_DSCP_EF }, { "inetcontrol", IPTOS_PREC_INTERNETCONTROL }, { "lowdelay", IPTOS_LOWDELAY }, { "netcontrol", IPTOS_PREC_NETCONTROL }, { "reliability", IPTOS_RELIABILITY }, { "throughput", IPTOS_THROUGHPUT }, }; const struct keywords *p; p = bsearch(s, toswords, nitems(toswords), sizeof(toswords[0]), kw_casecmp); if (p) { *val = p->k_val; return (1); } return (0); } static int getservice(char *n) { struct servent *s; s = getservbyname(n, "tcp"); if (s == NULL) s = getservbyname(n, "udp"); if (s == NULL) return -1; return s->s_port; } static int parse_flags(char *s) { const char *flags = FLOWSPEC_TCP_FLAG_STRING; char *p, *q; uint8_t f = 0; if (curflow->type == FLOWSPEC_TYPE_FRAG) { if (curflow->aid == AID_INET) flags = FLOWSPEC_FRAG_STRING4; else flags = FLOWSPEC_FRAG_STRING6; } for (p = s; *p; p++) { if ((q = strchr(flags, *p)) == NULL) return -1; f |= 1 << (q - flags); } return (f ? f : 0xff); } static void component_finish(int type, uint8_t *data, int len) { uint8_t *last; int i; switch (type) { case FLOWSPEC_TYPE_DEST: case FLOWSPEC_TYPE_SOURCE: /* nothing to do */ return; default: break; } i = 0; do { last = data + i; i += FLOWSPEC_OP_LEN(*last) + 1; } while (i < len); *last |= FLOWSPEC_OP_EOL; } static struct flowspec_config * flow_to_flowspec(struct flowspec_context *ctx) { struct flowspec_config *f; int i, len = 0; uint8_t aid; switch (ctx->aid) { case AID_INET: aid = AID_FLOWSPECv4; break; case AID_INET6: aid = AID_FLOWSPECv6; break; default: return NULL; } for (i = FLOWSPEC_TYPE_MIN; i < FLOWSPEC_TYPE_MAX; i++) if (ctx->components[i] != NULL) len += ctx->complen[i] + 1; f = flowspec_alloc(aid, len); if (f == NULL) return NULL; len = 0; for (i = FLOWSPEC_TYPE_MIN; i < FLOWSPEC_TYPE_MAX; i++) if (ctx->components[i] != NULL) { f->flow->data[len++] = i; component_finish(i, ctx->components[i], ctx->complen[i]); memcpy(f->flow->data + len, ctx->components[i], ctx->complen[i]); len += ctx->complen[i]; } return f; } static void flow_free(struct flowspec_context *ctx) { int i; for (i = 0; i < FLOWSPEC_TYPE_MAX; i++) free(ctx->components[i]); free(ctx); } static int push_prefix(struct bgpd_addr *addr, uint8_t len) { void *data; uint8_t *comp; int complen, l; if (curflow->components[curflow->addr_type] != NULL) { yyerror("flowspec address already set"); return -1; } if (curflow->aid != addr->aid) { yyerror("wrong address family for flowspec address"); return -1; } switch (curflow->aid) { case AID_INET: complen = PREFIX_SIZE(len); data = &addr->v4; break; case AID_INET6: /* IPv6 includes an offset byte */ complen = PREFIX_SIZE(len) + 1; data = &addr->v6; break; default: yyerror("unsupported address family for flowspec address"); return -1; } comp = malloc(complen); if (comp == NULL) { yyerror("out of memory"); return -1; } l = 0; comp[l++] = len; if (curflow->aid == AID_INET6) comp[l++] = 0; memcpy(comp + l, data, complen - l); curflow->complen[curflow->addr_type] = complen; curflow->components[curflow->addr_type] = comp; return 0; } static int push_binop(uint8_t binop, long long val) { uint8_t *comp; int complen; uint8_t u8; if (val < 0 || val > 0xff) { yyerror("unsupported value for flowspec bin_op"); return -1; } u8 = val; complen = curflow->complen[curflow->type]; comp = realloc(curflow->components[curflow->type], complen + 2); if (comp == NULL) { yyerror("out of memory"); return -1; } comp[complen++] = binop; comp[complen++] = u8; curflow->complen[curflow->type] = complen; curflow->components[curflow->type] = comp; return 0; } static uint8_t component_numop(enum comp_ops op, int and, int len) { uint8_t flag = 0; switch (op) { case OP_EQ: flag |= FLOWSPEC_OP_NUM_EQ; break; case OP_NE: flag |= FLOWSPEC_OP_NUM_NOT; break; case OP_LE: flag |= FLOWSPEC_OP_NUM_LE; break; case OP_LT: flag |= FLOWSPEC_OP_NUM_LT; break; case OP_GE: flag |= FLOWSPEC_OP_NUM_GE; break; case OP_GT: flag |= FLOWSPEC_OP_NUM_GT; break; default: fatalx("unsupported op"); } switch (len) { case 2: flag |= 1 << FLOWSPEC_OP_LEN_SHIFT; break; case 4: flag |= 2 << FLOWSPEC_OP_LEN_SHIFT; break; case 8: flag |= 3 << FLOWSPEC_OP_LEN_SHIFT; break; } if (and) flag |= FLOWSPEC_OP_AND; return flag; } static int push_numop(enum comp_ops op, int and, long long val) { uint8_t *comp; void *data; uint32_t u32; uint16_t u16; uint8_t u8; int len, complen; if (val < 0 || val > 0xffffffff) { yyerror("unsupported value for flowspec num_op"); return -1; } else if (val <= 255) { len = 1; u8 = val; data = &u8; } else if (val <= 0xffff) { len = 2; u16 = htons(val); data = &u16; } else { len = 4; u32 = htonl(val); data = &u32; } complen = curflow->complen[curflow->type]; comp = realloc(curflow->components[curflow->type], complen + len + 1); if (comp == NULL) { yyerror("out of memory"); return -1; } comp[complen++] = component_numop(op, and, len); memcpy(comp + complen, data, len); complen += len; curflow->complen[curflow->type] = complen; curflow->components[curflow->type] = comp; return 0; } static int push_unary_numop(enum comp_ops op, long long val) { return push_numop(op, 0, val); } static int push_binary_numop(enum comp_ops op, long long min, long long max) { switch (op) { case OP_RANGE: if (push_numop(OP_GE, 0, min) == -1) return -1; return push_numop(OP_LE, 1, max); case OP_XRANGE: if (push_numop(OP_LT, 0, min) == -1) return -1; return push_numop(OP_GT, 0, max); default: yyerror("unsupported binary flowspec num_op"); return -1; } } struct icmptypeent { const char *name; u_int8_t type; }; struct icmpcodeent { const char *name; u_int8_t type; u_int8_t code; }; static const struct icmptypeent icmp_type[] = { { "echoreq", ICMP_ECHO }, { "echorep", ICMP_ECHOREPLY }, { "unreach", ICMP_UNREACH }, { "squench", ICMP_SOURCEQUENCH }, { "redir", ICMP_REDIRECT }, { "althost", ICMP_ALTHOSTADDR }, { "routeradv", ICMP_ROUTERADVERT }, { "routersol", ICMP_ROUTERSOLICIT }, { "timex", ICMP_TIMXCEED }, { "paramprob", ICMP_PARAMPROB }, { "timereq", ICMP_TSTAMP }, { "timerep", ICMP_TSTAMPREPLY }, { "inforeq", ICMP_IREQ }, { "inforep", ICMP_IREQREPLY }, { "maskreq", ICMP_MASKREQ }, { "maskrep", ICMP_MASKREPLY }, { "trace", ICMP_TRACEROUTE }, { "dataconv", ICMP_DATACONVERR }, { "mobredir", ICMP_MOBILE_REDIRECT }, { "ipv6-where", ICMP_IPV6_WHEREAREYOU }, { "ipv6-here", ICMP_IPV6_IAMHERE }, { "mobregreq", ICMP_MOBILE_REGREQUEST }, { "mobregrep", ICMP_MOBILE_REGREPLY }, { "skip", ICMP_SKIP }, { "photuris", ICMP_PHOTURIS }, }; static const struct icmptypeent icmp6_type[] = { { "unreach", ICMP6_DST_UNREACH }, { "toobig", ICMP6_PACKET_TOO_BIG }, { "timex", ICMP6_TIME_EXCEEDED }, { "paramprob", ICMP6_PARAM_PROB }, { "echoreq", ICMP6_ECHO_REQUEST }, { "echorep", ICMP6_ECHO_REPLY }, { "groupqry", ICMP6_MEMBERSHIP_QUERY }, { "listqry", MLD_LISTENER_QUERY }, { "grouprep", ICMP6_MEMBERSHIP_REPORT }, { "listenrep", MLD_LISTENER_REPORT }, { "groupterm", ICMP6_MEMBERSHIP_REDUCTION }, { "listendone", MLD_LISTENER_DONE }, { "routersol", ND_ROUTER_SOLICIT }, { "routeradv", ND_ROUTER_ADVERT }, { "neighbrsol", ND_NEIGHBOR_SOLICIT }, { "neighbradv", ND_NEIGHBOR_ADVERT }, { "redir", ND_REDIRECT }, { "routrrenum", ICMP6_ROUTER_RENUMBERING }, { "wrureq", ICMP6_WRUREQUEST }, { "wrurep", ICMP6_WRUREPLY }, { "fqdnreq", ICMP6_FQDN_QUERY }, { "fqdnrep", ICMP6_FQDN_REPLY }, { "niqry", ICMP6_NI_QUERY }, { "nirep", ICMP6_NI_REPLY }, { "mtraceresp", MLD_MTRACE_RESP }, { "mtrace", MLD_MTRACE }, { "listenrepv2", MLDV2_LISTENER_REPORT }, }; static const struct icmpcodeent icmp_code[] = { { "net-unr", ICMP_UNREACH, ICMP_UNREACH_NET }, { "host-unr", ICMP_UNREACH, ICMP_UNREACH_HOST }, { "proto-unr", ICMP_UNREACH, ICMP_UNREACH_PROTOCOL }, { "port-unr", ICMP_UNREACH, ICMP_UNREACH_PORT }, { "needfrag", ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG }, { "srcfail", ICMP_UNREACH, ICMP_UNREACH_SRCFAIL }, { "net-unk", ICMP_UNREACH, ICMP_UNREACH_NET_UNKNOWN }, { "host-unk", ICMP_UNREACH, ICMP_UNREACH_HOST_UNKNOWN }, { "isolate", ICMP_UNREACH, ICMP_UNREACH_ISOLATED }, { "net-prohib", ICMP_UNREACH, ICMP_UNREACH_NET_PROHIB }, { "host-prohib", ICMP_UNREACH, ICMP_UNREACH_HOST_PROHIB }, { "net-tos", ICMP_UNREACH, ICMP_UNREACH_TOSNET }, { "host-tos", ICMP_UNREACH, ICMP_UNREACH_TOSHOST }, { "filter-prohib", ICMP_UNREACH, ICMP_UNREACH_FILTER_PROHIB }, { "host-preced", ICMP_UNREACH, ICMP_UNREACH_HOST_PRECEDENCE }, { "cutoff-preced", ICMP_UNREACH, ICMP_UNREACH_PRECEDENCE_CUTOFF }, { "redir-net", ICMP_REDIRECT, ICMP_REDIRECT_NET }, { "redir-host", ICMP_REDIRECT, ICMP_REDIRECT_HOST }, { "redir-tos-net", ICMP_REDIRECT, ICMP_REDIRECT_TOSNET }, { "redir-tos-host", ICMP_REDIRECT, ICMP_REDIRECT_TOSHOST }, { "normal-adv", ICMP_ROUTERADVERT, ICMP_ROUTERADVERT_NORMAL }, { "common-adv", ICMP_ROUTERADVERT, ICMP_ROUTERADVERT_NOROUTE_COMMON }, { "transit", ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS }, { "reassemb", ICMP_TIMXCEED, ICMP_TIMXCEED_REASS }, { "badhead", ICMP_PARAMPROB, ICMP_PARAMPROB_ERRATPTR }, { "optmiss", ICMP_PARAMPROB, ICMP_PARAMPROB_OPTABSENT }, { "badlen", ICMP_PARAMPROB, ICMP_PARAMPROB_LENGTH }, { "unknown-ind", ICMP_PHOTURIS, ICMP_PHOTURIS_UNKNOWN_INDEX }, { "auth-fail", ICMP_PHOTURIS, ICMP_PHOTURIS_AUTH_FAILED }, { "decrypt-fail", ICMP_PHOTURIS, ICMP_PHOTURIS_DECRYPT_FAILED }, }; static const struct icmpcodeent icmp6_code[] = { { "admin-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN }, { "noroute-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOROUTE }, { "beyond-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_BEYONDSCOPE }, { "addr-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR }, { "port-unr", ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT }, { "transit", ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_TRANSIT }, { "reassemb", ICMP6_TIME_EXCEEDED, ICMP6_TIME_EXCEED_REASSEMBLY }, { "badhead", ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER }, { "nxthdr", ICMP6_PARAM_PROB, ICMP6_PARAMPROB_NEXTHEADER }, { "redironlink", ND_REDIRECT, ND_REDIRECT_ONLINK }, { "redirrouter", ND_REDIRECT, ND_REDIRECT_ROUTER }, }; static int geticmptypebyname(char *w, uint8_t aid) { size_t i; switch (aid) { case AID_INET: for (i = 0; i < nitems(icmp_type); i++) { if (!strcmp(w, icmp_type[i].name)) return (icmp_type[i].type); } break; case AID_INET6: for (i = 0; i < nitems(icmp6_type); i++) { if (!strcmp(w, icmp6_type[i].name)) return (icmp6_type[i].type); } break; } return -1; } static int geticmpcodebyname(u_long type, char *w, uint8_t aid) { size_t i; switch (aid) { case AID_INET: for (i = 0; i < nitems(icmp_code); i++) { if (type == icmp_code[i].type && !strcmp(w, icmp_code[i].name)) return (icmp_code[i].code); } break; case AID_INET6: for (i = 0; i < nitems(icmp6_code); i++) { if (type == icmp6_code[i].type && !strcmp(w, icmp6_code[i].name)) return (icmp6_code[i].code); } break; } return -1; } static int merge_auth_conf(struct auth_config *to, struct auth_config *from) { if (to->method != 0) { /* extra magic for manual ipsec rules */ if (to->method == from->method && (to->method == AUTH_IPSEC_MANUAL_ESP || to->method == AUTH_IPSEC_MANUAL_AH)) { if (to->spi_in == 0 && from->spi_in != 0) { to->spi_in = from->spi_in; to->auth_alg_in = from->auth_alg_in; to->enc_alg_in = from->enc_alg_in; memcpy(to->enc_key_in, from->enc_key_in, sizeof(to->enc_key_in)); to->enc_keylen_in = from->enc_keylen_in; to->auth_keylen_in = from->auth_keylen_in; return 1; } else if (to->spi_out == 0 && from->spi_out != 0) { to->spi_out = from->spi_out; to->auth_alg_out = from->auth_alg_out; to->enc_alg_out = from->enc_alg_out; memcpy(to->enc_key_out, from->enc_key_out, sizeof(to->enc_key_out)); to->enc_keylen_out = from->enc_keylen_out; to->auth_keylen_out = from->auth_keylen_out; return 1; } } yyerror("auth method cannot be redefined"); return 0; } *to = *from; return 1; } openbgpd-8.8/src/bgpd/config.c100644 001750 001750 00000043143 14751151130 0012010/* $OpenBSD: config.c,v 1.113 2024/12/13 19:21:03 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" int host_ip(const char *, struct bgpd_addr *, uint8_t *); void free_networks(struct network_head *); void free_flowspecs(struct flowspec_tree *); struct bgpd_config * new_config(void) { struct bgpd_config *conf; if ((conf = calloc(1, sizeof(struct bgpd_config))) == NULL) fatal(NULL); if ((conf->filters = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); if ((conf->listen_addrs = calloc(1, sizeof(struct listen_addrs))) == NULL) fatal(NULL); if ((conf->mrt = calloc(1, sizeof(struct mrt_head))) == NULL) fatal(NULL); /* init the various list for later */ RB_INIT(&conf->peers); TAILQ_INIT(&conf->networks); RB_INIT(&conf->flowspecs); SIMPLEQ_INIT(&conf->l3vpns); SIMPLEQ_INIT(&conf->prefixsets); SIMPLEQ_INIT(&conf->originsets); SIMPLEQ_INIT(&conf->rde_prefixsets); SIMPLEQ_INIT(&conf->rde_originsets); RB_INIT(&conf->roa); RB_INIT(&conf->aspa); SIMPLEQ_INIT(&conf->as_sets); SIMPLEQ_INIT(&conf->rtrs); TAILQ_INIT(conf->filters); TAILQ_INIT(conf->listen_addrs); LIST_INIT(conf->mrt); return (conf); } void copy_config(struct bgpd_config *to, struct bgpd_config *from) { to->flags = from->flags; to->log = from->log; to->default_tableid = from->default_tableid; to->bgpid = from->bgpid; to->clusterid = from->clusterid; to->as = from->as; to->short_as = from->short_as; to->holdtime = from->holdtime; to->min_holdtime = from->min_holdtime; to->staletime = from->staletime; to->connectretry = from->connectretry; to->fib_priority = from->fib_priority; to->filtered_in_locrib = from->filtered_in_locrib; } void network_free(struct network *n) { rtlabel_unref(n->net.rtlabel); filterset_free(&n->net.attrset); free(n); } void free_networks(struct network_head *networks) { struct network *n; while ((n = TAILQ_FIRST(networks)) != NULL) { TAILQ_REMOVE(networks, n, entry); network_free(n); } } struct flowspec_config * flowspec_alloc(uint8_t aid, int len) { struct flowspec_config *conf; struct flowspec *flow; flow = malloc(FLOWSPEC_SIZE + len); if (flow == NULL) return NULL; memset(flow, 0, FLOWSPEC_SIZE); conf = calloc(1, sizeof(*conf)); if (conf == NULL) { free(flow); return NULL; } conf->flow = flow; TAILQ_INIT(&conf->attrset); flow->len = len; flow->aid = aid; return conf; } void flowspec_free(struct flowspec_config *f) { filterset_free(&f->attrset); free(f->flow); free(f); } void free_flowspecs(struct flowspec_tree *flowspecs) { struct flowspec_config *f, *nf; RB_FOREACH_SAFE(f, flowspec_tree, flowspecs, nf) { RB_REMOVE(flowspec_tree, flowspecs, f); flowspec_free(f); } } void free_l3vpns(struct l3vpn_head *l3vpns) { struct l3vpn *vpn; while ((vpn = SIMPLEQ_FIRST(l3vpns)) != NULL) { SIMPLEQ_REMOVE_HEAD(l3vpns, entry); filterset_free(&vpn->export); filterset_free(&vpn->import); free_networks(&vpn->net_l); free(vpn); } } void free_prefixsets(struct prefixset_head *psh) { struct prefixset *ps; while (!SIMPLEQ_EMPTY(psh)) { ps = SIMPLEQ_FIRST(psh); free_roatree(&ps->roaitems); free_prefixtree(&ps->psitems); SIMPLEQ_REMOVE_HEAD(psh, entry); free(ps); } } void free_rde_prefixsets(struct rde_prefixset_head *psh) { struct rde_prefixset *ps; if (psh == NULL) return; while (!SIMPLEQ_EMPTY(psh)) { ps = SIMPLEQ_FIRST(psh); trie_free(&ps->th); SIMPLEQ_REMOVE_HEAD(psh, entry); free(ps); } } void free_prefixtree(struct prefixset_tree *p) { struct prefixset_item *psi, *npsi; RB_FOREACH_SAFE(psi, prefixset_tree, p, npsi) { RB_REMOVE(prefixset_tree, p, psi); free(psi); } } void free_roatree(struct roa_tree *r) { struct roa *roa, *nroa; RB_FOREACH_SAFE(roa, roa_tree, r, nroa) { RB_REMOVE(roa_tree, r, roa); free(roa); } } void free_aspa(struct aspa_set *aspa) { if (aspa == NULL) return; free(aspa->tas); free(aspa); } void free_aspatree(struct aspa_tree *a) { struct aspa_set *aspa, *naspa; RB_FOREACH_SAFE(aspa, aspa_tree, a, naspa) { RB_REMOVE(aspa_tree, a, aspa); free_aspa(aspa); } } void free_rtrs(struct rtr_config_head *rh) { struct rtr_config *r; while (!SIMPLEQ_EMPTY(rh)) { r = SIMPLEQ_FIRST(rh); SIMPLEQ_REMOVE_HEAD(rh, entry); free(r); } } void free_config(struct bgpd_config *conf) { struct peer *p, *next; struct listen_addr *la; struct mrt *m; free_l3vpns(&conf->l3vpns); free_networks(&conf->networks); free_flowspecs(&conf->flowspecs); filterlist_free(conf->filters); free_prefixsets(&conf->prefixsets); free_prefixsets(&conf->originsets); free_rde_prefixsets(&conf->rde_prefixsets); free_rde_prefixsets(&conf->rde_originsets); as_sets_free(&conf->as_sets); free_roatree(&conf->roa); free_aspatree(&conf->aspa); free_rtrs(&conf->rtrs); while ((la = TAILQ_FIRST(conf->listen_addrs)) != NULL) { TAILQ_REMOVE(conf->listen_addrs, la, entry); free(la); } free(conf->listen_addrs); while ((m = LIST_FIRST(conf->mrt)) != NULL) { LIST_REMOVE(m, entry); free(m); } free(conf->mrt); RB_FOREACH_SAFE(p, peer_head, &conf->peers, next) { RB_REMOVE(peer_head, &conf->peers, p); free(p); } free(conf->csock); free(conf->rcsock); free(conf); } void merge_config(struct bgpd_config *xconf, struct bgpd_config *conf) { struct listen_addr *nla, *ola, *next; struct peer *p, *np, *nextp; struct flowspec_config *f, *nextf, *xf; /* * merge the freshly parsed conf into the running xconf */ /* adjust FIB priority if changed */ /* if xconf is uninitialized we get RTP_NONE */ if (xconf->fib_priority != conf->fib_priority) { kr_fib_decouple_all(); kr_fib_prio_set(conf->fib_priority); kr_fib_couple_all(); } /* take over the easy config changes */ copy_config(xconf, conf); /* clear old control sockets and use new */ free(xconf->csock); free(xconf->rcsock); xconf->csock = conf->csock; xconf->rcsock = conf->rcsock; /* set old one to NULL so we don't double free */ conf->csock = NULL; conf->rcsock = NULL; /* clear all current filters and take over the new ones */ filterlist_free(xconf->filters); xconf->filters = conf->filters; conf->filters = NULL; /* merge mrt config */ mrt_mergeconfig(xconf->mrt, conf->mrt); /* switch the roa, first remove the old one */ free_roatree(&xconf->roa); /* then move the RB tree root */ RB_ROOT(&xconf->roa) = RB_ROOT(&conf->roa); RB_ROOT(&conf->roa) = NULL; /* switch the aspa, first remove the old one */ free_aspatree(&xconf->aspa); /* then move the RB tree root */ RB_ROOT(&xconf->aspa) = RB_ROOT(&conf->aspa); RB_ROOT(&conf->aspa) = NULL; /* switch the rtr_configs, first remove the old ones */ free_rtrs(&xconf->rtrs); SIMPLEQ_CONCAT(&xconf->rtrs, &conf->rtrs); /* switch the prefixsets, first remove the old ones */ free_prefixsets(&xconf->prefixsets); SIMPLEQ_CONCAT(&xconf->prefixsets, &conf->prefixsets); /* switch the originsets, first remove the old ones */ free_prefixsets(&xconf->originsets); SIMPLEQ_CONCAT(&xconf->originsets, &conf->originsets); /* switch the as_sets, first remove the old ones */ as_sets_free(&xconf->as_sets); SIMPLEQ_CONCAT(&xconf->as_sets, &conf->as_sets); /* switch the network statements, but first remove the old ones */ free_networks(&xconf->networks); TAILQ_CONCAT(&xconf->networks, &conf->networks, entry); /* * Merge the flowspec statements. Mark the old ones for deletion * which happens when the flowspec is sent to the RDE. */ RB_FOREACH(f, flowspec_tree, &xconf->flowspecs) f->reconf_action = RECONF_DELETE; RB_FOREACH_SAFE(f, flowspec_tree, &conf->flowspecs, nextf) { RB_REMOVE(flowspec_tree, &conf->flowspecs, f); xf = RB_INSERT(flowspec_tree, &xconf->flowspecs, f); if (xf != NULL) { filterset_free(&xf->attrset); filterset_move(&f->attrset, &xf->attrset); flowspec_free(f); xf->reconf_action = RECONF_KEEP; } else f->reconf_action = RECONF_KEEP; } /* switch the l3vpn configs, first remove the old ones */ free_l3vpns(&xconf->l3vpns); SIMPLEQ_CONCAT(&xconf->l3vpns, &conf->l3vpns); /* * merge new listeners: * -flag all existing ones as to be deleted * -those that are in both new and old: flag to keep * -new ones get inserted and flagged as to reinit * -remove all that are still flagged for deletion */ TAILQ_FOREACH(nla, xconf->listen_addrs, entry) nla->reconf = RECONF_DELETE; /* no new listeners? preserve default ones */ if (TAILQ_EMPTY(conf->listen_addrs)) TAILQ_FOREACH(ola, xconf->listen_addrs, entry) if (ola->flags & DEFAULT_LISTENER) ola->reconf = RECONF_KEEP; /* else loop over listeners and merge configs */ for (nla = TAILQ_FIRST(conf->listen_addrs); nla != NULL; nla = next) { next = TAILQ_NEXT(nla, entry); TAILQ_FOREACH(ola, xconf->listen_addrs, entry) if (!memcmp(&nla->sa, &ola->sa, sizeof(nla->sa))) break; if (ola == NULL) { /* new listener, copy over */ TAILQ_REMOVE(conf->listen_addrs, nla, entry); TAILQ_INSERT_TAIL(xconf->listen_addrs, nla, entry); nla->reconf = RECONF_REINIT; } else /* exists, just flag */ ola->reconf = RECONF_KEEP; } /* finally clean up the original list and remove all stale entries */ for (nla = TAILQ_FIRST(xconf->listen_addrs); nla != NULL; nla = next) { next = TAILQ_NEXT(nla, entry); if (nla->reconf == RECONF_DELETE) { TAILQ_REMOVE(xconf->listen_addrs, nla, entry); free(nla); } } /* * merge peers: * - need to know which peers are new, replaced and removed * - walk over old peers and check if there is a corresponding new * peer if so mark it RECONF_KEEP. Mark all old peers RECONF_DELETE. */ RB_FOREACH_SAFE(p, peer_head, &xconf->peers, nextp) { np = getpeerbyid(conf, p->conf.id); if (np != NULL) { np->reconf_action = RECONF_KEEP; /* keep the auth state since parent needs it */ np->auth_state = p->auth_state; RB_REMOVE(peer_head, &xconf->peers, p); free(p); } else { p->reconf_action = RECONF_DELETE; } } RB_FOREACH_SAFE(np, peer_head, &conf->peers, nextp) { RB_REMOVE(peer_head, &conf->peers, np); if (RB_INSERT(peer_head, &xconf->peers, np) != NULL) fatalx("%s: peer tree is corrupt", __func__); } /* conf is merged so free it */ free_config(conf); } void free_deleted_peers(struct bgpd_config *conf) { struct peer *p, *nextp; RB_FOREACH_SAFE(p, peer_head, &conf->peers, nextp) { if (p->reconf_action == RECONF_DELETE) { /* peer no longer exists, clear pfkey state */ pfkey_remove(&p->auth_state); RB_REMOVE(peer_head, &conf->peers, p); free(p); } } } uint32_t get_bgpid(void) { struct ifaddrs *ifap, *ifa; uint32_t ip = 0, cur, localnet; localnet = INADDR_LOOPBACK & IN_CLASSA_NET; if (getifaddrs(&ifap) == -1) fatal("getifaddrs"); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET) continue; cur = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; cur = ntohl(cur); if ((cur & localnet) == localnet) /* skip 127/8 */ continue; if (cur > ip) ip = cur; } freeifaddrs(ifap); return (ip); } int host(const char *s, struct bgpd_addr *h, uint8_t *len) { int mask = 128; char *p, *ps; const char *errstr; if ((ps = strdup(s)) == NULL) fatal("%s: strdup", __func__); if ((p = strrchr(ps, '/')) != NULL) { mask = strtonum(p+1, 0, 128, &errstr); if (errstr) { log_warnx("prefixlen is %s: %s", errstr, p); free(ps); return (0); } p[0] = '\0'; } memset(h, 0, sizeof(*h)); if (host_ip(ps, h, len) == 0) { free(ps); return (0); } if (p != NULL) *len = mask; free(ps); return (1); } int host_ip(const char *s, struct bgpd_addr *h, uint8_t *len) { struct addrinfo hints, *res; int bits; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; if (getaddrinfo(s, NULL, &hints, &res) == 0) { *len = res->ai_family == AF_INET6 ? 128 : 32; sa2addr(res->ai_addr, h, NULL); freeaddrinfo(res); } else { /* ie. for 10/8 parsing */ if ((bits = inet_net_pton(AF_INET, s, &h->v4, sizeof(h->v4))) == -1) return (0); *len = bits; h->aid = AID_INET; } return (1); } int prepare_listeners(struct bgpd_config *conf) { struct listen_addr *la, *next; int opt = 1; int r = 0; for (la = TAILQ_FIRST(conf->listen_addrs); la != NULL; la = next) { next = TAILQ_NEXT(la, entry); if (la->reconf != RECONF_REINIT) continue; if ((la->fd = socket(la->sa.ss_family, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_TCP)) == -1) { if (la->flags & DEFAULT_LISTENER && (errno == EAFNOSUPPORT || errno == EPROTONOSUPPORT)) { TAILQ_REMOVE(conf->listen_addrs, la, entry); free(la); continue; } else fatal("socket"); } opt = 1; if (setsockopt(la->fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1) fatal("setsockopt SO_REUSEADDR"); #ifdef IPV6_V6ONLY if (la->sa.ss_family == AF_INET6) { opt = 1; if (setsockopt(la->fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt)) == -1) fatal("setsockopt IPV6_V6ONLY"); } #endif if (bind(la->fd, (struct sockaddr *)&la->sa, la->sa_len) == -1) { switch (la->sa.ss_family) { case AF_INET: log_warn("cannot bind to %s:%u", log_sockaddr((struct sockaddr *)&la->sa, la->sa_len), ntohs(((struct sockaddr_in *) &la->sa)->sin_port)); break; case AF_INET6: log_warn("cannot bind to [%s]:%u", log_sockaddr((struct sockaddr *)&la->sa, la->sa_len), ntohs(((struct sockaddr_in6 *) &la->sa)->sin6_port)); break; default: log_warn("cannot bind to %s", log_sockaddr((struct sockaddr *)&la->sa, la->sa_len)); break; } close(la->fd); TAILQ_REMOVE(conf->listen_addrs, la, entry); free(la); r = -1; continue; } } return (r); } void expand_networks(struct bgpd_config *c, struct network_head *nw) { struct network *n, *m, *tmp; struct prefixset *ps; struct prefixset_item *psi; TAILQ_FOREACH_SAFE(n, nw, entry, tmp) { if (n->net.type == NETWORK_PREFIXSET) { TAILQ_REMOVE(nw, n, entry); if ((ps = find_prefixset(n->net.psname, &c->prefixsets)) == NULL) fatal("%s: prefixset %s not found", __func__, n->net.psname); RB_FOREACH(psi, prefixset_tree, &ps->psitems) { if ((m = calloc(1, sizeof(struct network))) == NULL) fatal(NULL); memcpy(&m->net.prefix, &psi->p.addr, sizeof(m->net.prefix)); m->net.prefixlen = psi->p.len; filterset_copy(&n->net.attrset, &m->net.attrset); TAILQ_INSERT_TAIL(nw, m, entry); } network_free(n); } } } static inline int prefixset_cmp(struct prefixset_item *a, struct prefixset_item *b) { int i; if (a->p.addr.aid < b->p.addr.aid) return (-1); if (a->p.addr.aid > b->p.addr.aid) return (1); switch (a->p.addr.aid) { case AID_INET: i = memcmp(&a->p.addr.v4, &b->p.addr.v4, sizeof(struct in_addr)); break; case AID_INET6: i = memcmp(&a->p.addr.v6, &b->p.addr.v6, sizeof(struct in6_addr)); break; default: fatalx("%s: unknown af", __func__); } if (i > 0) return (1); if (i < 0) return (-1); if (a->p.len < b->p.len) return (-1); if (a->p.len > b->p.len) return (1); if (a->p.len_min < b->p.len_min) return (-1); if (a->p.len_min > b->p.len_min) return (1); if (a->p.len_max < b->p.len_max) return (-1); if (a->p.len_max > b->p.len_max) return (1); return (0); } RB_GENERATE(prefixset_tree, prefixset_item, entry, prefixset_cmp); static inline int roa_cmp(struct roa *a, struct roa *b) { int i; if (a->aid < b->aid) return (-1); if (a->aid > b->aid) return (1); switch (a->aid) { case AID_INET: i = memcmp(&a->prefix.inet, &b->prefix.inet, sizeof(struct in_addr)); break; case AID_INET6: i = memcmp(&a->prefix.inet6, &b->prefix.inet6, sizeof(struct in6_addr)); break; default: fatalx("%s: unknown af", __func__); } if (i > 0) return (1); if (i < 0) return (-1); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); if (a->asnum < b->asnum) return (-1); if (a->asnum > b->asnum) return (1); if (a->maxlen < b->maxlen) return (-1); if (a->maxlen > b->maxlen) return (1); return (0); } RB_GENERATE(roa_tree, roa, entry, roa_cmp); static inline int aspa_cmp(struct aspa_set *a, struct aspa_set *b) { if (a->as < b->as) return (-1); if (a->as > b->as) return (1); return (0); } RB_GENERATE(aspa_tree, aspa_set, entry, aspa_cmp); static inline int flowspec_config_cmp(struct flowspec_config *a, struct flowspec_config *b) { if (a->flow->aid < b->flow->aid) return -1; if (a->flow->aid > b->flow->aid) return 1; return flowspec_cmp(a->flow->data, a->flow->len, b->flow->data, b->flow->len, a->flow->aid == AID_FLOWSPECv6); } RB_GENERATE(flowspec_tree, flowspec_config, entry, flowspec_config_cmp); openbgpd-8.8/src/bgpd/rde.c100644 001750 001750 00000373204 14751151130 0011321/* $OpenBSD: rde.c,v 1.651 2025/02/04 18:16:56 denis Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2016 Job Snijders * Copyright (c) 2016 Peter Hessler * Copyright (c) 2018 Sebastian Benoit * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "log.h" #define PFD_PIPE_MAIN 0 #define PFD_PIPE_SESSION 1 #define PFD_PIPE_SESSION_CTL 2 #define PFD_PIPE_ROA 3 #define PFD_PIPE_COUNT 4 void rde_sighdlr(int); void rde_dispatch_imsg_session(struct imsgbuf *); void rde_dispatch_imsg_parent(struct imsgbuf *); void rde_dispatch_imsg_rtr(struct imsgbuf *); void rde_dispatch_imsg_peer(struct rde_peer *, void *); void rde_update_dispatch(struct rde_peer *, struct ibuf *); int rde_update_update(struct rde_peer *, uint32_t, struct filterstate *, struct bgpd_addr *, uint8_t); void rde_update_withdraw(struct rde_peer *, uint32_t, struct bgpd_addr *, uint8_t); int rde_attr_parse(struct ibuf *, struct rde_peer *, struct filterstate *, struct ibuf *, struct ibuf *); int rde_attr_add(struct filterstate *, struct ibuf *); uint8_t rde_attr_missing(struct rde_aspath *, int, uint16_t); int rde_get_mp_nexthop(struct ibuf *, uint8_t, struct rde_peer *, struct filterstate *); void rde_as4byte_fixup(struct rde_peer *, struct rde_aspath *); uint8_t rde_aspa_validity(struct rde_peer *, struct rde_aspath *, uint8_t); void rde_reflector(struct rde_peer *, struct rde_aspath *); void rde_dump_ctx_new(struct ctl_show_rib_request *, pid_t, enum imsg_type); void rde_dump_ctx_throttle(pid_t, int); void rde_dump_ctx_terminate(pid_t); void rde_dump_mrt_new(struct mrt *, pid_t, int); int rde_l3vpn_import(struct rde_community *, struct l3vpn *); static void rde_commit_pftable(void); void rde_reload_done(void); static void rde_softreconfig_in_done(void *, uint8_t); static void rde_softreconfig_out_done(void *, uint8_t); static void rde_softreconfig_done(void); static void rde_softreconfig_out(struct rib_entry *, void *); static void rde_softreconfig_in(struct rib_entry *, void *); static void rde_softreconfig_sync_reeval(struct rib_entry *, void *); static void rde_softreconfig_sync_fib(struct rib_entry *, void *); static void rde_softreconfig_sync_done(void *, uint8_t); static void rde_rpki_reload(void); static int rde_roa_reload(void); static int rde_aspa_reload(void); int rde_update_queue_pending(void); void rde_update_queue_runner(uint8_t); struct rde_prefixset *rde_find_prefixset(char *, struct rde_prefixset_head *); void rde_mark_prefixsets_dirty(struct rde_prefixset_head *, struct rde_prefixset_head *); uint8_t rde_roa_validity(struct rde_prefixset *, struct bgpd_addr *, uint8_t, uint32_t); static void rde_peer_recv_eor(struct rde_peer *, uint8_t); static void rde_peer_send_eor(struct rde_peer *, uint8_t); void network_add(struct network_config *, struct filterstate *); void network_delete(struct network_config *); static void network_dump_upcall(struct rib_entry *, void *); static void network_flush_upcall(struct rib_entry *, void *); void flowspec_add(struct flowspec *, struct filterstate *, struct filter_set_head *); void flowspec_delete(struct flowspec *); static void flowspec_flush_upcall(struct rib_entry *, void *); static void flowspec_dump_upcall(struct rib_entry *, void *); static void flowspec_dump_done(void *, uint8_t); void rde_shutdown(void); static int ovs_match(struct prefix *, uint32_t); static int avs_match(struct prefix *, uint32_t); static struct imsgbuf *ibuf_se; static struct imsgbuf *ibuf_se_ctl; static struct imsgbuf *ibuf_rtr; static struct imsgbuf *ibuf_main; static struct bgpd_config *conf, *nconf; static struct rde_prefixset rde_roa, roa_new; static struct rde_aspa *rde_aspa, *aspa_new; static uint8_t rde_aspa_generation; volatile sig_atomic_t rde_quit = 0; struct filter_head *out_rules, *out_rules_tmp; struct rde_memstats rdemem; int softreconfig; static int rde_eval_all; extern struct peer_tree peertable; extern struct rde_peer *peerself; struct rde_dump_ctx { LIST_ENTRY(rde_dump_ctx) entry; struct ctl_show_rib_request req; uint32_t peerid; uint8_t throttled; }; LIST_HEAD(, rde_dump_ctx) rde_dump_h = LIST_HEAD_INITIALIZER(rde_dump_h); struct rde_mrt_ctx { LIST_ENTRY(rde_mrt_ctx) entry; struct mrt mrt; }; LIST_HEAD(, rde_mrt_ctx) rde_mrts = LIST_HEAD_INITIALIZER(rde_mrts); u_int rde_mrt_cnt; void rde_sighdlr(int sig) { switch (sig) { case SIGINT: case SIGTERM: rde_quit = 1; break; } } void rde_main(int debug, int verbose) { struct passwd *pw; struct pollfd *pfd = NULL; struct rde_mrt_ctx *mctx, *xmctx; void *newp; u_int pfd_elms = 0, i, j; int timeout; uint8_t aid; log_init(debug, LOG_DAEMON); log_setverbose(verbose); log_procinit(log_procnames[PROC_RDE]); if ((pw = getpwnam(BGPD_USER)) == NULL) fatal("getpwnam"); if (chroot(pw->pw_dir) == -1) fatal("chroot"); if (chdir("/") == -1) fatal("chdir(\"/\")"); setproctitle("route decision engine"); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("can't drop privileges"); if (pledge("stdio recvfd", NULL) == -1) fatal("pledge"); signal(SIGTERM, rde_sighdlr); signal(SIGINT, rde_sighdlr); signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGALRM, SIG_IGN); signal(SIGUSR1, SIG_IGN); if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL) fatal(NULL); if (imsgbuf_init(ibuf_main, 3) == -1 || imsgbuf_set_maxsize(ibuf_main, MAX_BGPD_IMSGSIZE) == -1) fatal(NULL); imsgbuf_allow_fdpass(ibuf_main); /* initialize the RIB structures */ if ((out_rules = calloc(1, sizeof(struct filter_head))) == NULL) fatal(NULL); TAILQ_INIT(out_rules); pt_init(); peer_init(out_rules); /* make sure the default RIBs are setup */ rib_new("Adj-RIB-In", 0, F_RIB_NOFIB | F_RIB_NOEVALUATE); conf = new_config(); log_info("route decision engine ready"); while (rde_quit == 0) { if (pfd_elms < PFD_PIPE_COUNT + rde_mrt_cnt) { if ((newp = reallocarray(pfd, PFD_PIPE_COUNT + rde_mrt_cnt, sizeof(struct pollfd))) == NULL) { /* panic for now */ log_warn("could not resize pfd from %u -> %u" " entries", pfd_elms, PFD_PIPE_COUNT + rde_mrt_cnt); fatalx("exiting"); } pfd = newp; pfd_elms = PFD_PIPE_COUNT + rde_mrt_cnt; } timeout = -1; memset(pfd, 0, sizeof(struct pollfd) * pfd_elms); set_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main); set_pollfd(&pfd[PFD_PIPE_SESSION], ibuf_se); set_pollfd(&pfd[PFD_PIPE_SESSION_CTL], ibuf_se_ctl); set_pollfd(&pfd[PFD_PIPE_ROA], ibuf_rtr); i = PFD_PIPE_COUNT; for (mctx = LIST_FIRST(&rde_mrts); mctx != 0; mctx = xmctx) { xmctx = LIST_NEXT(mctx, entry); if (i >= pfd_elms) fatalx("poll pfd too small"); if (msgbuf_queuelen(mctx->mrt.wbuf) > 0) { pfd[i].fd = mctx->mrt.fd; pfd[i].events = POLLOUT; i++; } else if (mctx->mrt.state == MRT_STATE_REMOVE) { mrt_clean(&mctx->mrt); LIST_REMOVE(mctx, entry); free(mctx); rde_mrt_cnt--; } } if (peer_work_pending() || rde_update_queue_pending() || nexthop_pending() || rib_dump_pending()) timeout = 0; if (poll(pfd, i, timeout) == -1) { if (errno == EINTR) continue; fatal("poll error"); } if (handle_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main) == -1) fatalx("Lost connection to parent"); else rde_dispatch_imsg_parent(ibuf_main); if (handle_pollfd(&pfd[PFD_PIPE_SESSION], ibuf_se) == -1) { log_warnx("RDE: Lost connection to SE"); imsgbuf_clear(ibuf_se); free(ibuf_se); ibuf_se = NULL; } else rde_dispatch_imsg_session(ibuf_se); if (handle_pollfd(&pfd[PFD_PIPE_SESSION_CTL], ibuf_se_ctl) == -1) { log_warnx("RDE: Lost connection to SE control"); imsgbuf_clear(ibuf_se_ctl); free(ibuf_se_ctl); ibuf_se_ctl = NULL; } else rde_dispatch_imsg_session(ibuf_se_ctl); if (handle_pollfd(&pfd[PFD_PIPE_ROA], ibuf_rtr) == -1) { log_warnx("RDE: Lost connection to ROA"); imsgbuf_clear(ibuf_rtr); free(ibuf_rtr); ibuf_rtr = NULL; } else rde_dispatch_imsg_rtr(ibuf_rtr); for (j = PFD_PIPE_COUNT, mctx = LIST_FIRST(&rde_mrts); j < i && mctx != 0; j++) { if (pfd[j].fd == mctx->mrt.fd && pfd[j].revents & POLLOUT) mrt_write(&mctx->mrt); mctx = LIST_NEXT(mctx, entry); } peer_foreach(rde_dispatch_imsg_peer, NULL); peer_reaper(NULL); rib_dump_runner(); nexthop_runner(); if (ibuf_se && imsgbuf_queuelen(ibuf_se) < SESS_MSG_HIGH_MARK) { for (aid = AID_MIN; aid < AID_MAX; aid++) rde_update_queue_runner(aid); } /* commit pftable once per poll loop */ rde_commit_pftable(); } /* do not clean up on shutdown on production, it takes ages. */ if (debug) rde_shutdown(); free_config(conf); free(pfd); /* close pipes */ if (ibuf_se) { imsgbuf_clear(ibuf_se); close(ibuf_se->fd); free(ibuf_se); } if (ibuf_se_ctl) { imsgbuf_clear(ibuf_se_ctl); close(ibuf_se_ctl->fd); free(ibuf_se_ctl); } if (ibuf_rtr) { imsgbuf_clear(ibuf_rtr); close(ibuf_rtr->fd); free(ibuf_rtr); } imsgbuf_clear(ibuf_main); close(ibuf_main->fd); free(ibuf_main); while ((mctx = LIST_FIRST(&rde_mrts)) != NULL) { mrt_clean(&mctx->mrt); LIST_REMOVE(mctx, entry); free(mctx); } log_info("route decision engine exiting"); exit(0); } struct network_config netconf_s, netconf_p; struct filterstate netconf_state; struct filter_set_head session_set = TAILQ_HEAD_INITIALIZER(session_set); struct filter_set_head parent_set = TAILQ_HEAD_INITIALIZER(parent_set); void rde_dispatch_imsg_session(struct imsgbuf *imsgbuf) { static struct flowspec *curflow; struct imsg imsg; struct ibuf ibuf; struct rde_peer_stats stats; struct ctl_show_set cset; struct ctl_show_rib csr; struct ctl_show_rib_request req; struct session_up sup; struct peer_config pconf; struct rde_peer *peer; struct rde_aspath *asp; struct filter_set *s; struct as_set *aset; struct rde_prefixset *pset; ssize_t n; uint32_t peerid; pid_t pid; int verbose; uint8_t aid; while (imsgbuf) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("rde_dispatch_imsg_session: imsg_get error"); if (n == 0) break; peerid = imsg_get_id(&imsg); pid = imsg_get_pid(&imsg); switch (imsg_get_type(&imsg)) { case IMSG_UPDATE: case IMSG_REFRESH: if ((peer = peer_get(peerid)) == NULL) { log_warnx("rde_dispatch: unknown peer id %d", peerid); break; } if (peer_is_up(peer)) peer_imsg_push(peer, &imsg); break; case IMSG_SESSION_ADD: if (imsg_get_data(&imsg, &pconf, sizeof(pconf)) == -1) fatalx("incorrect size of session request"); peer = peer_add(peerid, &pconf, out_rules); /* make sure rde_eval_all is on if needed. */ if (peer->conf.flags & PEERFLAG_EVALUATE_ALL) rde_eval_all = 1; break; case IMSG_SESSION_UP: if ((peer = peer_get(peerid)) == NULL) { log_warnx("%s: unknown peer id %d", "IMSG_SESSION_UP", peerid); break; } if (imsg_get_data(&imsg, &sup, sizeof(sup)) == -1) fatalx("incorrect size of session request"); peer_up(peer, &sup); /* make sure rde_eval_all is on if needed. */ if (peer_has_add_path(peer, AID_UNSPEC, CAPA_AP_SEND)) rde_eval_all = 1; break; case IMSG_SESSION_DOWN: if ((peer = peer_get(peerid)) == NULL) { log_warnx("%s: unknown peer id %d", "IMSG_SESSION_DOWN", peerid); break; } peer_down(peer); break; case IMSG_SESSION_DELETE: /* silently ignore deletes for unknown peers */ if ((peer = peer_get(peerid)) == NULL) break; peer_delete(peer); break; case IMSG_SESSION_STALE: case IMSG_SESSION_NOGRACE: case IMSG_SESSION_FLUSH: case IMSG_SESSION_RESTARTED: if ((peer = peer_get(peerid)) == NULL) { log_warnx("%s: unknown peer id %d", "graceful restart", peerid); break; } if (imsg_get_data(&imsg, &aid, sizeof(aid)) == -1) { log_warnx("%s: wrong imsg len", __func__); break; } if (aid < AID_MIN || aid >= AID_MAX) { log_warnx("%s: bad AID", __func__); break; } switch (imsg_get_type(&imsg)) { case IMSG_SESSION_STALE: peer_stale(peer, aid, 0); break; case IMSG_SESSION_NOGRACE: peer_stale(peer, aid, 1); break; case IMSG_SESSION_FLUSH: peer_flush(peer, aid, peer->staletime[aid]); break; case IMSG_SESSION_RESTARTED: if (peer->staletime[aid]) peer_flush(peer, aid, peer->staletime[aid]); break; } break; case IMSG_NETWORK_ADD: if (imsg_get_data(&imsg, &netconf_s, sizeof(netconf_s)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); break; } TAILQ_INIT(&netconf_s.attrset); rde_filterstate_init(&netconf_state); asp = &netconf_state.aspath; asp->aspath = aspath_get(NULL, 0); asp->origin = ORIGIN_IGP; asp->flags = F_ATTR_ORIGIN | F_ATTR_ASPATH | F_ATTR_LOCALPREF | F_PREFIX_ANNOUNCED | F_ANN_DYNAMIC; break; case IMSG_NETWORK_ASPATH: if (imsg_get_ibuf(&imsg, &ibuf) == -1) { log_warnx("rde_dispatch: bad imsg"); memset(&netconf_s, 0, sizeof(netconf_s)); break; } if (ibuf_get(&ibuf, &csr, sizeof(csr)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); memset(&netconf_s, 0, sizeof(netconf_s)); break; } asp = &netconf_state.aspath; asp->lpref = csr.local_pref; asp->med = csr.med; asp->weight = csr.weight; asp->flags = csr.flags; asp->origin = csr.origin; asp->flags |= F_PREFIX_ANNOUNCED | F_ANN_DYNAMIC; aspath_put(asp->aspath); asp->aspath = aspath_get(ibuf_data(&ibuf), ibuf_size(&ibuf)); break; case IMSG_NETWORK_ATTR: /* parse optional path attributes */ if (imsg_get_ibuf(&imsg, &ibuf) == -1 || rde_attr_add(&netconf_state, &ibuf) == -1) { log_warnx("rde_dispatch: bad network " "attribute"); rde_filterstate_clean(&netconf_state); memset(&netconf_s, 0, sizeof(netconf_s)); break; } break; case IMSG_NETWORK_DONE: TAILQ_CONCAT(&netconf_s.attrset, &session_set, entry); switch (netconf_s.prefix.aid) { case AID_INET: if (netconf_s.prefixlen > 32) goto badnet; network_add(&netconf_s, &netconf_state); break; case AID_INET6: if (netconf_s.prefixlen > 128) goto badnet; network_add(&netconf_s, &netconf_state); break; case 0: /* something failed beforehand */ break; default: badnet: log_warnx("request to insert invalid network"); break; } rde_filterstate_clean(&netconf_state); break; case IMSG_NETWORK_REMOVE: if (imsg_get_data(&imsg, &netconf_s, sizeof(netconf_s)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); break; } TAILQ_INIT(&netconf_s.attrset); switch (netconf_s.prefix.aid) { case AID_INET: if (netconf_s.prefixlen > 32) goto badnetdel; network_delete(&netconf_s); break; case AID_INET6: if (netconf_s.prefixlen > 128) goto badnetdel; network_delete(&netconf_s); break; default: badnetdel: log_warnx("request to remove invalid network"); break; } break; case IMSG_NETWORK_FLUSH: if (rib_dump_new(RIB_ADJ_IN, AID_UNSPEC, RDE_RUNNER_ROUNDS, NULL, network_flush_upcall, NULL, NULL) == -1) log_warn("rde_dispatch: IMSG_NETWORK_FLUSH"); break; case IMSG_FLOWSPEC_ADD: if (curflow != NULL) { log_warnx("rde_dispatch: " "unexpected flowspec add"); break; } if (imsg_get_ibuf(&imsg, &ibuf) == -1 || ibuf_size(&ibuf) <= FLOWSPEC_SIZE) { log_warnx("rde_dispatch: wrong imsg len"); break; } curflow = malloc(ibuf_size(&ibuf)); if (curflow == NULL) fatal(NULL); memcpy(curflow, ibuf_data(&ibuf), ibuf_size(&ibuf)); if (curflow->len + FLOWSPEC_SIZE != ibuf_size(&ibuf)) { free(curflow); curflow = NULL; log_warnx("rde_dispatch: wrong flowspec len"); break; } rde_filterstate_init(&netconf_state); asp = &netconf_state.aspath; asp->aspath = aspath_get(NULL, 0); asp->origin = ORIGIN_IGP; asp->flags = F_ATTR_ORIGIN | F_ATTR_ASPATH | F_ATTR_LOCALPREF | F_PREFIX_ANNOUNCED | F_ANN_DYNAMIC; break; case IMSG_FLOWSPEC_DONE: if (curflow == NULL) { log_warnx("rde_dispatch: " "unexpected flowspec done"); break; } if (flowspec_valid(curflow->data, curflow->len, curflow->aid == AID_FLOWSPECv6) == -1) log_warnx("invalid flowspec update received " "from bgpctl"); else flowspec_add(curflow, &netconf_state, &session_set); rde_filterstate_clean(&netconf_state); filterset_free(&session_set); free(curflow); curflow = NULL; break; case IMSG_FLOWSPEC_REMOVE: if (curflow != NULL) { log_warnx("rde_dispatch: " "unexpected flowspec remove"); break; } if (imsg_get_ibuf(&imsg, &ibuf) == -1 || ibuf_size(&ibuf) <= FLOWSPEC_SIZE) { log_warnx("rde_dispatch: wrong imsg len"); break; } curflow = malloc(ibuf_size(&ibuf)); if (curflow == NULL) fatal(NULL); memcpy(curflow, ibuf_data(&ibuf), ibuf_size(&ibuf)); if (curflow->len + FLOWSPEC_SIZE != ibuf_size(&ibuf)) { free(curflow); curflow = NULL; log_warnx("rde_dispatch: wrong flowspec len"); break; } if (flowspec_valid(curflow->data, curflow->len, curflow->aid == AID_FLOWSPECv6) == -1) log_warnx("invalid flowspec withdraw received " "from bgpctl"); else flowspec_delete(curflow); free(curflow); curflow = NULL; break; case IMSG_FLOWSPEC_FLUSH: prefix_flowspec_dump(AID_UNSPEC, NULL, flowspec_flush_upcall, NULL); break; case IMSG_FILTER_SET: if ((s = malloc(sizeof(struct filter_set))) == NULL) fatal(NULL); if (imsg_get_data(&imsg, s, sizeof(struct filter_set)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); free(s); break; } if (s->type == ACTION_SET_NEXTHOP) { s->action.nh_ref = nexthop_get(&s->action.nexthop); s->type = ACTION_SET_NEXTHOP_REF; } TAILQ_INSERT_TAIL(&session_set, s, entry); break; case IMSG_CTL_SHOW_NETWORK: case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_RIB_PREFIX: if (imsg_get_data(&imsg, &req, sizeof(req)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); break; } rde_dump_ctx_new(&req, pid, imsg_get_type(&imsg)); break; case IMSG_CTL_SHOW_FLOWSPEC: if (imsg_get_data(&imsg, &req, sizeof(req)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); break; } prefix_flowspec_dump(req.aid, &pid, flowspec_dump_upcall, flowspec_dump_done); break; case IMSG_CTL_SHOW_NEIGHBOR: peer = peer_get(peerid); if (peer != NULL) memcpy(&stats, &peer->stats, sizeof(stats)); else memset(&stats, 0, sizeof(stats)); imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_NEIGHBOR, peerid, pid, -1, &stats, sizeof(stats)); break; case IMSG_CTL_SHOW_RIB_MEM: imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_MEM, 0, pid, -1, &rdemem, sizeof(rdemem)); break; case IMSG_CTL_SHOW_SET: /* first roa set */ pset = &rde_roa; memset(&cset, 0, sizeof(cset)); cset.type = ROA_SET; strlcpy(cset.name, "RPKI ROA", sizeof(cset.name)); cset.lastchange = pset->lastchange; cset.v4_cnt = pset->th.v4_cnt; cset.v6_cnt = pset->th.v6_cnt; imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0, pid, -1, &cset, sizeof(cset)); /* then aspa set */ memset(&cset, 0, sizeof(cset)); cset.type = ASPA_SET; strlcpy(cset.name, "RPKI ASPA", sizeof(cset.name)); aspa_table_stats(rde_aspa, &cset); imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0, pid, -1, &cset, sizeof(cset)); SIMPLEQ_FOREACH(aset, &conf->as_sets, entry) { memset(&cset, 0, sizeof(cset)); cset.type = ASNUM_SET; strlcpy(cset.name, aset->name, sizeof(cset.name)); cset.lastchange = aset->lastchange; cset.as_cnt = set_nmemb(aset->set); imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0, pid, -1, &cset, sizeof(cset)); } SIMPLEQ_FOREACH(pset, &conf->rde_prefixsets, entry) { memset(&cset, 0, sizeof(cset)); cset.type = PREFIX_SET; strlcpy(cset.name, pset->name, sizeof(cset.name)); cset.lastchange = pset->lastchange; cset.v4_cnt = pset->th.v4_cnt; cset.v6_cnt = pset->th.v6_cnt; imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0, pid, -1, &cset, sizeof(cset)); } SIMPLEQ_FOREACH(pset, &conf->rde_originsets, entry) { memset(&cset, 0, sizeof(cset)); cset.type = ORIGIN_SET; strlcpy(cset.name, pset->name, sizeof(cset.name)); cset.lastchange = pset->lastchange; cset.v4_cnt = pset->th.v4_cnt; cset.v6_cnt = pset->th.v6_cnt; imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_SET, 0, pid, -1, &cset, sizeof(cset)); } imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, pid, -1, NULL, 0); break; case IMSG_CTL_LOG_VERBOSE: /* already checked by SE */ if (imsg_get_data(&imsg, &verbose, sizeof(verbose)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); break; } log_setverbose(verbose); break; case IMSG_CTL_END: imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, pid, -1, NULL, 0); break; case IMSG_CTL_TERMINATE: rde_dump_ctx_terminate(pid); break; case IMSG_XON: if (peerid) { peer = peer_get(peerid); if (peer) peer->throttled = 0; } else { rde_dump_ctx_throttle(pid, 0); } break; case IMSG_XOFF: if (peerid) { peer = peer_get(peerid); if (peer) peer->throttled = 1; } else { rde_dump_ctx_throttle(pid, 1); } break; case IMSG_RECONF_DRAIN: imsg_compose(ibuf_se, IMSG_RECONF_DRAIN, 0, 0, -1, NULL, 0); break; default: break; } imsg_free(&imsg); } } void rde_dispatch_imsg_parent(struct imsgbuf *imsgbuf) { static struct rde_prefixset *last_prefixset; static struct as_set *last_as_set; static struct l3vpn *vpn; static struct flowspec *curflow; struct imsg imsg; struct ibuf ibuf; struct bgpd_config tconf; struct filterstate state; struct kroute_nexthop knext; struct mrt xmrt; struct prefixset_item psi; struct rde_rib rr; struct roa roa; char name[SET_NAME_LEN]; struct imsgbuf *i; struct filter_head *nr; struct filter_rule *r; struct filter_set *s; struct rib *rib; struct rde_prefixset *ps; struct rde_aspath *asp; size_t nmemb; int n, fd, rv; uint16_t rid; while (imsgbuf) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("rde_dispatch_imsg_parent: imsg_get error"); if (n == 0) break; switch (imsg_get_type(&imsg)) { case IMSG_SOCKET_CONN: case IMSG_SOCKET_CONN_CTL: case IMSG_SOCKET_CONN_RTR: if ((fd = imsg_get_fd(&imsg)) == -1) { log_warnx("expected to receive imsg fd " "but didn't receive any"); break; } if ((i = malloc(sizeof(struct imsgbuf))) == NULL) fatal(NULL); if (imsgbuf_init(i, fd) == -1 || imsgbuf_set_maxsize(i, MAX_BGPD_IMSGSIZE) == -1) fatal(NULL); switch (imsg_get_type(&imsg)) { case IMSG_SOCKET_CONN: if (ibuf_se) { log_warnx("Unexpected imsg connection " "to SE received"); imsgbuf_clear(ibuf_se); free(ibuf_se); } ibuf_se = i; break; case IMSG_SOCKET_CONN_CTL: if (ibuf_se_ctl) { log_warnx("Unexpected imsg ctl " "connection to SE received"); imsgbuf_clear(ibuf_se_ctl); free(ibuf_se_ctl); } ibuf_se_ctl = i; break; case IMSG_SOCKET_CONN_RTR: if (ibuf_rtr) { log_warnx("Unexpected imsg ctl " "connection to ROA received"); imsgbuf_clear(ibuf_rtr); free(ibuf_rtr); } ibuf_rtr = i; break; } break; case IMSG_NETWORK_ADD: if (imsg_get_data(&imsg, &netconf_p, sizeof(netconf_p)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); break; } TAILQ_INIT(&netconf_p.attrset); break; case IMSG_NETWORK_DONE: TAILQ_CONCAT(&netconf_p.attrset, &parent_set, entry); rde_filterstate_init(&state); asp = &state.aspath; asp->aspath = aspath_get(NULL, 0); asp->origin = ORIGIN_IGP; asp->flags = F_ATTR_ORIGIN | F_ATTR_ASPATH | F_ATTR_LOCALPREF | F_PREFIX_ANNOUNCED; network_add(&netconf_p, &state); rde_filterstate_clean(&state); break; case IMSG_NETWORK_REMOVE: if (imsg_get_data(&imsg, &netconf_p, sizeof(netconf_p)) == -1) { log_warnx("rde_dispatch: wrong imsg len"); break; } TAILQ_INIT(&netconf_p.attrset); network_delete(&netconf_p); break; case IMSG_FLOWSPEC_ADD: if (curflow != NULL) { log_warnx("rde_dispatch: " "unexpected flowspec add"); break; } if (imsg_get_ibuf(&imsg, &ibuf) == -1 || ibuf_size(&ibuf) <= FLOWSPEC_SIZE) { log_warnx("rde_dispatch: wrong imsg len"); break; } curflow = malloc(ibuf_size(&ibuf)); if (curflow == NULL) fatal(NULL); memcpy(curflow, ibuf_data(&ibuf), ibuf_size(&ibuf)); if (curflow->len + FLOWSPEC_SIZE != ibuf_size(&ibuf)) { free(curflow); curflow = NULL; log_warnx("rde_dispatch: wrong flowspec len"); break; } break; case IMSG_FLOWSPEC_DONE: if (curflow == NULL) { log_warnx("rde_dispatch: " "unexpected flowspec done"); break; } rde_filterstate_init(&state); asp = &state.aspath; asp->aspath = aspath_get(NULL, 0); asp->origin = ORIGIN_IGP; asp->flags = F_ATTR_ORIGIN | F_ATTR_ASPATH | F_ATTR_LOCALPREF | F_PREFIX_ANNOUNCED; if (flowspec_valid(curflow->data, curflow->len, curflow->aid == AID_FLOWSPECv6) == -1) log_warnx("invalid flowspec update received " "from parent"); else flowspec_add(curflow, &state, &parent_set); rde_filterstate_clean(&state); filterset_free(&parent_set); free(curflow); curflow = NULL; break; case IMSG_FLOWSPEC_REMOVE: if (curflow != NULL) { log_warnx("rde_dispatch: " "unexpected flowspec remove"); break; } if (imsg_get_ibuf(&imsg, &ibuf) == -1 || ibuf_size(&ibuf) <= FLOWSPEC_SIZE) { log_warnx("rde_dispatch: wrong imsg len"); break; } curflow = malloc(ibuf_size(&ibuf)); if (curflow == NULL) fatal(NULL); memcpy(curflow, ibuf_data(&ibuf), ibuf_size(&ibuf)); if (curflow->len + FLOWSPEC_SIZE != ibuf_size(&ibuf)) { free(curflow); curflow = NULL; log_warnx("rde_dispatch: wrong flowspec len"); break; } if (flowspec_valid(curflow->data, curflow->len, curflow->aid == AID_FLOWSPECv6) == -1) log_warnx("invalid flowspec withdraw received " "from parent"); else flowspec_delete(curflow); free(curflow); curflow = NULL; break; case IMSG_RECONF_CONF: if (imsg_get_data(&imsg, &tconf, sizeof(tconf)) == -1) fatalx("IMSG_RECONF_CONF bad len"); out_rules_tmp = calloc(1, sizeof(struct filter_head)); if (out_rules_tmp == NULL) fatal(NULL); TAILQ_INIT(out_rules_tmp); nconf = new_config(); copy_config(nconf, &tconf); for (rid = 0; rid < rib_size; rid++) { if ((rib = rib_byid(rid)) == NULL) continue; rib->state = RECONF_DELETE; rib->fibstate = RECONF_NONE; } break; case IMSG_RECONF_RIB: if (imsg_get_data(&imsg, &rr, sizeof(rr)) == -1) fatalx("IMSG_RECONF_RIB bad len"); rib = rib_byid(rib_find(rr.name)); if (rib == NULL) { rib = rib_new(rr.name, rr.rtableid, rr.flags); } else if (rib->flags == rr.flags && rib->rtableid == rr.rtableid) { /* no change to rib apart from filters */ rib->state = RECONF_KEEP; } else { /* reload rib because something changed */ rib->flags_tmp = rr.flags; rib->rtableid_tmp = rr.rtableid; rib->state = RECONF_RELOAD; } break; case IMSG_RECONF_FILTER: if ((r = malloc(sizeof(struct filter_rule))) == NULL) fatal(NULL); if (imsg_get_data(&imsg, r, sizeof(*r)) == -1) fatalx("IMSG_RECONF_FILTER bad len"); if (r->match.prefixset.name[0] != '\0') { r->match.prefixset.ps = rde_find_prefixset(r->match.prefixset.name, &nconf->rde_prefixsets); if (r->match.prefixset.ps == NULL) log_warnx("%s: no prefixset for %s", __func__, r->match.prefixset.name); } if (r->match.originset.name[0] != '\0') { r->match.originset.ps = rde_find_prefixset(r->match.originset.name, &nconf->rde_originsets); if (r->match.originset.ps == NULL) log_warnx("%s: no origin-set for %s", __func__, r->match.originset.name); } if (r->match.as.flags & AS_FLAG_AS_SET_NAME) { struct as_set * aset; aset = as_sets_lookup(&nconf->as_sets, r->match.as.name); if (aset == NULL) { log_warnx("%s: no as-set for %s", __func__, r->match.as.name); } else { r->match.as.flags = AS_FLAG_AS_SET; r->match.as.aset = aset; } } TAILQ_INIT(&r->set); TAILQ_CONCAT(&r->set, &parent_set, entry); if ((rib = rib_byid(rib_find(r->rib))) == NULL) { log_warnx("IMSG_RECONF_FILTER: filter rule " "for nonexistent rib %s", r->rib); filterset_free(&r->set); free(r); break; } r->peer.ribid = rib->id; if (r->dir == DIR_IN) { nr = rib->in_rules_tmp; if (nr == NULL) { nr = calloc(1, sizeof(struct filter_head)); if (nr == NULL) fatal(NULL); TAILQ_INIT(nr); rib->in_rules_tmp = nr; } TAILQ_INSERT_TAIL(nr, r, entry); } else { TAILQ_INSERT_TAIL(out_rules_tmp, r, entry); } break; case IMSG_RECONF_PREFIX_SET: case IMSG_RECONF_ORIGIN_SET: ps = calloc(1, sizeof(struct rde_prefixset)); if (ps == NULL) fatal(NULL); if (imsg_get_data(&imsg, ps->name, sizeof(ps->name)) == -1) fatalx("IMSG_RECONF_PREFIX_SET bad len"); if (imsg_get_type(&imsg) == IMSG_RECONF_ORIGIN_SET) { SIMPLEQ_INSERT_TAIL(&nconf->rde_originsets, ps, entry); } else { SIMPLEQ_INSERT_TAIL(&nconf->rde_prefixsets, ps, entry); } last_prefixset = ps; break; case IMSG_RECONF_ROA_ITEM: if (imsg_get_data(&imsg, &roa, sizeof(roa)) == -1) fatalx("IMSG_RECONF_ROA_ITEM bad len"); rv = trie_roa_add(&last_prefixset->th, &roa); break; case IMSG_RECONF_PREFIX_SET_ITEM: if (imsg_get_data(&imsg, &psi, sizeof(psi)) == -1) fatalx("IMSG_RECONF_PREFIX_SET_ITEM bad len"); if (last_prefixset == NULL) fatalx("King Bula has no prefixset"); rv = trie_add(&last_prefixset->th, &psi.p.addr, psi.p.len, psi.p.len_min, psi.p.len_max); if (rv == -1) log_warnx("trie_add(%s) %s/%u failed", last_prefixset->name, log_addr(&psi.p.addr), psi.p.len); break; case IMSG_RECONF_AS_SET: if (imsg_get_ibuf(&imsg, &ibuf) == -1 || ibuf_get(&ibuf, &nmemb, sizeof(nmemb)) == -1 || ibuf_get(&ibuf, name, sizeof(name)) == -1) fatalx("IMSG_RECONF_AS_SET bad len"); if (as_sets_lookup(&nconf->as_sets, name) != NULL) fatalx("duplicate as-set %s", name); last_as_set = as_sets_new(&nconf->as_sets, name, nmemb, sizeof(uint32_t)); break; case IMSG_RECONF_AS_SET_ITEMS: if (imsg_get_ibuf(&imsg, &ibuf) == -1 || ibuf_size(&ibuf) == 0 || ibuf_size(&ibuf) % sizeof(uint32_t) != 0) fatalx("IMSG_RECONF_AS_SET_ITEMS bad len"); nmemb = ibuf_size(&ibuf) / sizeof(uint32_t); if (set_add(last_as_set->set, ibuf_data(&ibuf), nmemb) != 0) fatal(NULL); break; case IMSG_RECONF_AS_SET_DONE: set_prep(last_as_set->set); last_as_set = NULL; break; case IMSG_RECONF_VPN: if ((vpn = malloc(sizeof(*vpn))) == NULL) fatal(NULL); if (imsg_get_data(&imsg, vpn, sizeof(*vpn)) == -1) fatalx("IMSG_RECONF_VPN bad len"); TAILQ_INIT(&vpn->import); TAILQ_INIT(&vpn->export); TAILQ_INIT(&vpn->net_l); SIMPLEQ_INSERT_TAIL(&nconf->l3vpns, vpn, entry); break; case IMSG_RECONF_VPN_EXPORT: if (vpn == NULL) { log_warnx("rde_dispatch_imsg_parent: " "IMSG_RECONF_VPN_EXPORT unexpected"); break; } TAILQ_CONCAT(&vpn->export, &parent_set, entry); break; case IMSG_RECONF_VPN_IMPORT: if (vpn == NULL) { log_warnx("rde_dispatch_imsg_parent: " "IMSG_RECONF_VPN_IMPORT unexpected"); break; } TAILQ_CONCAT(&vpn->import, &parent_set, entry); break; case IMSG_RECONF_VPN_DONE: break; case IMSG_RECONF_DRAIN: imsg_compose(ibuf_main, IMSG_RECONF_DRAIN, 0, 0, -1, NULL, 0); break; case IMSG_RECONF_DONE: if (nconf == NULL) fatalx("got IMSG_RECONF_DONE but no config"); last_prefixset = NULL; rde_reload_done(); break; case IMSG_NEXTHOP_UPDATE: if (imsg_get_data(&imsg, &knext, sizeof(knext)) == -1) fatalx("IMSG_NEXTHOP_UPDATE bad len"); nexthop_update(&knext); break; case IMSG_FILTER_SET: if ((s = malloc(sizeof(*s))) == NULL) fatal(NULL); if (imsg_get_data(&imsg, s, sizeof(*s)) == -1) fatalx("IMSG_FILTER_SET bad len"); if (s->type == ACTION_SET_NEXTHOP) { s->action.nh_ref = nexthop_get(&s->action.nexthop); s->type = ACTION_SET_NEXTHOP_REF; } TAILQ_INSERT_TAIL(&parent_set, s, entry); break; case IMSG_MRT_OPEN: case IMSG_MRT_REOPEN: if (imsg_get_data(&imsg, &xmrt, sizeof(xmrt)) == -1) { log_warnx("wrong imsg len"); break; } if ((fd = imsg_get_fd(&imsg)) == -1) log_warnx("expected to receive fd for mrt dump " "but didn't receive any"); else if (xmrt.type == MRT_TABLE_DUMP || xmrt.type == MRT_TABLE_DUMP_MP || xmrt.type == MRT_TABLE_DUMP_V2) { rde_dump_mrt_new(&xmrt, imsg_get_pid(&imsg), fd); } else close(fd); break; case IMSG_MRT_CLOSE: /* ignore end message because a dump is atomic */ break; default: fatalx("unhandled IMSG %u", imsg_get_type(&imsg)); } imsg_free(&imsg); } } void rde_dispatch_imsg_rtr(struct imsgbuf *imsgbuf) { static struct aspa_set *aspa; struct imsg imsg; struct roa roa; struct aspa_prep ap; int n; while (imsgbuf) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("rde_dispatch_imsg_parent: imsg_get error"); if (n == 0) break; switch (imsg_get_type(&imsg)) { case IMSG_RECONF_ROA_SET: /* start of update */ trie_free(&roa_new.th); /* clear new roa */ break; case IMSG_RECONF_ROA_ITEM: if (imsg_get_data(&imsg, &roa, sizeof(roa)) == -1) fatalx("IMSG_RECONF_ROA_ITEM bad len"); if (trie_roa_add(&roa_new.th, &roa) != 0) { #if defined(__GNUC__) && __GNUC__ < 4 struct bgpd_addr p = { .aid = roa.aid }; p.v6 = roa.prefix.inet6; #else struct bgpd_addr p = { .aid = roa.aid, .v6 = roa.prefix.inet6 }; #endif log_warnx("trie_roa_add %s/%u failed", log_addr(&p), roa.prefixlen); } break; case IMSG_RECONF_ASPA_PREP: if (imsg_get_data(&imsg, &ap, sizeof(ap)) == -1) fatalx("IMSG_RECONF_ASPA_PREP bad len"); if (aspa_new) fatalx("unexpected IMSG_RECONF_ASPA_PREP"); aspa_new = aspa_table_prep(ap.entries, ap.datasize); break; case IMSG_RECONF_ASPA: if (aspa_new == NULL) fatalx("unexpected IMSG_RECONF_ASPA"); if (aspa != NULL) fatalx("IMSG_RECONF_ASPA already sent"); if ((aspa = calloc(1, sizeof(*aspa))) == NULL) fatal("IMSG_RECONF_ASPA"); if (imsg_get_data(&imsg, aspa, offsetof(struct aspa_set, tas)) == -1) fatal("IMSG_RECONF_ASPA bad len"); break; case IMSG_RECONF_ASPA_TAS: if (aspa == NULL) fatalx("unexpected IMSG_RECONF_ASPA_TAS"); aspa->tas = reallocarray(NULL, aspa->num, sizeof(uint32_t)); if (aspa->tas == NULL) fatal("IMSG_RECONF_ASPA_TAS"); if (imsg_get_data(&imsg, aspa->tas, aspa->num * sizeof(uint32_t)) == -1) fatal("IMSG_RECONF_ASPA_TAS bad len"); break; case IMSG_RECONF_ASPA_DONE: if (aspa_new == NULL) fatalx("unexpected IMSG_RECONF_ASPA"); aspa_add_set(aspa_new, aspa->as, aspa->tas, aspa->num); free_aspa(aspa); aspa = NULL; break; case IMSG_RECONF_DONE: /* end of update */ if (rde_roa_reload() + rde_aspa_reload() != 0) rde_rpki_reload(); break; } imsg_free(&imsg); } } void rde_dispatch_imsg_peer(struct rde_peer *peer, void *bula) { struct route_refresh rr; struct imsg imsg; struct ibuf ibuf; if (!peer_is_up(peer)) { peer_imsg_flush(peer); return; } if (!peer_imsg_pop(peer, &imsg)) return; switch (imsg_get_type(&imsg)) { case IMSG_UPDATE: if (imsg_get_ibuf(&imsg, &ibuf) == -1) log_warn("update: bad imsg"); else rde_update_dispatch(peer, &ibuf); break; case IMSG_REFRESH: if (imsg_get_data(&imsg, &rr, sizeof(rr)) == -1) { log_warnx("route refresh: wrong imsg len"); break; } if (rr.aid < AID_MIN || rr.aid >= AID_MAX) { log_peer_warnx(&peer->conf, "route refresh: bad AID %d", rr.aid); break; } if (peer->capa.mp[rr.aid] == 0) { log_peer_warnx(&peer->conf, "route refresh: AID %s not negotiated", aid2str(rr.aid)); break; } switch (rr.subtype) { case ROUTE_REFRESH_REQUEST: peer_blast(peer, rr.aid); break; case ROUTE_REFRESH_BEGIN_RR: /* check if graceful restart EOR was received */ if ((peer->recv_eor & (1 << rr.aid)) == 0) { log_peer_warnx(&peer->conf, "received %s BoRR before EoR", aid2str(rr.aid)); break; } peer_begin_rrefresh(peer, rr.aid); break; case ROUTE_REFRESH_END_RR: if ((peer->recv_eor & (1 << rr.aid)) != 0 && peer->staletime[rr.aid]) peer_flush(peer, rr.aid, peer->staletime[rr.aid]); else log_peer_warnx(&peer->conf, "received unexpected %s EoRR", aid2str(rr.aid)); break; default: log_peer_warnx(&peer->conf, "route refresh: bad subtype %d", rr.subtype); break; } break; default: log_warnx("%s: unhandled imsg type %d", __func__, imsg_get_type(&imsg)); break; } imsg_free(&imsg); } /* handle routing updates from the session engine. */ void rde_update_dispatch(struct rde_peer *peer, struct ibuf *buf) { struct filterstate state; struct bgpd_addr prefix; struct ibuf wdbuf, attrbuf, nlribuf, reachbuf, unreachbuf; uint16_t afi, len; uint8_t aid, prefixlen, safi, subtype; uint32_t fas, pathid; if (ibuf_get_n16(buf, &len) == -1 || ibuf_get_ibuf(buf, len, &wdbuf) == -1 || ibuf_get_n16(buf, &len) == -1 || ibuf_get_ibuf(buf, len, &attrbuf) == -1 || ibuf_get_ibuf(buf, ibuf_size(buf), &nlribuf) == -1) { rde_update_err(peer, ERR_UPDATE, ERR_UPD_ATTRLIST, NULL); return; } if (ibuf_size(&attrbuf) == 0) { /* 0 = no NLRI information in this message */ if (ibuf_size(&nlribuf) != 0) { /* crap at end of update which should not be there */ rde_update_err(peer, ERR_UPDATE, ERR_UPD_ATTRLIST, NULL); return; } if (ibuf_size(&wdbuf) == 0) { /* EoR marker */ rde_peer_recv_eor(peer, AID_INET); return; } } ibuf_from_buffer(&reachbuf, NULL, 0); ibuf_from_buffer(&unreachbuf, NULL, 0); rde_filterstate_init(&state); if (ibuf_size(&attrbuf) != 0) { /* parse path attributes */ while (ibuf_size(&attrbuf) > 0) { if (rde_attr_parse(&attrbuf, peer, &state, &reachbuf, &unreachbuf) == -1) goto done; } /* check for missing but necessary attributes */ if ((subtype = rde_attr_missing(&state.aspath, peer->conf.ebgp, ibuf_size(&nlribuf)))) { struct ibuf sbuf; ibuf_from_buffer(&sbuf, &subtype, sizeof(subtype)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_MISSNG_WK_ATTR, &sbuf); goto done; } rde_as4byte_fixup(peer, &state.aspath); /* enforce remote AS if requested */ if (state.aspath.flags & F_ATTR_ASPATH && peer->conf.enforce_as == ENFORCE_AS_ON) { fas = aspath_neighbor(state.aspath.aspath); if (peer->conf.remote_as != fas) { log_peer_warnx(&peer->conf, "bad path, " "starting with %s expected %u, " "enforce neighbor-as enabled", log_as(fas), peer->conf.remote_as); rde_update_err(peer, ERR_UPDATE, ERR_UPD_ASPATH, NULL); goto done; } } /* aspath needs to be loop free. This is not a hard error. */ if (state.aspath.flags & F_ATTR_ASPATH && peer->conf.ebgp && peer->conf.enforce_local_as == ENFORCE_AS_ON && !aspath_loopfree(state.aspath.aspath, peer->conf.local_as)) state.aspath.flags |= F_ATTR_LOOP; rde_reflector(peer, &state.aspath); /* Cache aspa lookup for all updates from ebgp sessions. */ if (state.aspath.flags & F_ATTR_ASPATH && peer->conf.ebgp) { aspa_validation(rde_aspa, state.aspath.aspath, &state.aspath.aspa_state); state.aspath.aspa_generation = rde_aspa_generation; } } /* withdraw prefix */ if (ibuf_size(&wdbuf) > 0) { if (peer->capa.mp[AID_INET] == 0) { log_peer_warnx(&peer->conf, "bad withdraw, %s disabled", aid2str(AID_INET)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_NETWORK, NULL); goto done; } } while (ibuf_size(&wdbuf) > 0) { if (peer_has_add_path(peer, AID_INET, CAPA_AP_RECV)) { if (ibuf_get_n32(&wdbuf, &pathid) == -1) { log_peer_warnx(&peer->conf, "bad withdraw prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_NETWORK, NULL); goto done; } } else pathid = 0; if (nlri_get_prefix(&wdbuf, &prefix, &prefixlen) == -1) { /* * the RFC does not mention what we should do in * this case. Let's do the same as in the NLRI case. */ log_peer_warnx(&peer->conf, "bad withdraw prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_NETWORK, NULL); goto done; } rde_update_withdraw(peer, pathid, &prefix, prefixlen); } /* withdraw MP_UNREACH_NLRI if available */ if (ibuf_size(&unreachbuf) != 0) { if (ibuf_get_n16(&unreachbuf, &afi) == -1 || ibuf_get_n8(&unreachbuf, &safi) == -1 || afi2aid(afi, safi, &aid) == -1) { log_peer_warnx(&peer->conf, "bad AFI/SAFI pair in withdraw"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } if (peer->capa.mp[aid] == 0) { log_peer_warnx(&peer->conf, "bad withdraw, %s disabled", aid2str(aid)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } if ((state.aspath.flags & ~F_ATTR_MP_UNREACH) == 0 && ibuf_size(&unreachbuf) == 0) { /* EoR marker */ rde_peer_recv_eor(peer, aid); } while (ibuf_size(&unreachbuf) > 0) { if (peer_has_add_path(peer, aid, CAPA_AP_RECV)) { if (ibuf_get_n32(&unreachbuf, &pathid) == -1) { log_peer_warnx(&peer->conf, "bad %s withdraw prefix", aid2str(aid)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } } else pathid = 0; switch (aid) { case AID_INET: log_peer_warnx(&peer->conf, "bad MP withdraw for %s", aid2str(aid)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; case AID_INET6: if (nlri_get_prefix6(&unreachbuf, &prefix, &prefixlen) == -1) { log_peer_warnx(&peer->conf, "bad IPv6 withdraw prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } break; case AID_VPN_IPv4: if (nlri_get_vpn4(&unreachbuf, &prefix, &prefixlen, 1) == -1) { log_peer_warnx(&peer->conf, "bad VPNv4 withdraw prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } break; case AID_VPN_IPv6: if (nlri_get_vpn6(&unreachbuf, &prefix, &prefixlen, 1) == -1) { log_peer_warnx(&peer->conf, "bad VPNv6 withdraw prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } break; case AID_EVPN: if (nlri_get_evpn(&unreachbuf, &prefix, &prefixlen) == -1) { log_peer_warnx(&peer->conf, "bad EVPN withdraw prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: /* ignore flowspec for now */ default: /* ignore unsupported multiprotocol AF */ if (ibuf_skip(&unreachbuf, ibuf_size(&unreachbuf)) == -1) { log_peer_warnx(&peer->conf, "bad withdraw prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &unreachbuf); goto done; } continue; } rde_update_withdraw(peer, pathid, &prefix, prefixlen); } if ((state.aspath.flags & ~F_ATTR_MP_UNREACH) == 0) goto done; } /* parse nlri prefix */ if (ibuf_size(&nlribuf) > 0) { if (peer->capa.mp[AID_INET] == 0) { log_peer_warnx(&peer->conf, "bad update, %s disabled", aid2str(AID_INET)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_NETWORK, NULL); goto done; } /* inject open policy OTC attribute if needed */ if ((state.aspath.flags & F_ATTR_OTC) == 0) { uint32_t tmp; switch (peer->role) { case ROLE_CUSTOMER: case ROLE_RS_CLIENT: case ROLE_PEER: tmp = htonl(peer->conf.remote_as); if (attr_optadd(&state.aspath, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_OTC, &tmp, sizeof(tmp)) == -1) { rde_update_err(peer, ERR_UPDATE, ERR_UPD_ATTRLIST, NULL); goto done; } state.aspath.flags |= F_ATTR_OTC; break; default: break; } } } while (ibuf_size(&nlribuf) > 0) { if (peer_has_add_path(peer, AID_INET, CAPA_AP_RECV)) { if (ibuf_get_n32(&nlribuf, &pathid) == -1) { log_peer_warnx(&peer->conf, "bad nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_NETWORK, NULL); goto done; } } else pathid = 0; if (nlri_get_prefix(&nlribuf, &prefix, &prefixlen) == -1) { log_peer_warnx(&peer->conf, "bad nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_NETWORK, NULL); goto done; } if (rde_update_update(peer, pathid, &state, &prefix, prefixlen) == -1) goto done; } /* add MP_REACH_NLRI if available */ if (ibuf_size(&reachbuf) != 0) { if (ibuf_get_n16(&reachbuf, &afi) == -1 || ibuf_get_n8(&reachbuf, &safi) == -1 || afi2aid(afi, safi, &aid) == -1) { log_peer_warnx(&peer->conf, "bad AFI/SAFI pair in update"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } if (peer->capa.mp[aid] == 0) { log_peer_warnx(&peer->conf, "bad update, %s disabled", aid2str(aid)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } if (aid == AID_INET6 || aid == AID_INET) { /* inject open policy OTC attribute if needed */ if ((state.aspath.flags & F_ATTR_OTC) == 0) { uint32_t tmp; switch (peer->role) { case ROLE_CUSTOMER: case ROLE_RS_CLIENT: case ROLE_PEER: tmp = htonl(peer->conf.remote_as); if (attr_optadd(&state.aspath, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_OTC, &tmp, sizeof(tmp)) == -1) { rde_update_err(peer, ERR_UPDATE, ERR_UPD_ATTRLIST, NULL); goto done; } state.aspath.flags |= F_ATTR_OTC; break; default: break; } } } else { /* Only IPv4 and IPv6 unicast do OTC handling */ state.aspath.flags &= ~F_ATTR_OTC_LEAK; } /* unlock the previously locked nexthop, it is no longer used */ nexthop_unref(state.nexthop); state.nexthop = NULL; if (rde_get_mp_nexthop(&reachbuf, aid, peer, &state) == -1) { log_peer_warnx(&peer->conf, "bad nlri nexthop"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } while (ibuf_size(&reachbuf) > 0) { if (peer_has_add_path(peer, aid, CAPA_AP_RECV)) { if (ibuf_get_n32(&reachbuf, &pathid) == -1) { log_peer_warnx(&peer->conf, "bad %s nlri prefix", aid2str(aid)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } } else pathid = 0; switch (aid) { case AID_INET: /* * rde_get_mp_nexthop already enforces that * this is only used for RFC 8950. */ if (nlri_get_prefix(&reachbuf, &prefix, &prefixlen) == -1) { log_peer_warnx(&peer->conf, "bad IPv4 MP nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } break; case AID_INET6: if (nlri_get_prefix6(&reachbuf, &prefix, &prefixlen) == -1) { log_peer_warnx(&peer->conf, "bad IPv6 nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } break; case AID_VPN_IPv4: if (nlri_get_vpn4(&reachbuf, &prefix, &prefixlen, 0) == -1) { log_peer_warnx(&peer->conf, "bad VPNv4 nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } break; case AID_VPN_IPv6: if (nlri_get_vpn6(&reachbuf, &prefix, &prefixlen, 0) == -1) { log_peer_warnx(&peer->conf, "bad VPNv6 nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } break; case AID_EVPN: if (nlri_get_evpn(&reachbuf, &prefix, &prefixlen) == -1) { log_peer_warnx(&peer->conf, "bad EVPN nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: /* ignore flowspec for now */ default: /* ignore unsupported multiprotocol AF */ if (ibuf_skip(&reachbuf, ibuf_size(&reachbuf)) == -1) { log_peer_warnx(&peer->conf, "bad nlri prefix"); rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR, &reachbuf); goto done; } continue; } if (rde_update_update(peer, pathid, &state, &prefix, prefixlen) == -1) goto done; } } done: rde_filterstate_clean(&state); } /* * Check if path_id is already in use. */ static int pathid_conflict(struct rib_entry *re, uint32_t pathid) { struct prefix *p; if (re == NULL) return 0; TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) if (p->path_id_tx == pathid) return 1; return 0; } /* * Assign a send side path_id to all paths. */ static uint32_t pathid_assign(struct rde_peer *peer, uint32_t path_id, struct bgpd_addr *prefix, uint8_t prefixlen) { struct rib_entry *re; uint32_t path_id_tx; /* If peer has no add-path use the per peer path_id */ if (!peer_has_add_path(peer, prefix->aid, CAPA_AP_RECV)) return peer->path_id_tx; /* peer uses add-path, therefore new path_ids need to be assigned */ re = rib_get_addr(rib_byid(RIB_ADJ_IN), prefix, prefixlen); if (re != NULL) { struct prefix *p; p = prefix_bypeer(re, peer, path_id); if (p != NULL) return p->path_id_tx; } /* * Assign new local path_id, must be an odd number. * Even numbers are used by the per peer path_id_tx. */ do { path_id_tx = arc4random() | 1; } while (pathid_conflict(re, path_id_tx)); return path_id_tx; } int rde_update_update(struct rde_peer *peer, uint32_t path_id, struct filterstate *in, struct bgpd_addr *prefix, uint8_t prefixlen) { struct filterstate state; enum filter_actions action; uint32_t path_id_tx; uint16_t i; uint8_t roa_state, aspa_state; const char *wmsg = "filtered, withdraw"; peer->stats.prefix_rcvd_update++; roa_state = rde_roa_validity(&rde_roa, prefix, prefixlen, aspath_origin(in->aspath.aspath)); aspa_state = rde_aspa_validity(peer, &in->aspath, prefix->aid); rde_filterstate_set_vstate(in, roa_state, aspa_state); path_id_tx = pathid_assign(peer, path_id, prefix, prefixlen); /* add original path to the Adj-RIB-In */ if (prefix_update(rib_byid(RIB_ADJ_IN), peer, path_id, path_id_tx, in, 0, prefix, prefixlen) == 1) peer->stats.prefix_cnt++; /* max prefix checker */ if (peer->conf.max_prefix && peer->stats.prefix_cnt > peer->conf.max_prefix) { log_peer_warnx(&peer->conf, "prefix limit reached (>%u/%u)", peer->stats.prefix_cnt, peer->conf.max_prefix); rde_update_err(peer, ERR_CEASE, ERR_CEASE_MAX_PREFIX, NULL); return (-1); } if (in->aspath.flags & F_ATTR_PARSE_ERR) wmsg = "path invalid, withdraw"; for (i = RIB_LOC_START; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; rde_filterstate_copy(&state, in); /* input filter */ action = rde_filter(rib->in_rules, peer, peer, prefix, prefixlen, &state); if (action == ACTION_ALLOW) { rde_update_log("update", i, peer, &state.nexthop->exit_nexthop, prefix, prefixlen); prefix_update(rib, peer, path_id, path_id_tx, &state, 0, prefix, prefixlen); } else if (conf->filtered_in_locrib && i == RIB_LOC_START) { rde_update_log(wmsg, i, peer, NULL, prefix, prefixlen); prefix_update(rib, peer, path_id, path_id_tx, &state, 1, prefix, prefixlen); } else { if (prefix_withdraw(rib, peer, path_id, prefix, prefixlen)) rde_update_log(wmsg, i, peer, NULL, prefix, prefixlen); } rde_filterstate_clean(&state); } return (0); } void rde_update_withdraw(struct rde_peer *peer, uint32_t path_id, struct bgpd_addr *prefix, uint8_t prefixlen) { uint16_t i; for (i = RIB_LOC_START; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; if (prefix_withdraw(rib, peer, path_id, prefix, prefixlen)) rde_update_log("withdraw", i, peer, NULL, prefix, prefixlen); } /* remove original path form the Adj-RIB-In */ if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peer, path_id, prefix, prefixlen)) peer->stats.prefix_cnt--; peer->stats.prefix_rcvd_withdraw++; } /* * BGP UPDATE parser functions */ /* attribute parser specific macros */ #define CHECK_FLAGS(s, t, m) \ (((s) & ~(ATTR_DEFMASK | (m))) == (t)) int rde_attr_parse(struct ibuf *buf, struct rde_peer *peer, struct filterstate *state, struct ibuf *reach, struct ibuf *unreach) { struct bgpd_addr nexthop; struct rde_aspath *a = &state->aspath; struct ibuf attrbuf, tmpbuf, *npath = NULL; size_t alen, hlen; uint32_t tmp32, zero = 0; int error; uint8_t flags, type; ibuf_from_ibuf(&attrbuf, buf); if (ibuf_get_n8(&attrbuf, &flags) == -1 || ibuf_get_n8(&attrbuf, &type) == -1) goto bad_list; if (flags & ATTR_EXTLEN) { uint16_t attr_len; if (ibuf_get_n16(&attrbuf, &attr_len) == -1) goto bad_list; alen = attr_len; hlen = 4; } else { uint8_t attr_len; if (ibuf_get_n8(&attrbuf, &attr_len) == -1) goto bad_list; alen = attr_len; hlen = 3; } if (ibuf_truncate(&attrbuf, alen) == -1) goto bad_list; /* consume the attribute in buf before moving forward */ if (ibuf_skip(buf, hlen + alen) == -1) goto bad_list; switch (type) { case ATTR_UNDEF: /* ignore and drop path attributes with a type code of 0 */ break; case ATTR_ORIGIN: if (!CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0)) goto bad_flags; if (ibuf_size(&attrbuf) != 1) goto bad_len; if (a->flags & F_ATTR_ORIGIN) goto bad_list; if (ibuf_get_n8(&attrbuf, &a->origin) == -1) goto bad_len; if (a->origin > ORIGIN_INCOMPLETE) { /* * mark update as bad and withdraw all routes as per * RFC 7606 */ a->flags |= F_ATTR_PARSE_ERR; log_peer_warnx(&peer->conf, "bad ORIGIN %u, " "path invalidated and prefix withdrawn", a->origin); return (-1); } a->flags |= F_ATTR_ORIGIN; break; case ATTR_ASPATH: if (!CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0)) goto bad_flags; if (a->flags & F_ATTR_ASPATH) goto bad_list; error = aspath_verify(&attrbuf, peer_has_as4byte(peer), peer_permit_as_set(peer)); if (error != 0 && error != AS_ERR_SOFT) { log_peer_warnx(&peer->conf, "bad ASPATH, %s", log_aspath_error(error)); rde_update_err(peer, ERR_UPDATE, ERR_UPD_ASPATH, NULL); return (-1); } if (peer_has_as4byte(peer)) { ibuf_from_ibuf(&tmpbuf, &attrbuf); } else { if ((npath = aspath_inflate(&attrbuf)) == NULL) fatal("aspath_inflate"); ibuf_from_ibuf(&tmpbuf, npath); } if (error == AS_ERR_SOFT) { char *str; /* * soft errors like unexpected segment types are * not considered fatal and the path is just * marked invalid. */ a->flags |= F_ATTR_PARSE_ERR; aspath_asprint(&str, &tmpbuf); log_peer_warnx(&peer->conf, "bad ASPATH %s, " "path invalidated and prefix withdrawn", str ? str : "(bad aspath)"); free(str); } a->flags |= F_ATTR_ASPATH; a->aspath = aspath_get(ibuf_data(&tmpbuf), ibuf_size(&tmpbuf)); ibuf_free(npath); break; case ATTR_NEXTHOP: if (!CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0)) goto bad_flags; if (ibuf_size(&attrbuf) != 4) goto bad_len; if (a->flags & F_ATTR_NEXTHOP) goto bad_list; a->flags |= F_ATTR_NEXTHOP; memset(&nexthop, 0, sizeof(nexthop)); nexthop.aid = AID_INET; if (ibuf_get_h32(&attrbuf, &nexthop.v4.s_addr) == -1) goto bad_len; /* * Check if the nexthop is a valid IP address. We consider * multicast addresses as invalid. */ tmp32 = ntohl(nexthop.v4.s_addr); if (IN_MULTICAST(tmp32)) { rde_update_err(peer, ERR_UPDATE, ERR_UPD_NEXTHOP, &attrbuf); return (-1); } nexthop_unref(state->nexthop); /* just to be sure */ state->nexthop = nexthop_get(&nexthop); break; case ATTR_MED: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL, 0)) goto bad_flags; if (ibuf_size(&attrbuf) != 4) goto bad_len; if (a->flags & F_ATTR_MED) goto bad_list; if (ibuf_get_n32(&attrbuf, &a->med) == -1) goto bad_len; a->flags |= F_ATTR_MED; break; case ATTR_LOCALPREF: if (!CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0)) goto bad_flags; if (ibuf_size(&attrbuf) != 4) goto bad_len; if (peer->conf.ebgp) { /* ignore local-pref attr on non ibgp peers */ break; } if (a->flags & F_ATTR_LOCALPREF) goto bad_list; if (ibuf_get_n32(&attrbuf, &a->lpref) == -1) goto bad_len; a->flags |= F_ATTR_LOCALPREF; break; case ATTR_ATOMIC_AGGREGATE: if (!CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0)) goto bad_flags; if (ibuf_size(&attrbuf) != 0) goto bad_len; goto optattr; case ATTR_AGGREGATOR: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL)) goto bad_flags; if ((!peer_has_as4byte(peer) && ibuf_size(&attrbuf) != 6) || (peer_has_as4byte(peer) && ibuf_size(&attrbuf) != 8)) { /* * ignore attribute in case of error as per * RFC 7606 */ log_peer_warnx(&peer->conf, "bad AGGREGATOR, " "attribute discarded"); break; } if (!peer_has_as4byte(peer)) { /* need to inflate aggregator AS to 4-byte */ u_char t[8]; t[0] = t[1] = 0; if (ibuf_get(&attrbuf, &t[2], 6) == -1) goto bad_list; if (memcmp(t, &zero, sizeof(uint32_t)) == 0) { /* As per RFC7606 use "attribute discard". */ log_peer_warnx(&peer->conf, "bad AGGREGATOR, " "AS 0 not allowed, attribute discarded"); break; } if (attr_optadd(a, flags, type, t, sizeof(t)) == -1) goto bad_list; break; } /* 4-byte ready server take the default route */ ibuf_from_ibuf(&tmpbuf, &attrbuf); if (ibuf_get_n32(&tmpbuf, &tmp32) == -1) goto bad_len; if (tmp32 == 0) { /* As per RFC7606 use "attribute discard" here. */ char *pfmt = log_fmt_peer(&peer->conf); log_debug("%s: bad AGGREGATOR, " "AS 0 not allowed, attribute discarded", pfmt); free(pfmt); break; } goto optattr; case ATTR_COMMUNITIES: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL)) goto bad_flags; if (community_add(&state->communities, flags, &attrbuf) == -1) { /* * mark update as bad and withdraw all routes as per * RFC 7606 */ a->flags |= F_ATTR_PARSE_ERR; log_peer_warnx(&peer->conf, "bad COMMUNITIES, " "path invalidated and prefix withdrawn"); } break; case ATTR_LARGE_COMMUNITIES: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL)) goto bad_flags; if (community_large_add(&state->communities, flags, &attrbuf) == -1) { /* * mark update as bad and withdraw all routes as per * RFC 7606 */ a->flags |= F_ATTR_PARSE_ERR; log_peer_warnx(&peer->conf, "bad LARGE COMMUNITIES, " "path invalidated and prefix withdrawn"); } break; case ATTR_EXT_COMMUNITIES: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL)) goto bad_flags; if (community_ext_add(&state->communities, flags, peer->conf.ebgp, &attrbuf) == -1) { /* * mark update as bad and withdraw all routes as per * RFC 7606 */ a->flags |= F_ATTR_PARSE_ERR; log_peer_warnx(&peer->conf, "bad EXT_COMMUNITIES, " "path invalidated and prefix withdrawn"); } break; case ATTR_ORIGINATOR_ID: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL, 0)) goto bad_flags; if (ibuf_size(&attrbuf) != 4) goto bad_len; goto optattr; case ATTR_CLUSTER_LIST: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL, 0)) goto bad_flags; if (peer->conf.ebgp) { /* As per RFC7606 use "attribute discard" here. */ log_peer_warnx(&peer->conf, "bad CLUSTER_LIST, " "received from external peer, attribute discarded"); break; } if (ibuf_size(&attrbuf) % 4 != 0 || ibuf_size(&attrbuf) == 0) { /* * mark update as bad and withdraw all routes as per * RFC 7606 */ a->flags |= F_ATTR_PARSE_ERR; log_peer_warnx(&peer->conf, "bad CLUSTER_LIST, " "path invalidated and prefix withdrawn"); break; } goto optattr; case ATTR_MP_REACH_NLRI: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL, 0)) goto bad_flags; if (ibuf_size(&attrbuf) < 5) goto bad_len; /* the validity is checked in rde_update_dispatch() */ if (a->flags & F_ATTR_MP_REACH) goto bad_list; a->flags |= F_ATTR_MP_REACH; *reach = attrbuf; break; case ATTR_MP_UNREACH_NLRI: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL, 0)) goto bad_flags; if (ibuf_size(&attrbuf) < 3) goto bad_len; /* the validity is checked in rde_update_dispatch() */ if (a->flags & F_ATTR_MP_UNREACH) goto bad_list; a->flags |= F_ATTR_MP_UNREACH; *unreach = attrbuf; break; case ATTR_AS4_AGGREGATOR: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL)) goto bad_flags; if (ibuf_size(&attrbuf) != 8) { /* see ATTR_AGGREGATOR ... */ log_peer_warnx(&peer->conf, "bad AS4_AGGREGATOR, " "attribute discarded"); break; } ibuf_from_ibuf(&tmpbuf, &attrbuf); if (ibuf_get_n32(&tmpbuf, &tmp32) == -1) goto bad_len; if (tmp32 == 0) { /* As per RFC6793 use "attribute discard" here. */ log_peer_warnx(&peer->conf, "bad AS4_AGGREGATOR, " "AS 0 not allowed, attribute discarded"); break; } a->flags |= F_ATTR_AS4BYTE_NEW; goto optattr; case ATTR_AS4_PATH: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL)) goto bad_flags; if ((error = aspath_verify(&attrbuf, 1, peer_permit_as_set(peer))) != 0) { /* As per RFC6793 use "attribute discard" here. */ log_peer_warnx(&peer->conf, "bad AS4_PATH, " "attribute discarded"); break; } a->flags |= F_ATTR_AS4BYTE_NEW; goto optattr; case ATTR_OTC: if (!CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL)) goto bad_flags; if (ibuf_size(&attrbuf) != 4) { /* treat-as-withdraw */ a->flags |= F_ATTR_PARSE_ERR; log_peer_warnx(&peer->conf, "bad OTC, " "path invalidated and prefix withdrawn"); break; } switch (peer->role) { case ROLE_PROVIDER: case ROLE_RS: a->flags |= F_ATTR_OTC_LEAK; break; case ROLE_PEER: if (ibuf_get_n32(&attrbuf, &tmp32) == -1) goto bad_len; if (tmp32 != peer->conf.remote_as) a->flags |= F_ATTR_OTC_LEAK; break; default: break; } a->flags |= F_ATTR_OTC; goto optattr; default: if ((flags & ATTR_OPTIONAL) == 0) { rde_update_err(peer, ERR_UPDATE, ERR_UPD_UNKNWN_WK_ATTR, &attrbuf); return (-1); } optattr: if (attr_optadd(a, flags, type, ibuf_data(&attrbuf), ibuf_size(&attrbuf)) == -1) goto bad_list; break; } return (0); bad_len: rde_update_err(peer, ERR_UPDATE, ERR_UPD_ATTRLEN, &attrbuf); return (-1); bad_flags: rde_update_err(peer, ERR_UPDATE, ERR_UPD_ATTRFLAGS, &attrbuf); return (-1); bad_list: rde_update_err(peer, ERR_UPDATE, ERR_UPD_ATTRLIST, NULL); return (-1); } #undef CHECK_FLAGS int rde_attr_add(struct filterstate *state, struct ibuf *buf) { uint16_t attr_len; uint8_t flags; uint8_t type; uint8_t tmp8; if (ibuf_get_n8(buf, &flags) == -1 || ibuf_get_n8(buf, &type) == -1) return (-1); if (flags & ATTR_EXTLEN) { if (ibuf_get_n16(buf, &attr_len) == -1) return (-1); } else { if (ibuf_get_n8(buf, &tmp8) == -1) return (-1); attr_len = tmp8; } if (ibuf_size(buf) != attr_len) return (-1); switch (type) { case ATTR_COMMUNITIES: return community_add(&state->communities, flags, buf); case ATTR_LARGE_COMMUNITIES: return community_large_add(&state->communities, flags, buf); case ATTR_EXT_COMMUNITIES: return community_ext_add(&state->communities, flags, 0, buf); } if (attr_optadd(&state->aspath, flags, type, ibuf_data(buf), attr_len) == -1) return (-1); return (0); } uint8_t rde_attr_missing(struct rde_aspath *a, int ebgp, uint16_t nlrilen) { /* ATTR_MP_UNREACH_NLRI may be sent alone */ if (nlrilen == 0 && a->flags & F_ATTR_MP_UNREACH && (a->flags & F_ATTR_MP_REACH) == 0) return (0); if ((a->flags & F_ATTR_ORIGIN) == 0) return (ATTR_ORIGIN); if ((a->flags & F_ATTR_ASPATH) == 0) return (ATTR_ASPATH); if ((a->flags & F_ATTR_MP_REACH) == 0 && (a->flags & F_ATTR_NEXTHOP) == 0) return (ATTR_NEXTHOP); if (!ebgp) if ((a->flags & F_ATTR_LOCALPREF) == 0) return (ATTR_LOCALPREF); return (0); } int rde_get_mp_nexthop(struct ibuf *buf, uint8_t aid, struct rde_peer *peer, struct filterstate *state) { struct bgpd_addr nexthop; struct ibuf nhbuf; uint8_t nhlen; if (ibuf_get_n8(buf, &nhlen) == -1) return (-1); if (ibuf_get_ibuf(buf, nhlen, &nhbuf) == -1) return (-1); /* ignore reserved (old SNPA) field as per RFC4760 */ if (ibuf_skip(buf, 1) == -1) return (-1); if (aid == AID_INET && peer_has_ext_nexthop(peer, AID_INET) && (nhlen == 16 || nhlen == 32)) aid = AID_INET6; if (aid == AID_VPN_IPv4 && peer_has_ext_nexthop(peer, AID_VPN_IPv4) && (nhlen == 24 || nhlen == 48)) aid = AID_VPN_IPv6; memset(&nexthop, 0, sizeof(nexthop)); switch (aid) { case AID_INET: log_peer_warnx(&peer->conf, "bad multiprotocol nexthop, " "IPv4 unexpected"); return (-1); case AID_INET6: /* * RFC2545 describes that there may be a link-local * address carried in nexthop. Yikes! * This is not only silly, it is wrong and we just ignore * this link-local nexthop. The bgpd session doesn't run * over the link-local address so why should all other * traffic. */ if (nhlen != 16 && nhlen != 32) { log_peer_warnx(&peer->conf, "bad %s nexthop, " "bad size %d", aid2str(aid), nhlen); return (-1); } if (ibuf_get(&nhbuf, &nexthop.v6, sizeof(nexthop.v6)) == -1) return (-1); nexthop.aid = AID_INET6; if (IN6_IS_ADDR_LINKLOCAL(&nexthop.v6)) { if (peer->local_if_scope != 0) { nexthop.scope_id = peer->local_if_scope; } else { log_peer_warnx(&peer->conf, "unexpected link-local nexthop: %s", log_addr(&nexthop)); return (-1); } } break; case AID_VPN_IPv4: /* * Neither RFC4364 nor RFC3107 specify the format of the * nexthop in an explicit way. The quality of RFC went down * the toilet the larger the number got. * RFC4364 is very confusing about VPN-IPv4 address and the * VPN-IPv4 prefix that carries also a MPLS label. * So the nexthop is a 12-byte address with a 64bit RD and * an IPv4 address following. In the nexthop case the RD can * be ignored. * Since the nexthop has to be in the main IPv4 table just * create an AID_INET nexthop. So we don't need to handle * AID_VPN_IPv4 in nexthop and kroute. */ if (nhlen != 12) { log_peer_warnx(&peer->conf, "bad %s nexthop, " "bad size %d", aid2str(aid), nhlen); return (-1); } if (ibuf_skip(&nhbuf, sizeof(uint64_t)) == -1 || ibuf_get(&nhbuf, &nexthop.v4, sizeof(nexthop.v4)) == -1) return (-1); nexthop.aid = AID_INET; break; case AID_VPN_IPv6: if (nhlen != 24 && nhlen != 48) { log_peer_warnx(&peer->conf, "bad %s nexthop, " "bad size %d", aid2str(aid), nhlen); return (-1); } if (ibuf_skip(&nhbuf, sizeof(uint64_t)) == -1 || ibuf_get(&nhbuf, &nexthop.v6, sizeof(nexthop.v6)) == -1) return (-1); nexthop.aid = AID_INET6; if (IN6_IS_ADDR_LINKLOCAL(&nexthop.v6)) { if (peer->local_if_scope != 0) { nexthop.scope_id = peer->local_if_scope; } else { log_peer_warnx(&peer->conf, "unexpected link-local nexthop: %s", log_addr(&nexthop)); return (-1); } } break; case AID_EVPN: switch (nhlen) { case 4: if (ibuf_get_h32(&nhbuf, &nexthop.v4.s_addr) == -1) return (-1); nexthop.aid = AID_INET; break; case 16: case 32: if (ibuf_get(&nhbuf, &nexthop.v6, sizeof(nexthop.v6)) == -1) return (-1); nexthop.aid = AID_INET6; if (IN6_IS_ADDR_LINKLOCAL(&nexthop.v6)) { if (peer->local_if_scope != 0) { nexthop.scope_id = peer->local_if_scope; } else { log_peer_warnx(&peer->conf, "unexpected link-local nexthop: %s", log_addr(&nexthop)); return (-1); } } break; default: log_peer_warnx(&peer->conf, "bad %s nexthop, " "bad size %d", aid2str(aid), nhlen); return (-1); } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: /* nexthop must be 0 and ignored for flowspec */ if (nhlen != 0) { log_peer_warnx(&peer->conf, "bad %s nexthop, " "bad size %d", aid2str(aid), nhlen); return (-1); } return (0); default: log_peer_warnx(&peer->conf, "bad multiprotocol nexthop, " "bad AID"); return (-1); } state->nexthop = nexthop_get(&nexthop); return (0); } void rde_update_err(struct rde_peer *peer, uint8_t error, uint8_t suberr, struct ibuf *opt) { struct ibuf *wbuf; size_t size = 0; if (opt != NULL) { ibuf_rewind(opt); size = ibuf_size(opt); } if ((wbuf = imsg_create(ibuf_se, IMSG_UPDATE_ERR, peer->conf.id, 0, size + sizeof(error) + sizeof(suberr))) == NULL) fatal("%s %d imsg_create error", __func__, __LINE__); if (imsg_add(wbuf, &error, sizeof(error)) == -1 || imsg_add(wbuf, &suberr, sizeof(suberr)) == -1) fatal("%s %d imsg_add error", __func__, __LINE__); if (opt != NULL) if (ibuf_add_ibuf(wbuf, opt) == -1) fatal("%s %d ibuf_add_ibuf error", __func__, __LINE__); imsg_close(ibuf_se, wbuf); peer->state = PEER_ERR; } void rde_update_log(const char *message, uint16_t rid, const struct rde_peer *peer, const struct bgpd_addr *next, const struct bgpd_addr *prefix, uint8_t prefixlen) { char *l = NULL; char *n = NULL; char *p = NULL; if (!((conf->log & BGPD_LOG_UPDATES) || (peer->flags & PEERFLAG_LOG_UPDATES))) return; if (next != NULL) if (asprintf(&n, " via %s", log_addr(next)) == -1) n = NULL; if (asprintf(&p, "%s/%u", log_addr(prefix), prefixlen) == -1) p = NULL; l = log_fmt_peer(&peer->conf); log_info("Rib %s: %s AS%s: %s %s%s", rib_byid(rid)->name, l, log_as(peer->conf.remote_as), message, p ? p : "out of memory", n ? n : ""); free(l); free(n); free(p); } /* * 4-Byte ASN helper function. * Two scenarios need to be considered: * - NEW session with NEW attributes present -> just remove the attributes * - OLD session with NEW attributes present -> try to merge them */ void rde_as4byte_fixup(struct rde_peer *peer, struct rde_aspath *a) { struct attr *nasp, *naggr, *oaggr; uint32_t as; /* * if either ATTR_AS4_AGGREGATOR or ATTR_AS4_PATH is present * try to fixup the attributes. * Do not fixup if F_ATTR_PARSE_ERR is set. */ if (!(a->flags & F_ATTR_AS4BYTE_NEW) || a->flags & F_ATTR_PARSE_ERR) return; /* first get the attributes */ nasp = attr_optget(a, ATTR_AS4_PATH); naggr = attr_optget(a, ATTR_AS4_AGGREGATOR); if (peer_has_as4byte(peer)) { /* NEW session using 4-byte ASNs */ if (nasp) { log_peer_warnx(&peer->conf, "uses 4-byte ASN " "but sent AS4_PATH attribute."); attr_free(a, nasp); } if (naggr) { log_peer_warnx(&peer->conf, "uses 4-byte ASN " "but sent AS4_AGGREGATOR attribute."); attr_free(a, naggr); } return; } /* OLD session using 2-byte ASNs */ /* try to merge the new attributes into the old ones */ if ((oaggr = attr_optget(a, ATTR_AGGREGATOR))) { memcpy(&as, oaggr->data, sizeof(as)); if (ntohl(as) != AS_TRANS) { /* per RFC ignore AS4_PATH and AS4_AGGREGATOR */ if (nasp) attr_free(a, nasp); if (naggr) attr_free(a, naggr); return; } if (naggr) { /* switch over to new AGGREGATOR */ attr_free(a, oaggr); if (attr_optadd(a, ATTR_OPTIONAL | ATTR_TRANSITIVE, ATTR_AGGREGATOR, naggr->data, naggr->len)) fatalx("attr_optadd failed but impossible"); } } /* there is no need for AS4_AGGREGATOR any more */ if (naggr) attr_free(a, naggr); /* merge AS4_PATH with ASPATH */ if (nasp) aspath_merge(a, nasp); } uint8_t rde_aspa_validity(struct rde_peer *peer, struct rde_aspath *asp, uint8_t aid) { if (!peer->conf.ebgp) /* ASPA is only performed on ebgp sessions */ return ASPA_NEVER_KNOWN; if (aid != AID_INET && aid != AID_INET6) /* skip uncovered aids */ return ASPA_NEVER_KNOWN; #ifdef MAYBE /* * By default enforce neighbor-as is set for all ebgp sessions. * So if a admin disables this check should we really "reenable" * it here in such a dubious way? * This just fails the ASPA validation for these paths so maybe * this can be helpful. But it is not transparent to the admin. */ /* skip neighbor-as check for transparent RS sessions */ if (peer->role != ROLE_RS_CLIENT && peer->conf.enforce_as != ENFORCE_AS_ON) { uint32_t fas; fas = aspath_neighbor(asp->aspath); if (peer->conf.remote_as != fas) return ASPA_INVALID; } #endif /* if no role is set, the outcome is unknown */ if (peer->role == ROLE_NONE) return ASPA_UNKNOWN; if (peer->role == ROLE_CUSTOMER) return asp->aspa_state.downup; else return asp->aspa_state.onlyup; } /* * route reflector helper function */ void rde_reflector(struct rde_peer *peer, struct rde_aspath *asp) { struct attr *a; uint8_t *p; uint16_t len; uint32_t id; /* do not consider updates with parse errors */ if (asp->flags & F_ATTR_PARSE_ERR) return; /* check for originator id if eq router_id drop */ if ((a = attr_optget(asp, ATTR_ORIGINATOR_ID)) != NULL) { id = htonl(conf->bgpid); if (memcmp(&id, a->data, sizeof(id)) == 0) { /* this is coming from myself */ asp->flags |= F_ATTR_LOOP; return; } } else if (conf->flags & BGPD_FLAG_REFLECTOR) { if (peer->conf.ebgp) id = htonl(conf->bgpid); else id = htonl(peer->remote_bgpid); if (attr_optadd(asp, ATTR_OPTIONAL, ATTR_ORIGINATOR_ID, &id, sizeof(id)) == -1) fatalx("attr_optadd failed but impossible"); } /* check for own id in the cluster list */ if (conf->flags & BGPD_FLAG_REFLECTOR) { id = htonl(conf->clusterid); if ((a = attr_optget(asp, ATTR_CLUSTER_LIST)) != NULL) { for (len = 0; len < a->len; len += sizeof(id)) /* check if coming from my cluster */ if (memcmp(&id, a->data + len, sizeof(id)) == 0) { asp->flags |= F_ATTR_LOOP; return; } /* prepend own clusterid by replacing attribute */ len = a->len + sizeof(id); if (len < a->len) fatalx("rde_reflector: cluster-list overflow"); if ((p = malloc(len)) == NULL) fatal("rde_reflector"); memcpy(p, &id, sizeof(id)); memcpy(p + sizeof(id), a->data, a->len); attr_free(asp, a); if (attr_optadd(asp, ATTR_OPTIONAL, ATTR_CLUSTER_LIST, p, len) == -1) fatalx("attr_optadd failed but impossible"); free(p); } else if (attr_optadd(asp, ATTR_OPTIONAL, ATTR_CLUSTER_LIST, &id, sizeof(id)) == -1) fatalx("attr_optadd failed but impossible"); } } /* * control specific functions */ static void rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags, int adjout) { struct ctl_show_rib rib; struct ibuf *wbuf; struct attr *a; struct nexthop *nexthop; struct rib_entry *re; struct prefix *xp; struct rde_peer *peer; time_t staletime; size_t aslen; uint8_t l; nexthop = prefix_nexthop(p); peer = prefix_peer(p); memset(&rib, 0, sizeof(rib)); rib.age = getmonotime() - p->lastchange; rib.local_pref = asp->lpref; rib.med = asp->med; rib.weight = asp->weight; strlcpy(rib.descr, peer->conf.descr, sizeof(rib.descr)); memcpy(&rib.remote_addr, &peer->remote_addr, sizeof(rib.remote_addr)); rib.remote_id = peer->remote_bgpid; if (nexthop != NULL) { rib.exit_nexthop = nexthop->exit_nexthop; rib.true_nexthop = nexthop->true_nexthop; } else { /* announced network can have a NULL nexthop */ rib.exit_nexthop.aid = p->pt->aid; rib.true_nexthop.aid = p->pt->aid; } pt_getaddr(p->pt, &rib.prefix); rib.prefixlen = p->pt->prefixlen; rib.origin = asp->origin; rib.roa_validation_state = prefix_roa_vstate(p); rib.aspa_validation_state = prefix_aspa_vstate(p); rib.dmetric = p->dmetric; rib.flags = 0; if (!adjout && prefix_eligible(p)) { re = prefix_re(p); TAILQ_FOREACH(xp, &re->prefix_h, entry.list.rib) { switch (xp->dmetric) { case PREFIX_DMETRIC_BEST: if (xp == p) rib.flags |= F_PREF_BEST; break; case PREFIX_DMETRIC_ECMP: if (xp == p) rib.flags |= F_PREF_ECMP; break; case PREFIX_DMETRIC_AS_WIDE: if (xp == p) rib.flags |= F_PREF_AS_WIDE; break; default: xp = NULL; /* stop loop */ break; } if (xp == NULL || xp == p) break; } } if (!peer->conf.ebgp) rib.flags |= F_PREF_INTERNAL; if (asp->flags & F_PREFIX_ANNOUNCED) rib.flags |= F_PREF_ANNOUNCE; if (prefix_eligible(p)) rib.flags |= F_PREF_ELIGIBLE; if (prefix_filtered(p)) rib.flags |= F_PREF_FILTERED; /* otc loop includes parse err so skip the latter if the first is set */ if (asp->flags & F_ATTR_OTC_LEAK) rib.flags |= F_PREF_OTC_LEAK; else if (asp->flags & F_ATTR_PARSE_ERR) rib.flags |= F_PREF_INVALID; staletime = peer->staletime[p->pt->aid]; if (staletime && p->lastchange <= staletime) rib.flags |= F_PREF_STALE; if (!adjout) { if (peer_has_add_path(peer, p->pt->aid, CAPA_AP_RECV)) { rib.path_id = p->path_id; rib.flags |= F_PREF_PATH_ID; } } else { if (peer_has_add_path(peer, p->pt->aid, CAPA_AP_SEND)) { rib.path_id = p->path_id_tx; rib.flags |= F_PREF_PATH_ID; } } aslen = aspath_length(asp->aspath); if ((wbuf = imsg_create(ibuf_se_ctl, IMSG_CTL_SHOW_RIB, 0, pid, sizeof(rib) + aslen)) == NULL) return; if (imsg_add(wbuf, &rib, sizeof(rib)) == -1 || imsg_add(wbuf, aspath_dump(asp->aspath), aslen) == -1) return; imsg_close(ibuf_se_ctl, wbuf); if (flags & F_CTL_DETAIL) { struct rde_community *comm = prefix_communities(p); size_t len = comm->nentries * sizeof(struct community); if (comm->nentries > 0) { if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_COMMUNITIES, 0, pid, -1, comm->communities, len) == -1) return; } for (l = 0; l < asp->others_len; l++) { if ((a = asp->others[l]) == NULL) break; if ((wbuf = imsg_create(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_ATTR, 0, pid, 0)) == NULL) return; if (attr_writebuf(wbuf, a->flags, a->type, a->data, a->len) == -1) { ibuf_free(wbuf); return; } imsg_close(ibuf_se_ctl, wbuf); } } } int rde_match_peer(struct rde_peer *p, struct ctl_neighbor *n) { char *s; if (n && n->addr.aid) { if (memcmp(&p->conf.remote_addr, &n->addr, sizeof(p->conf.remote_addr))) return 0; } else if (n && n->descr[0]) { s = n->is_group ? p->conf.group : p->conf.descr; /* cannot trust n->descr to be properly terminated */ if (strncmp(s, n->descr, sizeof(n->descr))) return 0; } return 1; } static void rde_dump_filter(struct prefix *p, struct ctl_show_rib_request *req, int adjout) { struct rde_aspath *asp; if (!rde_match_peer(prefix_peer(p), &req->neighbor)) return; asp = prefix_aspath(p); if ((req->flags & F_CTL_BEST) && p->dmetric != PREFIX_DMETRIC_BEST) return; if ((req->flags & F_CTL_INVALID) && (asp->flags & F_ATTR_PARSE_ERR) == 0) return; if ((req->flags & F_CTL_FILTERED) && !prefix_filtered(p)) return; if ((req->flags & F_CTL_INELIGIBLE) && prefix_eligible(p)) return; if ((req->flags & F_CTL_LEAKED) && (asp->flags & F_ATTR_OTC_LEAK) == 0) return; if ((req->flags & F_CTL_HAS_PATHID)) { /* Match against the transmit path id if adjout is used. */ if (adjout) { if (req->path_id != p->path_id_tx) return; } else { if (req->path_id != p->path_id) return; } } if (req->as.type != AS_UNDEF && !aspath_match(asp->aspath, &req->as, 0)) return; if (req->community.flags != 0) { if (!community_match(prefix_communities(p), &req->community, NULL)) return; } if (!ovs_match(p, req->flags)) return; if (!avs_match(p, req->flags)) return; rde_dump_rib_as(p, asp, req->pid, req->flags, adjout); } static void rde_dump_upcall(struct rib_entry *re, void *ptr) { struct rde_dump_ctx *ctx = ptr; struct prefix *p; if (re == NULL) return; TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) rde_dump_filter(p, &ctx->req, 0); } static void rde_dump_adjout_upcall(struct prefix *p, void *ptr) { struct rde_dump_ctx *ctx = ptr; if ((p->flags & PREFIX_FLAG_ADJOUT) == 0) fatalx("%s: prefix without PREFIX_FLAG_ADJOUT hit", __func__); if (p->flags & (PREFIX_FLAG_WITHDRAW | PREFIX_FLAG_DEAD)) return; rde_dump_filter(p, &ctx->req, 1); } static int rde_dump_throttled(void *arg) { struct rde_dump_ctx *ctx = arg; return (ctx->throttled != 0); } static void rde_dump_done(void *arg, uint8_t aid) { struct rde_dump_ctx *ctx = arg; struct rde_peer *peer; u_int error; if (ctx->req.flags & F_CTL_ADJ_OUT) { peer = peer_match(&ctx->req.neighbor, ctx->peerid); if (peer == NULL) goto done; ctx->peerid = peer->conf.id; switch (ctx->req.type) { case IMSG_CTL_SHOW_RIB: if (prefix_dump_new(peer, ctx->req.aid, CTL_MSG_HIGH_MARK, ctx, rde_dump_adjout_upcall, rde_dump_done, rde_dump_throttled) == -1) goto nomem; break; case IMSG_CTL_SHOW_RIB_PREFIX: if (prefix_dump_subtree(peer, &ctx->req.prefix, ctx->req.prefixlen, CTL_MSG_HIGH_MARK, ctx, rde_dump_adjout_upcall, rde_dump_done, rde_dump_throttled) == -1) goto nomem; break; default: fatalx("%s: unsupported imsg type", __func__); } return; } done: imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, ctx->req.pid, -1, NULL, 0); LIST_REMOVE(ctx, entry); free(ctx); return; nomem: log_warn(__func__); error = CTL_RES_NOMEM; imsg_compose(ibuf_se_ctl, IMSG_CTL_RESULT, 0, ctx->req.pid, -1, &error, sizeof(error)); return; } void rde_dump_ctx_new(struct ctl_show_rib_request *req, pid_t pid, enum imsg_type type) { struct rde_dump_ctx *ctx; struct rib_entry *re; struct prefix *p; u_int error; uint8_t hostplen, plen; uint16_t rid; if ((ctx = calloc(1, sizeof(*ctx))) == NULL) { nomem: log_warn(__func__); error = CTL_RES_NOMEM; imsg_compose(ibuf_se_ctl, IMSG_CTL_RESULT, 0, pid, -1, &error, sizeof(error)); free(ctx); return; } if (strcmp(req->rib, "Adj-RIB-Out") == 0) req->flags |= F_CTL_ADJ_OUT; memcpy(&ctx->req, req, sizeof(struct ctl_show_rib_request)); ctx->req.pid = pid; ctx->req.type = type; if (req->flags & (F_CTL_ADJ_IN | F_CTL_INVALID)) { rid = RIB_ADJ_IN; } else if (req->flags & F_CTL_ADJ_OUT) { struct rde_peer *peer; peer = peer_match(&req->neighbor, 0); if (peer == NULL) { error = CTL_RES_NOSUCHPEER; imsg_compose(ibuf_se_ctl, IMSG_CTL_RESULT, 0, pid, -1, &error, sizeof(error)); free(ctx); return; } ctx->peerid = peer->conf.id; switch (ctx->req.type) { case IMSG_CTL_SHOW_RIB: if (prefix_dump_new(peer, ctx->req.aid, CTL_MSG_HIGH_MARK, ctx, rde_dump_adjout_upcall, rde_dump_done, rde_dump_throttled) == -1) goto nomem; break; case IMSG_CTL_SHOW_RIB_PREFIX: if (req->flags & F_LONGER) { if (prefix_dump_subtree(peer, &req->prefix, req->prefixlen, CTL_MSG_HIGH_MARK, ctx, rde_dump_adjout_upcall, rde_dump_done, rde_dump_throttled) == -1) goto nomem; break; } switch (req->prefix.aid) { case AID_INET: case AID_VPN_IPv4: hostplen = 32; break; case AID_INET6: case AID_VPN_IPv6: hostplen = 128; break; default: fatalx("%s: unknown af", __func__); } do { if (req->flags & F_SHORTER) { for (plen = 0; plen <= req->prefixlen; plen++) { p = prefix_adjout_lookup(peer, &req->prefix, plen); /* dump all matching paths */ while (p != NULL) { rde_dump_adjout_upcall( p, ctx); p = prefix_adjout_next( peer, p); } } p = NULL; } else if (req->prefixlen == hostplen) { p = prefix_adjout_match(peer, &req->prefix); } else { p = prefix_adjout_lookup(peer, &req->prefix, req->prefixlen); } /* dump all matching paths */ while (p != NULL) { rde_dump_adjout_upcall(p, ctx); p = prefix_adjout_next(peer, p); } } while ((peer = peer_match(&req->neighbor, peer->conf.id))); imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, ctx->req.pid, -1, NULL, 0); free(ctx); return; default: fatalx("%s: unsupported imsg type", __func__); } LIST_INSERT_HEAD(&rde_dump_h, ctx, entry); return; } else if ((rid = rib_find(req->rib)) == RIB_NOTFOUND) { log_warnx("%s: no such rib %s", __func__, req->rib); error = CTL_RES_NOSUCHRIB; imsg_compose(ibuf_se_ctl, IMSG_CTL_RESULT, 0, pid, -1, &error, sizeof(error)); free(ctx); return; } switch (ctx->req.type) { case IMSG_CTL_SHOW_NETWORK: if (rib_dump_new(rid, ctx->req.aid, CTL_MSG_HIGH_MARK, ctx, network_dump_upcall, rde_dump_done, rde_dump_throttled) == -1) goto nomem; break; case IMSG_CTL_SHOW_RIB: if (rib_dump_new(rid, ctx->req.aid, CTL_MSG_HIGH_MARK, ctx, rde_dump_upcall, rde_dump_done, rde_dump_throttled) == -1) goto nomem; break; case IMSG_CTL_SHOW_RIB_PREFIX: if (req->flags & F_LONGER) { if (rib_dump_subtree(rid, &req->prefix, req->prefixlen, CTL_MSG_HIGH_MARK, ctx, rde_dump_upcall, rde_dump_done, rde_dump_throttled) == -1) goto nomem; break; } switch (req->prefix.aid) { case AID_INET: case AID_VPN_IPv4: hostplen = 32; break; case AID_INET6: case AID_VPN_IPv6: hostplen = 128; break; default: fatalx("%s: unknown af", __func__); } if (req->flags & F_SHORTER) { for (plen = 0; plen <= req->prefixlen; plen++) { re = rib_get_addr(rib_byid(rid), &req->prefix, plen); rde_dump_upcall(re, ctx); } } else if (req->prefixlen == hostplen) { re = rib_match(rib_byid(rid), &req->prefix); rde_dump_upcall(re, ctx); } else { re = rib_get_addr(rib_byid(rid), &req->prefix, req->prefixlen); rde_dump_upcall(re, ctx); } imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, ctx->req.pid, -1, NULL, 0); free(ctx); return; default: fatalx("%s: unsupported imsg type", __func__); } LIST_INSERT_HEAD(&rde_dump_h, ctx, entry); } void rde_dump_ctx_throttle(pid_t pid, int throttle) { struct rde_dump_ctx *ctx; LIST_FOREACH(ctx, &rde_dump_h, entry) { if (ctx->req.pid == pid) { ctx->throttled = throttle; return; } } } void rde_dump_ctx_terminate(pid_t pid) { struct rde_dump_ctx *ctx; LIST_FOREACH(ctx, &rde_dump_h, entry) { if (ctx->req.pid == pid) { rib_dump_terminate(ctx); return; } } } static int rde_mrt_throttled(void *arg) { struct mrt *mrt = arg; return (msgbuf_queuelen(mrt->wbuf) > SESS_MSG_LOW_MARK); } static void rde_mrt_done(void *ptr, uint8_t aid) { mrt_done(ptr); } void rde_dump_mrt_new(struct mrt *mrt, pid_t pid, int fd) { struct rde_mrt_ctx *ctx; uint16_t rid; if ((ctx = calloc(1, sizeof(*ctx))) == NULL) { log_warn("rde_dump_mrt_new"); return; } memcpy(&ctx->mrt, mrt, sizeof(struct mrt)); if ((ctx->mrt.wbuf = msgbuf_new()) == NULL) { log_warn("rde_dump_mrt_new"); free(ctx); return; } ctx->mrt.fd = fd; ctx->mrt.state = MRT_STATE_RUNNING; rid = rib_find(ctx->mrt.rib); if (rid == RIB_NOTFOUND) { log_warnx("non existing RIB %s for mrt dump", ctx->mrt.rib); free(ctx); return; } if (ctx->mrt.type == MRT_TABLE_DUMP_V2) mrt_dump_v2_hdr(&ctx->mrt, conf); if (rib_dump_new(rid, AID_UNSPEC, CTL_MSG_HIGH_MARK, &ctx->mrt, mrt_dump_upcall, rde_mrt_done, rde_mrt_throttled) == -1) fatal("%s: rib_dump_new", __func__); LIST_INSERT_HEAD(&rde_mrts, ctx, entry); rde_mrt_cnt++; } /* * kroute specific functions */ int rde_l3vpn_import(struct rde_community *comm, struct l3vpn *rd) { struct filter_set *s; TAILQ_FOREACH(s, &rd->import, entry) { if (community_match(comm, &s->action.community, 0)) return (1); } return (0); } void rde_send_kroute_flush(struct rib *rib) { if (imsg_compose(ibuf_main, IMSG_KROUTE_FLUSH, rib->rtableid, 0, -1, NULL, 0) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); } void rde_send_kroute(struct rib *rib, struct prefix *new, struct prefix *old) { struct kroute_full kf; struct prefix *p; struct l3vpn *vpn; enum imsg_type type; /* * Make sure that self announce prefixes are not committed to the * FIB. If both prefixes are unreachable no update is needed. */ if ((old == NULL || prefix_aspath(old)->flags & F_PREFIX_ANNOUNCED) && (new == NULL || prefix_aspath(new)->flags & F_PREFIX_ANNOUNCED)) return; if (new == NULL || prefix_aspath(new)->flags & F_PREFIX_ANNOUNCED) { type = IMSG_KROUTE_DELETE; p = old; } else { type = IMSG_KROUTE_CHANGE; p = new; } memset(&kf, 0, sizeof(kf)); pt_getaddr(p->pt, &kf.prefix); kf.prefixlen = p->pt->prefixlen; if (type == IMSG_KROUTE_CHANGE) { if (prefix_nhflags(p) == NEXTHOP_REJECT) kf.flags |= F_REJECT; if (prefix_nhflags(p) == NEXTHOP_BLACKHOLE) kf.flags |= F_BLACKHOLE; kf.nexthop = prefix_nexthop(p)->exit_nexthop; strlcpy(kf.label, rtlabel_id2name(prefix_aspath(p)->rtlabelid), sizeof(kf.label)); } switch (kf.prefix.aid) { case AID_VPN_IPv4: /* XXX FIB can not handle non-IPv4 nexthop */ if (kf.nexthop.aid != AID_INET) type = IMSG_KROUTE_DELETE; /* FALLTHROUGH */ case AID_VPN_IPv6: if (!(rib->flags & F_RIB_LOCAL)) /* not Loc-RIB, no update for VPNs */ break; SIMPLEQ_FOREACH(vpn, &conf->l3vpns, entry) { if (!rde_l3vpn_import(prefix_communities(p), vpn)) continue; /* XXX not ideal but this will change */ kf.ifindex = if_nametoindex(vpn->ifmpe); if (imsg_compose(ibuf_main, type, vpn->rtableid, 0, -1, &kf, sizeof(kf)) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); } break; case AID_INET: /* XXX FIB can not handle non-IPv4 nexthop */ if (kf.nexthop.aid != AID_INET) type = IMSG_KROUTE_DELETE; /* FALLTHROUGH */ default: if (imsg_compose(ibuf_main, type, rib->rtableid, 0, -1, &kf, sizeof(kf)) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); break; } } /* * update specific functions */ int rde_evaluate_all(void) { return rde_eval_all; } /* flush Adj-RIB-Out by withdrawing all prefixes */ static void rde_up_flush_upcall(struct prefix *p, void *ptr) { prefix_adjout_withdraw(p); } int rde_update_queue_pending(void) { struct rde_peer *peer; uint8_t aid; if (ibuf_se && imsgbuf_queuelen(ibuf_se) >= SESS_MSG_HIGH_MARK) return 0; RB_FOREACH(peer, peer_tree, &peertable) { if (peer->conf.id == 0) continue; if (!peer_is_up(peer)) continue; if (peer->throttled) continue; for (aid = AID_MIN; aid < AID_MAX; aid++) { if (!RB_EMPTY(&peer->updates[aid]) || !RB_EMPTY(&peer->withdraws[aid])) return 1; } } return 0; } void rde_update_queue_runner(uint8_t aid) { struct rde_peer *peer; struct ibuf *buf; int sent, max = RDE_RUNNER_ROUNDS; /* first withdraws ... */ do { sent = 0; RB_FOREACH(peer, peer_tree, &peertable) { if (peer->conf.id == 0) continue; if (!peer_is_up(peer)) continue; if (peer->throttled) continue; if (RB_EMPTY(&peer->withdraws[aid])) continue; if ((buf = up_dump_withdraws(peer, aid)) == NULL) { continue; } if (imsg_compose_ibuf(ibuf_se, IMSG_UPDATE, peer->conf.id, 0, buf) == -1) fatal("%s: imsg_create error", __func__); sent++; } max -= sent; } while (sent != 0 && max > 0); /* ... then updates */ max = RDE_RUNNER_ROUNDS; do { sent = 0; RB_FOREACH(peer, peer_tree, &peertable) { if (peer->conf.id == 0) continue; if (!peer_is_up(peer)) continue; if (peer->throttled) continue; if (RB_EMPTY(&peer->updates[aid])) continue; if (up_is_eor(peer, aid)) { int sent_eor = peer->sent_eor & (1 << aid); if (peer->capa.grestart.restart && !sent_eor) rde_peer_send_eor(peer, aid); if (peer->capa.enhanced_rr && sent_eor) rde_peer_send_rrefresh(peer, aid, ROUTE_REFRESH_END_RR); continue; } if ((buf = up_dump_update(peer, aid)) == NULL) { continue; } if (imsg_compose_ibuf(ibuf_se, IMSG_UPDATE, peer->conf.id, 0, buf) == -1) fatal("%s: imsg_compose_ibuf error", __func__); sent++; } max -= sent; } while (sent != 0 && max > 0); } /* * pf table specific functions */ struct rde_pftable_node { RB_ENTRY(rde_pftable_node) entry; struct pt_entry *prefix; int refcnt; uint16_t id; }; RB_HEAD(rde_pftable_tree, rde_pftable_node); static inline int rde_pftable_cmp(struct rde_pftable_node *a, struct rde_pftable_node *b) { if (a->prefix > b->prefix) return 1; if (a->prefix < b->prefix) return -1; return (a->id - b->id); } RB_GENERATE_STATIC(rde_pftable_tree, rde_pftable_node, entry, rde_pftable_cmp); struct rde_pftable_tree pftable_tree = RB_INITIALIZER(&pftable_tree); int need_commit; static void rde_pftable_send(uint16_t id, struct pt_entry *pt, int del) { struct pftable_msg pfm; if (id == 0) return; /* do not run while cleaning up */ if (rde_quit) return; memset(&pfm, 0, sizeof(pfm)); strlcpy(pfm.pftable, pftable_id2name(id), sizeof(pfm.pftable)); pt_getaddr(pt, &pfm.addr); pfm.len = pt->prefixlen; if (imsg_compose(ibuf_main, del ? IMSG_PFTABLE_REMOVE : IMSG_PFTABLE_ADD, 0, 0, -1, &pfm, sizeof(pfm)) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); need_commit = 1; } void rde_pftable_add(uint16_t id, struct prefix *p) { struct rde_pftable_node *pfn, node; memset(&node, 0, sizeof(node)); node.prefix = p->pt; node.id = id; pfn = RB_FIND(rde_pftable_tree, &pftable_tree, &node); if (pfn == NULL) { if ((pfn = calloc(1, sizeof(*pfn))) == NULL) fatal("%s", __func__); pfn->prefix = pt_ref(p->pt); pfn->id = id; if (RB_INSERT(rde_pftable_tree, &pftable_tree, pfn) != NULL) fatalx("%s: tree corrupt", __func__); rde_pftable_send(id, p->pt, 0); } pfn->refcnt++; } void rde_pftable_del(uint16_t id, struct prefix *p) { struct rde_pftable_node *pfn, node; memset(&node, 0, sizeof(node)); node.prefix = p->pt; node.id = id; pfn = RB_FIND(rde_pftable_tree, &pftable_tree, &node); if (pfn == NULL) return; if (--pfn->refcnt <= 0) { rde_pftable_send(id, p->pt, 1); if (RB_REMOVE(rde_pftable_tree, &pftable_tree, pfn) == NULL) fatalx("%s: tree corrupt", __func__); pt_unref(pfn->prefix); free(pfn); } } void rde_commit_pftable(void) { /* do not run while cleaning up */ if (rde_quit) return; if (!need_commit) return; if (imsg_compose(ibuf_main, IMSG_PFTABLE_COMMIT, 0, 0, -1, NULL, 0) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); need_commit = 0; } /* * nexthop specific functions */ void rde_send_nexthop(struct bgpd_addr *next, int insert) { int type; if (insert) type = IMSG_NEXTHOP_ADD; else type = IMSG_NEXTHOP_REMOVE; if (imsg_compose(ibuf_main, type, 0, 0, -1, next, sizeof(struct bgpd_addr)) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); } /* * soft reconfig specific functions */ void rde_reload_done(void) { struct rde_peer *peer; struct filter_head *fh; struct rde_prefixset_head prefixsets_old; struct rde_prefixset_head originsets_old; struct as_set_head as_sets_old; uint16_t rid; int reload = 0, force_locrib = 0; softreconfig = 0; SIMPLEQ_INIT(&prefixsets_old); SIMPLEQ_INIT(&originsets_old); SIMPLEQ_INIT(&as_sets_old); SIMPLEQ_CONCAT(&prefixsets_old, &conf->rde_prefixsets); SIMPLEQ_CONCAT(&originsets_old, &conf->rde_originsets); SIMPLEQ_CONCAT(&as_sets_old, &conf->as_sets); /* run softreconfig in if filter mode changed */ if (conf->filtered_in_locrib != nconf->filtered_in_locrib) { log_debug("filter mode changed, reloading Loc-Rib"); force_locrib = 1; } /* merge the main config */ copy_config(conf, nconf); /* need to copy the sets and roa table and clear them in nconf */ SIMPLEQ_CONCAT(&conf->rde_prefixsets, &nconf->rde_prefixsets); SIMPLEQ_CONCAT(&conf->rde_originsets, &nconf->rde_originsets); SIMPLEQ_CONCAT(&conf->as_sets, &nconf->as_sets); /* apply new set of l3vpn, sync will be done later */ free_l3vpns(&conf->l3vpns); SIMPLEQ_CONCAT(&conf->l3vpns, &nconf->l3vpns); /* XXX WHERE IS THE SYNC ??? */ free_config(nconf); nconf = NULL; /* sync peerself with conf */ peerself->remote_bgpid = conf->bgpid; peerself->conf.local_as = conf->as; peerself->conf.remote_as = conf->as; peerself->conf.remote_addr.aid = AID_INET; peerself->conf.remote_addr.v4.s_addr = htonl(conf->bgpid); peerself->conf.remote_masklen = 32; peerself->short_as = conf->short_as; rde_mark_prefixsets_dirty(&prefixsets_old, &conf->rde_prefixsets); rde_mark_prefixsets_dirty(&originsets_old, &conf->rde_originsets); as_sets_mark_dirty(&as_sets_old, &conf->as_sets); /* make sure that rde_eval_all is correctly set after a config change */ rde_eval_all = 0; /* Make the new outbound filter rules the active one. */ filterlist_free(out_rules); out_rules = out_rules_tmp; out_rules_tmp = NULL; /* check if filter changed */ RB_FOREACH(peer, peer_tree, &peertable) { if (peer->conf.id == 0) /* ignore peerself */ continue; peer->reconf_out = 0; peer->reconf_rib = 0; /* max prefix checker */ if (peer->conf.max_prefix && peer->stats.prefix_cnt > peer->conf.max_prefix) { log_peer_warnx(&peer->conf, "prefix limit reached (>%u/%u)", peer->stats.prefix_cnt, peer->conf.max_prefix); rde_update_err(peer, ERR_CEASE, ERR_CEASE_MAX_PREFIX, NULL); } /* max prefix checker outbound */ if (peer->conf.max_out_prefix && peer->stats.prefix_out_cnt > peer->conf.max_out_prefix) { log_peer_warnx(&peer->conf, "outbound prefix limit reached (>%u/%u)", peer->stats.prefix_out_cnt, peer->conf.max_out_prefix); rde_update_err(peer, ERR_CEASE, ERR_CEASE_MAX_SENT_PREFIX, NULL); } if (peer->export_type != peer->conf.export_type) { log_peer_info(&peer->conf, "export type change, " "reloading"); peer->reconf_rib = 1; } if ((peer->flags & PEERFLAG_EVALUATE_ALL) != (peer->conf.flags & PEERFLAG_EVALUATE_ALL)) { log_peer_info(&peer->conf, "rde evaluate change, " "reloading"); peer->reconf_rib = 1; } if ((peer->flags & PEERFLAG_TRANS_AS) != (peer->conf.flags & PEERFLAG_TRANS_AS)) { log_peer_info(&peer->conf, "transparent-as change, " "reloading"); peer->reconf_rib = 1; } if (peer->loc_rib_id != rib_find(peer->conf.rib)) { log_peer_info(&peer->conf, "rib change, reloading"); peer->loc_rib_id = rib_find(peer->conf.rib); if (peer->loc_rib_id == RIB_NOTFOUND) fatalx("King Bula's peer met an unknown RIB"); peer->reconf_rib = 1; } /* * Update add-path settings but only if the session is * running with add-path and the config uses add-path * as well. */ if (peer_has_add_path(peer, AID_UNSPEC, CAPA_AP_SEND)) { if (peer->conf.eval.mode != ADDPATH_EVAL_NONE && memcmp(&peer->eval, &peer->conf.eval, sizeof(peer->eval)) != 0) { log_peer_info(&peer->conf, "addpath eval change, reloading"); peer->reconf_out = 1; peer->eval = peer->conf.eval; } /* add-path send needs rde_eval_all */ rde_eval_all = 1; } if (peer->role != peer->conf.role) { if (reload == 0) log_debug("peer role change: " "reloading Adj-RIB-In"); peer->role = peer->conf.role; reload++; } peer->export_type = peer->conf.export_type; peer->flags = peer->conf.flags; if (peer->flags & PEERFLAG_EVALUATE_ALL) rde_eval_all = 1; if (peer->reconf_rib) { if (prefix_dump_new(peer, AID_UNSPEC, RDE_RUNNER_ROUNDS, NULL, rde_up_flush_upcall, rde_softreconfig_in_done, NULL) == -1) fatal("%s: prefix_dump_new", __func__); log_peer_info(&peer->conf, "flushing Adj-RIB-Out"); softreconfig++; /* account for the running flush */ continue; } /* reapply outbound filters for this peer */ fh = peer_apply_out_filter(peer, out_rules); if (!rde_filter_equal(peer->out_rules, fh)) { char *p = log_fmt_peer(&peer->conf); log_debug("out filter change: reloading peer %s", p); free(p); peer->reconf_out = 1; } filterlist_free(fh); } /* bring ribs in sync */ for (rid = RIB_LOC_START; rid < rib_size; rid++) { struct rib *rib = rib_byid(rid); if (rib == NULL) continue; rde_filter_calc_skip_steps(rib->in_rules_tmp); /* flip rules, make new active */ fh = rib->in_rules; rib->in_rules = rib->in_rules_tmp; rib->in_rules_tmp = fh; switch (rib->state) { case RECONF_DELETE: rib_free(rib); break; case RECONF_RELOAD: if (rib_update(rib)) { RB_FOREACH(peer, peer_tree, &peertable) { /* ignore peerself */ if (peer->conf.id == 0) continue; /* skip peers using a different rib */ if (peer->loc_rib_id != rib->id) continue; /* peer rib is already being flushed */ if (peer->reconf_rib) continue; if (prefix_dump_new(peer, AID_UNSPEC, RDE_RUNNER_ROUNDS, NULL, rde_up_flush_upcall, rde_softreconfig_in_done, NULL) == -1) fatal("%s: prefix_dump_new", __func__); log_peer_info(&peer->conf, "flushing Adj-RIB-Out"); /* account for the running flush */ softreconfig++; } } rib->state = RECONF_KEEP; /* FALLTHROUGH */ case RECONF_KEEP: if (!(force_locrib && rid == RIB_LOC_START) && rde_filter_equal(rib->in_rules, rib->in_rules_tmp)) /* rib is in sync */ break; log_debug("filter change: reloading RIB %s", rib->name); rib->state = RECONF_RELOAD; reload++; break; case RECONF_REINIT: /* new rib */ rib->state = RECONF_RELOAD; reload++; break; case RECONF_NONE: break; } filterlist_free(rib->in_rules_tmp); rib->in_rules_tmp = NULL; } /* old filters removed, free all sets */ free_rde_prefixsets(&prefixsets_old); free_rde_prefixsets(&originsets_old); as_sets_free(&as_sets_old); log_info("RDE reconfigured"); softreconfig++; if (reload > 0) { if (rib_dump_new(RIB_ADJ_IN, AID_UNSPEC, RDE_RUNNER_ROUNDS, NULL, rde_softreconfig_in, rde_softreconfig_in_done, NULL) == -1) fatal("%s: rib_dump_new", __func__); log_info("running softreconfig in"); } else { rde_softreconfig_in_done((void *)1, AID_UNSPEC); } } static void rde_softreconfig_in_done(void *arg, uint8_t dummy) { struct rde_peer *peer; uint16_t i; softreconfig--; /* one guy done but other dumps are still running */ if (softreconfig > 0) return; if (arg == NULL) log_info("softreconfig in done"); /* now do the Adj-RIB-Out sync and a possible FIB sync */ softreconfig = 0; for (i = 0; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; rib->state = RECONF_NONE; if (rib->fibstate == RECONF_RELOAD) { if (rib_dump_new(i, AID_UNSPEC, RDE_RUNNER_ROUNDS, rib, rde_softreconfig_sync_fib, rde_softreconfig_sync_done, NULL) == -1) fatal("%s: rib_dump_new", __func__); softreconfig++; log_info("starting fib sync for rib %s", rib->name); } else if (rib->fibstate == RECONF_REINIT) { if (rib_dump_new(i, AID_UNSPEC, RDE_RUNNER_ROUNDS, rib, rde_softreconfig_sync_reeval, rde_softreconfig_sync_done, NULL) == -1) fatal("%s: rib_dump_new", __func__); softreconfig++; log_info("starting re-evaluation of rib %s", rib->name); } } RB_FOREACH(peer, peer_tree, &peertable) { uint8_t aid; if (peer->reconf_out) { if (peer->export_type == EXPORT_NONE) { /* nothing to do here */ peer->reconf_out = 0; } else if (peer->export_type == EXPORT_DEFAULT_ROUTE) { /* just resend the default route */ for (aid = AID_MIN; aid < AID_MAX; aid++) { if (peer->capa.mp[aid]) up_generate_default(peer, aid); } peer->reconf_out = 0; } else rib_byid(peer->loc_rib_id)->state = RECONF_RELOAD; } else if (peer->reconf_rib) { /* dump the full table to neighbors that changed rib */ for (aid = AID_MIN; aid < AID_MAX; aid++) { if (peer->capa.mp[aid]) peer_dump(peer, aid); } } } for (i = 0; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; if (rib->state == RECONF_RELOAD) { if (rib_dump_new(i, AID_UNSPEC, RDE_RUNNER_ROUNDS, rib, rde_softreconfig_out, rde_softreconfig_out_done, NULL) == -1) fatal("%s: rib_dump_new", __func__); softreconfig++; log_info("starting softreconfig out for rib %s", rib->name); } } /* if nothing to do move to last stage */ if (softreconfig == 0) rde_softreconfig_done(); } static void rde_softreconfig_out_done(void *arg, uint8_t aid) { struct rib *rib = arg; /* this RIB dump is done */ log_info("softreconfig out done for %s", rib->name); /* check if other dumps are still running */ if (--softreconfig == 0) rde_softreconfig_done(); } static void rde_softreconfig_done(void) { uint16_t i; for (i = 0; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; rib->state = RECONF_NONE; } log_info("RDE soft reconfiguration done"); imsg_compose(ibuf_main, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0); } static void rde_softreconfig_in(struct rib_entry *re, void *bula) { struct filterstate state; struct rib *rib; struct prefix *p; struct pt_entry *pt; struct rde_peer *peer; struct rde_aspath *asp; enum filter_actions action; struct bgpd_addr prefix; uint16_t i; uint8_t aspa_vstate; pt = re->prefix; pt_getaddr(pt, &prefix); TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) { asp = prefix_aspath(p); peer = prefix_peer(p); /* possible role change update ASPA validation state */ if (prefix_aspa_vstate(p) == ASPA_NEVER_KNOWN) aspa_vstate = ASPA_NEVER_KNOWN; else aspa_vstate = rde_aspa_validity(peer, asp, pt->aid); prefix_set_vstate(p, prefix_roa_vstate(p), aspa_vstate); /* skip announced networks, they are never filtered */ if (asp->flags & F_PREFIX_ANNOUNCED) continue; for (i = RIB_LOC_START; i < rib_size; i++) { rib = rib_byid(i); if (rib == NULL) continue; if (rib->state != RECONF_RELOAD) continue; rde_filterstate_prep(&state, p); action = rde_filter(rib->in_rules, peer, peer, &prefix, pt->prefixlen, &state); if (action == ACTION_ALLOW) { /* update Local-RIB */ prefix_update(rib, peer, p->path_id, p->path_id_tx, &state, 0, &prefix, pt->prefixlen); } else if (conf->filtered_in_locrib && i == RIB_LOC_START) { prefix_update(rib, peer, p->path_id, p->path_id_tx, &state, 1, &prefix, pt->prefixlen); } else { /* remove from Local-RIB */ prefix_withdraw(rib, peer, p->path_id, &prefix, pt->prefixlen); } rde_filterstate_clean(&state); } } } static void rde_softreconfig_out(struct rib_entry *re, void *arg) { if (prefix_best(re) == NULL) /* no valid path for prefix */ return; rde_generate_updates(re, NULL, NULL, EVAL_RECONF); } static void rde_softreconfig_sync_reeval(struct rib_entry *re, void *arg) { struct prefix_queue prefixes = TAILQ_HEAD_INITIALIZER(prefixes); struct prefix *p, *next; struct rib *rib = arg; if (rib->flags & F_RIB_NOEVALUATE) { /* * evaluation process is turned off * all dependent adj-rib-out were already flushed * unlink nexthop if it was linked */ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) { if (p->flags & PREFIX_NEXTHOP_LINKED) nexthop_unlink(p); p->dmetric = PREFIX_DMETRIC_INVALID; } return; } /* evaluation process is turned on, so evaluate all prefixes again */ TAILQ_CONCAT(&prefixes, &re->prefix_h, entry.list.rib); /* * TODO: this code works but is not optimal. prefix_evaluate() * does a lot of extra work in the worst case. Would be better * to resort the list once and then call rde_generate_updates() * and rde_send_kroute() once. */ TAILQ_FOREACH_SAFE(p, &prefixes, entry.list.rib, next) { /* need to re-link the nexthop if not already linked */ TAILQ_REMOVE(&prefixes, p, entry.list.rib); if ((p->flags & PREFIX_NEXTHOP_LINKED) == 0) nexthop_link(p); prefix_evaluate(re, p, NULL); } } static void rde_softreconfig_sync_fib(struct rib_entry *re, void *bula) { struct prefix *p; if ((p = prefix_best(re)) != NULL) rde_send_kroute(re_rib(re), p, NULL); } static void rde_softreconfig_sync_done(void *arg, uint8_t aid) { struct rib *rib = arg; /* this RIB dump is done */ if (rib->fibstate == RECONF_RELOAD) log_info("fib sync done for %s", rib->name); else log_info("re-evaluation done for %s", rib->name); rib->fibstate = RECONF_NONE; /* check if other dumps are still running */ if (--softreconfig == 0) rde_softreconfig_done(); } /* * ROA specific functions. The roa set is updated independent of the config * so this runs outside of the softreconfig handlers. */ static void rde_rpki_softreload(struct rib_entry *re, void *bula) { struct filterstate state; struct rib *rib; struct prefix *p; struct pt_entry *pt; struct rde_peer *peer; struct rde_aspath *asp; enum filter_actions action; struct bgpd_addr prefix; uint8_t roa_vstate, aspa_vstate; uint16_t i; pt = re->prefix; pt_getaddr(pt, &prefix); TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) { asp = prefix_aspath(p); peer = prefix_peer(p); /* ROA validation state update */ roa_vstate = rde_roa_validity(&rde_roa, &prefix, pt->prefixlen, aspath_origin(asp->aspath)); /* ASPA validation state update (if needed) */ if (prefix_aspa_vstate(p) == ASPA_NEVER_KNOWN) { aspa_vstate = ASPA_NEVER_KNOWN; } else { if (asp->aspa_generation != rde_aspa_generation) { asp->aspa_generation = rde_aspa_generation; aspa_validation(rde_aspa, asp->aspath, &asp->aspa_state); } aspa_vstate = rde_aspa_validity(peer, asp, pt->aid); } if (roa_vstate == prefix_roa_vstate(p) && aspa_vstate == prefix_aspa_vstate(p)) continue; prefix_set_vstate(p, roa_vstate, aspa_vstate); /* skip announced networks, they are never filtered */ if (asp->flags & F_PREFIX_ANNOUNCED) continue; for (i = RIB_LOC_START; i < rib_size; i++) { rib = rib_byid(i); if (rib == NULL) continue; rde_filterstate_prep(&state, p); action = rde_filter(rib->in_rules, peer, peer, &prefix, pt->prefixlen, &state); if (action == ACTION_ALLOW) { /* update Local-RIB */ prefix_update(rib, peer, p->path_id, p->path_id_tx, &state, 0, &prefix, pt->prefixlen); } else if (conf->filtered_in_locrib && i == RIB_LOC_START) { prefix_update(rib, peer, p->path_id, p->path_id_tx, &state, 1, &prefix, pt->prefixlen); } else { /* remove from Local-RIB */ prefix_withdraw(rib, peer, p->path_id, &prefix, pt->prefixlen); } rde_filterstate_clean(&state); } } } static int rpki_update_pending; static void rde_rpki_softreload_done(void *arg, uint8_t aid) { /* the roa update is done */ log_info("RPKI softreload done"); rpki_update_pending = 0; } static void rde_rpki_reload(void) { if (rpki_update_pending) { log_info("RPKI softreload skipped, old still running"); return; } rpki_update_pending = 1; if (rib_dump_new(RIB_ADJ_IN, AID_UNSPEC, RDE_RUNNER_ROUNDS, rib_byid(RIB_ADJ_IN), rde_rpki_softreload, rde_rpki_softreload_done, NULL) == -1) fatal("%s: rib_dump_new", __func__); } static int rde_roa_reload(void) { struct rde_prefixset roa_old; if (rpki_update_pending) { trie_free(&roa_new.th); /* can't use new roa table */ return 1; /* force call to rde_rpki_reload */ } roa_old = rde_roa; rde_roa = roa_new; memset(&roa_new, 0, sizeof(roa_new)); /* check if roa changed */ if (trie_equal(&rde_roa.th, &roa_old.th)) { rde_roa.lastchange = roa_old.lastchange; trie_free(&roa_old.th); /* old roa no longer needed */ return 0; } rde_roa.lastchange = getmonotime(); trie_free(&roa_old.th); /* old roa no longer needed */ log_debug("ROA change: reloading Adj-RIB-In"); return 1; } static int rde_aspa_reload(void) { struct rde_aspa *aspa_old; if (rpki_update_pending) { aspa_table_free(aspa_new); /* can't use new aspa table */ aspa_new = NULL; return 1; /* rpki_client_relaod warns */ } aspa_old = rde_aspa; rde_aspa = aspa_new; aspa_new = NULL; /* check if aspa changed */ if (aspa_table_equal(rde_aspa, aspa_old)) { aspa_table_unchanged(rde_aspa, aspa_old); aspa_table_free(aspa_old); /* old aspa no longer needed */ return 0; } aspa_table_free(aspa_old); /* old aspa no longer needed */ log_debug("ASPA change: reloading Adj-RIB-In"); rde_aspa_generation++; return 1; } /* * generic helper function */ uint32_t rde_local_as(void) { return (conf->as); } int rde_decisionflags(void) { return (conf->flags & BGPD_FLAG_DECISION_MASK); } /* End-of-RIB marker, RFC 4724 */ static void rde_peer_recv_eor(struct rde_peer *peer, uint8_t aid) { peer->stats.prefix_rcvd_eor++; peer->recv_eor |= 1 << aid; /* * First notify SE to avert a possible race with the restart timeout. * If the timeout fires before this imsg is processed by the SE it will * result in the same operation since the timeout issues a FLUSH which * does the same as the RESTARTED action (flushing stale routes). * The logic in the SE is so that only one of FLUSH or RESTARTED will * be sent back to the RDE and so peer_flush is only called once. */ if (imsg_compose(ibuf_se, IMSG_SESSION_RESTARTED, peer->conf.id, 0, -1, &aid, sizeof(aid)) == -1) fatal("imsg_compose error while receiving EoR"); log_peer_info(&peer->conf, "received %s EOR marker", aid2str(aid)); } static void rde_peer_send_eor(struct rde_peer *peer, uint8_t aid) { uint16_t afi; uint8_t safi; peer->stats.prefix_sent_eor++; peer->sent_eor |= 1 << aid; if (aid == AID_INET) { u_char null[4]; memset(&null, 0, 4); if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id, 0, -1, &null, 4) == -1) fatal("imsg_compose error while sending EoR"); } else { uint16_t i; u_char buf[10]; if (aid2afi(aid, &afi, &safi) == -1) fatalx("peer_send_eor: bad AID"); i = 0; /* v4 withdrawn len */ memcpy(&buf[0], &i, sizeof(i)); i = htons(6); /* path attr len */ memcpy(&buf[2], &i, sizeof(i)); buf[4] = ATTR_OPTIONAL; buf[5] = ATTR_MP_UNREACH_NLRI; buf[6] = 3; /* withdrawn len */ i = htons(afi); memcpy(&buf[7], &i, sizeof(i)); buf[9] = safi; if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id, 0, -1, &buf, 10) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); } log_peer_info(&peer->conf, "sending %s EOR marker", aid2str(aid)); } void rde_peer_send_rrefresh(struct rde_peer *peer, uint8_t aid, uint8_t subtype) { struct route_refresh rr; /* not strickly needed, the SE checks as well */ if (peer->capa.enhanced_rr == 0) return; switch (subtype) { case ROUTE_REFRESH_END_RR: case ROUTE_REFRESH_BEGIN_RR: break; default: fatalx("%s unexpected subtype %d", __func__, subtype); } rr.aid = aid; rr.subtype = subtype; if (imsg_compose(ibuf_se, IMSG_REFRESH, peer->conf.id, 0, -1, &rr, sizeof(rr)) == -1) fatal("%s %d imsg_compose error", __func__, __LINE__); log_peer_info(&peer->conf, "sending %s %s marker", aid2str(aid), subtype == ROUTE_REFRESH_END_RR ? "EoRR" : "BoRR"); } /* * network announcement stuff */ void network_add(struct network_config *nc, struct filterstate *state) { struct l3vpn *vpn; struct filter_set_head *vpnset = NULL; struct in_addr prefix4; struct in6_addr prefix6; uint32_t path_id_tx; uint16_t i; uint8_t vstate; if (nc->rd != 0) { SIMPLEQ_FOREACH(vpn, &conf->l3vpns, entry) { if (vpn->rd != nc->rd) continue; switch (nc->prefix.aid) { case AID_INET: prefix4 = nc->prefix.v4; memset(&nc->prefix, 0, sizeof(nc->prefix)); nc->prefix.aid = AID_VPN_IPv4; nc->prefix.rd = vpn->rd; nc->prefix.v4 = prefix4; nc->prefix.labellen = 3; nc->prefix.labelstack[0] = (vpn->label >> 12) & 0xff; nc->prefix.labelstack[1] = (vpn->label >> 4) & 0xff; nc->prefix.labelstack[2] = (vpn->label << 4) & 0xf0; nc->prefix.labelstack[2] |= BGP_MPLS_BOS; vpnset = &vpn->export; break; case AID_INET6: prefix6 = nc->prefix.v6; memset(&nc->prefix, 0, sizeof(nc->prefix)); nc->prefix.aid = AID_VPN_IPv6; nc->prefix.rd = vpn->rd; nc->prefix.v6 = prefix6; nc->prefix.labellen = 3; nc->prefix.labelstack[0] = (vpn->label >> 12) & 0xff; nc->prefix.labelstack[1] = (vpn->label >> 4) & 0xff; nc->prefix.labelstack[2] = (vpn->label << 4) & 0xf0; nc->prefix.labelstack[2] |= BGP_MPLS_BOS; vpnset = &vpn->export; break; default: log_warnx("unable to VPNize prefix"); filterset_free(&nc->attrset); return; } break; } if (vpn == NULL) { log_warnx("network_add: " "prefix %s/%u in non-existing l3vpn %s", log_addr(&nc->prefix), nc->prefixlen, log_rd(nc->rd)); return; } } rde_apply_set(&nc->attrset, peerself, peerself, state, nc->prefix.aid); if (vpnset) rde_apply_set(vpnset, peerself, peerself, state, nc->prefix.aid); vstate = rde_roa_validity(&rde_roa, &nc->prefix, nc->prefixlen, aspath_origin(state->aspath.aspath)); rde_filterstate_set_vstate(state, vstate, ASPA_NEVER_KNOWN); path_id_tx = pathid_assign(peerself, 0, &nc->prefix, nc->prefixlen); if (prefix_update(rib_byid(RIB_ADJ_IN), peerself, 0, path_id_tx, state, 0, &nc->prefix, nc->prefixlen) == 1) peerself->stats.prefix_cnt++; for (i = RIB_LOC_START; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; rde_update_log("announce", i, peerself, state->nexthop ? &state->nexthop->exit_nexthop : NULL, &nc->prefix, nc->prefixlen); prefix_update(rib, peerself, 0, path_id_tx, state, 0, &nc->prefix, nc->prefixlen); } filterset_free(&nc->attrset); } void network_delete(struct network_config *nc) { struct l3vpn *vpn; struct in_addr prefix4; struct in6_addr prefix6; uint32_t i; if (nc->rd) { SIMPLEQ_FOREACH(vpn, &conf->l3vpns, entry) { if (vpn->rd != nc->rd) continue; switch (nc->prefix.aid) { case AID_INET: prefix4 = nc->prefix.v4; memset(&nc->prefix, 0, sizeof(nc->prefix)); nc->prefix.aid = AID_VPN_IPv4; nc->prefix.rd = vpn->rd; nc->prefix.v4 = prefix4; nc->prefix.labellen = 3; nc->prefix.labelstack[0] = (vpn->label >> 12) & 0xff; nc->prefix.labelstack[1] = (vpn->label >> 4) & 0xff; nc->prefix.labelstack[2] = (vpn->label << 4) & 0xf0; nc->prefix.labelstack[2] |= BGP_MPLS_BOS; break; case AID_INET6: prefix6 = nc->prefix.v6; memset(&nc->prefix, 0, sizeof(nc->prefix)); nc->prefix.aid = AID_VPN_IPv6; nc->prefix.rd = vpn->rd; nc->prefix.v6 = prefix6; nc->prefix.labellen = 3; nc->prefix.labelstack[0] = (vpn->label >> 12) & 0xff; nc->prefix.labelstack[1] = (vpn->label >> 4) & 0xff; nc->prefix.labelstack[2] = (vpn->label << 4) & 0xf0; nc->prefix.labelstack[2] |= BGP_MPLS_BOS; break; default: log_warnx("unable to VPNize prefix"); return; } } } for (i = RIB_LOC_START; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; if (prefix_withdraw(rib, peerself, 0, &nc->prefix, nc->prefixlen)) rde_update_log("withdraw announce", i, peerself, NULL, &nc->prefix, nc->prefixlen); } if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peerself, 0, &nc->prefix, nc->prefixlen)) peerself->stats.prefix_cnt--; } static void network_dump_upcall(struct rib_entry *re, void *ptr) { struct prefix *p; struct rde_aspath *asp; struct kroute_full kf; struct bgpd_addr addr; struct rde_dump_ctx *ctx = ptr; TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) { asp = prefix_aspath(p); if (!(asp->flags & F_PREFIX_ANNOUNCED)) continue; pt_getaddr(p->pt, &addr); memset(&kf, 0, sizeof(kf)); kf.prefix = addr; kf.prefixlen = p->pt->prefixlen; if (prefix_nhvalid(p) && prefix_nexthop(p) != NULL) kf.nexthop = prefix_nexthop(p)->true_nexthop; else kf.nexthop.aid = kf.prefix.aid; if ((asp->flags & F_ANN_DYNAMIC) == 0) kf.flags = F_STATIC; if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_NETWORK, 0, ctx->req.pid, -1, &kf, sizeof(kf)) == -1) log_warnx("%s: imsg_compose error", __func__); } } static void network_flush_upcall(struct rib_entry *re, void *ptr) { struct bgpd_addr addr; struct prefix *p; uint32_t i; uint8_t prefixlen; p = prefix_bypeer(re, peerself, 0); if (p == NULL) return; if ((prefix_aspath(p)->flags & F_ANN_DYNAMIC) != F_ANN_DYNAMIC) return; pt_getaddr(re->prefix, &addr); prefixlen = re->prefix->prefixlen; for (i = RIB_LOC_START; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; if (prefix_withdraw(rib, peerself, 0, &addr, prefixlen) == 1) rde_update_log("flush announce", i, peerself, NULL, &addr, prefixlen); } if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peerself, 0, &addr, prefixlen) == 1) peerself->stats.prefix_cnt--; } /* * flowspec announcement stuff */ void flowspec_add(struct flowspec *f, struct filterstate *state, struct filter_set_head *attrset) { struct pt_entry *pte; uint32_t path_id_tx; rde_apply_set(attrset, peerself, peerself, state, f->aid); rde_filterstate_set_vstate(state, ROA_NOTFOUND, ASPA_NEVER_KNOWN); path_id_tx = peerself->path_id_tx; /* XXX should use pathid_assign() */ pte = pt_get_flow(f); if (pte == NULL) pte = pt_add_flow(f); if (prefix_flowspec_update(peerself, state, pte, path_id_tx) == 1) peerself->stats.prefix_cnt++; } void flowspec_delete(struct flowspec *f) { struct pt_entry *pte; pte = pt_get_flow(f); if (pte == NULL) return; if (prefix_flowspec_withdraw(peerself, pte) == 1) peerself->stats.prefix_cnt--; } static void flowspec_flush_upcall(struct rib_entry *re, void *ptr) { struct prefix *p; p = prefix_bypeer(re, peerself, 0); if (p == NULL) return; if ((prefix_aspath(p)->flags & F_ANN_DYNAMIC) != F_ANN_DYNAMIC) return; if (prefix_flowspec_withdraw(peerself, re->prefix) == 1) peerself->stats.prefix_cnt--; } static void flowspec_dump_upcall(struct rib_entry *re, void *ptr) { pid_t *pid = ptr; struct prefix *p; struct rde_aspath *asp; struct rde_community *comm; struct flowspec ff; struct ibuf *ibuf; uint8_t *flow; int len; TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) { asp = prefix_aspath(p); if (!(asp->flags & F_PREFIX_ANNOUNCED)) continue; comm = prefix_communities(p); len = pt_getflowspec(p->pt, &flow); memset(&ff, 0, sizeof(ff)); ff.aid = p->pt->aid; ff.len = len; if ((asp->flags & F_ANN_DYNAMIC) == 0) ff.flags = F_STATIC; if ((ibuf = imsg_create(ibuf_se_ctl, IMSG_CTL_SHOW_FLOWSPEC, 0, *pid, FLOWSPEC_SIZE + len)) == NULL) continue; if (imsg_add(ibuf, &ff, FLOWSPEC_SIZE) == -1 || imsg_add(ibuf, flow, len) == -1) continue; imsg_close(ibuf_se_ctl, ibuf); if (comm->nentries > 0) { if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_RIB_COMMUNITIES, 0, *pid, -1, comm->communities, comm->nentries * sizeof(struct community)) == -1) continue; } } } static void flowspec_dump_done(void *ptr, uint8_t aid) { pid_t *pid = ptr; imsg_compose(ibuf_se_ctl, IMSG_CTL_END, 0, *pid, -1, NULL, 0); } /* clean up */ void rde_shutdown(void) { /* * the decision process is turned off if rde_quit = 1 and * rde_shutdown depends on this. */ /* First all peers go down */ peer_shutdown(); /* free filters */ filterlist_free(out_rules); filterlist_free(out_rules_tmp); /* kill the VPN configs */ free_l3vpns(&conf->l3vpns); /* now check everything */ rib_shutdown(); nexthop_shutdown(); path_shutdown(); attr_shutdown(); pt_shutdown(); } struct rde_prefixset * rde_find_prefixset(char *name, struct rde_prefixset_head *p) { struct rde_prefixset *ps; SIMPLEQ_FOREACH(ps, p, entry) { if (!strcmp(ps->name, name)) return (ps); } return (NULL); } void rde_mark_prefixsets_dirty(struct rde_prefixset_head *psold, struct rde_prefixset_head *psnew) { struct rde_prefixset *new, *old; SIMPLEQ_FOREACH(new, psnew, entry) { if ((psold == NULL) || (old = rde_find_prefixset(new->name, psold)) == NULL) { new->dirty = 1; new->lastchange = getmonotime(); } else { if (trie_equal(&new->th, &old->th) == 0) { new->dirty = 1; new->lastchange = getmonotime(); } else new->lastchange = old->lastchange; } } } uint8_t rde_roa_validity(struct rde_prefixset *ps, struct bgpd_addr *prefix, uint8_t plen, uint32_t as) { int r; r = trie_roa_check(&ps->th, prefix, plen, as); return (r & ROA_MASK); } static int ovs_match(struct prefix *p, uint32_t flag) { if (flag & (F_CTL_OVS_VALID|F_CTL_OVS_INVALID|F_CTL_OVS_NOTFOUND)) { switch (prefix_roa_vstate(p)) { case ROA_VALID: if (!(flag & F_CTL_OVS_VALID)) return 0; break; case ROA_INVALID: if (!(flag & F_CTL_OVS_INVALID)) return 0; break; case ROA_NOTFOUND: if (!(flag & F_CTL_OVS_NOTFOUND)) return 0; break; default: break; } } return 1; } static int avs_match(struct prefix *p, uint32_t flag) { if (flag & (F_CTL_AVS_VALID|F_CTL_AVS_INVALID|F_CTL_AVS_UNKNOWN)) { switch (prefix_aspa_vstate(p) & ASPA_MASK) { case ASPA_VALID: if (!(flag & F_CTL_AVS_VALID)) return 0; break; case ASPA_INVALID: if (!(flag & F_CTL_AVS_INVALID)) return 0; break; case ASPA_UNKNOWN: if (!(flag & F_CTL_AVS_UNKNOWN)) return 0; break; default: break; } } return 1; } openbgpd-8.8/src/bgpd/rde_rib.c100644 001750 001750 00000135054 14751151130 0012154/* $OpenBSD: rde_rib.c,v 1.267 2025/01/14 12:24:23 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" /* * BGP RIB -- Routing Information Base * * The RIB is build with one aspect in mind. Speed -- actually update speed. * Therefore one thing needs to be absolutely avoided, long table walks. * This is achieved by heavily linking the different parts together. */ uint16_t rib_size; struct rib **ribs; struct rib flowrib = { .id = 1, .tree = RB_INITIALIZER(&flowrib.tree) }; struct rib_entry *rib_add(struct rib *, struct pt_entry *); static inline int rib_compare(const struct rib_entry *, const struct rib_entry *); void rib_remove(struct rib_entry *); int rib_empty(struct rib_entry *); static void rib_dump_abort(uint16_t); RB_PROTOTYPE(rib_tree, rib_entry, rib_e, rib_compare); RB_GENERATE(rib_tree, rib_entry, rib_e, rib_compare); struct rib_context { LIST_ENTRY(rib_context) entry; struct rib_entry *ctx_re; struct prefix *ctx_p; uint32_t ctx_id; void (*ctx_rib_call)(struct rib_entry *, void *); void (*ctx_prefix_call)(struct prefix *, void *); void (*ctx_done)(void *, uint8_t); int (*ctx_throttle)(void *); void *ctx_arg; struct bgpd_addr ctx_subtree; unsigned int ctx_count; uint8_t ctx_aid; uint8_t ctx_subtreelen; }; LIST_HEAD(, rib_context) rib_dumps = LIST_HEAD_INITIALIZER(rib_dumps); static void prefix_dump_r(struct rib_context *); static inline struct rib_entry * re_lock(struct rib_entry *re) { if (re->lock != 0) log_warnx("%s: entry already locked", __func__); re->lock = 1; return re; } static inline struct rib_entry * re_unlock(struct rib_entry *re) { if (re->lock == 0) log_warnx("%s: entry already unlocked", __func__); re->lock = 0; return re; } static inline int re_is_locked(struct rib_entry *re) { return (re->lock != 0); } static inline struct prefix * prefix_lock(struct prefix *p) { if (p->flags & PREFIX_FLAG_LOCKED) fatalx("%s: locking locked prefix", __func__); p->flags |= PREFIX_FLAG_LOCKED; return p; } static inline struct prefix * prefix_unlock(struct prefix *p) { if ((p->flags & PREFIX_FLAG_LOCKED) == 0) fatalx("%s: unlocking unlocked prefix", __func__); p->flags &= ~PREFIX_FLAG_LOCKED; return p; } static inline int prefix_is_locked(struct prefix *p) { return (p->flags & PREFIX_FLAG_LOCKED) != 0; } static inline int prefix_is_dead(struct prefix *p) { return (p->flags & PREFIX_FLAG_DEAD) != 0; } static inline struct rib_tree * rib_tree(struct rib *rib) { return (&rib->tree); } static inline int rib_compare(const struct rib_entry *a, const struct rib_entry *b) { return (pt_prefix_cmp(a->prefix, b->prefix)); } /* RIB specific functions */ struct rib * rib_new(char *name, u_int rtableid, uint16_t flags) { struct rib *new; uint16_t id; for (id = 0; id < rib_size; id++) { if (ribs[id] == NULL) break; } if (id >= rib_size) { if ((ribs = recallocarray(ribs, id, id + 8, sizeof(struct rib *))) == NULL) fatal(NULL); rib_size = id + 8; } if ((new = calloc(1, sizeof(*new))) == NULL) fatal(NULL); strlcpy(new->name, name, sizeof(new->name)); RB_INIT(rib_tree(new)); new->state = RECONF_REINIT; new->id = id; new->flags = flags; new->rtableid = rtableid; new->in_rules = calloc(1, sizeof(struct filter_head)); if (new->in_rules == NULL) fatal(NULL); TAILQ_INIT(new->in_rules); ribs[id] = new; log_debug("%s: %s -> %u", __func__, name, id); return (new); } /* * This function is only called when the FIB information of a RIB changed. * It will flush the FIB if there was one previously and change the fibstate * from RECONF_NONE (nothing to do) to either RECONF_RELOAD (reload the FIB) * or RECONF_REINIT (rerun the route decision process for every element) * depending on the new flags. */ int rib_update(struct rib *rib) { /* flush fib first if there was one */ if ((rib->flags & (F_RIB_NOFIB | F_RIB_NOEVALUATE)) == 0) rde_send_kroute_flush(rib); /* if no evaluate changes then a full reinit is needed */ if ((rib->flags & F_RIB_NOEVALUATE) != (rib->flags_tmp & F_RIB_NOEVALUATE)) rib->fibstate = RECONF_REINIT; rib->flags = rib->flags_tmp; rib->rtableid = rib->rtableid_tmp; /* reload fib if there is no reinit pending and there will be a fib */ if (rib->fibstate != RECONF_REINIT && (rib->flags & (F_RIB_NOFIB | F_RIB_NOEVALUATE)) == 0) rib->fibstate = RECONF_RELOAD; return (rib->fibstate == RECONF_REINIT); } struct rib * rib_byid(uint16_t id) { if (id == RIB_NOTFOUND || id >= rib_size || ribs[id] == NULL) return NULL; return ribs[id]; } uint16_t rib_find(char *name) { uint16_t id; /* no name returns the first Loc-RIB */ if (name == NULL || *name == '\0') return RIB_LOC_START; for (id = 0; id < rib_size; id++) { if (ribs[id] != NULL && !strcmp(ribs[id]->name, name)) return id; } return RIB_NOTFOUND; } void rib_free(struct rib *rib) { struct rib_entry *re, *xre; struct prefix *p; rib_dump_abort(rib->id); /* * flush the rib, disable route evaluation and fib sync to speed up * the prefix removal. Nothing depends on this data anymore. */ if ((rib->flags & (F_RIB_NOFIB | F_RIB_NOEVALUATE)) == 0) rde_send_kroute_flush(rib); rib->flags |= F_RIB_NOEVALUATE | F_RIB_NOFIB; for (re = RB_MIN(rib_tree, rib_tree(rib)); re != NULL; re = xre) { xre = RB_NEXT(rib_tree, rib_tree(rib), re); /* * Removing the prefixes is tricky because the last one * will remove the rib_entry as well and because we do * an empty check in prefix_destroy() it is not possible to * use the default for loop. */ while ((p = TAILQ_FIRST(&re->prefix_h))) { struct rde_aspath *asp = prefix_aspath(p); if (asp && asp->pftableid) rde_pftable_del(asp->pftableid, p); prefix_destroy(p); } } if (rib->id <= RIB_LOC_START) return; /* never remove the default ribs */ filterlist_free(rib->in_rules_tmp); filterlist_free(rib->in_rules); ribs[rib->id] = NULL; free(rib); } void rib_shutdown(void) { struct rib *rib; uint16_t id; for (id = 0; id < rib_size; id++) { rib = rib_byid(id); if (rib == NULL) continue; if (!RB_EMPTY(rib_tree(ribs[id]))) { log_warnx("%s: rib %s is not empty", __func__, ribs[id]->name); } rib_free(ribs[id]); } for (id = 0; id <= RIB_LOC_START; id++) { rib = rib_byid(id); if (rib == NULL) continue; filterlist_free(rib->in_rules_tmp); filterlist_free(rib->in_rules); ribs[id] = NULL; free(rib); } free(ribs); } struct rib_entry * rib_get(struct rib *rib, struct pt_entry *pte) { struct rib_entry xre, *re; memset(&xre, 0, sizeof(xre)); xre.prefix = pte; re = RB_FIND(rib_tree, rib_tree(rib), &xre); if (re && re->rib_id != rib->id) fatalx("%s: Unexpected RIB %u != %u.", __func__, re->rib_id, rib->id); return re; } struct rib_entry * rib_get_addr(struct rib *rib, struct bgpd_addr *prefix, int prefixlen) { return rib_get(rib, pt_fill(prefix, prefixlen)); } struct rib_entry * rib_match(struct rib *rib, struct bgpd_addr *addr) { struct rib_entry *re; int i; switch (addr->aid) { case AID_INET: case AID_VPN_IPv4: for (i = 32; i >= 0; i--) { re = rib_get_addr(rib, addr, i); if (re != NULL) return (re); } break; case AID_INET6: case AID_VPN_IPv6: for (i = 128; i >= 0; i--) { re = rib_get_addr(rib, addr, i); if (re != NULL) return (re); } break; default: fatalx("%s: unknown af", __func__); } return (NULL); } struct rib_entry * rib_add(struct rib *rib, struct pt_entry *pte) { struct rib_entry *re; if ((re = calloc(1, sizeof(*re))) == NULL) fatal("rib_add"); TAILQ_INIT(&re->prefix_h); re->prefix = pt_ref(pte); re->rib_id = rib->id; if (RB_INSERT(rib_tree, rib_tree(rib), re) != NULL) { log_warnx("rib_add: insert failed"); free(re); return (NULL); } rdemem.rib_cnt++; return (re); } void rib_remove(struct rib_entry *re) { if (!rib_empty(re)) fatalx("rib_remove: entry not empty"); if (re_is_locked(re)) /* entry is locked, don't free it. */ return; pt_unref(re->prefix); if (RB_REMOVE(rib_tree, rib_tree(re_rib(re)), re) == NULL) log_warnx("rib_remove: remove failed."); free(re); rdemem.rib_cnt--; } int rib_empty(struct rib_entry *re) { return TAILQ_EMPTY(&re->prefix_h); } static struct rib_entry * rib_restart(struct rib_context *ctx) { struct rib_entry *re = NULL; if (ctx->ctx_re) re = re_unlock(ctx->ctx_re); /* find first non empty element */ while (re && rib_empty(re)) re = RB_NEXT(rib_tree, unused, re); /* free the previously locked rib element if empty */ if (ctx->ctx_re && rib_empty(ctx->ctx_re)) rib_remove(ctx->ctx_re); ctx->ctx_re = NULL; return (re); } static void rib_dump_r(struct rib_context *ctx) { struct rib_entry *re, *next; struct rib *rib; unsigned int i; rib = rib_byid(ctx->ctx_id); if (rib == NULL) fatalx("%s: rib id %u gone", __func__, ctx->ctx_id); if (ctx->ctx_re == NULL && ctx->ctx_subtree.aid == AID_UNSPEC) re = RB_MIN(rib_tree, rib_tree(rib)); else re = rib_restart(ctx); for (i = 0; re != NULL; re = next) { next = RB_NEXT(rib_tree, unused, re); if (re->rib_id != ctx->ctx_id) fatalx("%s: Unexpected RIB %u != %u.", __func__, re->rib_id, ctx->ctx_id); if (ctx->ctx_aid != AID_UNSPEC && ctx->ctx_aid != re->prefix->aid) continue; if (ctx->ctx_subtree.aid != AID_UNSPEC) { struct bgpd_addr addr; pt_getaddr(re->prefix, &addr); if (prefix_compare(&ctx->ctx_subtree, &addr, ctx->ctx_subtreelen) != 0) /* left subtree, walk is done */ break; } if (ctx->ctx_count && i++ >= ctx->ctx_count && !re_is_locked(re)) { /* store and lock last element */ ctx->ctx_re = re_lock(re); return; } ctx->ctx_rib_call(re, ctx->ctx_arg); } if (ctx->ctx_done) ctx->ctx_done(ctx->ctx_arg, ctx->ctx_aid); LIST_REMOVE(ctx, entry); free(ctx); } int rib_dump_pending(void) { struct rib_context *ctx; /* return true if at least one context is not throttled */ LIST_FOREACH(ctx, &rib_dumps, entry) { if (ctx->ctx_throttle && ctx->ctx_throttle(ctx->ctx_arg)) continue; return 1; } return 0; } void rib_dump_runner(void) { struct rib_context *ctx, *next; LIST_FOREACH_SAFE(ctx, &rib_dumps, entry, next) { if (ctx->ctx_throttle && ctx->ctx_throttle(ctx->ctx_arg)) continue; if (ctx->ctx_rib_call != NULL) rib_dump_r(ctx); else prefix_dump_r(ctx); } } static void rib_dump_abort(uint16_t id) { struct rib_context *ctx, *next; LIST_FOREACH_SAFE(ctx, &rib_dumps, entry, next) { if (id != ctx->ctx_id) continue; if (ctx->ctx_done) ctx->ctx_done(ctx->ctx_arg, ctx->ctx_aid); if (ctx->ctx_re && rib_empty(re_unlock(ctx->ctx_re))) rib_remove(ctx->ctx_re); if (ctx->ctx_p && prefix_is_dead(prefix_unlock(ctx->ctx_p))) prefix_adjout_destroy(ctx->ctx_p); LIST_REMOVE(ctx, entry); free(ctx); } } void rib_dump_terminate(void *arg) { struct rib_context *ctx, *next; LIST_FOREACH_SAFE(ctx, &rib_dumps, entry, next) { if (ctx->ctx_arg != arg) continue; if (ctx->ctx_done) ctx->ctx_done(ctx->ctx_arg, ctx->ctx_aid); if (ctx->ctx_re && rib_empty(re_unlock(ctx->ctx_re))) rib_remove(ctx->ctx_re); if (ctx->ctx_p && prefix_is_dead(prefix_unlock(ctx->ctx_p))) prefix_adjout_destroy(ctx->ctx_p); LIST_REMOVE(ctx, entry); free(ctx); } } int rib_dump_new(uint16_t id, uint8_t aid, unsigned int count, void *arg, void (*upcall)(struct rib_entry *, void *), void (*done)(void *, uint8_t), int (*throttle)(void *)) { struct rib_context *ctx; if ((ctx = calloc(1, sizeof(*ctx))) == NULL) return -1; ctx->ctx_id = id; ctx->ctx_aid = aid; ctx->ctx_count = count; ctx->ctx_arg = arg; ctx->ctx_rib_call = upcall; ctx->ctx_done = done; ctx->ctx_throttle = throttle; LIST_INSERT_HEAD(&rib_dumps, ctx, entry); /* requested a sync traversal */ if (count == 0) rib_dump_r(ctx); return 0; } int rib_dump_subtree(uint16_t id, struct bgpd_addr *subtree, uint8_t subtreelen, unsigned int count, void *arg, void (*upcall)(struct rib_entry *, void *), void (*done)(void *, uint8_t), int (*throttle)(void *)) { struct rib_context *ctx; struct rib_entry xre; if ((ctx = calloc(1, sizeof(*ctx))) == NULL) return -1; ctx->ctx_id = id; ctx->ctx_aid = subtree->aid; ctx->ctx_count = count; ctx->ctx_arg = arg; ctx->ctx_rib_call = upcall; ctx->ctx_done = done; ctx->ctx_throttle = throttle; ctx->ctx_subtree = *subtree; ctx->ctx_subtreelen = subtreelen; LIST_INSERT_HEAD(&rib_dumps, ctx, entry); /* lookup start of subtree */ memset(&xre, 0, sizeof(xre)); xre.prefix = pt_fill(subtree, subtreelen); ctx->ctx_re = RB_NFIND(rib_tree, rib_tree(rib_byid(id)), &xre); if (ctx->ctx_re) re_lock(ctx->ctx_re); /* requested a sync traversal */ if (count == 0) rib_dump_r(ctx); return 0; } /* path specific functions */ static struct rde_aspath *path_lookup(struct rde_aspath *); static void path_link(struct rde_aspath *); static void path_unlink(struct rde_aspath *); static inline int path_compare(struct rde_aspath *a, struct rde_aspath *b) { int r; if (a == NULL && b == NULL) return (0); else if (b == NULL) return (1); else if (a == NULL) return (-1); if ((a->flags & ~F_ATTR_LINKED) > (b->flags & ~F_ATTR_LINKED)) return (1); if ((a->flags & ~F_ATTR_LINKED) < (b->flags & ~F_ATTR_LINKED)) return (-1); if (a->origin > b->origin) return (1); if (a->origin < b->origin) return (-1); if (a->med > b->med) return (1); if (a->med < b->med) return (-1); if (a->lpref > b->lpref) return (1); if (a->lpref < b->lpref) return (-1); if (a->weight > b->weight) return (1); if (a->weight < b->weight) return (-1); if (a->rtlabelid > b->rtlabelid) return (1); if (a->rtlabelid < b->rtlabelid) return (-1); if (a->pftableid > b->pftableid) return (1); if (a->pftableid < b->pftableid) return (-1); /* no need to check aspa_state or aspa_generation */ r = aspath_compare(a->aspath, b->aspath); if (r > 0) return (1); if (r < 0) return (-1); return (attr_compare(a, b)); } RB_HEAD(path_tree, rde_aspath) pathtable = RB_INITIALIZER(&pathtable); RB_GENERATE_STATIC(path_tree, rde_aspath, entry, path_compare); static inline struct rde_aspath * path_ref(struct rde_aspath *asp) { if ((asp->flags & F_ATTR_LINKED) == 0) fatalx("%s: unlinked object", __func__); asp->refcnt++; rdemem.path_refs++; return asp; } static inline void path_unref(struct rde_aspath *asp) { if (asp == NULL) return; if ((asp->flags & F_ATTR_LINKED) == 0) fatalx("%s: unlinked object", __func__); asp->refcnt--; rdemem.path_refs--; if (asp->refcnt <= 0) path_unlink(asp); } void path_shutdown(void) { if (!RB_EMPTY(&pathtable)) log_warnx("path_free: free non-free table"); } static struct rde_aspath * path_lookup(struct rde_aspath *aspath) { return (RB_FIND(path_tree, &pathtable, aspath)); } /* * Link this aspath into the global table. * The asp had to be alloced with path_get. */ static void path_link(struct rde_aspath *asp) { if (RB_INSERT(path_tree, &pathtable, asp) != NULL) fatalx("%s: already linked object", __func__); asp->flags |= F_ATTR_LINKED; } /* * This function can only be called when all prefix have been removed first. * Normally this happens directly out of the prefix removal functions. */ static void path_unlink(struct rde_aspath *asp) { if (asp == NULL) return; /* make sure no reference is hold for this rde_aspath */ if (asp->refcnt != 0) fatalx("%s: still holds references", __func__); RB_REMOVE(path_tree, &pathtable, asp); asp->flags &= ~F_ATTR_LINKED; path_put(asp); } /* * Copy asp to a new UNLINKED aspath. * On dst either path_get() or path_prep() had to be called before. */ struct rde_aspath * path_copy(struct rde_aspath *dst, const struct rde_aspath *src) { dst->aspath = aspath_copy(src->aspath); dst->refcnt = 0; dst->flags = src->flags & ~F_ATTR_LINKED; dst->med = src->med; dst->lpref = src->lpref; dst->weight = src->weight; dst->rtlabelid = rtlabel_ref(src->rtlabelid); dst->pftableid = pftable_ref(src->pftableid); dst->origin = src->origin; attr_copy(dst, src); return (dst); } /* initialize or prepare an aspath for use */ struct rde_aspath * path_prep(struct rde_aspath *asp) { memset(asp, 0, sizeof(*asp)); asp->origin = ORIGIN_INCOMPLETE; asp->lpref = DEFAULT_LPREF; return (asp); } /* alloc and initialize new entry. May not fail. */ struct rde_aspath * path_get(void) { struct rde_aspath *asp; asp = malloc(sizeof(*asp)); if (asp == NULL) fatal("path_get"); rdemem.path_cnt++; return (path_prep(asp)); } /* clean up an asp after use (frees all references to sub-objects) */ void path_clean(struct rde_aspath *asp) { if (asp->flags & F_ATTR_LINKED) fatalx("%s: linked object", __func__); rtlabel_unref(asp->rtlabelid); pftable_unref(asp->pftableid); aspath_put(asp->aspath); asp->aspath = NULL; attr_freeall(asp); } /* free an unlinked element */ void path_put(struct rde_aspath *asp) { if (asp == NULL) return; path_clean(asp); rdemem.path_cnt--; free(asp); } /* prefix specific functions */ static int prefix_add(struct bgpd_addr *, int, struct rib *, struct rde_peer *, uint32_t, uint32_t, struct rde_aspath *, struct rde_community *, struct nexthop *, uint8_t, uint8_t, int); static int prefix_move(struct prefix *, struct rde_peer *, struct rde_aspath *, struct rde_community *, struct nexthop *, uint8_t, uint8_t, int); static void prefix_link(struct prefix *, struct rib_entry *, struct pt_entry *, struct rde_peer *, uint32_t, uint32_t, struct rde_aspath *, struct rde_community *, struct nexthop *, uint8_t, uint8_t); static void prefix_unlink(struct prefix *); static struct prefix *prefix_alloc(void); static void prefix_free(struct prefix *); /* RB tree comparison function */ static inline int prefix_index_cmp(struct prefix *a, struct prefix *b) { int r; r = pt_prefix_cmp(a->pt, b->pt); if (r != 0) return r; if (a->path_id_tx > b->path_id_tx) return 1; if (a->path_id_tx < b->path_id_tx) return -1; return 0; } static inline int prefix_cmp(struct prefix *a, struct prefix *b) { if ((a->flags & PREFIX_FLAG_EOR) != (b->flags & PREFIX_FLAG_EOR)) return (a->flags & PREFIX_FLAG_EOR) ? 1 : -1; /* if EOR marker no need to check the rest */ if (a->flags & PREFIX_FLAG_EOR) return 0; if (a->aspath != b->aspath) return (a->aspath > b->aspath ? 1 : -1); if (a->communities != b->communities) return (a->communities > b->communities ? 1 : -1); if (a->nexthop != b->nexthop) return (a->nexthop > b->nexthop ? 1 : -1); if (a->nhflags != b->nhflags) return (a->nhflags > b->nhflags ? 1 : -1); return prefix_index_cmp(a, b); } RB_GENERATE(prefix_tree, prefix, entry.tree.update, prefix_cmp) RB_GENERATE_STATIC(prefix_index, prefix, entry.tree.index, prefix_index_cmp) /* * Search for specified prefix of a peer. Returns NULL if not found. */ struct prefix * prefix_get(struct rib *rib, struct rde_peer *peer, uint32_t path_id, struct bgpd_addr *prefix, int prefixlen) { struct rib_entry *re; re = rib_get_addr(rib, prefix, prefixlen); if (re == NULL) return (NULL); return (prefix_bypeer(re, peer, path_id)); } /* * Search for specified prefix in the peer prefix_index. * Returns NULL if not found. */ struct prefix * prefix_adjout_get(struct rde_peer *peer, uint32_t path_id_tx, struct pt_entry *pte) { struct prefix xp; memset(&xp, 0, sizeof(xp)); xp.pt = pte; xp.path_id_tx = path_id_tx; return RB_FIND(prefix_index, &peer->adj_rib_out, &xp); } /* * Lookup a prefix without considering path_id in the peer prefix_index. * Returns NULL if not found. */ struct prefix * prefix_adjout_first(struct rde_peer *peer, struct pt_entry *pte) { struct prefix xp, *np; memset(&xp, 0, sizeof(xp)); xp.pt = pte; np = RB_NFIND(prefix_index, &peer->adj_rib_out, &xp); if (np == NULL || pt_prefix_cmp(np->pt, xp.pt) != 0) return NULL; return np; } /* * Return next prefix after a lookup that is actually an update. */ struct prefix * prefix_adjout_next(struct rde_peer *peer, struct prefix *p) { struct prefix *np; np = RB_NEXT(prefix_index, &peer->adj_rib_out, p); if (np == NULL || np->pt != p->pt) return NULL; return np; } /* * Lookup addr/prefixlen in the peer prefix_index. Returns first match. * Returns NULL if not found. */ struct prefix * prefix_adjout_lookup(struct rde_peer *peer, struct bgpd_addr *addr, int plen) { return prefix_adjout_first(peer, pt_fill(addr, plen)); } /* * Lookup addr in the peer prefix_index. Returns first match. * Returns NULL if not found. */ struct prefix * prefix_adjout_match(struct rde_peer *peer, struct bgpd_addr *addr) { struct prefix *p; int i; switch (addr->aid) { case AID_INET: case AID_VPN_IPv4: for (i = 32; i >= 0; i--) { p = prefix_adjout_lookup(peer, addr, i); if (p != NULL) return p; } break; case AID_INET6: case AID_VPN_IPv6: for (i = 128; i >= 0; i--) { p = prefix_adjout_lookup(peer, addr, i); if (p != NULL) return p; } break; default: fatalx("%s: unknown af", __func__); } return NULL; } /* * Update a prefix. * Return 1 if prefix was newly added, 0 if it was just changed. */ int prefix_update(struct rib *rib, struct rde_peer *peer, uint32_t path_id, uint32_t path_id_tx, struct filterstate *state, int filtered, struct bgpd_addr *prefix, int prefixlen) { struct rde_aspath *asp, *nasp = &state->aspath; struct rde_community *comm, *ncomm = &state->communities; struct prefix *p; /* * First try to find a prefix in the specified RIB. */ if ((p = prefix_get(rib, peer, path_id, prefix, prefixlen)) != NULL) { if (path_id_tx != p->path_id_tx) fatalx("path_id mismatch"); if (prefix_nexthop(p) == state->nexthop && prefix_nhflags(p) == state->nhflags && communities_equal(ncomm, prefix_communities(p)) && path_compare(nasp, prefix_aspath(p)) == 0) { /* no change, update last change */ p->lastchange = getmonotime(); p->validation_state = state->vstate; if (filtered) p->flags |= PREFIX_FLAG_FILTERED; else p->flags &= ~PREFIX_FLAG_FILTERED; return (0); } } /* * Either the prefix does not exist or the path changed. * In both cases lookup the new aspath to make sure it is not * already in the RIB. */ if ((asp = path_lookup(nasp)) == NULL) { /* Path not available, create and link a new one. */ asp = path_copy(path_get(), nasp); path_link(asp); } if ((comm = communities_lookup(ncomm)) == NULL) { /* Communities not available, create and link a new one. */ comm = communities_link(ncomm); } /* If the prefix was found move it else add it to the RIB. */ if (p != NULL) return (prefix_move(p, peer, asp, comm, state->nexthop, state->nhflags, state->vstate, filtered)); else return (prefix_add(prefix, prefixlen, rib, peer, path_id, path_id_tx, asp, comm, state->nexthop, state->nhflags, state->vstate, filtered)); } /* * Adds or updates a prefix. */ static int prefix_add(struct bgpd_addr *prefix, int prefixlen, struct rib *rib, struct rde_peer *peer, uint32_t path_id, uint32_t path_id_tx, struct rde_aspath *asp, struct rde_community *comm, struct nexthop *nexthop, uint8_t nhflags, uint8_t vstate, int filtered) { struct pt_entry *pte; struct prefix *p; struct rib_entry *re; pte = pt_get(prefix, prefixlen); if (pte == NULL) pte = pt_add(prefix, prefixlen); re = rib_get(rib, pte); if (re == NULL) re = rib_add(rib, pte); p = prefix_alloc(); prefix_link(p, re, re->prefix, peer, path_id, path_id_tx, asp, comm, nexthop, nhflags, vstate); if (filtered) p->flags |= PREFIX_FLAG_FILTERED; /* add possible pftable reference form aspath */ if (asp && asp->pftableid) rde_pftable_add(asp->pftableid, p); /* make route decision */ prefix_evaluate(re, p, NULL); return (1); } /* * Move the prefix to the specified as path, removes the old asp if needed. */ static int prefix_move(struct prefix *p, struct rde_peer *peer, struct rde_aspath *asp, struct rde_community *comm, struct nexthop *nexthop, uint8_t nhflags, uint8_t vstate, int filtered) { struct prefix *np; if (p->flags & PREFIX_FLAG_ADJOUT) fatalx("%s: prefix with PREFIX_FLAG_ADJOUT hit", __func__); if (peer != prefix_peer(p)) fatalx("prefix_move: cross peer move"); /* add new prefix node */ np = prefix_alloc(); prefix_link(np, prefix_re(p), p->pt, peer, p->path_id, p->path_id_tx, asp, comm, nexthop, nhflags, vstate); if (filtered) np->flags |= PREFIX_FLAG_FILTERED; /* add possible pftable reference from new aspath */ if (asp && asp->pftableid) rde_pftable_add(asp->pftableid, np); /* * no need to update the peer prefix count because we are only moving * the prefix without changing the peer. */ prefix_evaluate(prefix_re(np), np, p); /* remove possible pftable reference from old path */ if (p->aspath && p->aspath->pftableid) rde_pftable_del(p->aspath->pftableid, p); /* remove old prefix node */ prefix_unlink(p); prefix_free(p); return (0); } /* * Removes a prefix from the specified RIB. If the parent objects -- rib_entry * or pt_entry -- become empty remove them too. */ int prefix_withdraw(struct rib *rib, struct rde_peer *peer, uint32_t path_id, struct bgpd_addr *prefix, int prefixlen) { struct prefix *p; struct rde_aspath *asp; p = prefix_get(rib, peer, path_id, prefix, prefixlen); if (p == NULL) /* Got a dummy withdrawn request. */ return (0); if (p->flags & PREFIX_FLAG_ADJOUT) fatalx("%s: prefix with PREFIX_FLAG_ADJOUT hit", __func__); asp = prefix_aspath(p); if (asp && asp->pftableid) /* only prefixes in the local RIB were pushed into pf */ rde_pftable_del(asp->pftableid, p); prefix_destroy(p); return (1); } /* * Special functions for flowspec until full integration is available. * This just directly feeds the prefixes into the Adj-RIB-Out bypassing * Adj-RIB-In and Loc-RIB for now. */ int prefix_flowspec_update(struct rde_peer *peer, struct filterstate *state, struct pt_entry *pte, uint32_t path_id_tx) { struct rde_aspath *asp, *nasp; struct rde_community *comm, *ncomm; struct rib_entry *re; struct prefix *new, *old; re = rib_get(&flowrib, pte); if (re == NULL) re = rib_add(&flowrib, pte); old = prefix_bypeer(re, peer, 0); new = prefix_alloc(); nasp = &state->aspath; ncomm = &state->communities; if ((asp = path_lookup(nasp)) == NULL) { /* Path not available, create and link a new one. */ asp = path_copy(path_get(), nasp); path_link(asp); } if ((comm = communities_lookup(ncomm)) == NULL) { /* Communities not available, create and link a new one. */ comm = communities_link(ncomm); } prefix_link(new, re, re->prefix, peer, 0, path_id_tx, asp, comm, NULL, 0, 0); TAILQ_INSERT_HEAD(&re->prefix_h, new, entry.list.rib); rde_generate_updates(re, new, old, EVAL_DEFAULT); if (old != NULL) { TAILQ_REMOVE(&re->prefix_h, old, entry.list.rib); prefix_unlink(old); prefix_free(old); return 0; } return 1; } /* * Remove a possible flowspec prefix from all Adj-RIB-Outs. */ int prefix_flowspec_withdraw(struct rde_peer *peer, struct pt_entry *pte) { struct rib_entry *re; struct prefix *p; re = rib_get(&flowrib, pte); if (re == NULL) return 0; p = prefix_bypeer(re, peer, 0); if (p == NULL) return 0; rde_generate_updates(re, NULL, p, EVAL_DEFAULT); TAILQ_REMOVE(&re->prefix_h, p, entry.list.rib); prefix_unlink(p); prefix_free(p); return 1; } /* * Push all flowspec rules into a newly available Adj-RIB-Out. */ void prefix_flowspec_dump(uint8_t aid, void *arg, void (*call)(struct rib_entry *, void *), void (*done)(void *, uint8_t)) { struct rib_entry *re, *next; RB_FOREACH_SAFE(re, rib_tree, rib_tree(&flowrib), next) { if (aid != AID_UNSPEC && aid != re->prefix->aid) continue; call(re, arg); } if (done != NULL) done(arg, aid); } /* * Insert an End-of-RIB marker into the update queue. */ void prefix_add_eor(struct rde_peer *peer, uint8_t aid) { struct prefix *p; p = prefix_alloc(); p->flags = PREFIX_FLAG_ADJOUT | PREFIX_FLAG_UPDATE | PREFIX_FLAG_EOR; if (RB_INSERT(prefix_tree, &peer->updates[aid], p) != NULL) /* no need to add if EoR marker already present */ prefix_free(p); /* EOR marker is not inserted into the adj_rib_out index */ } /* * Put a prefix from the Adj-RIB-Out onto the update queue. */ void prefix_adjout_update(struct prefix *p, struct rde_peer *peer, struct filterstate *state, struct pt_entry *pte, uint32_t path_id_tx) { struct rde_aspath *asp; struct rde_community *comm; if (p == NULL) { p = prefix_alloc(); /* initially mark DEAD so code below is skipped */ p->flags |= PREFIX_FLAG_ADJOUT | PREFIX_FLAG_DEAD; p->pt = pt_ref(pte); p->peer = peer; p->path_id_tx = path_id_tx; if (RB_INSERT(prefix_index, &peer->adj_rib_out, p) != NULL) fatalx("%s: RB index invariant violated", __func__); } if ((p->flags & PREFIX_FLAG_ADJOUT) == 0) fatalx("%s: prefix without PREFIX_FLAG_ADJOUT hit", __func__); if ((p->flags & (PREFIX_FLAG_WITHDRAW | PREFIX_FLAG_DEAD)) == 0) { /* * XXX for now treat a different path_id_tx like different * attributes and force out an update. It is unclear how * common it is to have equivalent updates from alternative * paths. */ if (p->path_id_tx == path_id_tx && prefix_nhflags(p) == state->nhflags && prefix_nexthop(p) == state->nexthop && communities_equal(&state->communities, prefix_communities(p)) && path_compare(&state->aspath, prefix_aspath(p)) == 0) { /* nothing changed */ p->validation_state = state->vstate; p->lastchange = getmonotime(); p->flags &= ~PREFIX_FLAG_STALE; return; } /* if pending update unhook it before it is unlinked */ if (p->flags & PREFIX_FLAG_UPDATE) { RB_REMOVE(prefix_tree, &peer->updates[pte->aid], p); peer->stats.pending_update--; } /* unlink prefix so it can be relinked below */ prefix_unlink(p); peer->stats.prefix_out_cnt--; } if (p->flags & PREFIX_FLAG_WITHDRAW) { RB_REMOVE(prefix_tree, &peer->withdraws[pte->aid], p); peer->stats.pending_withdraw--; } /* nothing needs to be done for PREFIX_FLAG_DEAD and STALE */ p->flags &= ~PREFIX_FLAG_MASK; /* update path_id_tx now that the prefix is unlinked */ if (p->path_id_tx != path_id_tx) { /* path_id_tx is part of the index so remove and re-insert p */ RB_REMOVE(prefix_index, &peer->adj_rib_out, p); p->path_id_tx = path_id_tx; if (RB_INSERT(prefix_index, &peer->adj_rib_out, p) != NULL) fatalx("%s: RB index invariant violated", __func__); } if ((asp = path_lookup(&state->aspath)) == NULL) { /* Path not available, create and link a new one. */ asp = path_copy(path_get(), &state->aspath); path_link(asp); } if ((comm = communities_lookup(&state->communities)) == NULL) { /* Communities not available, create and link a new one. */ comm = communities_link(&state->communities); } prefix_link(p, NULL, p->pt, peer, 0, p->path_id_tx, asp, comm, state->nexthop, state->nhflags, state->vstate); peer->stats.prefix_out_cnt++; if (p->flags & PREFIX_FLAG_MASK) fatalx("%s: bad flags %x", __func__, p->flags); if (peer_is_up(peer)) { p->flags |= PREFIX_FLAG_UPDATE; if (RB_INSERT(prefix_tree, &peer->updates[pte->aid], p) != NULL) fatalx("%s: RB tree invariant violated", __func__); peer->stats.pending_update++; } } /* * Withdraw a prefix from the Adj-RIB-Out, this unlinks the aspath but leaves * the prefix in the RIB linked to the peer withdraw list. */ void prefix_adjout_withdraw(struct prefix *p) { struct rde_peer *peer = prefix_peer(p); if ((p->flags & PREFIX_FLAG_ADJOUT) == 0) fatalx("%s: prefix without PREFIX_FLAG_ADJOUT hit", __func__); /* already a withdraw, shortcut */ if (p->flags & PREFIX_FLAG_WITHDRAW) { p->lastchange = getmonotime(); p->flags &= ~PREFIX_FLAG_STALE; return; } /* pending update just got withdrawn */ if (p->flags & PREFIX_FLAG_UPDATE) { RB_REMOVE(prefix_tree, &peer->updates[p->pt->aid], p); peer->stats.pending_update--; } /* unlink prefix if it was linked (not a withdraw or dead) */ if ((p->flags & (PREFIX_FLAG_WITHDRAW | PREFIX_FLAG_DEAD)) == 0) { prefix_unlink(p); peer->stats.prefix_out_cnt--; } /* nothing needs to be done for PREFIX_FLAG_DEAD and STALE */ p->flags &= ~PREFIX_FLAG_MASK; p->lastchange = getmonotime(); if (peer_is_up(peer)) { p->flags |= PREFIX_FLAG_WITHDRAW; if (RB_INSERT(prefix_tree, &peer->withdraws[p->pt->aid], p) != NULL) fatalx("%s: RB tree invariant violated", __func__); peer->stats.pending_withdraw++; } else { /* mark prefix dead to skip unlink on destroy */ p->flags |= PREFIX_FLAG_DEAD; prefix_adjout_destroy(p); } } void prefix_adjout_destroy(struct prefix *p) { struct rde_peer *peer = prefix_peer(p); if ((p->flags & PREFIX_FLAG_ADJOUT) == 0) fatalx("%s: prefix without PREFIX_FLAG_ADJOUT hit", __func__); if (p->flags & PREFIX_FLAG_EOR) { /* EOR marker is not linked in the index */ prefix_free(p); return; } if (p->flags & PREFIX_FLAG_WITHDRAW) { RB_REMOVE(prefix_tree, &peer->withdraws[p->pt->aid], p); peer->stats.pending_withdraw--; } if (p->flags & PREFIX_FLAG_UPDATE) { RB_REMOVE(prefix_tree, &peer->updates[p->pt->aid], p); peer->stats.pending_update--; } /* unlink prefix if it was linked (not a withdraw or dead) */ if ((p->flags & (PREFIX_FLAG_WITHDRAW | PREFIX_FLAG_DEAD)) == 0) { prefix_unlink(p); peer->stats.prefix_out_cnt--; } /* nothing needs to be done for PREFIX_FLAG_DEAD and STALE */ p->flags &= ~PREFIX_FLAG_MASK; if (prefix_is_locked(p)) { /* mark prefix dead but leave it for prefix_restart */ p->flags |= PREFIX_FLAG_DEAD; } else { RB_REMOVE(prefix_index, &peer->adj_rib_out, p); /* remove the last prefix reference before free */ pt_unref(p->pt); prefix_free(p); } } void prefix_adjout_flush_pending(struct rde_peer *peer) { struct prefix *p, *np; uint8_t aid; for (aid = AID_MIN; aid < AID_MAX; aid++) { RB_FOREACH_SAFE(p, prefix_tree, &peer->withdraws[aid], np) { prefix_adjout_destroy(p); } RB_FOREACH_SAFE(p, prefix_tree, &peer->updates[aid], np) { p->flags &= ~PREFIX_FLAG_UPDATE; RB_REMOVE(prefix_tree, &peer->updates[aid], p); peer->stats.pending_update--; } } } int prefix_adjout_reaper(struct rde_peer *peer) { struct prefix *p, *np; int count = RDE_REAPER_ROUNDS; RB_FOREACH_SAFE(p, prefix_index, &peer->adj_rib_out, np) { prefix_adjout_destroy(p); if (count-- <= 0) return 0; } return 1; } static struct prefix * prefix_restart(struct rib_context *ctx) { struct prefix *p = NULL; if (ctx->ctx_p) p = prefix_unlock(ctx->ctx_p); if (p && prefix_is_dead(p)) { struct prefix *next; next = RB_NEXT(prefix_index, unused, p); prefix_adjout_destroy(p); p = next; } ctx->ctx_p = NULL; return p; } static void prefix_dump_r(struct rib_context *ctx) { struct prefix *p, *next; struct rde_peer *peer; unsigned int i; if ((peer = peer_get(ctx->ctx_id)) == NULL) goto done; if (ctx->ctx_p == NULL && ctx->ctx_subtree.aid == AID_UNSPEC) p = RB_MIN(prefix_index, &peer->adj_rib_out); else p = prefix_restart(ctx); for (i = 0; p != NULL; p = next) { next = RB_NEXT(prefix_index, unused, p); if (prefix_is_dead(p)) continue; if (ctx->ctx_aid != AID_UNSPEC && ctx->ctx_aid != p->pt->aid) continue; if (ctx->ctx_subtree.aid != AID_UNSPEC) { struct bgpd_addr addr; pt_getaddr(p->pt, &addr); if (prefix_compare(&ctx->ctx_subtree, &addr, ctx->ctx_subtreelen) != 0) /* left subtree, walk is done */ break; } if (ctx->ctx_count && i++ >= ctx->ctx_count && !prefix_is_locked(p)) { /* store and lock last element */ ctx->ctx_p = prefix_lock(p); return; } ctx->ctx_prefix_call(p, ctx->ctx_arg); } done: if (ctx->ctx_done) ctx->ctx_done(ctx->ctx_arg, ctx->ctx_aid); LIST_REMOVE(ctx, entry); free(ctx); } int prefix_dump_new(struct rde_peer *peer, uint8_t aid, unsigned int count, void *arg, void (*upcall)(struct prefix *, void *), void (*done)(void *, uint8_t), int (*throttle)(void *)) { struct rib_context *ctx; if ((ctx = calloc(1, sizeof(*ctx))) == NULL) return -1; ctx->ctx_id = peer->conf.id; ctx->ctx_aid = aid; ctx->ctx_count = count; ctx->ctx_arg = arg; ctx->ctx_prefix_call = upcall; ctx->ctx_done = done; ctx->ctx_throttle = throttle; LIST_INSERT_HEAD(&rib_dumps, ctx, entry); /* requested a sync traversal */ if (count == 0) prefix_dump_r(ctx); return 0; } int prefix_dump_subtree(struct rde_peer *peer, struct bgpd_addr *subtree, uint8_t subtreelen, unsigned int count, void *arg, void (*upcall)(struct prefix *, void *), void (*done)(void *, uint8_t), int (*throttle)(void *)) { struct rib_context *ctx; struct prefix xp; if ((ctx = calloc(1, sizeof(*ctx))) == NULL) return -1; ctx->ctx_id = peer->conf.id; ctx->ctx_aid = subtree->aid; ctx->ctx_count = count; ctx->ctx_arg = arg; ctx->ctx_prefix_call = upcall; ctx->ctx_done = done; ctx->ctx_throttle = throttle; ctx->ctx_subtree = *subtree; ctx->ctx_subtreelen = subtreelen; LIST_INSERT_HEAD(&rib_dumps, ctx, entry); /* lookup start of subtree */ memset(&xp, 0, sizeof(xp)); xp.pt = pt_fill(subtree, subtreelen); ctx->ctx_p = RB_NFIND(prefix_index, &peer->adj_rib_out, &xp); if (ctx->ctx_p) prefix_lock(ctx->ctx_p); /* requested a sync traversal */ if (count == 0) prefix_dump_r(ctx); return 0; } /* * Searches in the prefix list of specified rib_entry for a prefix entry * belonging to the peer peer. Returns NULL if no match found. */ struct prefix * prefix_bypeer(struct rib_entry *re, struct rde_peer *peer, uint32_t path_id) { struct prefix *p; TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) if (prefix_peer(p) == peer && p->path_id == path_id) return (p); return (NULL); } /* kill a prefix. */ void prefix_destroy(struct prefix *p) { /* make route decision */ prefix_evaluate(prefix_re(p), NULL, p); prefix_unlink(p); prefix_free(p); } /* * Link a prefix into the different parent objects. */ static void prefix_link(struct prefix *p, struct rib_entry *re, struct pt_entry *pt, struct rde_peer *peer, uint32_t path_id, uint32_t path_id_tx, struct rde_aspath *asp, struct rde_community *comm, struct nexthop *nexthop, uint8_t nhflags, uint8_t vstate) { if (re) p->entry.list.re = re; p->aspath = path_ref(asp); p->communities = communities_ref(comm); p->peer = peer; p->pt = pt_ref(pt); p->path_id = path_id; p->path_id_tx = path_id_tx; p->validation_state = vstate; p->nhflags = nhflags; p->nexthop = nexthop_ref(nexthop); nexthop_link(p); p->lastchange = getmonotime(); } /* * Unlink a prefix from the different parent objects. */ static void prefix_unlink(struct prefix *p) { struct rib_entry *re = prefix_re(p); /* destroy all references to other objects */ /* remove nexthop ref ... */ nexthop_unlink(p); nexthop_unref(p->nexthop); p->nexthop = NULL; p->nhflags = 0; /* ... communities ... */ communities_unref(p->communities); p->communities = NULL; /* and unlink from aspath */ path_unref(p->aspath); p->aspath = NULL; if (re && rib_empty(re)) rib_remove(re); pt_unref(p->pt); } /* alloc and zero new entry. May not fail. */ static struct prefix * prefix_alloc(void) { struct prefix *p; p = calloc(1, sizeof(*p)); if (p == NULL) fatal("prefix_alloc"); rdemem.prefix_cnt++; return p; } /* free a unlinked entry */ static void prefix_free(struct prefix *p) { rdemem.prefix_cnt--; free(p); } /* * nexthop functions */ struct nexthop *nexthop_lookup(struct bgpd_addr *); /* * In BGP there exist two nexthops: the exit nexthop which was announced via * BGP and the true nexthop which is used in the FIB -- forward information * base a.k.a kernel routing table. When sending updates it is even more * confusing. In IBGP we pass the unmodified exit nexthop to the neighbors * while in EBGP normally the address of the router is sent. The exit nexthop * may be passed to the external neighbor if the neighbor and the exit nexthop * reside in the same subnet -- directly connected. */ TAILQ_HEAD(nexthop_queue, nexthop) nexthop_runners = TAILQ_HEAD_INITIALIZER(nexthop_runners); RB_HEAD(nexthop_tree, nexthop) nexthoptable = RB_INITIALIZER(&nexthoptree); static inline int nexthop_cmp(struct nexthop *, struct nexthop *); RB_GENERATE_STATIC(nexthop_tree, nexthop, entry, nexthop_cmp); void nexthop_shutdown(void) { struct nexthop *nh, *nnh; RB_FOREACH_SAFE(nh, nexthop_tree, &nexthoptable, nnh) { nh->state = NEXTHOP_UNREACH; nexthop_unref(nh); } RB_FOREACH(nh, nexthop_tree, &nexthoptable) { log_warnx("%s: nexthop %s refcnt %d", __func__, log_addr(&nh->exit_nexthop), nh->refcnt); } } int nexthop_pending(void) { return !TAILQ_EMPTY(&nexthop_runners); } void nexthop_runner(void) { struct nexthop *nh; struct prefix *p; uint32_t j; nh = TAILQ_FIRST(&nexthop_runners); if (nh == NULL) return; /* remove from runnner queue */ TAILQ_REMOVE(&nexthop_runners, nh, runner_l); p = nh->next_prefix; for (j = 0; p != NULL && j < RDE_RUNNER_ROUNDS; j++) { prefix_evaluate_nexthop(p, nh->state, nh->oldstate); p = LIST_NEXT(p, entry.list.nexthop); } /* prep for next run, if not finished readd to tail of queue */ nh->next_prefix = p; if (p != NULL) TAILQ_INSERT_TAIL(&nexthop_runners, nh, runner_l); else log_debug("nexthop %s update finished", log_addr(&nh->exit_nexthop)); } void nexthop_update(struct kroute_nexthop *msg) { struct nexthop *nh; nh = nexthop_lookup(&msg->nexthop); if (nh == NULL) { log_warnx("nexthop_update: non-existent nexthop %s", log_addr(&msg->nexthop)); return; } nh->oldstate = nh->state; if (msg->valid) nh->state = NEXTHOP_REACH; else nh->state = NEXTHOP_UNREACH; if (nh->oldstate == NEXTHOP_LOOKUP) /* drop reference which was hold during the lookup */ if (nexthop_unref(nh)) return; /* nh lost last ref, no work left */ if (nh->next_prefix) { /* * If nexthop_runner() is not finished with this nexthop * then ensure that all prefixes are updated by setting * the oldstate to NEXTHOP_FLAPPED. */ nh->oldstate = NEXTHOP_FLAPPED; TAILQ_REMOVE(&nexthop_runners, nh, runner_l); } if (msg->connected) nh->flags |= NEXTHOP_CONNECTED; nh->true_nexthop = msg->gateway; nh->nexthop_net = msg->net; nh->nexthop_netlen = msg->netlen; nh->next_prefix = LIST_FIRST(&nh->prefix_h); if (nh->next_prefix != NULL) { TAILQ_INSERT_HEAD(&nexthop_runners, nh, runner_l); log_debug("nexthop %s update starting", log_addr(&nh->exit_nexthop)); } } void nexthop_modify(struct nexthop *setnh, enum action_types type, uint8_t aid, struct nexthop **nexthop, uint8_t *flags) { switch (type) { case ACTION_SET_NEXTHOP_REJECT: *flags = NEXTHOP_REJECT; break; case ACTION_SET_NEXTHOP_BLACKHOLE: *flags = NEXTHOP_BLACKHOLE; break; case ACTION_SET_NEXTHOP_NOMODIFY: *flags = NEXTHOP_NOMODIFY; break; case ACTION_SET_NEXTHOP_SELF: *flags = NEXTHOP_SELF; break; case ACTION_SET_NEXTHOP_REF: /* * it is possible that a prefix matches but has the wrong * address family for the set nexthop. In this case ignore it. */ if (aid != setnh->exit_nexthop.aid) break; nexthop_unref(*nexthop); *nexthop = nexthop_ref(setnh); *flags = 0; break; default: break; } } void nexthop_link(struct prefix *p) { p->nhflags &= ~NEXTHOP_VALID; if (p->flags & PREFIX_FLAG_ADJOUT) { /* All nexthops are valid in Adj-RIB-Out */ p->nhflags |= NEXTHOP_VALID; return; } /* no need to link prefixes in RIBs that have no decision process */ if (re_rib(prefix_re(p))->flags & F_RIB_NOEVALUATE) return; /* self-announce networks use nexthop NULL and are valid as well */ if (p->nexthop == NULL || p->nexthop->state == NEXTHOP_REACH) p->nhflags |= NEXTHOP_VALID; if (p->nexthop == NULL) return; p->flags |= PREFIX_NEXTHOP_LINKED; LIST_INSERT_HEAD(&p->nexthop->prefix_h, p, entry.list.nexthop); } void nexthop_unlink(struct prefix *p) { p->nhflags &= ~NEXTHOP_VALID; if (p->nexthop == NULL || (p->flags & PREFIX_NEXTHOP_LINKED) == 0) return; if (p == p->nexthop->next_prefix) { p->nexthop->next_prefix = LIST_NEXT(p, entry.list.nexthop); /* remove nexthop from list if no prefixes left to update */ if (p->nexthop->next_prefix == NULL) { TAILQ_REMOVE(&nexthop_runners, p->nexthop, runner_l); log_debug("nexthop %s update finished", log_addr(&p->nexthop->exit_nexthop)); } } p->flags &= ~PREFIX_NEXTHOP_LINKED; LIST_REMOVE(p, entry.list.nexthop); } struct nexthop * nexthop_get(struct bgpd_addr *nexthop) { struct nexthop *nh; nh = nexthop_lookup(nexthop); if (nh == NULL) { nh = calloc(1, sizeof(*nh)); if (nh == NULL) fatal("nexthop_get"); rdemem.nexthop_cnt++; LIST_INIT(&nh->prefix_h); nh->state = NEXTHOP_LOOKUP; nexthop_ref(nh); /* take reference for lookup */ nh->exit_nexthop = *nexthop; if (RB_INSERT(nexthop_tree, &nexthoptable, nh) != NULL) fatalx("nexthop tree inconsistency"); rde_send_nexthop(&nh->exit_nexthop, 1); } return nexthop_ref(nh); } struct nexthop * nexthop_ref(struct nexthop *nexthop) { if (nexthop) nexthop->refcnt++; return (nexthop); } int nexthop_unref(struct nexthop *nh) { if (nh == NULL) return (0); if (--nh->refcnt > 0) return (0); /* sanity check */ if (!LIST_EMPTY(&nh->prefix_h) || nh->state == NEXTHOP_LOOKUP) fatalx("%s: refcnt error", __func__); /* is nexthop update running? impossible, that is a refcnt error */ if (nh->next_prefix) fatalx("%s: next_prefix not NULL", __func__); RB_REMOVE(nexthop_tree, &nexthoptable, nh); rde_send_nexthop(&nh->exit_nexthop, 0); rdemem.nexthop_cnt--; free(nh); return (1); } static inline int nexthop_cmp(struct nexthop *na, struct nexthop *nb) { struct bgpd_addr *a, *b; if (na == nb) return (0); if (na == NULL) return (-1); if (nb == NULL) return (1); a = &na->exit_nexthop; b = &nb->exit_nexthop; if (a->aid != b->aid) return (a->aid - b->aid); switch (a->aid) { case AID_INET: if (ntohl(a->v4.s_addr) > ntohl(b->v4.s_addr)) return (1); if (ntohl(a->v4.s_addr) < ntohl(b->v4.s_addr)) return (-1); return (0); case AID_INET6: return (memcmp(&a->v6, &b->v6, sizeof(struct in6_addr))); default: fatalx("nexthop_cmp: %s is unsupported", aid2str(a->aid)); } return (-1); } struct nexthop * nexthop_lookup(struct bgpd_addr *nexthop) { struct nexthop needle = { 0 }; needle.exit_nexthop = *nexthop; return RB_FIND(nexthop_tree, &nexthoptable, &needle); } openbgpd-8.8/src/bgpd/rde_decide.c100644 001750 001750 00000047612 14673014240 0012622/* $OpenBSD: rde_decide.c,v 1.103 2024/08/14 19:09:51 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" int prefix_cmp(struct prefix *, struct prefix *, int *); void prefix_set_dmetric(struct prefix *, struct prefix *); void prefix_insert(struct prefix *, struct prefix *, struct rib_entry *); void prefix_remove(struct prefix *, struct rib_entry *); /* * Decision Engine RFC implementation: * Phase 1: * - calculate LOCAL_PREF if needed -- EBGP or IGP learnt routes * - IBGP routes may either use LOCAL_PREF or the local system computes * the degree of preference * - If the route is ineligible, the route MAY NOT serve as an input to * the next phase of route selection * - if the route is eligible the computed value MUST be used as the * LOCAL_PREF value in any IBGP readvertisement * * Phase 2: * - If the NEXT_HOP attribute of a BGP route depicts an address that is * not resolvable the BGP route MUST be excluded from the Phase 2 decision * function. * - If the AS_PATH attribute of a BGP route contains an AS loop, the BGP * route should be excluded from the Phase 2 decision function. * - The local BGP speaker identifies the route that has: * a) the highest degree of preference of any route to the same set * of destinations * b) is the only route to that destination * c) is selected as a result of the Phase 2 tie breaking rules * - The local speaker MUST determine the immediate next-hop address from * the NEXT_HOP attribute of the selected route. * - If either the immediate next hop or the IGP cost to the NEXT_HOP changes, * Phase 2 Route Selection MUST be performed again. * * Route Resolvability Condition * - A route Rte1, referencing only the intermediate network address, is * considered resolvable if the Routing Table contains at least one * resolvable route Rte2 that matches Rte1's intermediate network address * and is not recursively resolved through Rte1. * - Routes referencing interfaces are considered resolvable if the state of * the referenced interface is up and IP processing is enabled. * * Breaking Ties (Phase 2) * 1. Remove from consideration all routes which are not tied for having the * smallest number of AS numbers present in their AS_PATH attributes. * Note, that when counting this number, an AS_SET counts as 1 * 2. Remove from consideration all routes which are not tied for having the * lowest Origin number in their Origin attribute. * 3. Remove from consideration routes with less-preferred MULTI_EXIT_DISC * attributes. MULTI_EXIT_DISC is only comparable between routes learned * from the same neighboring AS. * 4. If at least one of the candidate routes was received via EBGP, * remove from consideration all routes which were received via IBGP. * 5. Remove from consideration any routes with less-preferred interior cost. * If the NEXT_HOP hop for a route is reachable, but no cost can be * determined, then this step should be skipped. * 6. Remove from consideration all routes other than the route that was * advertised by the BGP speaker whose BGP Identifier has the lowest value. * 7. Prefer the route received from the lowest peer address. * * Phase 3: Route Dissemination * - All routes in the Loc-RIB are processed into Adj-RIBs-Out according * to configured policy. A route SHALL NOT be installed in the Adj-Rib-Out * unless the destination and NEXT_HOP described by this route may be * forwarded appropriately by the Routing Table. */ /* * Decision Engine OUR implementation: * The filtering is done first. The filtering calculates the preference and * stores it in LOCAL_PREF (Phase 1). * Ineligible routes are flagged as ineligible via nexthop_add(). * Phase 3 is done together with Phase 2. * In following cases a prefix needs to be reevaluated: * - update of a prefix (prefix_update) * - withdraw of a prefix (prefix_withdraw) * - state change of the nexthop (nexthop-{in}validate) * - state change of session (session down) */ /* * Compare two prefixes with equal pt_entry. Returns an integer greater than or * less than 0, according to whether the prefix p1 is more or less preferred * than the prefix p2. p1 should be used for the new prefix and p2 for a * already added prefix. The absolute value returned specifies the similarity * of the prefixes. * 1: prefixes differ because of validity * 2: prefixes don't belong in any multipath set * 3: prefixes belong only in the as-wide multipath set * 4: prefixes belong in both the ecmp and as-wide multipath set * TODO: maybe we also need a strict ecmp set that requires * prefixes to e.g. equal ASPATH or equal neighbor-as (like for MED). */ int prefix_cmp(struct prefix *p1, struct prefix *p2, int *testall) { struct rde_aspath *asp1, *asp2; struct rde_peer *peer1, *peer2; struct attr *a; uint32_t p1id, p2id; int p1cnt, p2cnt, i; int rv = 1; /* * If a match happens before the MED check then the list is * correctly sorted. If a match happens after MED then further * elements may need to be checked to ensure that all paths * which could affect this path were considered. This only * matters for strict MED evaluation and in that case testall * is set to 1. If the check happens to be on the MED check * itself testall is set to 2. */ *testall = 0; if (p1 == NULL) return -rv; if (p2 == NULL) return rv; asp1 = prefix_aspath(p1); asp2 = prefix_aspath(p2); peer1 = prefix_peer(p1); peer2 = prefix_peer(p2); /* 1. check if prefix is eligible a.k.a reachable */ if (!prefix_eligible(p2)) return rv; if (!prefix_eligible(p1)) return -rv; /* bump rv, from here on prefix is considered valid */ rv++; /* 2. local preference of prefix, bigger is better */ if (asp1->lpref > asp2->lpref) return rv; if (asp1->lpref < asp2->lpref) return -rv; /* 3. aspath count, the shorter the better */ if (asp1->aspath->ascnt < asp2->aspath->ascnt) return rv; if (asp1->aspath->ascnt > asp2->aspath->ascnt) return -rv; /* 4. origin, the lower the better */ if (asp1->origin < asp2->origin) return rv; if (asp1->origin > asp2->origin) return -rv; /* * 5. MED decision * Only comparable between the same neighboring AS or if * 'rde med compare always' is set. In the first case * set the testall flag since further elements need to be * evaluated as well. */ if ((rde_decisionflags() & BGPD_FLAG_DECISION_MED_ALWAYS) || aspath_neighbor(asp1->aspath) == aspath_neighbor(asp2->aspath)) { if (!(rde_decisionflags() & BGPD_FLAG_DECISION_MED_ALWAYS)) *testall = 2; /* lowest value wins */ if (asp1->med < asp2->med) return rv; if (asp1->med > asp2->med) return -rv; } if (!(rde_decisionflags() & BGPD_FLAG_DECISION_MED_ALWAYS)) *testall = 1; /* * 6. EBGP is cooler than IBGP * It is absolutely important that the ebgp value in peer_config.ebgp * is bigger than all other ones (IBGP, confederations) */ if (peer1->conf.ebgp != peer2->conf.ebgp) { if (peer1->conf.ebgp) /* peer1 is EBGP other is lower */ return rv; else if (peer2->conf.ebgp) /* peer2 is EBGP */ return -rv; } /* bump rv, as-wide multipath */ rv++; /* * 7. local tie-breaker, this weight is here to tip equal long AS * paths in one or the other direction. It happens more and more * that AS paths are equally long and so traffic engineering needs * a metric that weights a prefix at a very late stage in the * decision process. */ if (asp1->weight > asp2->weight) return rv; if (asp1->weight < asp2->weight) return -rv; /* 8. nexthop costs. NOT YET -> IGNORE */ /* bump rv, equal cost multipath */ rv++; /* * 9. older route (more stable) wins but only if route-age * evaluation is enabled. */ if (rde_decisionflags() & BGPD_FLAG_DECISION_ROUTEAGE) { if (p1->lastchange < p2->lastchange) /* p1 is older */ return rv; if (p1->lastchange > p2->lastchange) return -rv; } /* 10. lowest BGP Id wins, use ORIGINATOR_ID if present */ if ((a = attr_optget(asp1, ATTR_ORIGINATOR_ID)) != NULL) { memcpy(&p1id, a->data, sizeof(p1id)); p1id = ntohl(p1id); } else p1id = peer1->remote_bgpid; if ((a = attr_optget(asp2, ATTR_ORIGINATOR_ID)) != NULL) { memcpy(&p2id, a->data, sizeof(p2id)); p2id = ntohl(p2id); } else p2id = peer2->remote_bgpid; if (p1id < p2id) return rv; if (p1id > p2id) return -rv; /* 11. compare CLUSTER_LIST length, shorter is better */ p1cnt = p2cnt = 0; if ((a = attr_optget(asp1, ATTR_CLUSTER_LIST)) != NULL) p1cnt = a->len / sizeof(uint32_t); if ((a = attr_optget(asp2, ATTR_CLUSTER_LIST)) != NULL) p2cnt = a->len / sizeof(uint32_t); if (p1cnt < p2cnt) return rv; if (p1cnt > p2cnt) return -rv; /* 12. lowest peer address wins (IPv4 is better than IPv6) */ if (peer1->remote_addr.aid < peer2->remote_addr.aid) return rv; if (peer1->remote_addr.aid > peer2->remote_addr.aid) return -rv; switch (peer1->remote_addr.aid) { case AID_INET: i = memcmp(&peer1->remote_addr.v4, &peer2->remote_addr.v4, sizeof(struct in_addr)); break; case AID_INET6: i = memcmp(&peer1->remote_addr.v6, &peer2->remote_addr.v6, sizeof(struct in6_addr)); break; default: fatalx("%s: unknown af", __func__); } if (i < 0) return rv; if (i > 0) return -rv; /* RFC7911 does not specify this but something like this is needed. */ /* 13. lowest path identifier wins */ if (p1->path_id < p2->path_id) return rv; if (p1->path_id > p2->path_id) return -rv; fatalx("Uh, oh a politician in the decision process"); } /* * set the dmetric value of np based on the return value of * prefix_evaluate(pp, np) or set it to either PREFIX_DMETRIC_BEST * or PREFIX_DMETRIC_INVALID for the first element. */ void prefix_set_dmetric(struct prefix *pp, struct prefix *np) { int testall; if (np != NULL) { if (pp == NULL) np->dmetric = prefix_eligible(np) ? PREFIX_DMETRIC_BEST : PREFIX_DMETRIC_INVALID; else np->dmetric = prefix_cmp(pp, np, &testall); if (np->dmetric < 0) { struct bgpd_addr addr; pt_getaddr(np->pt, &addr); log_debug("bad dmetric in decision process: %s/%u", log_addr(&addr), np->pt->prefixlen); } } } /* * Insert a prefix keeping the total order of the list. For routes * that may depend on a MED selection the set is scanned until the * condition is cleared. If a MED inversion is detected the respective * prefix is taken of the rib list and put onto a redo queue. All * prefixes on the redo queue are re-inserted at the end. */ void prefix_insert(struct prefix *new, struct prefix *ep, struct rib_entry *re) { struct prefix_queue redo = TAILQ_HEAD_INITIALIZER(redo); struct prefix *xp, *np, *insertp = ep; int testall, preferred, selected = 0, removed = 0; /* start scan at the entry point (ep) or the head if ep == NULL */ if (ep == NULL) ep = TAILQ_FIRST(&re->prefix_h); for (xp = ep; xp != NULL; xp = np) { np = TAILQ_NEXT(xp, entry.list.rib); if ((preferred = (prefix_cmp(new, xp, &testall) > 0))) { /* new is preferred over xp */ if (testall == 2) { /* * MED inversion, take out prefix and * put it onto redo queue. */ TAILQ_REMOVE(&re->prefix_h, xp, entry.list.rib); TAILQ_INSERT_TAIL(&redo, xp, entry.list.rib); removed = 1; continue; } if (testall == 1) { /* * lock insertion point and * continue on with scan */ selected = 1; } } else { /* * xp is preferred over new. * Remember insertion point for later unless the * traverse is just looking for a possible MED * inversion (selected == 1). * If the last comparison's tie-breaker was the MED * check reset selected and with it insertp since * this was an actual MED priority inversion. */ if (testall == 2) selected = 0; if (!selected) insertp = xp; } /* * If previous element(s) got removed, fixup the * dmetric, now that it is clear that this element * is on the list. */ if (removed) { prefix_set_dmetric(TAILQ_PREV(xp, prefix_queue, entry.list.rib), xp); removed = 0; } if (preferred && testall == 0) break; /* we're done */ } if (insertp == NULL) { TAILQ_INSERT_HEAD(&re->prefix_h, new, entry.list.rib); } else { TAILQ_INSERT_AFTER(&re->prefix_h, insertp, new, entry.list.rib); } prefix_set_dmetric(insertp, new); prefix_set_dmetric(new, TAILQ_NEXT(new, entry.list.rib)); /* Fixup MED order again. All elements are < new */ while (!TAILQ_EMPTY(&redo)) { xp = TAILQ_FIRST(&redo); TAILQ_REMOVE(&redo, xp, entry.list.rib); prefix_insert(xp, new, re); } } /* * Remove a prefix from the RIB list ensuring that the total order of the * list remains intact. All routes that differ in the MED are taken of the * list and put on the redo list. To figure out if a route could cause a * resort because of a MED check the next prefix of the to-remove prefix * is compared with the old prefix. A full scan is only done if the next * route differs because of the MED or later checks. * Again at the end all routes on the redo queue are reinserted. */ void prefix_remove(struct prefix *old, struct rib_entry *re) { struct prefix_queue redo = TAILQ_HEAD_INITIALIZER(redo); struct prefix *xp, *np, *pp; int testall, removed = 0; xp = TAILQ_NEXT(old, entry.list.rib); pp = TAILQ_PREV(old, prefix_queue, entry.list.rib); TAILQ_REMOVE(&re->prefix_h, old, entry.list.rib); /* check if a MED inversion could be possible */ prefix_cmp(old, xp, &testall); if (testall > 0) { /* maybe MED route, scan tail for other possible routes */ for (; xp != NULL; xp = np) { np = TAILQ_NEXT(xp, entry.list.rib); /* only interested in the testall result */ prefix_cmp(old, xp, &testall); if (testall == 2) { /* * possible MED inversion, take out prefix and * put it onto redo queue. */ TAILQ_REMOVE(&re->prefix_h, xp, entry.list.rib); TAILQ_INSERT_TAIL(&redo, xp, entry.list.rib); removed = 1; continue; } /* * If previous element(s) got removed, fixup the * dmetric, now that it is clear that this element * is on the list. */ if (removed) { prefix_set_dmetric(TAILQ_PREV(xp, prefix_queue, entry.list.rib), xp); removed = 0; } if (testall == 0) break; /* we're done */ } } if (pp) prefix_set_dmetric(pp, TAILQ_NEXT(pp, entry.list.rib)); else prefix_set_dmetric(NULL, TAILQ_FIRST(&re->prefix_h)); /* Fixup MED order again, reinsert prefixes from the start */ while (!TAILQ_EMPTY(&redo)) { xp = TAILQ_FIRST(&redo); TAILQ_REMOVE(&redo, xp, entry.list.rib); prefix_insert(xp, NULL, re); } } /* helper function to check if a prefix is valid to be selected */ int prefix_eligible(struct prefix *p) { struct rde_aspath *asp = prefix_aspath(p); /* prefix itself is marked ineligible */ if (prefix_filtered(p)) return 0; /* The aspath needs to be loop and error free */ if (asp == NULL || asp->flags & (F_ATTR_LOOP|F_ATTR_OTC_LEAK|F_ATTR_PARSE_ERR)) return 0; /* The nexthop must be valid. */ if (!prefix_nhvalid(p)) return 0; return 1; } struct prefix * prefix_best(struct rib_entry *re) { struct prefix *xp; struct rib *rib; rib = re_rib(re); if (rib->flags & F_RIB_NOEVALUATE) /* decision process is turned off */ return NULL; xp = TAILQ_FIRST(&re->prefix_h); if (xp != NULL && !prefix_eligible(xp)) xp = NULL; return xp; } /* * Find the correct place to insert the prefix in the prefix list. * If the active prefix has changed we need to send an update also special * treatment is needed if 'rde evaluate all' is used on some peers. * To re-evaluate a prefix just call prefix_evaluate with old and new pointing * to the same prefix. */ void prefix_evaluate(struct rib_entry *re, struct prefix *new, struct prefix *old) { struct prefix *newbest, *oldbest; struct rib *rib; rib = re_rib(re); if (rib->flags & F_RIB_NOEVALUATE) { /* decision process is turned off */ if (old != NULL) TAILQ_REMOVE(&re->prefix_h, old, entry.list.rib); if (new != NULL) { TAILQ_INSERT_HEAD(&re->prefix_h, new, entry.list.rib); new->dmetric = PREFIX_DMETRIC_INVALID; } return; } oldbest = prefix_best(re); if (old != NULL) prefix_remove(old, re); if (new != NULL) prefix_insert(new, NULL, re); newbest = prefix_best(re); /* * If the active prefix changed or the active prefix was removed * and added again then generate an update. */ if (oldbest != newbest || (old != NULL && newbest == old)) { /* * Send update withdrawing oldbest and adding newbest * but remember that newbest may be NULL aka ineligible. * Additional decision may be made by the called functions. */ if ((rib->flags & F_RIB_NOFIB) == 0) rde_send_kroute(rib, newbest, oldbest); rde_generate_updates(re, new, old, EVAL_DEFAULT); return; } /* * If there are peers with 'rde evaluate all' every update needs * to be passed on (not only a change of the best prefix). * rde_generate_updates() will then take care of distribution. */ if (rde_evaluate_all()) { if (new != NULL && !prefix_eligible(new)) new = NULL; if (new != NULL || old != NULL) rde_generate_updates(re, new, old, EVAL_ALL); } } void prefix_evaluate_nexthop(struct prefix *p, enum nexthop_state state, enum nexthop_state oldstate) { struct rib_entry *re = prefix_re(p); struct prefix *newbest, *oldbest, *new, *old; struct rib *rib; /* Skip non local-RIBs or RIBs that are flagged as noeval. */ rib = re_rib(re); if (rib->flags & F_RIB_NOEVALUATE) { log_warnx("%s: prefix with F_RIB_NOEVALUATE hit", __func__); return; } if (oldstate == state) { /* * The state of the nexthop did not change. The only * thing that may have changed is the true_nexthop * or other internal infos. This will not change * the routing decision so shortcut here. * XXX needs to be changed for ECMP */ if (state == NEXTHOP_REACH) { if ((rib->flags & F_RIB_NOFIB) == 0 && p == prefix_best(re)) rde_send_kroute(rib, p, NULL); } return; } /* * Re-evaluate the prefix by removing the prefix then updating the * nexthop state and reinserting the prefix again. */ old = p; oldbest = prefix_best(re); prefix_remove(p, re); if (state == NEXTHOP_REACH) p->nhflags |= NEXTHOP_VALID; else p->nhflags &= ~NEXTHOP_VALID; prefix_insert(p, NULL, re); newbest = prefix_best(re); new = p; if (!prefix_eligible(new)) new = NULL; /* * If the active prefix changed or the active prefix was removed * and added again then generate an update. */ if (oldbest != newbest || newbest == p) { /* * Send update withdrawing oldbest and adding newbest * but remember that newbest may be NULL aka ineligible. * Additional decision may be made by the called functions. */ if ((rib->flags & F_RIB_NOFIB) == 0) rde_send_kroute(rib, newbest, oldbest); rde_generate_updates(re, new, old, EVAL_DEFAULT); return; } /* * If there are peers with 'rde evaluate all' every update needs * to be passed on (not only a change of the best prefix). * rde_generate_updates() will then take care of distribution. */ if (rde_evaluate_all()) rde_generate_updates(re, new, old, EVAL_ALL); } openbgpd-8.8/src/bgpd/rde_prefix.c100644 001750 001750 00000045764 14751151130 0012705/* $OpenBSD: rde_prefix.c,v 1.57 2025/02/04 18:16:56 denis Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" /* * Prefix Table functions: * pt_add: create new prefix and link it into the prefix table * pt_remove: Checks if there is no bgp prefix linked to the prefix, * unlinks from the prefix table and frees the pt_entry. * pt_get: get a prefix/prefixlen entry. While pt_lookup searches for the * best matching prefix pt_get only finds the prefix/prefixlen * entry. The speed of pt_get is important for the bgp updates. * pt_getaddr: convert the address into a struct bgpd_addr. * pt_lookup: lookup a IP in the prefix table. Mainly for "show ip bgp". * pt_empty: returns true if there is no bgp prefix linked to the pt_entry. * pt_init: initialize prefix table. * pt_alloc: allocate a AF specific pt_entry. Internal function. * pt_free: free a pt_entry. Internal function. */ /* internal prototypes */ static struct pt_entry *pt_alloc(struct pt_entry *, int len); static void pt_free(struct pt_entry *); struct pt_entry4 { RB_ENTRY(pt_entry) pt_e; uint8_t aid; uint8_t prefixlen; uint16_t len; uint32_t refcnt; struct in_addr prefix4; }; struct pt_entry6 { RB_ENTRY(pt_entry) pt_e; uint8_t aid; uint8_t prefixlen; uint16_t len; uint32_t refcnt; struct in6_addr prefix6; }; struct pt_entry_vpn4 { RB_ENTRY(pt_entry) pt_e; uint8_t aid; uint8_t prefixlen; uint16_t len; uint32_t refcnt; uint64_t rd; struct in_addr prefix4; uint8_t labelstack[21]; uint8_t labellen; uint8_t pad1; uint8_t pad2; }; struct pt_entry_vpn6 { RB_ENTRY(pt_entry) pt_e; uint8_t aid; uint8_t prefixlen; uint16_t len; uint32_t refcnt; uint64_t rd; struct in6_addr prefix6; uint8_t labelstack[21]; uint8_t labellen; uint8_t pad1; uint8_t pad2; }; struct pt_entry_evpn { RB_ENTRY(pt_entry) pt_e; uint8_t aid; uint8_t prefixlen; uint16_t len; uint32_t refcnt; uint64_t rd; uint32_t ethtag; uint8_t esi[ESI_ADDR_LEN]; uint8_t mac[ETHER_ADDR_LEN]; uint8_t labelstack[6]; uint8_t labellen; uint8_t type; uint8_t vpnaid; union { struct in_addr prefix4; struct in6_addr prefix6; }; }; struct pt_entry_flow { RB_ENTRY(pt_entry) pt_e; uint8_t aid; uint8_t prefixlen; /* unused ??? */ uint16_t len; uint32_t refcnt; uint64_t rd; uint8_t flow[1]; /* NLRI */ }; #define PT_FLOW_SIZE (offsetof(struct pt_entry_flow, flow)) RB_HEAD(pt_tree, pt_entry); RB_PROTOTYPE(pt_tree, pt_entry, pt_e, pt_prefix_cmp); RB_GENERATE(pt_tree, pt_entry, pt_e, pt_prefix_cmp); struct pt_tree pttable; void pt_init(void) { RB_INIT(&pttable); } void pt_shutdown(void) { if (!RB_EMPTY(&pttable)) log_debug("pt_shutdown: tree is not empty."); } void pt_getaddr(struct pt_entry *pte, struct bgpd_addr *addr) { struct pt_entry_flow *pflow; struct pt_entry_evpn *evpn; memset(addr, 0, sizeof(struct bgpd_addr)); addr->aid = pte->aid; switch (addr->aid) { case AID_INET: addr->v4 = ((struct pt_entry4 *)pte)->prefix4; break; case AID_INET6: addr->v6 = ((struct pt_entry6 *)pte)->prefix6; /* XXX scope_id ??? */ break; case AID_VPN_IPv4: addr->v4 = ((struct pt_entry_vpn4 *)pte)->prefix4; addr->rd = ((struct pt_entry_vpn4 *)pte)->rd; addr->labellen = ((struct pt_entry_vpn4 *)pte)->labellen; memcpy(addr->labelstack, ((struct pt_entry_vpn4 *)pte)->labelstack, addr->labellen); break; case AID_VPN_IPv6: addr->v6 = ((struct pt_entry_vpn6 *)pte)->prefix6; addr->rd = ((struct pt_entry_vpn6 *)pte)->rd; addr->labellen = ((struct pt_entry_vpn6 *)pte)->labellen; memcpy(addr->labelstack, ((struct pt_entry_vpn6 *)pte)->labelstack, addr->labellen); break; case AID_EVPN: evpn = (struct pt_entry_evpn *)pte; addr->evpn.type = evpn->type; addr->rd = evpn->rd; addr->evpn.ethtag = evpn->ethtag; addr->labellen = evpn->labellen; addr->evpn.aid = evpn->vpnaid; memcpy(addr->labelstack, evpn->labelstack, addr->labellen); memcpy(addr->evpn.esi, evpn->esi, sizeof(evpn->esi)); memcpy(addr->evpn.mac, evpn->mac, sizeof(evpn->mac)); switch (evpn->vpnaid) { case AID_INET: addr->evpn.v4 = evpn->prefix4; break; case AID_INET6: addr->evpn.v6 = evpn->prefix6; break; } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: pflow = (struct pt_entry_flow *)pte; flowspec_get_addr(pflow->flow, pflow->len - PT_FLOW_SIZE, FLOWSPEC_TYPE_DEST, addr->aid == AID_FLOWSPECv6, addr, &pflow->prefixlen, NULL); break; default: fatalx("pt_getaddr: unknown af"); } } int pt_getflowspec(struct pt_entry *pte, uint8_t **flow) { struct pt_entry_flow *pflow; switch (pte->aid) { case AID_FLOWSPECv4: case AID_FLOWSPECv6: pflow = (struct pt_entry_flow *)pte; *flow = pflow->flow; return pflow->len - PT_FLOW_SIZE; default: fatalx("pt_getflowspec: unknown af"); } } struct pt_entry * pt_fill(struct bgpd_addr *prefix, int prefixlen) { static struct pt_entry4 pte4; static struct pt_entry6 pte6; static struct pt_entry_vpn4 pte_vpn4; static struct pt_entry_vpn6 pte_vpn6; static struct pt_entry_evpn pte_evpn; switch (prefix->aid) { case AID_INET: memset(&pte4, 0, sizeof(pte4)); pte4.len = sizeof(pte4); pte4.refcnt = UINT32_MAX; pte4.aid = prefix->aid; if (prefixlen > 32) fatalx("pt_fill: bad IPv4 prefixlen"); inet4applymask(&pte4.prefix4, &prefix->v4, prefixlen); pte4.prefixlen = prefixlen; return ((struct pt_entry *)&pte4); case AID_INET6: memset(&pte6, 0, sizeof(pte6)); pte6.len = sizeof(pte6); pte6.refcnt = UINT32_MAX; pte6.aid = prefix->aid; if (prefixlen > 128) fatalx("pt_fill: bad IPv6 prefixlen"); inet6applymask(&pte6.prefix6, &prefix->v6, prefixlen); pte6.prefixlen = prefixlen; return ((struct pt_entry *)&pte6); case AID_VPN_IPv4: memset(&pte_vpn4, 0, sizeof(pte_vpn4)); pte_vpn4.len = sizeof(pte_vpn4); pte_vpn4.refcnt = UINT32_MAX; pte_vpn4.aid = prefix->aid; if (prefixlen > 32) fatalx("pt_fill: bad IPv4 prefixlen"); inet4applymask(&pte_vpn4.prefix4, &prefix->v4, prefixlen); pte_vpn4.prefixlen = prefixlen; pte_vpn4.rd = prefix->rd; pte_vpn4.labellen = prefix->labellen; memcpy(pte_vpn4.labelstack, prefix->labelstack, prefix->labellen); return ((struct pt_entry *)&pte_vpn4); case AID_VPN_IPv6: memset(&pte_vpn6, 0, sizeof(pte_vpn6)); pte_vpn6.len = sizeof(pte_vpn6); pte_vpn6.refcnt = UINT32_MAX; pte_vpn6.aid = prefix->aid; if (prefixlen > 128) fatalx("pt_fill: bad IPv6 prefixlen"); inet6applymask(&pte_vpn6.prefix6, &prefix->v6, prefixlen); pte_vpn6.prefixlen = prefixlen; pte_vpn6.rd = prefix->rd; pte_vpn6.labellen = prefix->labellen; memcpy(pte_vpn6.labelstack, prefix->labelstack, prefix->labellen); return ((struct pt_entry *)&pte_vpn6); case AID_EVPN: memset(&pte_evpn, 0, sizeof(pte_evpn)); pte_evpn.len = sizeof(pte_evpn); pte_evpn.refcnt = UINT32_MAX; switch (prefix->evpn.aid) { case AID_UNSPEC: /* See rfc7432 section 7.2 */ break; case AID_INET: pte_evpn.prefix4 = prefix->evpn.v4; break; case AID_INET6: pte_evpn.prefix6 = prefix->evpn.v6; break; default: fatalx("pt_fill: bad EVPN prefixlen"); } pte_evpn.aid = prefix->aid; pte_evpn.vpnaid = prefix->evpn.aid; pte_evpn.prefixlen = prefixlen; pte_evpn.type = prefix->evpn.type; pte_evpn.rd = prefix->rd; pte_evpn.ethtag = prefix->evpn.ethtag; pte_evpn.labellen = prefix->labellen; memcpy(pte_evpn.labelstack, prefix->labelstack, pte_evpn.labellen); memcpy(pte_evpn.esi, prefix->evpn.esi, sizeof(prefix->evpn.esi)); memcpy(pte_evpn.mac, prefix->evpn.mac, sizeof(prefix->evpn.mac)); return ((struct pt_entry *)&pte_evpn); default: fatalx("pt_fill: unknown af"); } } struct pt_entry * pt_get(struct bgpd_addr *prefix, int prefixlen) { struct pt_entry *pte; pte = pt_fill(prefix, prefixlen); return RB_FIND(pt_tree, &pttable, pte); } struct pt_entry * pt_add(struct bgpd_addr *prefix, int prefixlen) { struct pt_entry *p = NULL; p = pt_fill(prefix, prefixlen); p = pt_alloc(p, p->len); if (RB_INSERT(pt_tree, &pttable, p) != NULL) fatalx("pt_add: insert failed"); return (p); } struct pt_entry * pt_get_flow(struct flowspec *f) { struct pt_entry *needle; union { struct pt_entry_flow flow; uint8_t buf[4096]; } x; needle = (struct pt_entry *)&x.flow; memset(needle, 0, PT_FLOW_SIZE); needle->aid = f->aid; needle->len = f->len + PT_FLOW_SIZE; memcpy(((struct pt_entry_flow *)needle)->flow, f->data, f->len); return RB_FIND(pt_tree, &pttable, (struct pt_entry *)needle); } struct pt_entry * pt_add_flow(struct flowspec *f) { struct pt_entry *p; int len = f->len + PT_FLOW_SIZE; p = malloc(len); if (p == NULL) fatal(__func__); rdemem.pt_cnt[f->aid]++; rdemem.pt_size[f->aid] += len; memset(p, 0, PT_FLOW_SIZE); p->len = len; p->aid = f->aid; memcpy(((struct pt_entry_flow *)p)->flow, f->data, f->len); if (RB_INSERT(pt_tree, &pttable, p) != NULL) fatalx("pt_add: insert failed"); return (p); } void pt_remove(struct pt_entry *pte) { if (pte->refcnt != 0) fatalx("pt_remove: entry still holds references"); if (RB_REMOVE(pt_tree, &pttable, pte) == NULL) log_warnx("pt_remove: remove failed."); pt_free(pte); } struct pt_entry * pt_lookup(struct bgpd_addr *addr) { struct pt_entry *p; int i; switch (addr->aid) { case AID_INET: case AID_VPN_IPv4: i = 32; break; case AID_INET6: case AID_VPN_IPv6: i = 128; break; default: fatalx("pt_lookup: unknown af"); } for (; i >= 0; i--) { p = pt_get(addr, i); if (p != NULL) return (p); } return (NULL); } int pt_prefix_cmp(const struct pt_entry *a, const struct pt_entry *b) { const struct pt_entry4 *a4, *b4; const struct pt_entry6 *a6, *b6; const struct pt_entry_vpn4 *va4, *vb4; const struct pt_entry_vpn6 *va6, *vb6; const struct pt_entry_flow *af, *bf; const struct pt_entry_evpn *ea, *eb; int i; if (a->aid > b->aid) return (1); if (a->aid < b->aid) return (-1); switch (a->aid) { case AID_INET: a4 = (const struct pt_entry4 *)a; b4 = (const struct pt_entry4 *)b; if (ntohl(a4->prefix4.s_addr) > ntohl(b4->prefix4.s_addr)) return (1); if (ntohl(a4->prefix4.s_addr) < ntohl(b4->prefix4.s_addr)) return (-1); if (a4->prefixlen > b4->prefixlen) return (1); if (a4->prefixlen < b4->prefixlen) return (-1); return (0); case AID_INET6: a6 = (const struct pt_entry6 *)a; b6 = (const struct pt_entry6 *)b; i = memcmp(&a6->prefix6, &b6->prefix6, sizeof(struct in6_addr)); if (i > 0) return (1); if (i < 0) return (-1); if (a6->prefixlen < b6->prefixlen) return (-1); if (a6->prefixlen > b6->prefixlen) return (1); return (0); case AID_VPN_IPv4: va4 = (const struct pt_entry_vpn4 *)a; vb4 = (const struct pt_entry_vpn4 *)b; if (be64toh(va4->rd) > be64toh(vb4->rd)) return (1); if (be64toh(va4->rd) < be64toh(vb4->rd)) return (-1); if (ntohl(va4->prefix4.s_addr) > ntohl(vb4->prefix4.s_addr)) return (1); if (ntohl(va4->prefix4.s_addr) < ntohl(vb4->prefix4.s_addr)) return (-1); if (va4->prefixlen > vb4->prefixlen) return (1); if (va4->prefixlen < vb4->prefixlen) return (-1); return (0); case AID_VPN_IPv6: va6 = (const struct pt_entry_vpn6 *)a; vb6 = (const struct pt_entry_vpn6 *)b; if (be64toh(va6->rd) > be64toh(vb6->rd)) return (1); if (be64toh(va6->rd) < be64toh(vb6->rd)) return (-1); i = memcmp(&va6->prefix6, &vb6->prefix6, sizeof(struct in6_addr)); if (i > 0) return (1); if (i < 0) return (-1); if (va6->prefixlen > vb6->prefixlen) return (1); if (va6->prefixlen < vb6->prefixlen) return (-1); return (0); case AID_EVPN: /* XXXX Need different comparator for different types */ ea = (const struct pt_entry_evpn *)a; eb = (const struct pt_entry_evpn *)b; if (ea->ethtag > eb->ethtag) return (1); if (ea->ethtag < eb->ethtag) return (-1); /* MAC length is always 48 */ i = memcmp(&ea->mac, &eb->mac, sizeof(ea->mac)); if (i > 0) return (1); if (i < 0) return (-1); if (ea->prefixlen > eb->prefixlen) return (1); if (ea->prefixlen < eb->prefixlen) return (-1); switch (ea->vpnaid) { case AID_UNSPEC: break; case AID_INET: i = memcmp(&ea->prefix4, &eb->prefix4, sizeof(struct in_addr)); if (i > 0) return (1); if (i < 0) return (-1); break; case AID_INET6: i = memcmp(&ea->prefix6, &eb->prefix6, sizeof(struct in6_addr)); if (i > 0) return (1); if (i < 0) return (-1); break; default: fatalx("pt_prefix_cmp: unknown evpn af %d", ea->vpnaid); } return (0); case AID_FLOWSPECv4: case AID_FLOWSPECv6: af = (const struct pt_entry_flow *)a; bf = (const struct pt_entry_flow *)b; return flowspec_cmp(af->flow, af->len - PT_FLOW_SIZE, bf->flow, bf->len - PT_FLOW_SIZE, a->aid == AID_FLOWSPECv6); default: fatalx("pt_prefix_cmp: unknown af %d", a->aid); } return (-1); } /* * Returns a pt_entry cloned from the one passed in. * Function may not return on failure. */ static struct pt_entry * pt_alloc(struct pt_entry *op, int len) { struct pt_entry *p; p = malloc(len); if (p == NULL) fatal("pt_alloc"); rdemem.pt_cnt[op->aid]++; rdemem.pt_size[op->aid] += len; memcpy(p, op, len); p->refcnt = 0; return (p); } static void pt_free(struct pt_entry *pte) { rdemem.pt_cnt[pte->aid]--; rdemem.pt_size[pte->aid] -= pte->len; free(pte); } /* dump a prefix into specified buffer */ int pt_writebuf(struct ibuf *buf, struct pt_entry *pte, int withdraw, int add_path, uint32_t pathid) { struct pt_entry_vpn4 *pvpn4 = (struct pt_entry_vpn4 *)pte; struct pt_entry_vpn6 *pvpn6 = (struct pt_entry_vpn6 *)pte; struct pt_entry_flow *pflow = (struct pt_entry_flow *)pte; struct pt_entry_evpn *pevpn = (struct pt_entry_evpn *)pte; struct ibuf *tmp; int flowlen, psize; uint16_t plen; if ((tmp = ibuf_dynamic(32, UINT16_MAX)) == NULL) goto fail; if (add_path) { if (ibuf_add_n32(tmp, pathid) == -1) goto fail; } switch (pte->aid) { case AID_INET: case AID_INET6: plen = pte->prefixlen; if (ibuf_add_n8(tmp, plen) == -1) goto fail; if (ibuf_add(tmp, pte->data, PREFIX_SIZE(plen) - 1) == -1) goto fail; break; case AID_VPN_IPv4: plen = pvpn4->prefixlen; psize = PREFIX_SIZE(plen) - 1; plen += sizeof(pvpn4->rd) * 8; if (withdraw) { /* withdraw have one compat label as placeholder */ plen += 3 * 8; } else { plen += pvpn4->labellen * 8; } if (ibuf_add_n8(tmp, plen) == -1) goto fail; if (withdraw) { /* magic compatibility label as per rfc8277 */ if (ibuf_add_n8(tmp, 0x80) == -1 || ibuf_add_zero(tmp, 2) == -1) goto fail; } else { if (ibuf_add(tmp, &pvpn4->labelstack, pvpn4->labellen) == -1) goto fail; } if (ibuf_add(tmp, &pvpn4->rd, sizeof(pvpn4->rd)) == -1 || ibuf_add(tmp, &pvpn4->prefix4, psize) == -1) goto fail; break; case AID_VPN_IPv6: plen = pvpn6->prefixlen; psize = PREFIX_SIZE(plen) - 1; plen += sizeof(pvpn6->rd) * 8; if (withdraw) { /* withdraw have one compat label as placeholder */ plen += 3 * 8; } else { plen += pvpn6->labellen * 8; } if (ibuf_add_n8(tmp, plen) == -1) goto fail; if (withdraw) { /* magic compatibility label as per rfc8277 */ if (ibuf_add_n8(tmp, 0x80) == -1 || ibuf_add_zero(tmp, 2) == -1) goto fail; } else { if (ibuf_add(tmp, &pvpn6->labelstack, pvpn6->labellen) == -1) goto fail; } if (ibuf_add(tmp, &pvpn6->rd, sizeof(pvpn6->rd)) == -1 || ibuf_add(tmp, &pvpn6->prefix6, psize) == -1) goto fail; break; case AID_EVPN: if (ibuf_add_n8(tmp, pevpn->type) == -1) goto fail; switch (pevpn->type) { case EVPN_ROUTE_TYPE_2: plen = sizeof(pevpn->rd) * 8; plen += sizeof(pevpn->esi) * 8; plen += sizeof(pevpn->ethtag) * 8; plen += 8; /* MAC length */ plen += sizeof(pevpn->mac) * 8; plen += 8; /* IP length */ plen += pevpn->prefixlen; plen += pevpn->labellen * 8; if (ibuf_add_n8(tmp, PREFIX_SIZE(plen) - 1) == -1) goto fail; if (ibuf_add_h64(tmp, pevpn->rd) == -1 || ibuf_add(tmp, pevpn->esi, sizeof(pevpn->esi)) == -1 || ibuf_add_h32(tmp, pevpn->ethtag) == -1) goto fail; if (ibuf_add_n8(tmp, sizeof(pevpn->mac) * 8) == -1 || ibuf_add(tmp, pevpn->mac, sizeof(pevpn->mac)) == -1) goto fail; if (ibuf_add_n8(tmp, pevpn->prefixlen) == -1) goto fail; switch(pevpn->vpnaid) { case AID_UNSPEC: /* See rfc7432 section 7.2 */ break; case AID_INET: if (ibuf_add(tmp, &pevpn->prefix4, sizeof(pevpn->prefix4)) == -1) goto fail; break; case AID_INET6: if (ibuf_add(tmp, &pevpn->prefix6, sizeof(pevpn->prefix6)) == -1) goto fail; break; default: goto fail; } if (ibuf_add(tmp, pevpn->labelstack, pevpn->labellen) == -1) goto fail; break; case EVPN_ROUTE_TYPE_3: plen = sizeof(pevpn->rd) * 8; plen += sizeof(pevpn->ethtag) * 8; plen += 8; /* IP length */ plen += pevpn->prefixlen; if (ibuf_add_n8(tmp, PREFIX_SIZE(plen) - 1) == -1) goto fail; if (ibuf_add_h64(tmp, pevpn->rd) == -1 || ibuf_add_h32(tmp, pevpn->ethtag) == -1) goto fail; if (ibuf_add_n8(tmp, pevpn->prefixlen) == -1) goto fail; switch(pevpn->vpnaid) { case AID_INET: if (ibuf_add(tmp, &pevpn->prefix4, sizeof(pevpn->prefix4)) == -1) goto fail; break; case AID_INET6: if (ibuf_add(tmp, &pevpn->prefix6, sizeof(pevpn->prefix6)) == -1) goto fail; break; default: goto fail; } } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: flowlen = pflow->len - PT_FLOW_SIZE; if (flowlen < FLOWSPEC_LEN_LIMIT) { if (ibuf_add_n8(tmp, flowlen) == -1) goto fail; } else { if (ibuf_add_n8(tmp, 0xf0 | (flowlen >> 8)) == -1 || ibuf_add_n8(tmp, flowlen) == -1) goto fail; } if (ibuf_add(tmp, &pflow->flow, flowlen) == -1) goto fail; break; default: fatalx("%s: unknown aid %d", __func__, pte->aid); } /* keep 2 bytes reserved in the withdraw case for IPv4 encoding */ if (withdraw && ibuf_left(buf) < ibuf_size(tmp) + 2) goto fail; if (ibuf_add_ibuf(buf, tmp) == -1) goto fail; ibuf_free(tmp); return 0; fail: ibuf_free(tmp); return -1; } openbgpd-8.8/src/bgpd/mrt.c100644 001750 001750 00000072474 14751151130 0011356/* $OpenBSD: mrt.c,v 1.124 2025/01/31 20:07:18 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "session.h" #include "mrt.h" #include "log.h" static int mrt_attr_dump(struct ibuf *, struct rde_aspath *, struct rde_community *, struct bgpd_addr *, int); static int mrt_dump_entry_mp(struct mrt *, struct prefix *, uint16_t, struct rde_peer*); static int mrt_dump_entry(struct mrt *, struct prefix *, uint16_t, struct rde_peer*); static int mrt_dump_entry_v2(struct mrt *, struct rib_entry *, uint32_t); static int mrt_dump_peer(struct ibuf *, struct rde_peer *); static int mrt_dump_hdr_se(struct ibuf **, struct peer *, uint16_t, uint16_t, uint32_t, int); static int mrt_dump_hdr_rde(struct ibuf **, uint16_t type, uint16_t, uint32_t); static int mrt_open(struct mrt *, time_t); #define RDEIDX 0 #define SEIDX 1 #define TYPE2IDX(x) ((x == MRT_TABLE_DUMP || \ x == MRT_TABLE_DUMP_MP || \ x == MRT_TABLE_DUMP_V2) ? RDEIDX : SEIDX \ ) static uint8_t mrt_update_msg_guess_aid(struct ibuf *pkg) { struct ibuf buf; uint16_t wlen, alen, len, afi; uint8_t type, flags, aid, safi; ibuf_from_ibuf(&buf, pkg); if (ibuf_skip(&buf, MSGSIZE_HEADER) == -1 || ibuf_get_n16(&buf, &wlen) == -1) goto bad; if (wlen > 0) { /* UPDATE has withdraw routes, therefore IPv4 */ return AID_INET; } if (ibuf_get_n16(&buf, &alen) == -1) goto bad; if (alen < ibuf_size(&buf)) { /* UPDATE has NLRI prefixes, therefore IPv4 */ return AID_INET; } if (wlen == 0 && alen == 0) { /* UPDATE is an IPv4 EoR marker */ return AID_INET; } /* bad attribute length */ if (alen > ibuf_size(&buf)) goto bad; /* try to extract AFI/SAFI from the MP attributes */ while (ibuf_size(&buf) > 0) { if (ibuf_get_n8(&buf, &flags) == -1 || ibuf_get_n8(&buf, &type) == -1) goto bad; if (flags & ATTR_EXTLEN) { if (ibuf_get_n16(&buf, &len) == -1) goto bad; } else { uint8_t tmp; if (ibuf_get_n8(&buf, &tmp) == -1) goto bad; len = tmp; } if (len > ibuf_size(&buf)) goto bad; if (type == ATTR_MP_REACH_NLRI || type == ATTR_MP_UNREACH_NLRI) { if (ibuf_get_n16(&buf, &afi) == -1 || ibuf_get_n8(&buf, &safi) == -1) goto bad; if (afi2aid(afi, safi, &aid) == -1) goto bad; return aid; } if (ibuf_skip(&buf, len) == -1) goto bad; } bad: return AID_UNSPEC; } static uint16_t mrt_bgp_msg_subtype(struct mrt *mrt, struct ibuf *pkg, struct peer *peer, enum msg_type msgtype, int in) { uint16_t subtype = BGP4MP_MESSAGE; uint8_t aid, mask; if (peer->capa.neg.as4byte) subtype = BGP4MP_MESSAGE_AS4; if (msgtype != BGP_UPDATE) return subtype; /* * RFC8050 adjust types for add-path enabled sessions. * It is necessary to extract the AID from UPDATES to decide * if the add-path types are needed or not. The ADDPATH * subtypes only matter for BGP UPDATES. */ mask = in ? CAPA_AP_RECV : CAPA_AP_SEND; /* only guess if add-path could be active */ if (peer->capa.neg.add_path[0] & mask) { aid = mrt_update_msg_guess_aid(pkg); if (aid != AID_UNSPEC && (peer->capa.neg.add_path[aid] & mask)) { if (peer->capa.neg.as4byte) subtype = BGP4MP_MESSAGE_AS4_ADDPATH; else subtype = BGP4MP_MESSAGE_ADDPATH; } } return subtype; } void mrt_dump_bgp_msg(struct mrt *mrt, struct ibuf *pkg, struct peer *peer, enum msg_type msgtype) { struct ibuf *buf; int in = 0; uint16_t subtype = BGP4MP_MESSAGE; /* get the direction of the message to swap address and AS fields */ if (mrt->type == MRT_ALL_IN || mrt->type == MRT_UPDATE_IN) in = 1; subtype = mrt_bgp_msg_subtype(mrt, pkg, peer, msgtype, in); if (mrt_dump_hdr_se(&buf, peer, MSG_PROTOCOL_BGP4MP_ET, subtype, ibuf_size(pkg), in) == -1) goto fail; if (ibuf_add_ibuf(buf, pkg) == -1) goto fail; ibuf_close(mrt->wbuf, buf); return; fail: log_warn("%s: ibuf error", __func__); ibuf_free(buf); } void mrt_dump_state(struct mrt *mrt, uint16_t old_state, uint16_t new_state, struct peer *peer) { struct ibuf *buf; uint16_t subtype = BGP4MP_STATE_CHANGE; if (peer->capa.neg.as4byte) subtype = BGP4MP_STATE_CHANGE_AS4; if (mrt_dump_hdr_se(&buf, peer, MSG_PROTOCOL_BGP4MP_ET, subtype, 2 * sizeof(short), 0) == -1) goto fail; if (ibuf_add_n16(buf, old_state) == -1) goto fail; if (ibuf_add_n16(buf, new_state) == -1) goto fail; ibuf_close(mrt->wbuf, buf); return; fail: log_warn("%s: ibuf error", __func__); ibuf_free(buf); } static int mrt_attr_dump(struct ibuf *buf, struct rde_aspath *a, struct rde_community *c, struct bgpd_addr *nexthop, int v2) { struct attr *oa; u_char *pdata; uint32_t tmp; int neednewpath = 0; uint16_t plen, afi; uint8_t l, safi; /* origin */ if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_ORIGIN, &a->origin, 1) == -1) return (-1); /* aspath */ plen = aspath_length(a->aspath); pdata = aspath_dump(a->aspath); if (!v2) pdata = aspath_deflate(pdata, &plen, &neednewpath); if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_ASPATH, pdata, plen) == -1) { if (!v2) free(pdata); return (-1); } if (!v2) free(pdata); if (nexthop && nexthop->aid == AID_INET) { /* nexthop, already network byte order */ if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_NEXTHOP, &nexthop->v4.s_addr, 4) == -1) return (-1); } /* MED, non transitive */ if (a->med != 0) { tmp = htonl(a->med); if (attr_writebuf(buf, ATTR_OPTIONAL, ATTR_MED, &tmp, 4) == -1) return (-1); } /* local preference */ tmp = htonl(a->lpref); if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_LOCALPREF, &tmp, 4) == -1) return (-1); /* communities */ if (community_writebuf(c, ATTR_COMMUNITIES, 0, buf) == -1 || community_writebuf(c, ATTR_EXT_COMMUNITIES, 0, buf) == -1 || community_writebuf(c, ATTR_LARGE_COMMUNITIES, 0, buf) == -1) return (-1); /* dump all other path attributes without modification */ for (l = 0; l < a->others_len; l++) { if ((oa = a->others[l]) == NULL) break; if (attr_writebuf(buf, oa->flags, oa->type, oa->data, oa->len) == -1) return (-1); } if (nexthop && nexthop->aid != AID_INET) { struct ibuf *nhbuf; if ((nhbuf = ibuf_dynamic(0, UCHAR_MAX)) == NULL) return (-1); if (!v2) { if (aid2afi(nexthop->aid, &afi, &safi)) goto fail; if (ibuf_add_n16(nhbuf, afi) == -1) goto fail; if (ibuf_add_n8(nhbuf, safi) == -1) goto fail; } switch (nexthop->aid) { case AID_INET6: if (ibuf_add_n8(nhbuf, sizeof(struct in6_addr)) == -1) goto fail; if (ibuf_add(nhbuf, &nexthop->v6, sizeof(struct in6_addr)) == -1) goto fail; break; case AID_VPN_IPv4: if (ibuf_add_n8(nhbuf, sizeof(uint64_t) + sizeof(struct in_addr)) == -1) goto fail; if (ibuf_add_n64(nhbuf, 0) == -1) /* set RD to 0 */ goto fail; if (ibuf_add(nhbuf, &nexthop->v4, sizeof(nexthop->v4)) == -1) goto fail; break; case AID_VPN_IPv6: if (ibuf_add_n8(nhbuf, sizeof(uint64_t) + sizeof(struct in6_addr)) == -1) goto fail; if (ibuf_add_n64(nhbuf, 0) == -1) /* set RD to 0 */ goto fail; if (ibuf_add(nhbuf, &nexthop->v6, sizeof(nexthop->v6)) == -1) goto fail; break; } if (!v2) if (ibuf_add_n8(nhbuf, 0) == -1) goto fail; if (attr_writebuf(buf, ATTR_OPTIONAL, ATTR_MP_REACH_NLRI, ibuf_data(nhbuf), ibuf_size(nhbuf)) == -1) { fail: ibuf_free(nhbuf); return (-1); } ibuf_free(nhbuf); } if (neednewpath) { pdata = aspath_prepend(a->aspath, rde_local_as(), 0, &plen); if (plen != 0) if (attr_writebuf(buf, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_AS4_PATH, pdata, plen) == -1) { free(pdata); return (-1); } free(pdata); } return (0); } static int mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, uint16_t snum, struct rde_peer *peer) { struct ibuf *buf, *hbuf = NULL, *h2buf = NULL; struct nexthop *n; struct bgpd_addr nexthop, *nh; uint16_t len; uint8_t aid; if ((buf = ibuf_dynamic(0, MAX_PKTSIZE)) == NULL) { log_warn("mrt_dump_entry_mp: ibuf_dynamic"); return (-1); } if (mrt_attr_dump(buf, prefix_aspath(p), prefix_communities(p), NULL, 0) == -1) goto fail; len = ibuf_size(buf); if ((h2buf = ibuf_dynamic(MRT_BGP4MP_IPv4_HEADER_SIZE + MRT_BGP4MP_IPv4_ENTRY_SIZE, MRT_BGP4MP_IPv6_HEADER_SIZE + MRT_BGP4MP_IPv6_ENTRY_SIZE + MRT_BGP4MP_MAX_PREFIXLEN)) == NULL) goto fail; if (ibuf_add_n16(h2buf, peer->conf.local_short_as) == -1) goto fail; if (ibuf_add_n16(h2buf, peer->short_as) == -1) goto fail; if (ibuf_add_n16(h2buf, /* ifindex */ 0) == -1) goto fail; /* XXX is this for peer self? */ aid = peer->remote_addr.aid == AID_UNSPEC ? p->pt->aid : peer->remote_addr.aid; switch (aid) { case AID_INET: case AID_VPN_IPv4: if (ibuf_add_n16(h2buf, AFI_IPv4) == -1) goto fail; if (ibuf_add(h2buf, &peer->local_v4_addr.v4, sizeof(peer->local_v4_addr.v4)) == -1 || ibuf_add(h2buf, &peer->remote_addr.v4, sizeof(peer->remote_addr.v4)) == -1) goto fail; break; case AID_INET6: case AID_VPN_IPv6: if (ibuf_add_n16(h2buf, AFI_IPv6) == -1) goto fail; if (ibuf_add(h2buf, &peer->local_v6_addr.v6, sizeof(peer->local_v6_addr.v6)) == -1 || ibuf_add(h2buf, &peer->remote_addr.v6, sizeof(peer->remote_addr.v6)) == -1) goto fail; break; default: log_warnx("king bula found new AF %d in %s", aid, __func__); goto fail; } if (ibuf_add_n16(h2buf, 0) == -1) /* view */ goto fail; if (ibuf_add_n16(h2buf, 1) == -1) /* status */ goto fail; /* originated timestamp */ if (ibuf_add_n32(h2buf, time(NULL) - (getmonotime() - p->lastchange)) == -1) goto fail; n = prefix_nexthop(p); if (n == NULL) { memset(&nexthop, 0, sizeof(struct bgpd_addr)); nexthop.aid = p->pt->aid; nh = &nexthop; } else nh = &n->exit_nexthop; switch (p->pt->aid) { case AID_INET: if (ibuf_add_n16(h2buf, AFI_IPv4) == -1) /* afi */ goto fail; if (ibuf_add_n8(h2buf, SAFI_UNICAST) == -1) /* safi */ goto fail; if (ibuf_add_n8(h2buf, 4) == -1) /* nhlen */ goto fail; if (ibuf_add(h2buf, &nh->v4, sizeof(nh->v4)) == -1) goto fail; break; case AID_INET6: if (ibuf_add_n16(h2buf, AFI_IPv6) == -1) /* afi */ goto fail; if (ibuf_add_n8(h2buf, SAFI_UNICAST) == -1) /* safi */ goto fail; if (ibuf_add_n8(h2buf, 16) == -1) /* nhlen */ goto fail; if (ibuf_add(h2buf, &nh->v6, sizeof(nh->v6)) == -1) goto fail; break; case AID_VPN_IPv4: if (ibuf_add_n16(h2buf, AFI_IPv4) == -1) /* afi */ goto fail; if (ibuf_add_n8(h2buf, SAFI_MPLSVPN) == -1) /* safi */ goto fail; if (ibuf_add_n8(h2buf, sizeof(uint64_t) + sizeof(struct in_addr)) == -1) goto fail; if (ibuf_add_n64(h2buf, 0) == -1) /* set RD to 0 */ goto fail; if (ibuf_add(h2buf, &nh->v4, sizeof(nh->v4)) == -1) goto fail; break; case AID_VPN_IPv6: if (ibuf_add_n16(h2buf, AFI_IPv6) == -1) /* afi */ goto fail; if (ibuf_add_n8(h2buf, SAFI_MPLSVPN) == -1) /* safi */ goto fail; if (ibuf_add_n8(h2buf, sizeof(uint64_t) + sizeof(struct in6_addr)) == -1) goto fail; if (ibuf_add_n64(h2buf, 0) == -1) /* set RD to 0 */ goto fail; if (ibuf_add(h2buf, &nh->v6, sizeof(nh->v6)) == -1) goto fail; break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: if (p->pt->aid == AID_FLOWSPECv4) { if (ibuf_add_n16(h2buf, AFI_IPv4) == -1) /* afi */ goto fail; } else { if (ibuf_add_n16(h2buf, AFI_IPv6) == -1) /* afi */ goto fail; } if (ibuf_add_n8(h2buf, SAFI_FLOWSPEC) == -1) /* safi */ goto fail; if (ibuf_add_n8(h2buf, 0) == -1) /* nhlen */ goto fail; break; default: log_warnx("king bula found new AF in %s", __func__); goto fail; } if (pt_writebuf(h2buf, p->pt, 0, 0, 0) == -1) goto fail; if (ibuf_add_n16(h2buf, len) == -1) goto fail; len += ibuf_size(h2buf); if (mrt_dump_hdr_rde(&hbuf, MSG_PROTOCOL_BGP4MP, BGP4MP_ENTRY, len) == -1) goto fail; ibuf_close(mrt->wbuf, hbuf); ibuf_close(mrt->wbuf, h2buf); ibuf_close(mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); fail: log_warn("%s: ibuf error", __func__); ibuf_free(hbuf); ibuf_free(h2buf); ibuf_free(buf); return (-1); } static int mrt_dump_entry(struct mrt *mrt, struct prefix *p, uint16_t snum, struct rde_peer *peer) { struct ibuf *buf, *hbuf = NULL; struct nexthop *nexthop; struct bgpd_addr addr, *nh; size_t len; uint16_t subtype; uint8_t dummy; if (p->pt->aid != peer->remote_addr.aid && p->pt->aid != AID_INET && p->pt->aid != AID_INET6) /* only able to dump pure IPv4/IPv6 */ return (0); if ((buf = ibuf_dynamic(0, MAX_PKTSIZE)) == NULL) { log_warn("mrt_dump_entry: ibuf_dynamic"); return (-1); } nexthop = prefix_nexthop(p); if (nexthop == NULL) { memset(&addr, 0, sizeof(struct bgpd_addr)); addr.aid = p->pt->aid; nh = &addr; } else nh = &nexthop->exit_nexthop; if (mrt_attr_dump(buf, prefix_aspath(p), prefix_communities(p), nh, 0) == -1) goto fail; len = ibuf_size(buf); aid2afi(p->pt->aid, &subtype, &dummy); if (mrt_dump_hdr_rde(&hbuf, MSG_TABLE_DUMP, subtype, len) == -1) goto fail; if (ibuf_add_n16(hbuf, 0) == -1) goto fail; if (ibuf_add_n16(hbuf, snum) == -1) goto fail; pt_getaddr(p->pt, &addr); switch (p->pt->aid) { case AID_INET: if (ibuf_add(hbuf, &addr.v4, sizeof(addr.v4)) == -1) goto fail; break; case AID_INET6: if (ibuf_add(hbuf, &addr.v6, sizeof(addr.v6)) == -1) goto fail; break; } if (ibuf_add_n8(hbuf, p->pt->prefixlen) == -1) goto fail; if (ibuf_add_n8(hbuf, 1) == -1) /* state */ goto fail; /* originated timestamp */ if (ibuf_add_n32(hbuf, time(NULL) - (getmonotime() - p->lastchange)) == -1) goto fail; switch (p->pt->aid) { case AID_INET: if (ibuf_add(hbuf, &peer->remote_addr.v4, sizeof(peer->remote_addr.v4)) == -1) goto fail; break; case AID_INET6: if (ibuf_add(hbuf, &peer->remote_addr.v6, sizeof(peer->remote_addr.v6)) == -1) goto fail; break; } if (ibuf_add_n16(hbuf, peer->short_as) == -1) goto fail; if (ibuf_add_n16(hbuf, len) == -1) goto fail; ibuf_close(mrt->wbuf, hbuf); ibuf_close(mrt->wbuf, buf); return (len + MRT_HEADER_SIZE); fail: log_warn("%s: ibuf error", __func__); ibuf_free(hbuf); ibuf_free(buf); return (-1); } static int mrt_dump_entry_v2_rib(struct rib_entry *re, struct ibuf **nb, struct ibuf **apb, uint16_t *np, uint16_t *app) { struct bgpd_addr addr; struct ibuf *buf = NULL, **bp; struct ibuf *tbuf = NULL; struct prefix *p; int addpath; *np = 0; *app = 0; TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) { struct nexthop *nexthop; struct bgpd_addr *nh; addpath = peer_has_add_path(prefix_peer(p), re->prefix->aid, CAPA_AP_RECV); if (addpath) { bp = apb; *app += 1; } else { bp = nb; *np += 1; } if ((buf = *bp) == NULL) { if ((buf = ibuf_dynamic(0, UINT_MAX)) == NULL) goto fail; *bp = buf; } nexthop = prefix_nexthop(p); if (nexthop == NULL) { memset(&addr, 0, sizeof(struct bgpd_addr)); addr.aid = re->prefix->aid; nh = &addr; } else nh = &nexthop->exit_nexthop; if (ibuf_add_n16(buf, prefix_peer(p)->mrt_idx) == -1) goto fail; /* originated timestamp */ if (ibuf_add_n32(buf, time(NULL) - (getmonotime() - p->lastchange)) == -1) goto fail; /* RFC8050: path-id if add-path is used */ if (addpath) if (ibuf_add_n32(buf, p->path_id) == -1) goto fail; if ((tbuf = ibuf_dynamic(0, MAX_PKTSIZE)) == NULL) goto fail; if (mrt_attr_dump(tbuf, prefix_aspath(p), prefix_communities(p), nh, 1) == -1) goto fail; if (ibuf_add_n16(buf, ibuf_size(tbuf)) == -1) goto fail; if (ibuf_add_ibuf(buf, tbuf) == -1) goto fail; ibuf_free(tbuf); tbuf = NULL; } return 0; fail: ibuf_free(tbuf); return -1; } static int mrt_dump_entry_v2(struct mrt *mrt, struct rib_entry *re, uint32_t snum) { struct ibuf *hbuf = NULL, *nbuf = NULL, *apbuf = NULL, *pbuf; size_t hlen, len; uint16_t subtype, apsubtype, nump, apnump, afi; uint8_t safi; if ((pbuf = ibuf_dynamic(0, UINT_MAX)) == NULL) { log_warn("%s: ibuf_dynamic", __func__); return -1; } switch (re->prefix->aid) { case AID_INET: subtype = MRT_DUMP_V2_RIB_IPV4_UNICAST; apsubtype = MRT_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH; break; case AID_INET6: subtype = MRT_DUMP_V2_RIB_IPV6_UNICAST; apsubtype = MRT_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH; break; default: /* * XXX The RFC defined the format for this type differently * and it is prohibitly expensive to implement that format. * Instead do what gobgp does and encode it like the other * types. */ subtype = MRT_DUMP_V2_RIB_GENERIC; apsubtype = MRT_DUMP_V2_RIB_GENERIC_ADDPATH; aid2afi(re->prefix->aid, &afi, &safi); /* first add 3-bytes AFI/SAFI */ if (ibuf_add_n16(pbuf, afi) == -1) goto fail; if (ibuf_add_n8(pbuf, safi) == -1) goto fail; break; } if (pt_writebuf(pbuf, re->prefix, 0, 0, 0) == -1) goto fail; hlen = sizeof(snum) + sizeof(nump) + ibuf_size(pbuf); if (mrt_dump_entry_v2_rib(re, &nbuf, &apbuf, &nump, &apnump)) goto fail; if (nump > 0) { len = ibuf_size(nbuf) + hlen; if (mrt_dump_hdr_rde(&hbuf, MSG_TABLE_DUMP_V2, subtype, len) == -1) goto fail; if (ibuf_add_n32(hbuf, snum) == -1) goto fail; if (ibuf_add_ibuf(hbuf, pbuf) == -1) goto fail; if (ibuf_add_n16(hbuf, nump) == -1) goto fail; ibuf_close(mrt->wbuf, hbuf); ibuf_close(mrt->wbuf, nbuf); hbuf = NULL; nbuf = NULL; } if (apnump > 0) { len = ibuf_size(apbuf) + hlen; if (mrt_dump_hdr_rde(&hbuf, MSG_TABLE_DUMP_V2, apsubtype, len) == -1) goto fail; if (ibuf_add_n32(hbuf, snum) == -1) goto fail; if (ibuf_add_ibuf(hbuf, pbuf) == -1) goto fail; if (ibuf_add_n16(hbuf, apnump) == -1) goto fail; ibuf_close(mrt->wbuf, hbuf); ibuf_close(mrt->wbuf, apbuf); hbuf = NULL; apbuf = NULL; } ibuf_free(pbuf); return (0); fail: log_warn("%s: ibuf error", __func__); ibuf_free(apbuf); ibuf_free(nbuf); ibuf_free(hbuf); ibuf_free(pbuf); return (-1); } struct cb_arg { struct ibuf *buf; int nump; }; static void mrt_dump_v2_hdr_peer(struct rde_peer *peer, void *arg) { struct cb_arg *a = arg; if (a->nump == -1) return; peer->mrt_idx = a->nump; if (mrt_dump_peer(a->buf, peer) == -1) { a->nump = -1; return; } a->nump++; } int mrt_dump_v2_hdr(struct mrt *mrt, struct bgpd_config *conf) { struct ibuf *buf, *hbuf = NULL; size_t len, off; uint16_t nlen, nump; struct cb_arg arg; if ((buf = ibuf_dynamic(0, UINT_MAX)) == NULL) { log_warn("%s: ibuf_dynamic", __func__); return (-1); } if (ibuf_add_n32(buf, conf->bgpid) == -1) goto fail; nlen = strlen(mrt->rib); if (nlen > 0) nlen += 1; if (ibuf_add_n16(buf, nlen) == -1) goto fail; if (ibuf_add(buf, mrt->rib, nlen) == -1) goto fail; off = ibuf_size(buf); if (ibuf_add_zero(buf, sizeof(nump)) == -1) goto fail; arg.nump = 0; arg.buf = buf; peer_foreach(mrt_dump_v2_hdr_peer, &arg); if (arg.nump == -1) goto fail; if (ibuf_set_n16(buf, off, arg.nump) == -1) goto fail; len = ibuf_size(buf); if (mrt_dump_hdr_rde(&hbuf, MSG_TABLE_DUMP_V2, MRT_DUMP_V2_PEER_INDEX_TABLE, len) == -1) goto fail; ibuf_close(mrt->wbuf, hbuf); ibuf_close(mrt->wbuf, buf); return (0); fail: log_warn("%s: ibuf error", __func__); ibuf_free(hbuf); ibuf_free(buf); return (-1); } static int mrt_dump_peer(struct ibuf *buf, struct rde_peer *peer) { uint8_t type = 0; if (peer->capa.as4byte) type |= MRT_DUMP_V2_PEER_BIT_A; if (peer->remote_addr.aid == AID_INET6) type |= MRT_DUMP_V2_PEER_BIT_I; if (ibuf_add_n8(buf, type) == -1) goto fail; if (ibuf_add_n32(buf, peer->remote_bgpid) == -1) goto fail; switch (peer->remote_addr.aid) { case AID_INET: if (ibuf_add(buf, &peer->remote_addr.v4, sizeof(peer->remote_addr.v4)) == -1) goto fail; break; case AID_INET6: if (ibuf_add(buf, &peer->remote_addr.v6, sizeof(peer->remote_addr.v6)) == -1) goto fail; break; case AID_UNSPEC: /* XXX special handling for peerself? */ if (ibuf_add_n32(buf, 0) == -1) goto fail; break; default: log_warnx("king bula found new AF in %s", __func__); goto fail; } if (peer->capa.as4byte) { if (ibuf_add_n32(buf, peer->conf.remote_as) == -1) goto fail; } else { if (ibuf_add_n16(buf, peer->short_as) == -1) goto fail; } return (0); fail: log_warn("%s: ibuf error", __func__); return (-1); } void mrt_dump_upcall(struct rib_entry *re, void *ptr) { struct mrt *mrtbuf = ptr; struct prefix *p; if (mrtbuf->type == MRT_TABLE_DUMP_V2) { mrt_dump_entry_v2(mrtbuf, re, mrtbuf->seqnum++); return; } /* * dump all prefixes even the inactive ones. That is the way zebra * dumps the table so we do the same. If only the active route should * be dumped p should be set to p = pt->active. */ TAILQ_FOREACH(p, &re->prefix_h, entry.list.rib) { if (mrtbuf->type == MRT_TABLE_DUMP) mrt_dump_entry(mrtbuf, p, mrtbuf->seqnum++, prefix_peer(p)); else mrt_dump_entry_mp(mrtbuf, p, mrtbuf->seqnum++, prefix_peer(p)); } } void mrt_done(struct mrt *mrtbuf) { mrtbuf->state = MRT_STATE_REMOVE; } static int mrt_dump_hdr_se(struct ibuf ** bp, struct peer *peer, uint16_t type, uint16_t subtype, uint32_t len, int swap) { struct timespec time; if ((*bp = ibuf_dynamic(MRT_ET_HEADER_SIZE, MRT_ET_HEADER_SIZE + MRT_BGP4MP_AS4_IPv6_HEADER_SIZE + len)) == NULL) return (-1); clock_gettime(CLOCK_REALTIME, &time); if (ibuf_add_n32(*bp, time.tv_sec) == -1) goto fail; if (ibuf_add_n16(*bp, type) == -1) goto fail; if (ibuf_add_n16(*bp, subtype) == -1) goto fail; switch (peer->local.aid) { case AID_INET: if (subtype == BGP4MP_STATE_CHANGE_AS4 || subtype == BGP4MP_MESSAGE_AS4 || subtype == BGP4MP_MESSAGE_AS4_ADDPATH) len += MRT_BGP4MP_ET_AS4_IPv4_HEADER_SIZE; else len += MRT_BGP4MP_ET_IPv4_HEADER_SIZE; break; case AID_INET6: if (subtype == BGP4MP_STATE_CHANGE_AS4 || subtype == BGP4MP_MESSAGE_AS4 || subtype == BGP4MP_MESSAGE_AS4_ADDPATH) len += MRT_BGP4MP_ET_AS4_IPv6_HEADER_SIZE; else len += MRT_BGP4MP_ET_IPv6_HEADER_SIZE; break; case 0: goto fail; default: log_warnx("king bula found new AF in %s", __func__); goto fail; } if (ibuf_add_n32(*bp, len) == -1) goto fail; /* millisecond field use by the _ET format */ if (ibuf_add_n32(*bp, time.tv_nsec / 1000) == -1) goto fail; if (subtype == BGP4MP_STATE_CHANGE_AS4 || subtype == BGP4MP_MESSAGE_AS4 || subtype == BGP4MP_MESSAGE_AS4_ADDPATH) { if (!swap) if (ibuf_add_n32(*bp, peer->conf.local_as) == -1) goto fail; if (ibuf_add_n32(*bp, peer->conf.remote_as) == -1) goto fail; if (swap) if (ibuf_add_n32(*bp, peer->conf.local_as) == -1) goto fail; } else { if (!swap) if (ibuf_add_n16(*bp, peer->conf.local_short_as) == -1) goto fail; if (ibuf_add_n16(*bp, peer->short_as) == -1) goto fail; if (swap) if (ibuf_add_n16(*bp, peer->conf.local_short_as) == -1) goto fail; } if (ibuf_add_n16(*bp, /* ifindex */ 0) == -1) goto fail; switch (peer->local.aid) { case AID_INET: if (ibuf_add_n16(*bp, AFI_IPv4) == -1) goto fail; if (!swap) if (ibuf_add(*bp, &peer->local.v4, sizeof(peer->local.v4)) == -1) goto fail; if (ibuf_add(*bp, &peer->remote.v4, sizeof(peer->remote.v4)) == -1) goto fail; if (swap) if (ibuf_add(*bp, &peer->local.v4, sizeof(peer->local.v4)) == -1) goto fail; break; case AID_INET6: if (ibuf_add_n16(*bp, AFI_IPv6) == -1) goto fail; if (!swap) if (ibuf_add(*bp, &peer->local.v6, sizeof(peer->local.v6)) == -1) goto fail; if (ibuf_add(*bp, &peer->remote.v6, sizeof(peer->remote.v6)) == -1) goto fail; if (swap) if (ibuf_add(*bp, &peer->local.v6, sizeof(peer->local.v6)) == -1) goto fail; break; } return (0); fail: ibuf_free(*bp); *bp = NULL; return (-1); } int mrt_dump_hdr_rde(struct ibuf **bp, uint16_t type, uint16_t subtype, uint32_t len) { struct timespec time; if ((*bp = ibuf_dynamic(MRT_HEADER_SIZE, MRT_HEADER_SIZE + MRT_BGP4MP_AS4_IPv6_HEADER_SIZE + MRT_BGP4MP_IPv6_ENTRY_SIZE)) == NULL) return (-1); clock_gettime(CLOCK_REALTIME, &time); if (ibuf_add_n32(*bp, time.tv_sec) == -1) goto fail; if (ibuf_add_n16(*bp, type) == -1) goto fail; if (ibuf_add_n16(*bp, subtype) == -1) goto fail; switch (type) { case MSG_TABLE_DUMP: switch (subtype) { case AFI_IPv4: len += MRT_DUMP_HEADER_SIZE; break; case AFI_IPv6: len += MRT_DUMP_HEADER_SIZE_V6; break; } if (ibuf_add_n32(*bp, len) == -1) goto fail; break; case MSG_PROTOCOL_BGP4MP: case MSG_TABLE_DUMP_V2: if (ibuf_add_n32(*bp, len) == -1) goto fail; break; default: log_warnx("mrt_dump_hdr_rde: unsupported type"); goto fail; } return (0); fail: ibuf_free(*bp); *bp = NULL; return (-1); } void mrt_write(struct mrt *mrt) { if (ibuf_write(mrt->fd, mrt->wbuf) == -1) { log_warn("mrt dump aborted, mrt_write"); mrt_clean(mrt); mrt_done(mrt); } } void mrt_clean(struct mrt *mrt) { close(mrt->fd); msgbuf_free(mrt->wbuf); mrt->wbuf = NULL; } static struct imsgbuf *mrt_imsgbuf[2]; void mrt_init(struct imsgbuf *rde, struct imsgbuf *se) { mrt_imsgbuf[RDEIDX] = rde; mrt_imsgbuf[SEIDX] = se; } int mrt_open(struct mrt *mrt, time_t now) { enum imsg_type type; int fd; if (strftime(MRT2MC(mrt)->file, sizeof(MRT2MC(mrt)->file), MRT2MC(mrt)->name, localtime(&now)) == 0) { log_warnx("mrt_open: strftime conversion failed"); return (-1); } fd = open(MRT2MC(mrt)->file, O_WRONLY|O_NONBLOCK|O_CREAT|O_TRUNC|O_CLOEXEC, 0644); if (fd == -1) { log_warn("mrt_open %s", MRT2MC(mrt)->file); return (1); } if (mrt->state == MRT_STATE_OPEN) type = IMSG_MRT_OPEN; else type = IMSG_MRT_REOPEN; if (imsg_compose(mrt_imsgbuf[TYPE2IDX(mrt->type)], type, 0, 0, fd, mrt, sizeof(struct mrt)) == -1) log_warn("mrt_open"); return (1); } time_t mrt_timeout(struct mrt_head *mrt) { struct mrt *m; time_t now; time_t timeout = -1; now = time(NULL); LIST_FOREACH(m, mrt, entry) { if (m->state == MRT_STATE_RUNNING && MRT2MC(m)->ReopenTimerInterval != 0) { if (MRT2MC(m)->ReopenTimer <= now) { mrt_open(m, now); MRT2MC(m)->ReopenTimer = now + MRT2MC(m)->ReopenTimerInterval; } if (timeout == -1 || MRT2MC(m)->ReopenTimer - now < timeout) timeout = MRT2MC(m)->ReopenTimer - now; } } return (timeout); } void mrt_reconfigure(struct mrt_head *mrt) { struct mrt *m, *xm; time_t now; now = time(NULL); for (m = LIST_FIRST(mrt); m != NULL; m = xm) { xm = LIST_NEXT(m, entry); if (m->state == MRT_STATE_OPEN || m->state == MRT_STATE_REOPEN) { if (mrt_open(m, now) == -1) continue; if (MRT2MC(m)->ReopenTimerInterval != 0) MRT2MC(m)->ReopenTimer = now + MRT2MC(m)->ReopenTimerInterval; m->state = MRT_STATE_RUNNING; } if (m->state == MRT_STATE_REMOVE) { if (imsg_compose(mrt_imsgbuf[TYPE2IDX(m->type)], IMSG_MRT_CLOSE, 0, 0, -1, m, sizeof(struct mrt)) == -1) log_warn("mrt_reconfigure"); LIST_REMOVE(m, entry); free(m); continue; } } } void mrt_handler(struct mrt_head *mrt) { struct mrt *m; time_t now; now = time(NULL); LIST_FOREACH(m, mrt, entry) { if (m->state == MRT_STATE_RUNNING && (MRT2MC(m)->ReopenTimerInterval != 0 || m->type == MRT_TABLE_DUMP || m->type == MRT_TABLE_DUMP_MP || m->type == MRT_TABLE_DUMP_V2)) { if (mrt_open(m, now) == -1) continue; MRT2MC(m)->ReopenTimer = now + MRT2MC(m)->ReopenTimerInterval; } } } struct mrt * mrt_get(struct mrt_head *c, struct mrt *m) { struct mrt *t; LIST_FOREACH(t, c, entry) { if (t->type != m->type) continue; if (strcmp(t->rib, m->rib)) continue; if (t->peer_id == m->peer_id && t->group_id == m->group_id) return (t); } return (NULL); } void mrt_mergeconfig(struct mrt_head *xconf, struct mrt_head *nconf) { struct mrt *m, *xm; /* both lists here are actually struct mrt_conifg nodes */ LIST_FOREACH(m, nconf, entry) { if ((xm = mrt_get(xconf, m)) == NULL) { /* NEW */ if ((xm = malloc(sizeof(struct mrt_config))) == NULL) fatal("mrt_mergeconfig"); memcpy(xm, m, sizeof(struct mrt_config)); xm->state = MRT_STATE_OPEN; LIST_INSERT_HEAD(xconf, xm, entry); } else { /* MERGE */ if (strlcpy(MRT2MC(xm)->name, MRT2MC(m)->name, sizeof(MRT2MC(xm)->name)) >= sizeof(MRT2MC(xm)->name)) fatalx("mrt_mergeconfig: strlcpy"); MRT2MC(xm)->ReopenTimerInterval = MRT2MC(m)->ReopenTimerInterval; xm->state = MRT_STATE_REOPEN; } } LIST_FOREACH(xm, xconf, entry) if (mrt_get(nconf, xm) == NULL) /* REMOVE */ xm->state = MRT_STATE_REMOVE; /* free config */ while ((m = LIST_FIRST(nconf)) != NULL) { LIST_REMOVE(m, entry); free(m); } } openbgpd-8.8/src/bgpd/kroute-disabled.c100644 001750 001750 00000041335 14730304744 0013632/* $OpenBSD$ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" struct kroute { RB_ENTRY(kroute) entry; struct kroute *next; struct in_addr prefix; struct in_addr nexthop; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct kroute6 { RB_ENTRY(kroute6) entry; struct kroute6 *next; struct in6_addr prefix; struct in6_addr nexthop; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct knexthop { RB_ENTRY(knexthop) entry; struct bgpd_addr nexthop; void *kroute; }; struct kredist_node { RB_ENTRY(kredist_node) entry; struct bgpd_addr prefix; uint64_t rd; uint8_t prefixlen; uint8_t dynamic; }; struct ktable krt; const u_int krt_size = 1; struct ktable *ktable_get(u_int); static uint8_t mask2prefixlen4(struct sockaddr_in *); static uint8_t mask2prefixlen6(struct sockaddr_in6 *); static inline int knexthop_compare(struct knexthop *a, struct knexthop *b) { int i; if (a->nexthop.aid != b->nexthop.aid) return (b->nexthop.aid - a->nexthop.aid); switch (a->nexthop.aid) { case AID_INET: if (ntohl(a->nexthop.v4.s_addr) < ntohl(b->nexthop.v4.s_addr)) return (-1); if (ntohl(a->nexthop.v4.s_addr) > ntohl(b->nexthop.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->nexthop.v6.s6_addr[i] < b->nexthop.v6.s6_addr[i]) return (-1); if (a->nexthop.v6.s6_addr[i] > b->nexthop.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } return (0); } static inline int kredist_compare(struct kredist_node *a, struct kredist_node *b) { int i; if (a->prefix.aid != b->prefix.aid) return (b->prefix.aid - a->prefix.aid); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); switch (a->prefix.aid) { case AID_INET: if (ntohl(a->prefix.v4.s_addr) < ntohl(b->prefix.v4.s_addr)) return (-1); if (ntohl(a->prefix.v4.s_addr) > ntohl(b->prefix.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->prefix.v6.s6_addr[i] < b->prefix.v6.s6_addr[i]) return (-1); if (a->prefix.v6.s6_addr[i] > b->prefix.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } if (a->rd < b->rd) return (-1); if (a->rd > b->rd) return (1); return (0); } RB_PROTOTYPE(knexthop_tree, knexthop, entry, knexthop_compare) RB_GENERATE(knexthop_tree, knexthop, entry, knexthop_compare) RB_PROTOTYPE(kredist_tree, kredist_node, entry, kredist_compare) RB_GENERATE(kredist_tree, kredist_node, entry, kredist_compare) #define KT2KNT(x) (&(ktable_get((x)->nhtableid)->knt)) void knexthop_send_update(struct knexthop *); static struct knexthop * knexthop_find(struct ktable *kt, struct bgpd_addr *addr) { struct knexthop s; bzero(&s, sizeof(s)); memcpy(&s.nexthop, addr, sizeof(s.nexthop)); return (RB_FIND(knexthop_tree, KT2KNT(kt), &s)); } static int knexthop_insert(struct ktable *kt, struct knexthop *kn) { if (RB_INSERT(knexthop_tree, KT2KNT(kt), kn) != NULL) { log_warnx("%s: failed for %s", __func__, log_addr(&kn->nexthop)); free(kn); return (-1); } knexthop_send_update(kn); return (0); } static int knexthop_remove(struct ktable *kt, struct knexthop *kn) { if (RB_REMOVE(knexthop_tree, KT2KNT(kt), kn) == NULL) { log_warnx("%s: failed for %s", __func__, log_addr(&kn->nexthop)); return (-1); } free(kn); return (0); } static void knexthop_clear(struct ktable *kt) { struct knexthop *kn; while ((kn = RB_MIN(knexthop_tree, KT2KNT(kt))) != NULL) knexthop_remove(kt, kn); } int kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *h; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return (0); } if ((h = knexthop_find(kt, addr)) != NULL) { /* should not happen... this is actually an error path */ knexthop_send_update(h); } else { if ((h = calloc(1, sizeof(struct knexthop))) == NULL) { log_warn("%s", __func__); return (-1); } memcpy(&h->nexthop, addr, sizeof(h->nexthop)); if (knexthop_insert(kt, h) == -1) return (-1); } return (0); } void kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *kn; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return; } if ((kn = knexthop_find(kt, addr)) == NULL) return; knexthop_remove(kt, kn); } void knexthop_send_update(struct knexthop *kn) { struct kroute_nexthop n; #if 0 struct kroute *kr; struct kroute6 *kr6; #endif struct ifaddrs *ifap, *ifa; bzero(&n, sizeof(n)); memcpy(&n.nexthop, &kn->nexthop, sizeof(n.nexthop)); #if 0 if (kn->kroute == NULL) { n.valid = 0; /* NH is not valid */ send_nexthop_update(&n); return; } switch (kn->nexthop.aid) { case AID_INET: kr = kn->kroute; n.valid = kroute_validate(&kr->r); n.connected = kr->r.flags & F_CONNECTED; if (kr->r.nexthop.s_addr != 0) { n.gateway.aid = AID_INET; n.gateway.v4.s_addr = kr->r.nexthop.s_addr; } if (n.connected) { n.net.aid = AID_INET; n.net.v4.s_addr = kr->r.prefix.s_addr; n.netlen = kr->r.prefixlen; } break; case AID_INET6: kr6 = kn->kroute; n.valid = kroute6_validate(&kr6->r); n.connected = kr6->r.flags & F_CONNECTED; if (memcmp(&kr6->r.nexthop, &in6addr_any, sizeof(struct in6_addr)) != 0) { n.gateway.aid = AID_INET6; memcpy(&n.gateway.v6, &kr6->r.nexthop, sizeof(struct in6_addr)); } if (n.connected) { n.net.aid = AID_INET6; memcpy(&n.net.v6, &kr6->r.prefix, sizeof(struct in6_addr)); n.netlen = kr6->r.prefixlen; } break; } #else n.valid = 1; /* NH is always valid */ memcpy(&n.gateway, &kn->nexthop, sizeof(n.gateway)); if (getifaddrs(&ifap) == -1) fatal("getifaddrs"); for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { struct bgpd_addr addr; struct sockaddr_in *m4; struct sockaddr_in6 *m6; int plen; if (ifa->ifa_addr == NULL) continue; switch (ifa->ifa_addr->sa_family) { case AF_INET: m4 = (struct sockaddr_in *)ifa->ifa_netmask; if (m4 == NULL) plen = 32; else plen = mask2prefixlen4(m4); break; case AF_INET6: m6 = (struct sockaddr_in6 *)ifa->ifa_netmask; if (m6 == NULL) plen = 128; else plen = mask2prefixlen6(m6); break; default: continue; } sa2addr(ifa->ifa_addr, &addr, NULL); if (prefix_compare(&n.nexthop, &addr, plen) != 0) continue; n.connected = F_CONNECTED; n.gateway = addr; n.net = addr; n.netlen = plen; break; } freeifaddrs(ifap); #endif send_nexthop_update(&n); } int kr_init(int *fd, uint8_t fib_prio) { struct ktable *kt = &krt; /* initialize structure ... */ strlcpy(kt->descr, "rdomain_0", sizeof(kt->descr)); RB_INIT(&kt->krt); RB_INIT(&kt->krt6); RB_INIT(&kt->knt); TAILQ_INIT(&kt->krn); kt->fib_conf = kt->fib_sync = 0; kt->rtableid = 0; kt->nhtableid = 0; /* XXX need to return an FD that can be polled */ *fd = -1; return (0); } int kr_default_prio(void) { return 2; } int kr_check_prio(long long prio) { if (prio != kr_default_prio()) return 0; return 1; } void kr_shutdown(void) { knexthop_clear(&krt); } void kr_fib_couple(u_int rtableid) { } void kr_fib_couple_all(void) { } void kr_fib_decouple(u_int rtableid) { } void kr_fib_decouple_all(void) { } void kr_fib_prio_set(uint8_t prio) { } int kr_dispatch_msg(void) { return (0); } int kr_change(u_int rtableid, struct kroute_full *kl) { return (0); } int kr_delete(u_int rtableid, struct kroute_full *kl) { return (0); } static int kr_net_redist_add(struct ktable *kt, struct network_config *net, struct filter_set_head *attr, int dynamic) { struct kredist_node *r, *xr; if ((r = calloc(1, sizeof(*r))) == NULL) fatal("%s", __func__); r->prefix = net->prefix; r->prefixlen = net->prefixlen; r->rd = net->rd; r->dynamic = dynamic; xr = RB_INSERT(kredist_tree, &kt->kredist, r); if (xr != NULL) { free(r); if (dynamic != xr->dynamic && dynamic) { /* * ignore update a non-dynamic announcement is * already present which has preference. */ return 0; } /* * only equal or non-dynamic announcement ends up here. * In both cases reset the dynamic flag (nop for equal) and * redistribute. */ xr->dynamic = dynamic; } if (send_network(IMSG_NETWORK_ADD, net, attr) == -1) log_warnx("%s: failed to send network update", __func__); return 1; } static void kr_net_redist_del(struct ktable *kt, struct network_config *net, int dynamic) { struct kredist_node *r, node; bzero(&node, sizeof(node)); node.prefix = net->prefix; node.prefixlen = net->prefixlen; node.rd = net->rd; r = RB_FIND(kredist_tree, &kt->kredist, &node); if (r == NULL || dynamic != r->dynamic) return; if (RB_REMOVE(kredist_tree, &kt->kredist, r) == NULL) { log_warnx("%s: failed to remove network %s/%u", __func__, log_addr(&node.prefix), node.prefixlen); return; } free(r); if (send_network(IMSG_NETWORK_REMOVE, net, NULL) == -1) log_warnx("%s: failed to send network removal", __func__); } static struct network * kr_net_find(struct ktable *kt, struct network *n) { struct network *xn; TAILQ_FOREACH(xn, &kt->krn, entry) { if (n->net.type != xn->net.type || n->net.prefixlen != xn->net.prefixlen || n->net.rd != xn->net.rd) continue; if (memcmp(&n->net.prefix, &xn->net.prefix, sizeof(n->net.prefix)) == 0) return (xn); } return (NULL); } static void kr_net_delete(struct network *n) { filterset_free(&n->net.attrset); free(n); } void kr_net_reload(u_int rtableid, uint64_t rd, struct network_head *nh) { struct network *n, *xn; struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) fatalx("%s: non-existent rtableid %d", __func__, rtableid); while ((n = TAILQ_FIRST(nh)) != NULL) { TAILQ_REMOVE(nh, n, entry); if (n->net.type != NETWORK_DEFAULT) { log_warnx("dynamic network statements unimplemened, " "network ignored"); kr_net_delete(n); continue; } n->net.old = 0; n->net.rd = rd; xn = kr_net_find(kt, n); if (xn) { xn->net.old = 0; filterset_free(&xn->net.attrset); filterset_move(&n->net.attrset, &xn->net.attrset); kr_net_delete(n); } else { TAILQ_INSERT_TAIL(&kt->krn, n, entry); } } } int kr_reload(void) { struct ktable *kt; struct network *n; u_int rid; for (rid = 0; rid < krt_size; rid++) { if ((kt = ktable_get(rid)) == NULL) continue; TAILQ_FOREACH(n, &kt->krn, entry) if (n->net.type == NETWORK_DEFAULT) { kr_net_redist_add(kt, &n->net, &n->net.attrset, 0); } else fatalx("%s: dynamic networks not implemented", __func__); } return (0); } int kr_flush(u_int rtableid) { /* nothing to flush for now */ return (0); } void kr_show_route(struct imsg *imsg) { struct ctl_show_nexthop snh; struct ktable *kt; struct knexthop *h; uint32_t tableid; pid_t pid; int code; tableid = imsg_get_id(imsg); pid = imsg_get_pid(imsg); switch (imsg_get_type(imsg)) { case IMSG_CTL_SHOW_NEXTHOP: kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } RB_FOREACH(h, knexthop_tree, KT2KNT(kt)) { bzero(&snh, sizeof(snh)); memcpy(&snh.addr, &h->nexthop, sizeof(snh.addr)); #if 0 if (h->kroute != NULL) { switch (h->nexthop.aid) { case AID_INET: kr = h->kroute; snh.valid = kroute_validate(&kr->r); snh.krvalid = 1; memcpy(&snh.kr.kr4, &kr->r, sizeof(snh.kr.kr4)); ifindex = kr->r.ifindex; break; case AID_INET6: kr6 = h->kroute; snh.valid = kroute6_validate(&kr6->r); snh.krvalid = 1; memcpy(&snh.kr.kr6, &kr6->r, sizeof(snh.kr.kr6)); ifindex = kr6->r.ifindex; break; } if ((kif = kif_find(ifindex)) != NULL) memcpy(&snh.iface, kr_show_interface(&kif->k), sizeof(snh.iface)); } #else snh.valid = 1; snh.krvalid = 1; #endif send_imsg_session(IMSG_CTL_SHOW_NEXTHOP, pid, &snh, sizeof(snh)); } break; case IMSG_CTL_SHOW_FIB_TABLES: { struct ktable ktab; ktab = krt; /* do not leak internal information */ RB_INIT(&ktab.krt); RB_INIT(&ktab.krt6); RB_INIT(&ktab.knt); TAILQ_INIT(&ktab.krn); send_imsg_session(IMSG_CTL_SHOW_FIB_TABLES, pid, &ktab, sizeof(ktab)); } break; default: /* nada */ code = CTL_RES_OPNOTSUPP; send_imsg_session(IMSG_CTL_RESULT, pid, &code, sizeof(code)); return; } send_imsg_session(IMSG_CTL_END, pid, NULL, 0); } void kr_ifinfo(char *ifname) { } int ktable_exists(u_int rtableid, u_int *rdomid) { if (rtableid == 0) { *rdomid = 0; return (1); } return (0); } struct ktable * ktable_get(u_int rtableid) { if (rtableid == 0) return &krt; return NULL; } static void ktable_free(u_int rtableid) { fatalx("%s not implemented", __func__); } int ktable_update(u_int rtableid, char *name, int flags) { struct ktable *kt; kt = ktable_get(rtableid); if (kt == NULL) { return (-1); } else { /* fib sync has higher preference then no sync */ if (kt->state == RECONF_DELETE) { kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); kt->state = RECONF_KEEP; } else if (!kt->fib_conf) kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); strlcpy(kt->descr, name, sizeof(kt->descr)); } return (0); } void ktable_preload(void) { struct ktable *kt; struct network *n; u_int i; for (i = 0; i < krt_size; i++) { if ((kt = ktable_get(i)) == NULL) continue; kt->state = RECONF_DELETE; /* mark all networks as old */ TAILQ_FOREACH(n, &kt->krn, entry) n->net.old = 1; } } void ktable_postload(void) { struct ktable *kt; struct network *n, *xn; u_int i; for (i = krt_size; i > 0; i--) { if ((kt = ktable_get(i - 1)) == NULL) continue; if (kt->state == RECONF_DELETE) { ktable_free(i - 1); continue; } else if (kt->state == RECONF_REINIT) kt->fib_sync = kt->fib_conf; /* cleanup old networks */ TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { if (n->net.old) { TAILQ_REMOVE(&kt->krn, n, entry); if (n->net.type == NETWORK_DEFAULT) kr_net_redist_del(kt, &n->net, 0); kr_net_delete(n); } } } } int get_mpe_config(const char *name, u_int *rdomain, u_int *label) { return (-1); } static uint8_t mask2prefixlen4(struct sockaddr_in *sa_in) { in_addr_t ina; ina = sa_in->sin_addr.s_addr; if (ina == 0) return (0); else return (33 - ffs(ntohl(ina))); } static uint8_t mask2prefixlen6(struct sockaddr_in6 *sa_in6) { uint8_t *ap, *ep; u_int l = 0; /* * There is no sin6_len for portability so calculate the end pointer * so that a full IPv6 address fits. On systems without sa_len this * is fine, on OpenBSD this is also correct. On other systems the * assumtion is they behave like OpenBSD or that there is at least * a 0 byte right after the end of the truncated sockaddr_in6. */ ap = (uint8_t *)&sa_in6->sin6_addr; ep = ap + sizeof(struct in6_addr); for (; ap < ep; ap++) { /* this "beauty" is adopted from sbin/route/show.c ... */ switch (*ap) { case 0xff: l += 8; break; case 0xfe: l += 7; goto done; case 0xfc: l += 6; goto done; case 0xf8: l += 5; goto done; case 0xf0: l += 4; goto done; case 0xe0: l += 3; goto done; case 0xc0: l += 2; goto done; case 0x80: l += 1; goto done; case 0x00: goto done; default: fatalx("non contiguous inet6 netmask"); } } done: if (l > sizeof(struct in6_addr) * 8) fatalx("%s: prefixlen %d out of bound", __func__, l); return (l); } uint8_t mask2prefixlen(sa_family_t af, struct sockaddr *mask) { switch (af) { case AF_INET: return mask2prefixlen4((struct sockaddr_in *)mask); case AF_INET6: return mask2prefixlen6((struct sockaddr_in6 *)mask); default: fatalx("%s: unsupported af", __func__); } } openbgpd-8.8/src/bgpd/kroute.c100644 001750 001750 00000224255 14751151130 0012061/* $OpenBSD: kroute.c,v 1.313 2025/02/04 16:07:46 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2022 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "log.h" #define RTP_MINE 0xff struct ktable **krt; u_int krt_size; struct { uint32_t rtseq; pid_t pid; int fd; uint8_t fib_prio; } kr_state; struct kroute { RB_ENTRY(kroute) entry; struct kroute *next; struct in_addr prefix; struct in_addr nexthop; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct kroute6 { RB_ENTRY(kroute6) entry; struct kroute6 *next; struct in6_addr prefix; struct in6_addr nexthop; uint32_t prefix_scope_id; /* because ... */ uint32_t nexthop_scope_id; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct knexthop { RB_ENTRY(knexthop) entry; struct bgpd_addr nexthop; void *kroute; u_short ifindex; }; struct kredist_node { RB_ENTRY(kredist_node) entry; struct bgpd_addr prefix; uint64_t rd; uint8_t prefixlen; uint8_t dynamic; }; struct kif { RB_ENTRY(kif) entry; char ifname[IFNAMSIZ]; uint64_t baudrate; u_int rdomain; int flags; u_short ifindex; uint8_t if_type; uint8_t link_state; uint8_t nh_reachable; /* for nexthop verification */ uint8_t depend_state; /* for session depend on */ }; int ktable_new(u_int, u_int, char *, int); void ktable_free(u_int); void ktable_destroy(struct ktable *); struct ktable *ktable_get(u_int); int kr4_change(struct ktable *, struct kroute_full *); int kr6_change(struct ktable *, struct kroute_full *); int krVPN4_change(struct ktable *, struct kroute_full *); int krVPN6_change(struct ktable *, struct kroute_full *); int kr_net_match(struct ktable *, struct network_config *, uint16_t, int); struct network *kr_net_find(struct ktable *, struct network *); void kr_net_clear(struct ktable *); void kr_redistribute(int, struct ktable *, struct kroute_full *); uint8_t kr_priority(struct kroute_full *); struct kroute_full *kr_tofull(struct kroute *); struct kroute_full *kr6_tofull(struct kroute6 *); int kroute_compare(struct kroute *, struct kroute *); int kroute6_compare(struct kroute6 *, struct kroute6 *); int knexthop_compare(struct knexthop *, struct knexthop *); int kredist_compare(struct kredist_node *, struct kredist_node *); int kif_compare(struct kif *, struct kif *); struct kroute *kroute_find(struct ktable *, const struct bgpd_addr *, uint8_t, uint8_t); struct kroute *kroute_matchgw(struct kroute *, struct kroute_full *); int kroute_insert(struct ktable *, struct kroute_full *); int kroute_remove(struct ktable *, struct kroute_full *, int); void kroute_clear(struct ktable *); struct kroute6 *kroute6_find(struct ktable *, const struct bgpd_addr *, uint8_t, uint8_t); struct kroute6 *kroute6_matchgw(struct kroute6 *, struct kroute_full *); void kroute6_clear(struct ktable *); struct knexthop *knexthop_find(struct ktable *, struct bgpd_addr *); int knexthop_insert(struct ktable *, struct knexthop *); void knexthop_remove(struct ktable *, struct knexthop *); void knexthop_clear(struct ktable *); struct kif *kif_find(int); int kif_insert(struct kif *); int kif_remove(struct kif *); void kif_clear(void); int kroute_validate(struct kroute *); int kroute6_validate(struct kroute6 *); int knexthop_true_nexthop(struct ktable *, struct kroute_full *); void knexthop_validate(struct ktable *, struct knexthop *); void knexthop_track(struct ktable *, u_short); void knexthop_update(struct ktable *, struct kroute_full *); void knexthop_send_update(struct knexthop *); struct kroute *kroute_match(struct ktable *, struct bgpd_addr *, int); struct kroute6 *kroute6_match(struct ktable *, struct bgpd_addr *, int); void kroute_detach_nexthop(struct ktable *, struct knexthop *); uint8_t prefixlen_classful(in_addr_t); uint64_t ift2ifm(uint8_t); const char *get_media_descr(uint64_t); const char *get_linkstate(uint8_t, int); void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); void if_change(u_short, int, struct if_data *); void if_announce(void *); int send_rtmsg(int, struct ktable *, struct kroute_full *); int dispatch_rtmsg(void); int fetchtable(struct ktable *); int fetchifs(int); int dispatch_rtmsg_addr(struct rt_msghdr *, struct kroute_full *); int kr_fib_delete(struct ktable *, struct kroute_full *, int); int kr_fib_change(struct ktable *, struct kroute_full *, int, int); RB_PROTOTYPE(kroute_tree, kroute, entry, kroute_compare) RB_GENERATE(kroute_tree, kroute, entry, kroute_compare) RB_PROTOTYPE(kroute6_tree, kroute6, entry, kroute6_compare) RB_GENERATE(kroute6_tree, kroute6, entry, kroute6_compare) RB_PROTOTYPE(knexthop_tree, knexthop, entry, knexthop_compare) RB_GENERATE(knexthop_tree, knexthop, entry, knexthop_compare) RB_PROTOTYPE(kredist_tree, kredist_node, entry, kredist_compare) RB_GENERATE(kredist_tree, kredist_node, entry, kredist_compare) RB_HEAD(kif_tree, kif) kit; RB_PROTOTYPE(kif_tree, kif, entry, kif_compare) RB_GENERATE(kif_tree, kif, entry, kif_compare) #define KT2KNT(x) (&(ktable_get((x)->nhtableid)->knt)) /* * exported functions */ int kr_init(int *fd, uint8_t fib_prio) { int opt = 0, rcvbuf, default_rcvbuf; unsigned int tid = RTABLE_ANY; socklen_t optlen; if ((kr_state.fd = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1) { log_warn("%s: socket", __func__); return (-1); } /* not interested in my own messages */ if (setsockopt(kr_state.fd, SOL_SOCKET, SO_USELOOPBACK, &opt, sizeof(opt)) == -1) log_warn("%s: setsockopt", __func__); /* not fatal */ /* grow receive buffer, don't wanna miss messages */ optlen = sizeof(default_rcvbuf); if (getsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF, &default_rcvbuf, &optlen) == -1) log_warn("%s: getsockopt SOL_SOCKET SO_RCVBUF", __func__); else for (rcvbuf = MAX_RTSOCK_BUF; rcvbuf > default_rcvbuf && setsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)) == -1 && errno == ENOBUFS; rcvbuf /= 2) ; /* nothing */ if (setsockopt(kr_state.fd, AF_ROUTE, ROUTE_TABLEFILTER, &tid, sizeof(tid)) == -1) { log_warn("%s: setsockopt AF_ROUTE ROUTE_TABLEFILTER", __func__); return (-1); } kr_state.pid = getpid(); kr_state.rtseq = 1; kr_state.fib_prio = fib_prio; RB_INIT(&kit); if (fetchifs(0) == -1) return (-1); *fd = kr_state.fd; return (0); } int kr_default_prio(void) { return RTP_BGP; } int kr_check_prio(long long prio) { if (prio <= RTP_LOCAL || prio > RTP_MAX) return 0; return 1; } int ktable_new(u_int rtableid, u_int rdomid, char *name, int fs) { struct ktable **xkrt; struct ktable *kt; size_t oldsize; /* resize index table if needed */ if (rtableid >= krt_size) { oldsize = sizeof(struct ktable *) * krt_size; if ((xkrt = reallocarray(krt, rtableid + 1, sizeof(struct ktable *))) == NULL) { log_warn("%s", __func__); return (-1); } krt = xkrt; krt_size = rtableid + 1; memset((char *)krt + oldsize, 0, krt_size * sizeof(struct ktable *) - oldsize); } if (krt[rtableid]) fatalx("ktable_new: table already exists."); /* allocate new element */ kt = krt[rtableid] = calloc(1, sizeof(struct ktable)); if (kt == NULL) { log_warn("%s", __func__); return (-1); } /* initialize structure ... */ strlcpy(kt->descr, name, sizeof(kt->descr)); RB_INIT(&kt->krt); RB_INIT(&kt->krt6); RB_INIT(&kt->knt); TAILQ_INIT(&kt->krn); kt->fib_conf = kt->fib_sync = fs; kt->rtableid = rtableid; kt->nhtableid = rdomid; /* bump refcount of rdomain table for the nexthop lookups */ ktable_get(kt->nhtableid)->nhrefcnt++; /* ... and load it */ if (fetchtable(kt) == -1) return (-1); /* everything is up and running */ kt->state = RECONF_REINIT; log_debug("%s: %s with rtableid %d rdomain %d", __func__, name, rtableid, rdomid); return (0); } void ktable_free(u_int rtableid) { struct ktable *kt, *nkt; if ((kt = ktable_get(rtableid)) == NULL) return; /* decouple from kernel, no new routes will be entered from here */ kr_fib_decouple(kt->rtableid); /* first unhook from the nexthop table */ nkt = ktable_get(kt->nhtableid); nkt->nhrefcnt--; /* * Evil little details: * If kt->nhrefcnt > 0 then kt == nkt and nothing needs to be done. * If kt != nkt then kt->nhrefcnt must be 0 and kt must be killed. * If nkt is no longer referenced it must be killed (possible double * free so check that kt != nkt). */ if (kt != nkt && nkt->nhrefcnt <= 0) ktable_destroy(nkt); if (kt->nhrefcnt <= 0) ktable_destroy(kt); } void ktable_destroy(struct ktable *kt) { /* decouple just to be sure, does not hurt */ kr_fib_decouple(kt->rtableid); log_debug("%s: freeing ktable %s rtableid %u", __func__, kt->descr, kt->rtableid); /* only clear nexthop table if it is the main rdomain table */ if (kt->rtableid == kt->nhtableid) knexthop_clear(kt); kroute_clear(kt); kroute6_clear(kt); kr_net_clear(kt); krt[kt->rtableid] = NULL; free(kt); } struct ktable * ktable_get(u_int rtableid) { if (rtableid >= krt_size) return (NULL); return (krt[rtableid]); } int ktable_update(u_int rtableid, char *name, int flags) { struct ktable *kt, *rkt; u_int rdomid; if (!ktable_exists(rtableid, &rdomid)) fatalx("King Bula lost a table"); /* may not happen */ if (rdomid != rtableid || flags & F_RIB_NOFIB) { rkt = ktable_get(rdomid); if (rkt == NULL) { char buf[32]; snprintf(buf, sizeof(buf), "rdomain_%d", rdomid); if (ktable_new(rdomid, rdomid, buf, 0)) return (-1); } else { /* there is no need for full fib synchronisation if * the table is only used for nexthop lookups. */ if (rkt->state == RECONF_DELETE) { rkt->fib_conf = 0; rkt->state = RECONF_KEEP; } } } if (flags & (F_RIB_NOFIB | F_RIB_NOEVALUATE)) /* only rdomain table must exist */ return (0); kt = ktable_get(rtableid); if (kt == NULL) { if (ktable_new(rtableid, rdomid, name, !(flags & F_RIB_NOFIBSYNC))) return (-1); } else { /* fib sync has higher preference then no sync */ if (kt->state == RECONF_DELETE) { kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); kt->state = RECONF_KEEP; } else if (!kt->fib_conf) kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); strlcpy(kt->descr, name, sizeof(kt->descr)); } return (0); } int ktable_exists(u_int rtableid, u_int *rdomid) { size_t len; struct rt_tableinfo info; int mib[6]; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_TABLE; mib[5] = rtableid; len = sizeof(info); if (sysctl(mib, 6, &info, &len, NULL, 0) == -1) { if (errno == ENOENT) /* table nonexistent */ return (0); log_warn("sysctl net.route.rtableid"); /* must return 0 so that the table is considered non-existent */ return (0); } if (rdomid) *rdomid = info.rti_domainid; return (1); } int kr_change(u_int rtableid, struct kroute_full *kf) { struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); kf->flags |= F_BGPD; kf->priority = RTP_MINE; if (!knexthop_true_nexthop(kt, kf)) return kroute_remove(kt, kf, 1); switch (kf->prefix.aid) { case AID_INET: return (kr4_change(kt, kf)); case AID_INET6: return (kr6_change(kt, kf)); case AID_VPN_IPv4: return (krVPN4_change(kt, kf)); case AID_VPN_IPv6: return (krVPN6_change(kt, kf)); case AID_EVPN: /* XXX ignored for now */ return (0); } log_warnx("%s: not handled AID", __func__); return (-1); } int kr4_change(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr; /* for blackhole and reject routes nexthop needs to be 127.0.0.1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) kf->nexthop.v4.s_addr = htonl(INADDR_LOOPBACK); /* nexthop within 127/8 -> ignore silently */ else if ((kf->nexthop.v4.s_addr & htonl(IN_CLASSA_NET)) == htonl(INADDR_LOOPBACK & IN_CLASSA_NET)) return (0); if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { kr->nexthop.s_addr = kf->nexthop.v4.s_addr; rtlabel_unref(kr->labelid); kr->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr->flags |= F_BLACKHOLE; else kr->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr->flags |= F_REJECT; else kr->flags &= ~F_REJECT; if (kr->flags & F_NEXTHOP) knexthop_update(kt, kf); if (send_rtmsg(RTM_CHANGE, kt, kf)) kr->flags |= F_BGPD_INSERTED; } return (0); } int kr6_change(struct ktable *kt, struct kroute_full *kf) { struct kroute6 *kr6; struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT; /* for blackhole and reject routes nexthop needs to be ::1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) memcpy(&kf->nexthop.v6, &lo6, sizeof(kf->nexthop.v6)); /* nexthop to loopback -> ignore silently */ else if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) return (0); if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { memcpy(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)); kr6->nexthop_scope_id = kf->nexthop.scope_id; rtlabel_unref(kr6->labelid); kr6->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr6->flags |= F_BLACKHOLE; else kr6->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr6->flags |= F_REJECT; else kr6->flags &= ~F_REJECT; if (kr6->flags & F_NEXTHOP) knexthop_update(kt, kf); if (send_rtmsg(RTM_CHANGE, kt, kf)) kr6->flags |= F_BGPD_INSERTED; } return (0); } int krVPN4_change(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr; uint32_t mplslabel = 0; /* nexthop within 127/8 -> ignore silently */ if ((kf->nexthop.v4.s_addr & htonl(IN_CLASSA_NET)) == htonl(INADDR_LOOPBACK & IN_CLASSA_NET)) return (0); /* only a single MPLS label is supported for now */ if (kf->prefix.labellen != 3) { log_warnx("%s: %s/%u has not a single label", __func__, log_addr(&kf->prefix), kf->prefixlen); return (0); } mplslabel = (kf->prefix.labelstack[0] << 24) | (kf->prefix.labelstack[1] << 16) | (kf->prefix.labelstack[2] << 8); mplslabel = htonl(mplslabel); kf->flags |= F_MPLS; kf->mplslabel = mplslabel; /* for blackhole and reject routes nexthop needs to be 127.0.0.1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) kf->nexthop.v4.s_addr = htonl(INADDR_LOOPBACK); if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { kr->mplslabel = mplslabel; kr->flags |= F_MPLS; kr->ifindex = kf->ifindex; kr->nexthop.s_addr = kf->nexthop.v4.s_addr; rtlabel_unref(kr->labelid); kr->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr->flags |= F_BLACKHOLE; else kr->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr->flags |= F_REJECT; else kr->flags &= ~F_REJECT; if (send_rtmsg(RTM_CHANGE, kt, kf)) kr->flags |= F_BGPD_INSERTED; } return (0); } int krVPN6_change(struct ktable *kt, struct kroute_full *kf) { struct kroute6 *kr6; struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT; uint32_t mplslabel = 0; /* nexthop to loopback -> ignore silently */ if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) return (0); /* only a single MPLS label is supported for now */ if (kf->prefix.labellen != 3) { log_warnx("%s: %s/%u has not a single label", __func__, log_addr(&kf->prefix), kf->prefixlen); return (0); } mplslabel = (kf->prefix.labelstack[0] << 24) | (kf->prefix.labelstack[1] << 16) | (kf->prefix.labelstack[2] << 8); mplslabel = htonl(mplslabel); kf->flags |= F_MPLS; kf->mplslabel = mplslabel; /* for blackhole and reject routes nexthop needs to be ::1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) memcpy(&kf->nexthop.v6, &lo6, sizeof(kf->nexthop.v6)); if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { kr6->mplslabel = mplslabel; kr6->flags |= F_MPLS; kr6->ifindex = kf->ifindex; memcpy(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)); kr6->nexthop_scope_id = kf->nexthop.scope_id; rtlabel_unref(kr6->labelid); kr6->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr6->flags |= F_BLACKHOLE; else kr6->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr6->flags |= F_REJECT; else kr6->flags &= ~F_REJECT; if (send_rtmsg(RTM_CHANGE, kt, kf)) kr6->flags |= F_BGPD_INSERTED; } return (0); } int kr_delete(u_int rtableid, struct kroute_full *kf) { struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); kf->flags |= F_BGPD; kf->priority = RTP_MINE; return kroute_remove(kt, kf, 1); } int kr_flush(u_int rtableid) { struct ktable *kt; struct kroute *kr, *next; struct kroute6 *kr6, *next6; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); RB_FOREACH_SAFE(kr, kroute_tree, &kt->krt, next) if ((kr->flags & F_BGPD_INSERTED)) { if (kroute_remove(kt, kr_tofull(kr), 1) == -1) return (-1); } RB_FOREACH_SAFE(kr6, kroute6_tree, &kt->krt6, next6) if ((kr6->flags & F_BGPD_INSERTED)) { if (kroute_remove(kt, kr6_tofull(kr6), 1) == -1) return (-1); } kt->fib_sync = 0; return (0); } void kr_shutdown(void) { u_int i; for (i = krt_size; i > 0; i--) ktable_free(i - 1); kif_clear(); free(krt); } void kr_fib_couple(u_int rtableid) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */ return; if (kt->fib_sync) /* already coupled */ return; kt->fib_sync = 1; RB_FOREACH(kr, kroute_tree, &kt->krt) if (kr->flags & F_BGPD) { if (send_rtmsg(RTM_ADD, kt, kr_tofull(kr))) kr->flags |= F_BGPD_INSERTED; } RB_FOREACH(kr6, kroute6_tree, &kt->krt6) if (kr6->flags & F_BGPD) { if (send_rtmsg(RTM_ADD, kt, kr6_tofull(kr6))) kr6->flags |= F_BGPD_INSERTED; } log_info("kernel routing table %u (%s) coupled", kt->rtableid, kt->descr); } void kr_fib_couple_all(void) { u_int i; for (i = krt_size; i > 0; i--) kr_fib_couple(i - 1); } void kr_fib_decouple(u_int rtableid) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */ return; if (!kt->fib_sync) /* already decoupled */ return; RB_FOREACH(kr, kroute_tree, &kt->krt) if ((kr->flags & F_BGPD_INSERTED)) { if (send_rtmsg(RTM_DELETE, kt, kr_tofull(kr))) kr->flags &= ~F_BGPD_INSERTED; } RB_FOREACH(kr6, kroute6_tree, &kt->krt6) if ((kr6->flags & F_BGPD_INSERTED)) { if (send_rtmsg(RTM_DELETE, kt, kr6_tofull(kr6))) kr6->flags &= ~F_BGPD_INSERTED; } kt->fib_sync = 0; log_info("kernel routing table %u (%s) decoupled", kt->rtableid, kt->descr); } void kr_fib_decouple_all(void) { u_int i; for (i = krt_size; i > 0; i--) kr_fib_decouple(i - 1); } void kr_fib_prio_set(uint8_t prio) { kr_state.fib_prio = prio; } int kr_dispatch_msg(void) { return (dispatch_rtmsg()); } int kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *h; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return (0); } if ((h = knexthop_find(kt, addr)) != NULL) { /* should not happen... this is actually an error path */ knexthop_send_update(h); } else { if ((h = calloc(1, sizeof(*h))) == NULL) { log_warn("%s", __func__); return (-1); } memcpy(&h->nexthop, addr, sizeof(h->nexthop)); if (knexthop_insert(kt, h) == -1) return (-1); } return (0); } void kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *kn; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return; } if ((kn = knexthop_find(kt, addr)) == NULL) return; knexthop_remove(kt, kn); } static struct ctl_show_interface * kr_show_interface(struct kif *kif) { static struct ctl_show_interface iface; uint64_t ifms_type; memset(&iface, 0, sizeof(iface)); strlcpy(iface.ifname, kif->ifname, sizeof(iface.ifname)); snprintf(iface.linkstate, sizeof(iface.linkstate), "%s", get_linkstate(kif->if_type, kif->link_state)); if ((ifms_type = ift2ifm(kif->if_type)) != 0) snprintf(iface.media, sizeof(iface.media), "%s", get_media_descr(ifms_type)); iface.baudrate = kif->baudrate; iface.rdomain = kif->rdomain; iface.nh_reachable = kif->nh_reachable; iface.is_up = (kif->flags & IFF_UP) == IFF_UP; return &iface; } void kr_show_route(struct imsg *imsg) { struct ktable *kt; struct kroute *kr, *kn; struct kroute6 *kr6, *kn6; struct kroute_full *kf; struct bgpd_addr addr; struct ctl_kroute_req req; struct ctl_show_nexthop snh; struct knexthop *h; struct kif *kif; uint32_t tableid; pid_t pid; u_int i; u_short ifindex = 0; tableid = imsg_get_id(imsg); pid = imsg_get_pid(imsg); switch (imsg_get_type(imsg)) { case IMSG_CTL_KROUTE: if (imsg_get_data(imsg, &req, sizeof(req)) == -1) { log_warnx("%s: wrong imsg len", __func__); break; } kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } if (!req.af || req.af == AF_INET) RB_FOREACH(kr, kroute_tree, &kt->krt) { if (req.flags && (kr->flags & req.flags) == 0) continue; kn = kr; do { kf = kr_tofull(kn); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } while ((kn = kn->next) != NULL); } if (!req.af || req.af == AF_INET6) RB_FOREACH(kr6, kroute6_tree, &kt->krt6) { if (req.flags && (kr6->flags & req.flags) == 0) continue; kn6 = kr6; do { kf = kr6_tofull(kn6); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } while ((kn6 = kn6->next) != NULL); } break; case IMSG_CTL_KROUTE_ADDR: if (imsg_get_data(imsg, &addr, sizeof(addr)) == -1) { log_warnx("%s: wrong imsg len", __func__); break; } kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } kr = NULL; switch (addr.aid) { case AID_INET: kr = kroute_match(kt, &addr, 1); if (kr != NULL) { kf = kr_tofull(kr); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } break; case AID_INET6: kr6 = kroute6_match(kt, &addr, 1); if (kr6 != NULL) { kf = kr6_tofull(kr6); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } break; } break; case IMSG_CTL_SHOW_NEXTHOP: kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } RB_FOREACH(h, knexthop_tree, KT2KNT(kt)) { memset(&snh, 0, sizeof(snh)); memcpy(&snh.addr, &h->nexthop, sizeof(snh.addr)); if (h->kroute != NULL) { switch (h->nexthop.aid) { case AID_INET: kr = h->kroute; snh.valid = kroute_validate(kr); snh.krvalid = 1; snh.kr = *kr_tofull(kr); ifindex = kr->ifindex; break; case AID_INET6: kr6 = h->kroute; snh.valid = kroute6_validate(kr6); snh.krvalid = 1; snh.kr = *kr6_tofull(kr6); ifindex = kr6->ifindex; break; } snh.kr.priority = kr_priority(&snh.kr); if ((kif = kif_find(ifindex)) != NULL) memcpy(&snh.iface, kr_show_interface(kif), sizeof(snh.iface)); } send_imsg_session(IMSG_CTL_SHOW_NEXTHOP, pid, &snh, sizeof(snh)); } break; case IMSG_CTL_SHOW_INTERFACE: RB_FOREACH(kif, kif_tree, &kit) send_imsg_session(IMSG_CTL_SHOW_INTERFACE, pid, kr_show_interface(kif), sizeof(struct ctl_show_interface)); break; case IMSG_CTL_SHOW_FIB_TABLES: for (i = 0; i < krt_size; i++) { struct ktable ktab; if ((kt = ktable_get(i)) == NULL) continue; ktab = *kt; /* do not leak internal information */ RB_INIT(&ktab.krt); RB_INIT(&ktab.krt6); RB_INIT(&ktab.knt); TAILQ_INIT(&ktab.krn); send_imsg_session(IMSG_CTL_SHOW_FIB_TABLES, pid, &ktab, sizeof(ktab)); } break; default: /* nada */ break; } send_imsg_session(IMSG_CTL_END, pid, NULL, 0); } static void kr_send_dependon(struct kif *kif) { struct session_dependon sdon = { 0 }; strlcpy(sdon.ifname, kif->ifname, sizeof(sdon.ifname)); sdon.depend_state = kif->depend_state; send_imsg_session(IMSG_SESSION_DEPENDON, 0, &sdon, sizeof(sdon)); } void kr_ifinfo(char *ifname) { struct kif *kif; RB_FOREACH(kif, kif_tree, &kit) if (!strcmp(ifname, kif->ifname)) { kr_send_dependon(kif); return; } } static int kr_net_redist_add(struct ktable *kt, struct network_config *net, struct filter_set_head *attr, int dynamic) { struct kredist_node *r, *xr; if ((r = calloc(1, sizeof(*r))) == NULL) fatal("%s", __func__); r->prefix = net->prefix; r->prefixlen = net->prefixlen; r->rd = net->rd; r->dynamic = dynamic; xr = RB_INSERT(kredist_tree, &kt->kredist, r); if (xr != NULL) { free(r); if (dynamic != xr->dynamic && dynamic) { /* * ignore update a non-dynamic announcement is * already present which has preference. */ return 0; } /* * only equal or non-dynamic announcement ends up here. * In both cases reset the dynamic flag (nop for equal) and * redistribute. */ xr->dynamic = dynamic; } if (send_network(IMSG_NETWORK_ADD, net, attr) == -1) log_warnx("%s: failed to send network update", __func__); return 1; } static void kr_net_redist_del(struct ktable *kt, struct network_config *net, int dynamic) { struct kredist_node *r, node; memset(&node, 0, sizeof(node)); node.prefix = net->prefix; node.prefixlen = net->prefixlen; node.rd = net->rd; r = RB_FIND(kredist_tree, &kt->kredist, &node); if (r == NULL || dynamic != r->dynamic) return; if (RB_REMOVE(kredist_tree, &kt->kredist, r) == NULL) { log_warnx("%s: failed to remove network %s/%u", __func__, log_addr(&node.prefix), node.prefixlen); return; } free(r); if (send_network(IMSG_NETWORK_REMOVE, net, NULL) == -1) log_warnx("%s: failed to send network removal", __func__); } int kr_net_match(struct ktable *kt, struct network_config *net, uint16_t flags, int loopback) { struct network *xn; TAILQ_FOREACH(xn, &kt->krn, entry) { if (xn->net.prefix.aid != net->prefix.aid) continue; switch (xn->net.type) { case NETWORK_DEFAULT: /* static match already redistributed */ continue; case NETWORK_STATIC: /* Skip networks with nexthop on loopback. */ if (loopback) continue; if (flags & F_STATIC) break; continue; case NETWORK_CONNECTED: /* Skip networks with nexthop on loopback. */ if (loopback) continue; if (flags & F_CONNECTED) break; continue; case NETWORK_RTLABEL: if (net->rtlabel == xn->net.rtlabel) break; continue; case NETWORK_PRIORITY: if (net->priority == xn->net.priority) break; continue; case NETWORK_MRTCLONE: case NETWORK_PREFIXSET: /* must not happen */ log_warnx("%s: found a NETWORK_PREFIXSET, " "please send a bug report", __func__); continue; } net->rd = xn->net.rd; if (kr_net_redist_add(kt, net, &xn->net.attrset, 1)) return (1); } return (0); } struct network * kr_net_find(struct ktable *kt, struct network *n) { struct network *xn; TAILQ_FOREACH(xn, &kt->krn, entry) { if (n->net.type != xn->net.type || n->net.prefixlen != xn->net.prefixlen || n->net.rd != xn->net.rd || n->net.rtlabel != xn->net.rtlabel || n->net.priority != xn->net.priority) continue; if (memcmp(&n->net.prefix, &xn->net.prefix, sizeof(n->net.prefix)) == 0) return (xn); } return (NULL); } void kr_net_reload(u_int rtableid, uint64_t rd, struct network_head *nh) { struct network *n, *xn; struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) fatalx("%s: non-existent rtableid %d", __func__, rtableid); while ((n = TAILQ_FIRST(nh)) != NULL) { TAILQ_REMOVE(nh, n, entry); n->net.old = 0; n->net.rd = rd; xn = kr_net_find(kt, n); if (xn) { xn->net.old = 0; filterset_free(&xn->net.attrset); filterset_move(&n->net.attrset, &xn->net.attrset); network_free(n); } else TAILQ_INSERT_TAIL(&kt->krn, n, entry); } } void kr_net_clear(struct ktable *kt) { struct network *n, *xn; TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { TAILQ_REMOVE(&kt->krn, n, entry); if (n->net.type == NETWORK_DEFAULT) kr_net_redist_del(kt, &n->net, 0); network_free(n); } } void kr_redistribute(int type, struct ktable *kt, struct kroute_full *kf) { struct network_config net; uint32_t a; int loflag = 0; memset(&net, 0, sizeof(net)); net.prefix = kf->prefix; net.prefixlen = kf->prefixlen; net.rtlabel = rtlabel_name2id(kf->label); rtlabel_unref(net.rtlabel); /* drop reference now, which is ok here */ net.priority = kf->priority; /* shortcut for removals */ if (type == IMSG_NETWORK_REMOVE) { kr_net_redist_del(kt, &net, 1); return; } if (kf->flags & F_BGPD) return; switch (kf->prefix.aid) { case AID_INET: /* * We consider the loopback net and multicast addresses * as not redistributable. */ a = ntohl(kf->prefix.v4.s_addr); if (IN_MULTICAST(a) || (a >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) return; /* Check if the nexthop is the loopback addr. */ if (kf->nexthop.v4.s_addr == htonl(INADDR_LOOPBACK)) loflag = 1; break; case AID_INET6: /* * We consider unspecified, loopback, multicast, * link- and site-local, IPv4 mapped and IPv4 compatible * addresses as not redistributable. */ if (IN6_IS_ADDR_UNSPECIFIED(&kf->prefix.v6) || IN6_IS_ADDR_LOOPBACK(&kf->prefix.v6) || IN6_IS_ADDR_MULTICAST(&kf->prefix.v6) || IN6_IS_ADDR_LINKLOCAL(&kf->prefix.v6) || IN6_IS_ADDR_SITELOCAL(&kf->prefix.v6) || IN6_IS_ADDR_V4MAPPED(&kf->prefix.v6) || IN6_IS_ADDR_V4COMPAT(&kf->prefix.v6)) return; /* Check if the nexthop is the loopback addr. */ if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) loflag = 1; break; default: /* unhandled AID cannot be redistributed */ return; } /* * never allow 0/0 or ::/0 the default route can only be redistributed * with announce default. */ if (kf->prefixlen == 0) return; if (kr_net_match(kt, &net, kf->flags, loflag) == 0) /* no longer matches, if still present remove it */ kr_net_redist_del(kt, &net, 1); } void ktable_preload(void) { struct ktable *kt; struct network *n; u_int i; for (i = 0; i < krt_size; i++) { if ((kt = ktable_get(i)) == NULL) continue; kt->state = RECONF_DELETE; /* mark all networks as old */ TAILQ_FOREACH(n, &kt->krn, entry) n->net.old = 1; } } void ktable_postload(void) { struct ktable *kt; struct network *n, *xn; u_int i; for (i = krt_size; i > 0; i--) { if ((kt = ktable_get(i - 1)) == NULL) continue; if (kt->state == RECONF_DELETE) { ktable_free(i - 1); continue; } else if (kt->state == RECONF_REINIT) kt->fib_sync = kt->fib_conf; /* cleanup old networks */ TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { if (n->net.old) { TAILQ_REMOVE(&kt->krn, n, entry); if (n->net.type == NETWORK_DEFAULT) kr_net_redist_del(kt, &n->net, 0); network_free(n); } } } } int kr_reload(void) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; struct knexthop *nh; struct network *n; u_int rid; int hasdyn = 0; for (rid = 0; rid < krt_size; rid++) { if ((kt = ktable_get(rid)) == NULL) continue; /* if this is the main nexthop table revalidate nexthops */ if (kt->rtableid == kt->nhtableid) RB_FOREACH(nh, knexthop_tree, KT2KNT(kt)) knexthop_validate(kt, nh); TAILQ_FOREACH(n, &kt->krn, entry) if (n->net.type == NETWORK_DEFAULT) { kr_net_redist_add(kt, &n->net, &n->net.attrset, 0); } else hasdyn = 1; if (hasdyn) { /* only evaluate the full tree if we need */ RB_FOREACH(kr, kroute_tree, &kt->krt) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); RB_FOREACH(kr6, kroute6_tree, &kt->krt6) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); } } return (0); } uint8_t kr_priority(struct kroute_full *kf) { if (kf->priority == RTP_MINE) return kr_state.fib_prio; return kf->priority; } struct kroute_full * kr_tofull(struct kroute *kr) { static struct kroute_full kf; memset(&kf, 0, sizeof(kf)); kf.prefix.aid = AID_INET; kf.prefix.v4.s_addr = kr->prefix.s_addr; kf.nexthop.aid = AID_INET; kf.nexthop.v4.s_addr = kr->nexthop.s_addr; strlcpy(kf.label, rtlabel_id2name(kr->labelid), sizeof(kf.label)); kf.flags = kr->flags; kf.ifindex = kr->ifindex; kf.prefixlen = kr->prefixlen; kf.priority = kr->priority; kf.mplslabel = kr->mplslabel; return (&kf); } struct kroute_full * kr6_tofull(struct kroute6 *kr6) { static struct kroute_full kf; memset(&kf, 0, sizeof(kf)); kf.prefix.aid = AID_INET6; kf.prefix.v6 = kr6->prefix; kf.prefix.scope_id = kr6->prefix_scope_id; kf.nexthop.aid = AID_INET6; kf.nexthop.v6 = kr6->nexthop; kf.nexthop.scope_id = kr6->nexthop_scope_id; strlcpy(kf.label, rtlabel_id2name(kr6->labelid), sizeof(kf.label)); kf.flags = kr6->flags; kf.ifindex = kr6->ifindex; kf.prefixlen = kr6->prefixlen; kf.priority = kr6->priority; kf.mplslabel = kr6->mplslabel; return (&kf); } /* * RB-tree compare functions */ int kroute_compare(struct kroute *a, struct kroute *b) { if (ntohl(a->prefix.s_addr) < ntohl(b->prefix.s_addr)) return (-1); if (ntohl(a->prefix.s_addr) > ntohl(b->prefix.s_addr)) return (1); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); /* if the priority is RTP_ANY finish on the first address hit */ if (a->priority == RTP_ANY || b->priority == RTP_ANY) return (0); if (a->priority < b->priority) return (-1); if (a->priority > b->priority) return (1); return (0); } int kroute6_compare(struct kroute6 *a, struct kroute6 *b) { int i; for (i = 0; i < 16; i++) { if (a->prefix.s6_addr[i] < b->prefix.s6_addr[i]) return (-1); if (a->prefix.s6_addr[i] > b->prefix.s6_addr[i]) return (1); } if (a->prefix_scope_id < b->prefix_scope_id) return (-1); if (a->prefix_scope_id > b->prefix_scope_id) return (1); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); /* if the priority is RTP_ANY finish on the first address hit */ if (a->priority == RTP_ANY || b->priority == RTP_ANY) return (0); if (a->priority < b->priority) return (-1); if (a->priority > b->priority) return (1); return (0); } int knexthop_compare(struct knexthop *a, struct knexthop *b) { int i; if (a->nexthop.aid != b->nexthop.aid) return (b->nexthop.aid - a->nexthop.aid); switch (a->nexthop.aid) { case AID_INET: if (ntohl(a->nexthop.v4.s_addr) < ntohl(b->nexthop.v4.s_addr)) return (-1); if (ntohl(a->nexthop.v4.s_addr) > ntohl(b->nexthop.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->nexthop.v6.s6_addr[i] < b->nexthop.v6.s6_addr[i]) return (-1); if (a->nexthop.v6.s6_addr[i] > b->nexthop.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } return (0); } int kredist_compare(struct kredist_node *a, struct kredist_node *b) { int i; if (a->prefix.aid != b->prefix.aid) return (b->prefix.aid - a->prefix.aid); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); switch (a->prefix.aid) { case AID_INET: if (ntohl(a->prefix.v4.s_addr) < ntohl(b->prefix.v4.s_addr)) return (-1); if (ntohl(a->prefix.v4.s_addr) > ntohl(b->prefix.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->prefix.v6.s6_addr[i] < b->prefix.v6.s6_addr[i]) return (-1); if (a->prefix.v6.s6_addr[i] > b->prefix.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } if (a->rd < b->rd) return (-1); if (a->rd > b->rd) return (1); return (0); } int kif_compare(struct kif *a, struct kif *b) { return (b->ifindex - a->ifindex); } /* * tree management functions */ struct kroute * kroute_find(struct ktable *kt, const struct bgpd_addr *prefix, uint8_t prefixlen, uint8_t prio) { struct kroute s; struct kroute *kn, *tmp; s.prefix = prefix->v4; s.prefixlen = prefixlen; s.priority = prio; kn = RB_FIND(kroute_tree, &kt->krt, &s); if (kn && prio == RTP_ANY) { tmp = RB_PREV(kroute_tree, &kt->krt, kn); while (tmp) { if (kroute_compare(&s, tmp) == 0) kn = tmp; else break; tmp = RB_PREV(kroute_tree, &kt->krt, kn); } } return (kn); } struct kroute * kroute_matchgw(struct kroute *kr, struct kroute_full *kf) { in_addr_t nexthop; if (kf->flags & F_CONNECTED) { do { if (kr->ifindex == kf->ifindex) return (kr); kr = kr->next; } while (kr); return (NULL); } nexthop = kf->nexthop.v4.s_addr; do { if (kr->nexthop.s_addr == nexthop) return (kr); kr = kr->next; } while (kr); return (NULL); } int kroute_insert(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr, *krm; struct kroute6 *kr6, *kr6m; struct knexthop *n; uint32_t mplslabel = 0; int multipath = 0; if (kf->prefix.aid == AID_VPN_IPv4 || kf->prefix.aid == AID_VPN_IPv6) { /* only a single MPLS label is supported for now */ if (kf->prefix.labellen != 3) { log_warnx("%s/%u does not have a single label", log_addr(&kf->prefix), kf->prefixlen); return -1; } mplslabel = (kf->prefix.labelstack[0] << 24) | (kf->prefix.labelstack[1] << 16) | (kf->prefix.labelstack[2] << 8); } switch (kf->prefix.aid) { case AID_INET: case AID_VPN_IPv4: if ((kr = calloc(1, sizeof(*kr))) == NULL) { log_warn("%s", __func__); return (-1); } kr->flags = kf->flags; kr->prefix = kf->prefix.v4; kr->prefixlen = kf->prefixlen; if (kf->nexthop.aid == AID_INET) kr->nexthop = kf->nexthop.v4; if (kf->prefix.aid == AID_VPN_IPv4) { kr->flags |= F_MPLS; kr->mplslabel = htonl(mplslabel); } kr->ifindex = kf->ifindex; kr->priority = kf->priority; kr->labelid = rtlabel_name2id(kf->label); if ((krm = RB_INSERT(kroute_tree, &kt->krt, kr)) != NULL) { /* multipath route, add at end of list */ while (krm->next != NULL) krm = krm->next; krm->next = kr; multipath = 1; } if (kf->flags & F_BGPD) if (send_rtmsg(RTM_ADD, kt, kf)) kr->flags |= F_BGPD_INSERTED; break; case AID_INET6: case AID_VPN_IPv6: if ((kr6 = calloc(1, sizeof(*kr6))) == NULL) { log_warn("%s", __func__); return (-1); } kr6->flags = kf->flags; kr6->prefix = kf->prefix.v6; kr6->prefix_scope_id = kf->prefix.scope_id; kr6->prefixlen = kf->prefixlen; if (kf->nexthop.aid == AID_INET6) { kr6->nexthop = kf->nexthop.v6; kr6->nexthop_scope_id = kf->nexthop.scope_id; } else kr6->nexthop = in6addr_any; if (kf->prefix.aid == AID_VPN_IPv6) { kr6->flags |= F_MPLS; kr6->mplslabel = htonl(mplslabel); } kr6->ifindex = kf->ifindex; kr6->priority = kf->priority; kr6->labelid = rtlabel_name2id(kf->label); if ((kr6m = RB_INSERT(kroute6_tree, &kt->krt6, kr6)) != NULL) { /* multipath route, add at end of list */ while (kr6m->next != NULL) kr6m = kr6m->next; kr6m->next = kr6; multipath = 1; } if (kf->flags & F_BGPD) if (send_rtmsg(RTM_ADD, kt, kf)) kr6->flags |= F_BGPD_INSERTED; break; } if (bgpd_has_bgpnh() || !(kf->flags & F_BGPD)) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) if (prefix_compare(&kf->prefix, &n->nexthop, kf->prefixlen) == 0) knexthop_validate(kt, n); } if (!(kf->flags & F_BGPD)) { /* redistribute multipath routes only once */ if (!multipath) kr_redistribute(IMSG_NETWORK_ADD, kt, kf); } return (0); } static int kroute4_remove(struct ktable *kt, struct kroute_full *kf, int any) { struct kroute *kr, *krm; struct knexthop *n; int multipath = 1; if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (-1); if ((kr->flags & F_BGPD) != (kf->flags & F_BGPD)) { log_warnx("%s: wrong type for %s/%u", __func__, log_addr(&kf->prefix), kf->prefixlen); if (!(kf->flags & F_BGPD)) kr->flags &= ~F_BGPD_INSERTED; return (-1); } /* get the correct route to remove */ krm = kr; if (!any) { if ((krm = kroute_matchgw(kr, kf)) == NULL) { log_warnx("delete %s/%u: route not found", log_addr(&kf->prefix), kf->prefixlen); return (-2); } } if (krm == kr) { /* head element */ RB_REMOVE(kroute_tree, &kt->krt, krm); if (krm->next != NULL) { kr = krm->next; if (RB_INSERT(kroute_tree, &kt->krt, kr) != NULL) { log_warnx("%s: failed to add %s/%u", __func__, inet_ntoa(kr->prefix), kr->prefixlen); return (-2); } } else { multipath = 0; } } else { /* somewhere in the list */ while (kr->next != krm && kr->next != NULL) kr = kr->next; if (kr->next == NULL) { log_warnx("%s: multipath list corrupted for %s/%u", __func__, inet_ntoa(kr->prefix), kr->prefixlen); return (-2); } kr->next = krm->next; } /* check whether a nexthop depends on this kroute */ if (krm->flags & F_NEXTHOP) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) { if (n->kroute == krm) knexthop_validate(kt, n); } } *kf = *kr_tofull(krm); rtlabel_unref(krm->labelid); free(krm); return (multipath); } static int kroute6_remove(struct ktable *kt, struct kroute_full *kf, int any) { struct kroute6 *kr, *krm; struct knexthop *n; int multipath = 1; if ((kr = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (-1); if ((kr->flags & F_BGPD) != (kf->flags & F_BGPD)) { log_warnx("%s: wrong type for %s/%u", __func__, log_addr(&kf->prefix), kf->prefixlen); if (!(kf->flags & F_BGPD)) kr->flags &= ~F_BGPD_INSERTED; return (-1); } /* get the correct route to remove */ krm = kr; if (!any) { if ((krm = kroute6_matchgw(kr, kf)) == NULL) { log_warnx("delete %s/%u: route not found", log_addr(&kf->prefix), kf->prefixlen); return (-2); } } if (krm == kr) { /* head element */ RB_REMOVE(kroute6_tree, &kt->krt6, krm); if (krm->next != NULL) { kr = krm->next; if (RB_INSERT(kroute6_tree, &kt->krt6, kr) != NULL) { log_warnx("%s: failed to add %s/%u", __func__, log_in6addr(&kr->prefix), kr->prefixlen); return (-2); } } else { multipath = 0; } } else { /* somewhere in the list */ while (kr->next != krm && kr->next != NULL) kr = kr->next; if (kr->next == NULL) { log_warnx("%s: multipath list corrupted for %s/%u", __func__, log_in6addr(&kr->prefix), kr->prefixlen); return (-2); } kr->next = krm->next; } /* check whether a nexthop depends on this kroute */ if (krm->flags & F_NEXTHOP) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) { if (n->kroute == krm) knexthop_validate(kt, n); } } *kf = *kr6_tofull(krm); rtlabel_unref(krm->labelid); free(krm); return (multipath); } int kroute_remove(struct ktable *kt, struct kroute_full *kf, int any) { int multipath; switch (kf->prefix.aid) { case AID_INET: case AID_VPN_IPv4: multipath = kroute4_remove(kt, kf, any); break; case AID_INET6: case AID_VPN_IPv6: multipath = kroute6_remove(kt, kf, any); break; case AID_EVPN: /* XXX ignored for now */ return (0); default: log_warnx("%s: not handled AID", __func__); return (-1); } if (multipath < 0) return (multipath + 1); if (kf->flags & F_BGPD_INSERTED) send_rtmsg(RTM_DELETE, kt, kf); /* remove only once all multipath routes are gone */ if (!(kf->flags & F_BGPD) && !multipath) kr_redistribute(IMSG_NETWORK_REMOVE, kt, kf); return (0); } void kroute_clear(struct ktable *kt) { struct kroute *kr; while ((kr = RB_MIN(kroute_tree, &kt->krt)) != NULL) kroute_remove(kt, kr_tofull(kr), 1); } struct kroute6 * kroute6_find(struct ktable *kt, const struct bgpd_addr *prefix, uint8_t prefixlen, uint8_t prio) { struct kroute6 s; struct kroute6 *kn6, *tmp; s.prefix = prefix->v6; s.prefix_scope_id = prefix->scope_id; s.prefixlen = prefixlen; s.priority = prio; kn6 = RB_FIND(kroute6_tree, &kt->krt6, &s); if (kn6 && prio == RTP_ANY) { tmp = RB_PREV(kroute6_tree, &kt->krt6, kn6); while (tmp) { if (kroute6_compare(&s, tmp) == 0) kn6 = tmp; else break; tmp = RB_PREV(kroute6_tree, &kt->krt6, kn6); } } return (kn6); } struct kroute6 * kroute6_matchgw(struct kroute6 *kr, struct kroute_full *kf) { struct in6_addr nexthop; if (kf->flags & F_CONNECTED) { do { if (kr->ifindex == kf->ifindex) return (kr); kr = kr->next; } while (kr); return (NULL); } nexthop = kf->nexthop.v6; do { if (memcmp(&kr->nexthop, &nexthop, sizeof(nexthop)) == 0 && kr->nexthop_scope_id == kf->nexthop.scope_id) return (kr); kr = kr->next; } while (kr); return (NULL); } void kroute6_clear(struct ktable *kt) { struct kroute6 *kr; while ((kr = RB_MIN(kroute6_tree, &kt->krt6)) != NULL) kroute_remove(kt, kr6_tofull(kr), 1); } struct knexthop * knexthop_find(struct ktable *kt, struct bgpd_addr *addr) { struct knexthop s; memset(&s, 0, sizeof(s)); memcpy(&s.nexthop, addr, sizeof(s.nexthop)); return (RB_FIND(knexthop_tree, KT2KNT(kt), &s)); } int knexthop_insert(struct ktable *kt, struct knexthop *kn) { if (RB_INSERT(knexthop_tree, KT2KNT(kt), kn) != NULL) { log_warnx("%s: failed for %s", __func__, log_addr(&kn->nexthop)); free(kn); return (-1); } knexthop_validate(kt, kn); return (0); } void knexthop_remove(struct ktable *kt, struct knexthop *kn) { kroute_detach_nexthop(kt, kn); RB_REMOVE(knexthop_tree, KT2KNT(kt), kn); free(kn); } void knexthop_clear(struct ktable *kt) { struct knexthop *kn; while ((kn = RB_MIN(knexthop_tree, KT2KNT(kt))) != NULL) knexthop_remove(kt, kn); } struct kif * kif_find(int ifindex) { struct kif s; memset(&s, 0, sizeof(s)); s.ifindex = ifindex; return (RB_FIND(kif_tree, &kit, &s)); } int kif_insert(struct kif *kif) { if (RB_INSERT(kif_tree, &kit, kif) != NULL) { log_warnx("RB_INSERT(kif_tree, &kit, kif)"); free(kif); return (-1); } return (0); } int kif_remove(struct kif *kif) { struct ktable *kt; kif->flags &= ~IFF_UP; /* * TODO, remove all kroutes using this interface, * the kernel does this for us but better to do it * here as well. */ if ((kt = ktable_get(kif->rdomain)) != NULL) knexthop_track(kt, kif->ifindex); RB_REMOVE(kif_tree, &kit, kif); free(kif); return (0); } void kif_clear(void) { struct kif *kif; while ((kif = RB_MIN(kif_tree, &kit)) != NULL) kif_remove(kif); } /* * nexthop validation */ static int kif_validate(struct kif *kif) { if (!(kif->flags & IFF_UP)) return (0); /* * we treat link_state == LINK_STATE_UNKNOWN as valid, * not all interfaces have a concept of "link state" and/or * do not report up */ if (kif->link_state == LINK_STATE_DOWN) return (0); return (1); } /* * return 1 when the interface is up and the link state is up or unknown * except when this is a carp interface, then return 1 only when link state * is up */ static int kif_depend_state(struct kif *kif) { if (!(kif->flags & IFF_UP)) return (0); if (kif->if_type == IFT_CARP && kif->link_state == LINK_STATE_UNKNOWN) return (0); return LINK_STATE_IS_UP(kif->link_state); } int kroute_validate(struct kroute *kr) { struct kif *kif; if (kr->flags & (F_REJECT | F_BLACKHOLE)) return (0); if ((kif = kif_find(kr->ifindex)) == NULL) { if (kr->ifindex) log_warnx("%s: interface with index %d not found, " "referenced from route for %s/%u", __func__, kr->ifindex, inet_ntoa(kr->prefix), kr->prefixlen); return (1); } return (kif->nh_reachable); } int kroute6_validate(struct kroute6 *kr) { struct kif *kif; if (kr->flags & (F_REJECT | F_BLACKHOLE)) return (0); if ((kif = kif_find(kr->ifindex)) == NULL) { if (kr->ifindex) log_warnx("%s: interface with index %d not found, " "referenced from route for %s/%u", __func__, kr->ifindex, log_in6addr(&kr->prefix), kr->prefixlen); return (1); } return (kif->nh_reachable); } int knexthop_true_nexthop(struct ktable *kt, struct kroute_full *kf) { struct bgpd_addr gateway = { 0 }; struct knexthop *kn; struct kroute *kr; struct kroute6 *kr6; /* * Ignore the nexthop for VPN routes. The gateway is forced * to an mpe(4) interface route using an MPLS label. */ switch (kf->prefix.aid) { case AID_VPN_IPv4: case AID_VPN_IPv6: return 1; } kn = knexthop_find(kt, &kf->nexthop); if (kn == NULL) { log_warnx("%s: nexthop %s not found", __func__, log_addr(&kf->nexthop)); return 0; } if (kn->kroute == NULL) return 0; switch (kn->nexthop.aid) { case AID_INET: kr = kn->kroute; if (kr->flags & F_CONNECTED) return 1; gateway.aid = AID_INET; gateway.v4.s_addr = kr->nexthop.s_addr; break; case AID_INET6: kr6 = kn->kroute; if (kr6->flags & F_CONNECTED) return 1; gateway.aid = AID_INET6; gateway.v6 = kr6->nexthop; gateway.scope_id = kr6->nexthop_scope_id; break; } kf->nexthop = gateway; return 1; } void knexthop_validate(struct ktable *kt, struct knexthop *kn) { void *oldk; struct kroute *kr; struct kroute6 *kr6; oldk = kn->kroute; kroute_detach_nexthop(kt, kn); if ((kt = ktable_get(kt->nhtableid)) == NULL) fatalx("%s: lost nexthop routing table", __func__); switch (kn->nexthop.aid) { case AID_INET: kr = kroute_match(kt, &kn->nexthop, 0); if (kr != NULL) { kn->kroute = kr; kn->ifindex = kr->ifindex; kr->flags |= F_NEXTHOP; } /* * Send update if nexthop route changed under us if * the route remains the same then the NH state has not * changed. */ if (kr != oldk) knexthop_send_update(kn); break; case AID_INET6: kr6 = kroute6_match(kt, &kn->nexthop, 0); if (kr6 != NULL) { kn->kroute = kr6; kn->ifindex = kr6->ifindex; kr6->flags |= F_NEXTHOP; } if (kr6 != oldk) knexthop_send_update(kn); break; } } /* * Called on interface state change. */ void knexthop_track(struct ktable *kt, u_short ifindex) { struct knexthop *kn; RB_FOREACH(kn, knexthop_tree, KT2KNT(kt)) if (kn->ifindex == ifindex) knexthop_validate(kt, kn); } /* * Called on route change. */ void knexthop_update(struct ktable *kt, struct kroute_full *kf) { struct knexthop *kn; RB_FOREACH(kn, knexthop_tree, KT2KNT(kt)) if (prefix_compare(&kf->prefix, &kn->nexthop, kf->prefixlen) == 0) knexthop_send_update(kn); } void knexthop_send_update(struct knexthop *kn) { struct kroute_nexthop n; struct kroute *kr; struct kroute6 *kr6; memset(&n, 0, sizeof(n)); n.nexthop = kn->nexthop; if (kn->kroute == NULL) { n.valid = 0; /* NH is not valid */ send_nexthop_update(&n); return; } switch (kn->nexthop.aid) { case AID_INET: kr = kn->kroute; n.valid = kroute_validate(kr); n.connected = kr->flags & F_CONNECTED; if (!n.connected) { n.gateway.aid = AID_INET; n.gateway.v4.s_addr = kr->nexthop.s_addr; } else { n.gateway = n.nexthop; n.net.aid = AID_INET; n.net.v4.s_addr = kr->prefix.s_addr; n.netlen = kr->prefixlen; } break; case AID_INET6: kr6 = kn->kroute; n.valid = kroute6_validate(kr6); n.connected = kr6->flags & F_CONNECTED; if (!n.connected) { n.gateway.aid = AID_INET6; n.gateway.v6 = kr6->nexthop; n.gateway.scope_id = kr6->nexthop_scope_id; } else { n.gateway = n.nexthop; n.net.aid = AID_INET6; n.net.v6 = kr6->prefix; n.net.scope_id = kr6->prefix_scope_id; n.netlen = kr6->prefixlen; } break; } send_nexthop_update(&n); } struct kroute * kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchany) { int i; struct kroute *kr; struct bgpd_addr masked; for (i = 32; i >= 0; i--) { applymask(&masked, key, i); if ((kr = kroute_find(kt, &masked, i, RTP_ANY)) != NULL) if (matchany || bgpd_oknexthop(kr_tofull(kr))) return (kr); } return (NULL); } struct kroute6 * kroute6_match(struct ktable *kt, struct bgpd_addr *key, int matchany) { int i; struct kroute6 *kr6; struct bgpd_addr masked; for (i = 128; i >= 0; i--) { applymask(&masked, key, i); if ((kr6 = kroute6_find(kt, &masked, i, RTP_ANY)) != NULL) if (matchany || bgpd_oknexthop(kr6_tofull(kr6))) return (kr6); } return (NULL); } void kroute_detach_nexthop(struct ktable *kt, struct knexthop *kn) { struct knexthop *s; struct kroute *k; struct kroute6 *k6; if (kn->kroute == NULL) return; /* * check whether there's another nexthop depending on this kroute * if not remove the flag */ RB_FOREACH(s, knexthop_tree, KT2KNT(kt)) if (s->kroute == kn->kroute && s != kn) break; if (s == NULL) { switch (kn->nexthop.aid) { case AID_INET: k = kn->kroute; k->flags &= ~F_NEXTHOP; break; case AID_INET6: k6 = kn->kroute; k6->flags &= ~F_NEXTHOP; break; } } kn->kroute = NULL; kn->ifindex = 0; } /* * misc helpers */ uint8_t prefixlen_classful(in_addr_t ina) { /* it hurt to write this. */ if (ina >= 0xf0000000U) /* class E */ return (32); else if (ina >= 0xe0000000U) /* class D */ return (4); else if (ina >= 0xc0000000U) /* class C */ return (24); else if (ina >= 0x80000000U) /* class B */ return (16); else /* class A */ return (8); } static uint8_t mask2prefixlen4(struct sockaddr_in *sa_in) { in_addr_t ina; ina = sa_in->sin_addr.s_addr; if (ina == 0) return (0); else return (33 - ffs(ntohl(ina))); } static uint8_t mask2prefixlen6(struct sockaddr_in6 *sa_in6) { uint8_t *ap, *ep; u_int l = 0; /* * sin6_len is the size of the sockaddr so subtract the offset of * the possibly truncated sin6_addr struct. */ ap = (uint8_t *)&sa_in6->sin6_addr; ep = (uint8_t *)sa_in6 + sa_in6->sin6_len; for (; ap < ep; ap++) { /* this "beauty" is adopted from sbin/route/show.c ... */ switch (*ap) { case 0xff: l += 8; break; case 0xfe: l += 7; goto done; case 0xfc: l += 6; goto done; case 0xf8: l += 5; goto done; case 0xf0: l += 4; goto done; case 0xe0: l += 3; goto done; case 0xc0: l += 2; goto done; case 0x80: l += 1; goto done; case 0x00: goto done; default: fatalx("non contiguous inet6 netmask"); } } done: if (l > sizeof(struct in6_addr) * 8) fatalx("%s: prefixlen %d out of bound", __func__, l); return (l); } uint8_t mask2prefixlen(sa_family_t af, struct sockaddr *mask) { switch (af) { case AF_INET: return mask2prefixlen4((struct sockaddr_in *)mask); case AF_INET6: return mask2prefixlen6((struct sockaddr_in6 *)mask); default: fatalx("%s: unsupported af", __func__); } } const struct if_status_description if_status_descriptions[] = LINK_STATE_DESCRIPTIONS; const struct ifmedia_description ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS; uint64_t ift2ifm(uint8_t if_type) { switch (if_type) { case IFT_ETHER: return (IFM_ETHER); case IFT_FDDI: return (IFM_FDDI); case IFT_CARP: return (IFM_CARP); case IFT_IEEE80211: return (IFM_IEEE80211); default: return (0); } } const char * get_media_descr(uint64_t media_type) { const struct ifmedia_description *p; for (p = ifm_type_descriptions; p->ifmt_string != NULL; p++) if (media_type == p->ifmt_word) return (p->ifmt_string); return ("unknown media"); } const char * get_linkstate(uint8_t if_type, int link_state) { const struct if_status_description *p; static char buf[8]; for (p = if_status_descriptions; p->ifs_string != NULL; p++) { if (LINK_STATE_DESC_MATCH(p, if_type, link_state)) return (p->ifs_string); } snprintf(buf, sizeof(buf), "[#%d]", link_state); return (buf); } #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) void get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) { int i; for (i = 0; i < RTAX_MAX; i++) { if (addrs & (1 << i)) { rti_info[i] = sa; sa = (struct sockaddr *)((char *)(sa) + ROUNDUP(sa->sa_len)); } else rti_info[i] = NULL; } } void if_change(u_short ifindex, int flags, struct if_data *ifd) { struct ktable *kt; struct kif *kif; uint8_t reachable; if ((kif = kif_find(ifindex)) == NULL) { log_warnx("%s: interface with index %u not found", __func__, ifindex); return; } log_info("%s: %s: rdomain %u %s, %s, %s, %s", __func__, kif->ifname, ifd->ifi_rdomain, flags & IFF_UP ? "UP" : "DOWN", get_media_descr(ift2ifm(ifd->ifi_type)), get_linkstate(ifd->ifi_type, ifd->ifi_link_state), get_baudrate(ifd->ifi_baudrate, "bps")); kif->flags = flags; kif->link_state = ifd->ifi_link_state; kif->if_type = ifd->ifi_type; kif->rdomain = ifd->ifi_rdomain; kif->baudrate = ifd->ifi_baudrate; kif->depend_state = kif_depend_state(kif); kr_send_dependon(kif); if ((reachable = kif_validate(kif)) == kif->nh_reachable) return; /* nothing changed wrt nexthop validity */ kif->nh_reachable = reachable; kt = ktable_get(kif->rdomain); if (kt == NULL) return; knexthop_track(kt, ifindex); } void if_announce(void *msg) { struct if_announcemsghdr *ifan; struct kif *kif; ifan = msg; switch (ifan->ifan_what) { case IFAN_ARRIVAL: if ((kif = calloc(1, sizeof(*kif))) == NULL) { log_warn("%s", __func__); return; } kif->ifindex = ifan->ifan_index; strlcpy(kif->ifname, ifan->ifan_name, sizeof(kif->ifname)); kif_insert(kif); break; case IFAN_DEPARTURE: kif = kif_find(ifan->ifan_index); if (kif != NULL) kif_remove(kif); break; } } int get_mpe_config(const char *name, u_int *rdomain, u_int *label) { struct ifreq ifr; struct shim_hdr shim; int s; *label = 0; *rdomain = 0; s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); if (s == -1) return (-1); memset(&shim, 0, sizeof(shim)); memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); ifr.ifr_data = (caddr_t)&shim; if (ioctl(s, SIOCGETLABEL, (caddr_t)&ifr) == -1) { close(s); return (-1); } ifr.ifr_data = NULL; if (ioctl(s, SIOCGIFRDOMAIN, (caddr_t)&ifr) == -1) { close(s); return (-1); } close(s); *rdomain = ifr.ifr_rdomainid; *label = shim.shim_label; return (0); } /* * rtsock related functions */ #define satosin6(sa) ((struct sockaddr_in6 *)(sa)) int send_rtmsg(int action, struct ktable *kt, struct kroute_full *kf) { struct iovec iov[7]; struct rt_msghdr hdr; struct sockaddr_storage prefix, nexthop, mask, ifp, label, mpls; struct bgpd_addr netmask; struct sockaddr *sa; struct sockaddr_dl *dl; struct sockaddr_mpls *mp; struct sockaddr_rtlabel *la; socklen_t salen; int iovcnt = 0; if (!kt->fib_sync) return (0); /* initialize header */ memset(&hdr, 0, sizeof(hdr)); hdr.rtm_version = RTM_VERSION; hdr.rtm_type = action; hdr.rtm_tableid = kt->rtableid; hdr.rtm_priority = kr_state.fib_prio; if (kf->flags & F_BLACKHOLE) hdr.rtm_flags |= RTF_BLACKHOLE; if (kf->flags & F_REJECT) hdr.rtm_flags |= RTF_REJECT; if (action == RTM_CHANGE) /* reset these flags on change */ hdr.rtm_fmask = RTF_REJECT|RTF_BLACKHOLE; hdr.rtm_seq = kr_state.rtseq++; /* overflow doesn't matter */ hdr.rtm_msglen = sizeof(hdr); /* adjust iovec */ iov[iovcnt].iov_base = &hdr; iov[iovcnt++].iov_len = sizeof(hdr); memset(&prefix, 0, sizeof(prefix)); sa = addr2sa(&kf->prefix, 0, &salen); sa->sa_len = salen; #ifdef __KAME__ /* XXX need to embed the stupid scope for now */ if (sa->sa_family == AF_INET6 && (IN6_IS_ADDR_LINKLOCAL(&satosin6(sa)->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&satosin6(sa)->sin6_addr) || IN6_IS_ADDR_MC_NODELOCAL(&satosin6(sa)->sin6_addr))) { *(u_int16_t *)&satosin6(sa)->sin6_addr.s6_addr[2] = htons(satosin6(sa)->sin6_scope_id); satosin6(sa)->sin6_scope_id = 0; } #endif memcpy(&prefix, sa, salen); /* adjust header */ hdr.rtm_addrs |= RTA_DST; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &prefix; iov[iovcnt++].iov_len = ROUNDUP(salen); /* XXX can we even have no nexthop ??? */ if (kf->nexthop.aid != AID_UNSPEC) { memset(&nexthop, 0, sizeof(nexthop)); sa = addr2sa(&kf->nexthop, 0, &salen); sa->sa_len = salen; #ifdef __KAME__ /* XXX need to embed the stupid scope for now */ if (sa->sa_family == AF_INET6 && (IN6_IS_ADDR_LINKLOCAL(&satosin6(sa)->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&satosin6(sa)->sin6_addr) || IN6_IS_ADDR_MC_NODELOCAL(&satosin6(sa)->sin6_addr))) { *(u_int16_t *)&satosin6(sa)->sin6_addr.s6_addr[2] = htons(satosin6(sa)->sin6_scope_id); satosin6(sa)->sin6_scope_id = 0; } #endif memcpy(&nexthop, sa, salen); /* adjust header */ hdr.rtm_flags |= RTF_GATEWAY; hdr.rtm_addrs |= RTA_GATEWAY; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &nexthop; iov[iovcnt++].iov_len = ROUNDUP(salen); } memset(&netmask, 0, sizeof(netmask)); memset(&netmask.v6, 0xff, sizeof(netmask.v6)); netmask.aid = kf->prefix.aid; applymask(&netmask, &netmask, kf->prefixlen); memset(&mask, 0, sizeof(mask)); sa = addr2sa(&netmask, 0, &salen); sa->sa_len = salen; memcpy(&mask, sa, salen); /* adjust header */ hdr.rtm_addrs |= RTA_NETMASK; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &mask; iov[iovcnt++].iov_len = ROUNDUP(salen); if (kf->flags & F_MPLS) { /* need to force interface for mpe(4) routes */ memset(&ifp, 0, sizeof(ifp)); dl = (struct sockaddr_dl *)&ifp; salen = sizeof(*dl); dl->sdl_len = salen; dl->sdl_family = AF_LINK; dl->sdl_index = kf->ifindex; /* adjust header */ hdr.rtm_addrs |= RTA_IFP; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &ifp; iov[iovcnt++].iov_len = ROUNDUP(salen); memset(&mpls, 0, sizeof(mpls)); mp = (struct sockaddr_mpls *)&mpls; salen = sizeof(*mp); mp->smpls_len = salen; mp->smpls_family = AF_MPLS; mp->smpls_label = kf->mplslabel; /* adjust header */ hdr.rtm_flags |= RTF_MPLS; hdr.rtm_mpls = MPLS_OP_PUSH; hdr.rtm_addrs |= RTA_SRC; hdr.rtm_msglen += ROUNDUP(salen); /* clear gateway flag since this is for mpe(4) */ hdr.rtm_flags &= ~RTF_GATEWAY; /* adjust iovec */ iov[iovcnt].iov_base = &mpls; iov[iovcnt++].iov_len = ROUNDUP(salen); } if (kf->label[0] != '\0') { memset(&label, 0, sizeof(label)); la = (struct sockaddr_rtlabel *)&label; salen = sizeof(struct sockaddr_rtlabel); label.ss_len = salen; strlcpy(la->sr_label, kf->label, sizeof(la->sr_label)); /* adjust header */ hdr.rtm_addrs |= RTA_LABEL; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &label; iov[iovcnt++].iov_len = ROUNDUP(salen); } retry: if (writev(kr_state.fd, iov, iovcnt) == -1) { if (errno == ESRCH) { if (hdr.rtm_type == RTM_CHANGE) { hdr.rtm_type = RTM_ADD; goto retry; } else if (hdr.rtm_type == RTM_DELETE) { log_info("route %s/%u vanished before delete", log_addr(&kf->prefix), kf->prefixlen); return (1); } } log_warn("%s: action %u, prefix %s/%u", __func__, hdr.rtm_type, log_addr(&kf->prefix), kf->prefixlen); return (0); } return (1); } int fetchtable(struct ktable *kt) { size_t len; int mib[7]; char *buf = NULL, *next, *lim; struct rt_msghdr *rtm; struct kroute_full kf; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_DUMP; mib[5] = 0; mib[6] = kt->rtableid; if (sysctl(mib, 7, NULL, &len, NULL, 0) == -1) { if (kt->rtableid != 0 && errno == EINVAL) /* table nonexistent */ return (0); log_warn("%s: sysctl", __func__); return (-1); } if (len > 0) { if ((buf = malloc(len)) == NULL) { log_warn("%s", __func__); return (-1); } if (sysctl(mib, 7, buf, &len, NULL, 0) == -1) { log_warn("%s: sysctl2", __func__); free(buf); return (-1); } } lim = buf + len; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; if (rtm->rtm_version != RTM_VERSION) continue; if (dispatch_rtmsg_addr(rtm, &kf) == -1) continue; if (kf.priority == RTP_MINE) send_rtmsg(RTM_DELETE, kt, &kf); else kroute_insert(kt, &kf); } free(buf); return (0); } int fetchifs(int ifindex) { size_t len; int mib[6]; char *buf, *next, *lim; struct if_msghdr ifm; struct kif *kif; struct sockaddr *sa, *rti_info[RTAX_MAX]; struct sockaddr_dl *sdl; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = AF_INET; /* AF does not matter but AF_INET is shorter */ mib[4] = NET_RT_IFLIST; mib[5] = ifindex; if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) { log_warn("%s: sysctl", __func__); return (-1); } if ((buf = malloc(len)) == NULL) { log_warn("%s", __func__); return (-1); } if (sysctl(mib, 6, buf, &len, NULL, 0) == -1) { log_warn("%s: sysctl2", __func__); free(buf); return (-1); } lim = buf + len; for (next = buf; next < lim; next += ifm.ifm_msglen) { memcpy(&ifm, next, sizeof(ifm)); if (ifm.ifm_version != RTM_VERSION) continue; if (ifm.ifm_type != RTM_IFINFO) continue; sa = (struct sockaddr *)(next + sizeof(ifm)); get_rtaddrs(ifm.ifm_addrs, sa, rti_info); if ((kif = calloc(1, sizeof(*kif))) == NULL) { log_warn("%s", __func__); free(buf); return (-1); } kif->ifindex = ifm.ifm_index; kif->flags = ifm.ifm_flags; kif->link_state = ifm.ifm_data.ifi_link_state; kif->if_type = ifm.ifm_data.ifi_type; kif->rdomain = ifm.ifm_data.ifi_rdomain; kif->baudrate = ifm.ifm_data.ifi_baudrate; kif->nh_reachable = kif_validate(kif); kif->depend_state = kif_depend_state(kif); if ((sa = rti_info[RTAX_IFP]) != NULL) if (sa->sa_family == AF_LINK) { sdl = (struct sockaddr_dl *)sa; if (sdl->sdl_nlen >= sizeof(kif->ifname)) memcpy(kif->ifname, sdl->sdl_data, sizeof(kif->ifname) - 1); else if (sdl->sdl_nlen > 0) memcpy(kif->ifname, sdl->sdl_data, sdl->sdl_nlen); /* string already terminated via calloc() */ } kif_insert(kif); } free(buf); return (0); } int dispatch_rtmsg(void) { char buf[RT_BUF_SIZE]; ssize_t n; char *next, *lim; struct rt_msghdr *rtm; struct if_msghdr ifm; struct kroute_full kf; struct ktable *kt; int mpath = 0; if ((n = read(kr_state.fd, &buf, sizeof(buf))) == -1) { if (errno == EAGAIN || errno == EINTR) return (0); log_warn("%s: read error", __func__); return (-1); } if (n == 0) { log_warnx("routing socket closed"); return (-1); } lim = buf + n; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; if (lim < next + sizeof(u_short) || lim < next + rtm->rtm_msglen) fatalx("%s: partial rtm in buffer", __func__); if (rtm->rtm_version != RTM_VERSION) continue; switch (rtm->rtm_type) { case RTM_ADD: case RTM_CHANGE: case RTM_DELETE: if (rtm->rtm_pid == kr_state.pid) /* cause by us */ continue; /* failed attempts */ if (rtm->rtm_errno || !(rtm->rtm_flags & RTF_DONE)) continue; if ((kt = ktable_get(rtm->rtm_tableid)) == NULL) continue; if (dispatch_rtmsg_addr(rtm, &kf) == -1) continue; if (rtm->rtm_flags & RTF_MPATH) mpath = 1; switch (rtm->rtm_type) { case RTM_ADD: case RTM_CHANGE: if (kr_fib_change(kt, &kf, rtm->rtm_type, mpath) == -1) return -1; break; case RTM_DELETE: if (kr_fib_delete(kt, &kf, mpath) == -1) return -1; break; } break; case RTM_IFINFO: memcpy(&ifm, next, sizeof(ifm)); if_change(ifm.ifm_index, ifm.ifm_flags, &ifm.ifm_data); break; case RTM_IFANNOUNCE: if_announce(next); break; default: /* ignore for now */ break; } } return (0); } int dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct kroute_full *kf) { struct sockaddr *sa, *rti_info[RTAX_MAX]; struct sockaddr_in *sa_in; struct sockaddr_in6 *sa_in6; struct sockaddr_rtlabel *label; sa = (struct sockaddr *)((char *)rtm + rtm->rtm_hdrlen); get_rtaddrs(rtm->rtm_addrs, sa, rti_info); /* Skip ARP/ND cache, broadcast and dynamic routes. */ if (rtm->rtm_flags & (RTF_LLINFO|RTF_BROADCAST|RTF_DYNAMIC)) return (-1); if ((sa = rti_info[RTAX_DST]) == NULL) { log_warnx("route message without destination"); return (-1); } memset(kf, 0, sizeof(*kf)); if (rtm->rtm_flags & RTF_STATIC) kf->flags |= F_STATIC; if (rtm->rtm_flags & RTF_BLACKHOLE) kf->flags |= F_BLACKHOLE; if (rtm->rtm_flags & RTF_REJECT) kf->flags |= F_REJECT; /* adjust priority here */ if (rtm->rtm_priority == kr_state.fib_prio) kf->priority = RTP_MINE; else kf->priority = rtm->rtm_priority; label = (struct sockaddr_rtlabel *)rti_info[RTAX_LABEL]; if (label != NULL) if (strlcpy(kf->label, label->sr_label, sizeof(kf->label)) >= sizeof(kf->label)) fatalx("rtm label overflow"); sa2addr(sa, &kf->prefix, NULL); switch (sa->sa_family) { case AF_INET: sa_in = (struct sockaddr_in *)rti_info[RTAX_NETMASK]; if (rtm->rtm_flags & RTF_HOST) kf->prefixlen = 32; else if (sa_in != NULL) kf->prefixlen = mask2prefixlen4(sa_in); else kf->prefixlen = prefixlen_classful(kf->prefix.v4.s_addr); break; case AF_INET6: sa_in6 = (struct sockaddr_in6 *)rti_info[RTAX_NETMASK]; if (rtm->rtm_flags & RTF_HOST) kf->prefixlen = 128; else if (sa_in6 != NULL) kf->prefixlen = mask2prefixlen6(sa_in6); else fatalx("in6 net addr without netmask"); break; default: return (-1); } if ((sa = rti_info[RTAX_GATEWAY]) == NULL) { log_warnx("route %s/%u without gateway", log_addr(&kf->prefix), kf->prefixlen); return (-1); } kf->ifindex = rtm->rtm_index; if (rtm->rtm_flags & RTF_GATEWAY) { switch (sa->sa_family) { case AF_LINK: kf->flags |= F_CONNECTED; break; case AF_INET: case AF_INET6: sa2addr(rti_info[RTAX_GATEWAY], &kf->nexthop, NULL); break; } } else { kf->flags |= F_CONNECTED; } return (0); } int kr_fib_delete(struct ktable *kt, struct kroute_full *kf, int mpath) { return kroute_remove(kt, kf, !mpath); } int kr_fib_change(struct ktable *kt, struct kroute_full *kf, int type, int mpath) { struct kroute *kr; struct kroute6 *kr6; int flags, oflags; int changed = 0, rtlabel_changed = 0; uint16_t new_labelid; flags = kf->flags; switch (kf->prefix.aid) { case AID_INET: if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { if (!(kf->flags & F_BGPD)) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr = kroute_matchgw(kr, kf)) == NULL) { log_warnx("%s[change]: " "mpath route not found", __func__); goto add4; } else if (mpath && type == RTM_ADD) goto add4; if (kf->nexthop.aid == AID_INET) { if (kr->nexthop.s_addr != kf->nexthop.v4.s_addr) changed = 1; kr->nexthop.s_addr = kf->nexthop.v4.s_addr; kr->ifindex = kf->ifindex; } else { if (kr->nexthop.s_addr != 0) changed = 1; kr->nexthop.s_addr = 0; kr->ifindex = kf->ifindex; } if (kr->flags & F_NEXTHOP) flags |= F_NEXTHOP; new_labelid = rtlabel_name2id(kf->label); if (kr->labelid != new_labelid) { rtlabel_unref(kr->labelid); kr->labelid = new_labelid; rtlabel_changed = 1; } oflags = kr->flags; if (flags != oflags) changed = 1; kr->flags = flags; if (rtlabel_changed) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if ((oflags & F_CONNECTED) && !(flags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if ((flags & F_CONNECTED) && !(oflags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if (kr->flags & F_NEXTHOP && changed) knexthop_update(kt, kf); } else { kr->flags &= ~F_BGPD_INSERTED; } } else { add4: kroute_insert(kt, kf); } break; case AID_INET6: if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { if (!(kf->flags & F_BGPD)) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr6 = kroute6_matchgw(kr6, kf)) == NULL) { log_warnx("%s[change]: IPv6 mpath " "route not found", __func__); goto add6; } else if (mpath && type == RTM_ADD) goto add6; if (kf->nexthop.aid == AID_INET6) { if (memcmp(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)) || kr6->nexthop_scope_id != kf->nexthop.scope_id) changed = 1; kr6->nexthop = kf->nexthop.v6; kr6->nexthop_scope_id = kf->nexthop.scope_id; kr6->ifindex = kf->ifindex; } else { if (memcmp(&kr6->nexthop, &in6addr_any, sizeof(struct in6_addr))) changed = 1; kr6->nexthop = in6addr_any; kr6->nexthop_scope_id = 0; kr6->ifindex = kf->ifindex; } if (kr6->flags & F_NEXTHOP) flags |= F_NEXTHOP; new_labelid = rtlabel_name2id(kf->label); if (kr6->labelid != new_labelid) { rtlabel_unref(kr6->labelid); kr6->labelid = new_labelid; rtlabel_changed = 1; } oflags = kr6->flags; if (flags != oflags) changed = 1; kr6->flags = flags; if (rtlabel_changed) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if ((oflags & F_CONNECTED) && !(flags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if ((flags & F_CONNECTED) && !(oflags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if (kr6->flags & F_NEXTHOP && changed) knexthop_update(kt, kf); } else { kr6->flags &= ~F_BGPD_INSERTED; } } else { add6: kroute_insert(kt, kf); } break; } return (0); } openbgpd-8.8/src/bgpd/kroute-freebsd.c100644 001750 001750 00000212575 14751151116 0013477/* $OpenBSD: kroute.c,v 1.299 2022/09/15 08:20:14 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2022 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "log.h" #define RTP_ANY 0x0 #define RTP_KERN 0x1 #define RTP_PROTO1 0x11 #define RTP_PROTO2 0x12 #define RTP_PROTO3 0x13 #define RTP_MINE 0xff struct ktable **krt; u_int krt_size; struct { uint32_t rtseq; pid_t pid; int fd; uint8_t fib_prio; } kr_state; struct kroute { RB_ENTRY(kroute) entry; struct kroute *next; struct in_addr prefix; struct in_addr nexthop; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct kroute6 { RB_ENTRY(kroute6) entry; struct kroute6 *next; struct in6_addr prefix; struct in6_addr nexthop; uint32_t prefix_scope_id; /* because ... */ uint32_t nexthop_scope_id; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct knexthop { RB_ENTRY(knexthop) entry; struct bgpd_addr nexthop; void *kroute; u_short ifindex; }; struct kredist_node { RB_ENTRY(kredist_node) entry; struct bgpd_addr prefix; uint64_t rd; uint8_t prefixlen; uint8_t dynamic; }; struct kif { RB_ENTRY(kif) entry; char ifname[IFNAMSIZ]; uint64_t baudrate; u_int rdomain; int flags; u_short ifindex; uint8_t if_type; uint8_t link_state; uint8_t nh_reachable; /* for nexthop verification */ uint8_t depend_state; /* for session depend on */ }; int ktable_new(u_int, u_int, char *, int); void ktable_free(u_int); void ktable_destroy(struct ktable *); struct ktable *ktable_get(u_int); int kr4_change(struct ktable *, struct kroute_full *); int kr6_change(struct ktable *, struct kroute_full *); int kr_net_match(struct ktable *, struct network_config *, uint16_t, int); struct network *kr_net_find(struct ktable *, struct network *); void kr_net_clear(struct ktable *); void kr_redistribute(int, struct ktable *, struct kroute_full *); uint8_t kr_priority(struct kroute_full *); struct kroute_full *kr_tofull(struct kroute *); struct kroute_full *kr6_tofull(struct kroute6 *); int kroute_compare(struct kroute *, struct kroute *); int kroute6_compare(struct kroute6 *, struct kroute6 *); int knexthop_compare(struct knexthop *, struct knexthop *); int kredist_compare(struct kredist_node *, struct kredist_node *); int kif_compare(struct kif *, struct kif *); struct kroute *kroute_find(struct ktable *, const struct bgpd_addr *, uint8_t, uint8_t); struct kroute *kroute_matchgw(struct kroute *, struct kroute_full *); int kroute_insert(struct ktable *, struct kroute_full *); int kroute_remove(struct ktable *, struct kroute_full *, int); void kroute_clear(struct ktable *); struct kroute6 *kroute6_find(struct ktable *, const struct bgpd_addr *, uint8_t, uint8_t); struct kroute6 *kroute6_matchgw(struct kroute6 *, struct kroute_full *); void kroute6_clear(struct ktable *); struct knexthop *knexthop_find(struct ktable *, struct bgpd_addr *); int knexthop_insert(struct ktable *, struct knexthop *); void knexthop_remove(struct ktable *, struct knexthop *); void knexthop_clear(struct ktable *); struct kif *kif_find(int); int kif_insert(struct kif *); int kif_remove(struct kif *); void kif_clear(void); int kroute_validate(struct kroute *); int kroute6_validate(struct kroute6 *); int knexthop_true_nexthop(struct ktable *, struct kroute_full *); void knexthop_validate(struct ktable *, struct knexthop *); void knexthop_track(struct ktable *, u_short); void knexthop_update(struct ktable *, struct kroute_full *); void knexthop_send_update(struct knexthop *); struct kroute *kroute_match(struct ktable *, struct bgpd_addr *, int); struct kroute6 *kroute6_match(struct ktable *, struct bgpd_addr *, int); void kroute_detach_nexthop(struct ktable *, struct knexthop *); uint8_t prefixlen_classful(in_addr_t); static uint8_t mask2prefixlen4(struct sockaddr_in *); static uint8_t mask2prefixlen6(struct sockaddr_in6 *); int ift2ifm(uint8_t); const char *get_media_descr(int); const char *get_linkstate(uint8_t, int); void get_rtaddrs(int, struct sockaddr *, struct sockaddr **); void if_change(u_short, int, struct if_data *); void if_announce(void *); int send_rtmsg(int, struct ktable *, struct kroute_full *); int dispatch_rtmsg(void); int fetchtable(struct ktable *); int fetchifs(int); int dispatch_rtmsg_addr(struct rt_msghdr *, struct kroute_full *); int kr_fib_delete(struct ktable *, struct kroute_full *, int); int kr_fib_change(struct ktable *, struct kroute_full *, int, int); RB_PROTOTYPE(kroute_tree, kroute, entry, kroute_compare) RB_GENERATE(kroute_tree, kroute, entry, kroute_compare) RB_PROTOTYPE(kroute6_tree, kroute6, entry, kroute6_compare) RB_GENERATE(kroute6_tree, kroute6, entry, kroute6_compare) RB_PROTOTYPE(knexthop_tree, knexthop, entry, knexthop_compare) RB_GENERATE(knexthop_tree, knexthop, entry, knexthop_compare) RB_PROTOTYPE(kredist_tree, kredist_node, entry, kredist_compare) RB_GENERATE(kredist_tree, kredist_node, entry, kredist_compare) RB_HEAD(kif_tree, kif) kit; RB_PROTOTYPE(kif_tree, kif, entry, kif_compare) RB_GENERATE(kif_tree, kif, entry, kif_compare) #define KT2KNT(x) (&(ktable_get((x)->nhtableid)->knt)) #define LINK_STATE_IS_UP(_s) \ ((_s) == LINK_STATE_UP || (_s) == LINK_STATE_UNKNOWN) /* * exported functions */ int kr_init(int *fd, uint8_t fib_prio) { int opt = 0, rcvbuf, default_rcvbuf; socklen_t optlen; if ((kr_state.fd = socket(AF_ROUTE, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1) { log_warn("%s: socket", __func__); return (-1); } /* not interested in my own messages */ if (setsockopt(kr_state.fd, SOL_SOCKET, SO_USELOOPBACK, &opt, sizeof(opt)) == -1) log_warn("%s: setsockopt", __func__); /* not fatal */ /* grow receive buffer, don't wanna miss messages */ optlen = sizeof(default_rcvbuf); if (getsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF, &default_rcvbuf, &optlen) == -1) log_warn("%s: getsockopt SOL_SOCKET SO_RCVBUF", __func__); else for (rcvbuf = MAX_RTSOCK_BUF; rcvbuf > default_rcvbuf && setsockopt(kr_state.fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)) == -1 && errno == ENOBUFS; rcvbuf /= 2) ; /* nothing */ kr_state.pid = getpid(); kr_state.rtseq = 1; kr_state.fib_prio = fib_prio; RB_INIT(&kit); if (fetchifs(0) == -1) return (-1); *fd = kr_state.fd; return (0); } int kr_default_prio(void) { return RTP_PROTO3; } int kr_check_prio(long long prio) { if (prio < RTP_PROTO1 || prio > RTP_PROTO3) return 0; return 1; } int ktable_new(u_int rtableid, u_int rdomid, char *name, int fs) { struct ktable **xkrt; struct ktable *kt; size_t oldsize; /* resize index table if needed */ if (rtableid >= krt_size) { oldsize = sizeof(struct ktable *) * krt_size; if ((xkrt = reallocarray(krt, rtableid + 1, sizeof(struct ktable *))) == NULL) { log_warn("%s", __func__); return (-1); } krt = xkrt; krt_size = rtableid + 1; memset((char *)krt + oldsize, 0, krt_size * sizeof(struct ktable *) - oldsize); } if (krt[rtableid]) fatalx("ktable_new: table already exists."); /* allocate new element */ kt = krt[rtableid] = calloc(1, sizeof(struct ktable)); if (kt == NULL) { log_warn("%s", __func__); return (-1); } /* initialize structure ... */ strlcpy(kt->descr, name, sizeof(kt->descr)); RB_INIT(&kt->krt); RB_INIT(&kt->krt6); RB_INIT(&kt->knt); TAILQ_INIT(&kt->krn); kt->fib_conf = kt->fib_sync = fs; kt->rtableid = rtableid; kt->nhtableid = rdomid; /* bump refcount of rdomain table for the nexthop lookups */ ktable_get(kt->nhtableid)->nhrefcnt++; /* ... and load it */ if (fetchtable(kt) == -1) return (-1); /* everything is up and running */ kt->state = RECONF_REINIT; log_debug("%s: %s with rtableid %d rdomain %d", __func__, name, rtableid, rdomid); return (0); } void ktable_free(u_int rtableid) { struct ktable *kt, *nkt; if ((kt = ktable_get(rtableid)) == NULL) return; /* decouple from kernel, no new routes will be entered from here */ kr_fib_decouple(kt->rtableid); /* first unhook from the nexthop table */ nkt = ktable_get(kt->nhtableid); nkt->nhrefcnt--; /* * Evil little details: * If kt->nhrefcnt > 0 then kt == nkt and nothing needs to be done. * If kt != nkt then kt->nhrefcnt must be 0 and kt must be killed. * If nkt is no longer referenced it must be killed (possible double * free so check that kt != nkt). */ if (kt != nkt && nkt->nhrefcnt <= 0) ktable_destroy(nkt); if (kt->nhrefcnt <= 0) ktable_destroy(kt); } void ktable_destroy(struct ktable *kt) { /* decouple just to be sure, does not hurt */ kr_fib_decouple(kt->rtableid); log_debug("%s: freeing ktable %s rtableid %u", __func__, kt->descr, kt->rtableid); /* only clear nexthop table if it is the main rdomain table */ if (kt->rtableid == kt->nhtableid) knexthop_clear(kt); kroute_clear(kt); kroute6_clear(kt); kr_net_clear(kt); krt[kt->rtableid] = NULL; free(kt); } struct ktable * ktable_get(u_int rtableid) { if (rtableid >= krt_size) return (NULL); return (krt[rtableid]); } int ktable_update(u_int rtableid, char *name, int flags) { struct ktable *kt, *rkt; u_int rdomid; if (!ktable_exists(rtableid, &rdomid)) fatalx("King Bula lost a table"); /* may not happen */ if (rdomid != rtableid || flags & F_RIB_NOFIB) { rkt = ktable_get(rdomid); if (rkt == NULL) { char buf[32]; snprintf(buf, sizeof(buf), "rdomain_%d", rdomid); if (ktable_new(rdomid, rdomid, buf, 0)) return (-1); } else { /* there is no need for full fib synchronisation if * the table is only used for nexthop lookups. */ if (rkt->state == RECONF_DELETE) { rkt->fib_conf = 0; rkt->state = RECONF_KEEP; } } } if (flags & (F_RIB_NOFIB | F_RIB_NOEVALUATE)) /* only rdomain table must exist */ return (0); kt = ktable_get(rtableid); if (kt == NULL) { if (ktable_new(rtableid, rdomid, name, !(flags & F_RIB_NOFIBSYNC))) return (-1); } else { /* fib sync has higher preference then no sync */ if (kt->state == RECONF_DELETE) { kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); kt->state = RECONF_KEEP; } else if (!kt->fib_conf) kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); strlcpy(kt->descr, name, sizeof(kt->descr)); } return (0); } int ktable_exists(u_int rtableid, u_int *rdomid) { int fib = 0; size_t len = sizeof(fib); if (sysctlbyname("net.my_fibnum", &fib, &len, NULL, 0) == -1) if (errno != ENOENT) { log_warn("sysctl net.my_fibnum"); return (0); } /* only one FIB at a time */ if ((u_int)fib != rtableid) return (0); if (rdomid) *rdomid = rtableid; return (1); } int kr_change(u_int rtableid, struct kroute_full *kf) { struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); kf->flags |= F_BGPD; kf->priority = RTP_MINE; if (!knexthop_true_nexthop(kt, kf)) return kroute_remove(kt, kf, 1); switch (kf->prefix.aid) { case AID_INET: return (kr4_change(kt, kf)); case AID_INET6: return (kr6_change(kt, kf)); default: log_warnx("%s: not handled AID", __func__); return (-1); } } int kr4_change(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr; /* for blackhole and reject routes nexthop needs to be 127.0.0.1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) kf->nexthop.v4.s_addr = htonl(INADDR_LOOPBACK); /* nexthop within 127/8 -> ignore silently */ else if ((kf->nexthop.v4.s_addr & htonl(IN_CLASSA_NET)) == htonl(INADDR_LOOPBACK & IN_CLASSA_NET)) return (0); if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { kr->nexthop.s_addr = kf->nexthop.v4.s_addr; rtlabel_unref(kr->labelid); kr->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr->flags |= F_BLACKHOLE; else kr->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr->flags |= F_REJECT; else kr->flags &= ~F_REJECT; if (kr->flags & F_NEXTHOP) knexthop_update(kt, kf); /* check if there is already a kernel, higher prio route */ if (kroute_find(kt, &kf->prefix, kf->prefixlen, RTP_KERN) == NULL) if (send_rtmsg(RTM_CHANGE, kt, kf)) kr->flags |= F_BGPD_INSERTED; } return (0); } int kr6_change(struct ktable *kt, struct kroute_full *kf) { struct kroute6 *kr6; struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT; /* for blackhole and reject routes nexthop needs to be ::1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) memcpy(&kf->nexthop.v6, &lo6, sizeof(kf->nexthop.v6)); /* nexthop to loopback -> ignore silently */ else if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) return (0); if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { memcpy(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)); kr6->nexthop_scope_id = kf->nexthop.scope_id; rtlabel_unref(kr6->labelid); kr6->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr6->flags |= F_BLACKHOLE; else kr6->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr6->flags |= F_REJECT; else kr6->flags &= ~F_REJECT; if (kr6->flags & F_NEXTHOP) knexthop_update(kt, kf); /* check if there is already a kernel, higher prio route */ if (kroute6_find(kt, &kf->prefix, kf->prefixlen, RTP_KERN) == NULL) if (send_rtmsg(RTM_CHANGE, kt, kf)) kr6->flags |= F_BGPD_INSERTED; } return (0); } int kr_delete(u_int rtableid, struct kroute_full *kf) { struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); kf->flags |= F_BGPD; kf->priority = RTP_MINE; return kroute_remove(kt, kf, 1); } int kr_flush(u_int rtableid) { struct ktable *kt; struct kroute *kr, *next; struct kroute6 *kr6, *next6; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); RB_FOREACH_SAFE(kr, kroute_tree, &kt->krt, next) if ((kr->flags & F_BGPD_INSERTED)) { if (kroute_remove(kt, kr_tofull(kr), 1) == -1) return (-1); } RB_FOREACH_SAFE(kr6, kroute6_tree, &kt->krt6, next6) if ((kr6->flags & F_BGPD_INSERTED)) { if (kroute_remove(kt, kr6_tofull(kr6), 1) == -1) return (-1); } kt->fib_sync = 0; return (0); } void kr_shutdown(void) { u_int i; for (i = krt_size; i > 0; i--) ktable_free(i - 1); kif_clear(); free(krt); } void kr_fib_couple(u_int rtableid) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */ return; if (kt->fib_sync) /* already coupled */ return; kt->fib_sync = 1; RB_FOREACH(kr, kroute_tree, &kt->krt) if (kr->flags & F_BGPD) { if (send_rtmsg(RTM_ADD, kt, kr_tofull(kr))) kr->flags |= F_BGPD_INSERTED; } RB_FOREACH(kr6, kroute6_tree, &kt->krt6) if (kr6->flags & F_BGPD) { if (send_rtmsg(RTM_ADD, kt, kr6_tofull(kr6))) kr6->flags |= F_BGPD_INSERTED; } log_info("kernel routing table %u (%s) coupled", kt->rtableid, kt->descr); } void kr_fib_couple_all(void) { u_int i; for (i = krt_size; i > 0; i--) kr_fib_couple(i - 1); } void kr_fib_decouple(u_int rtableid) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */ return; if (!kt->fib_sync) /* already decoupled */ return; RB_FOREACH(kr, kroute_tree, &kt->krt) if ((kr->flags & F_BGPD_INSERTED)) { if (send_rtmsg(RTM_DELETE, kt, kr_tofull(kr))) kr->flags &= ~F_BGPD_INSERTED; } RB_FOREACH(kr6, kroute6_tree, &kt->krt6) if ((kr6->flags & F_BGPD_INSERTED)) { if (send_rtmsg(RTM_DELETE, kt, kr6_tofull(kr6))) kr6->flags &= ~F_BGPD_INSERTED; } kt->fib_sync = 0; log_info("kernel routing table %u (%s) decoupled", kt->rtableid, kt->descr); } void kr_fib_decouple_all(void) { u_int i; for (i = krt_size; i > 0; i--) kr_fib_decouple(i - 1); } void kr_fib_prio_set(uint8_t prio) { kr_state.fib_prio = prio; } int kr_dispatch_msg(void) { return (dispatch_rtmsg()); } int kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *h; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return (0); } if ((h = knexthop_find(kt, addr)) != NULL) { /* should not happen... this is actually an error path */ knexthop_send_update(h); } else { if ((h = calloc(1, sizeof(*h))) == NULL) { log_warn("%s", __func__); return (-1); } memcpy(&h->nexthop, addr, sizeof(h->nexthop)); if (knexthop_insert(kt, h) == -1) return (-1); } return (0); } void kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *kn; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return; } if ((kn = knexthop_find(kt, addr)) == NULL) return; knexthop_remove(kt, kn); } static struct ctl_show_interface * kr_show_interface(struct kif *kif) { static struct ctl_show_interface iface; uint64_t ifms_type; memset(&iface, 0, sizeof(iface)); strlcpy(iface.ifname, kif->ifname, sizeof(iface.ifname)); snprintf(iface.linkstate, sizeof(iface.linkstate), "%s", get_linkstate(kif->if_type, kif->link_state)); if ((ifms_type = ift2ifm(kif->if_type)) != 0) snprintf(iface.media, sizeof(iface.media), "%s", get_media_descr(ifms_type)); iface.baudrate = kif->baudrate; iface.rdomain = kif->rdomain; iface.nh_reachable = kif->nh_reachable; iface.is_up = (kif->flags & IFF_UP) == IFF_UP; return &iface; } void kr_show_route(struct imsg *imsg) { struct ktable *kt; struct kroute *kr, *kn; struct kroute6 *kr6, *kn6; struct kroute_full *kf; struct bgpd_addr addr; struct ctl_kroute_req req; struct ctl_show_nexthop snh; struct knexthop *h; struct kif *kif; uint32_t tableid; pid_t pid; u_int i; u_short ifindex = 0; tableid = imsg_get_id(imsg); pid = imsg_get_pid(imsg); switch (imsg_get_type(imsg)) { case IMSG_CTL_KROUTE: if (imsg_get_data(imsg, &req, sizeof(req)) == -1) { log_warnx("%s: wrong imsg len", __func__); break; } kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } if (!req.af || req.af == AF_INET) RB_FOREACH(kr, kroute_tree, &kt->krt) { if (req.flags && (kr->flags & req.flags) == 0) continue; kn = kr; do { kf = kr_tofull(kn); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } while ((kn = kn->next) != NULL); } if (!req.af || req.af == AF_INET6) RB_FOREACH(kr6, kroute6_tree, &kt->krt6) { if (req.flags && (kr6->flags & req.flags) == 0) continue; kn6 = kr6; do { kf = kr6_tofull(kn6); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } while ((kn6 = kn6->next) != NULL); } break; case IMSG_CTL_KROUTE_ADDR: if (imsg_get_data(imsg, &addr, sizeof(addr)) == -1) { log_warnx("%s: wrong imsg len", __func__); break; } kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } kr = NULL; switch (addr.aid) { case AID_INET: kr = kroute_match(kt, &addr, 1); if (kr != NULL) { kf = kr_tofull(kr); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } break; case AID_INET6: kr6 = kroute6_match(kt, &addr, 1); if (kr6 != NULL) { kf = kr6_tofull(kr6); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } break; } break; case IMSG_CTL_SHOW_NEXTHOP: kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } RB_FOREACH(h, knexthop_tree, KT2KNT(kt)) { memset(&snh, 0, sizeof(snh)); memcpy(&snh.addr, &h->nexthop, sizeof(snh.addr)); if (h->kroute != NULL) { switch (h->nexthop.aid) { case AID_INET: kr = h->kroute; snh.valid = kroute_validate(kr); snh.krvalid = 1; snh.kr = *kr_tofull(kr); ifindex = kr->ifindex; break; case AID_INET6: kr6 = h->kroute; snh.valid = kroute6_validate(kr6); snh.krvalid = 1; snh.kr = *kr6_tofull(kr6); ifindex = kr6->ifindex; break; } snh.kr.priority = kr_priority(&snh.kr); if ((kif = kif_find(ifindex)) != NULL) memcpy(&snh.iface, kr_show_interface(kif), sizeof(snh.iface)); } send_imsg_session(IMSG_CTL_SHOW_NEXTHOP, pid, &snh, sizeof(snh)); } break; case IMSG_CTL_SHOW_INTERFACE: RB_FOREACH(kif, kif_tree, &kit) send_imsg_session(IMSG_CTL_SHOW_INTERFACE, pid, kr_show_interface(kif), sizeof(struct ctl_show_interface)); break; case IMSG_CTL_SHOW_FIB_TABLES: for (i = 0; i < krt_size; i++) { struct ktable ktab; if ((kt = ktable_get(i)) == NULL) continue; ktab = *kt; /* do not leak internal information */ RB_INIT(&ktab.krt); RB_INIT(&ktab.krt6); RB_INIT(&ktab.knt); TAILQ_INIT(&ktab.krn); send_imsg_session(IMSG_CTL_SHOW_FIB_TABLES, pid, &ktab, sizeof(ktab)); } break; default: /* nada */ break; } send_imsg_session(IMSG_CTL_END, pid, NULL, 0); } static void kr_send_dependon(struct kif *kif) { struct session_dependon sdon = { {0} }; strlcpy(sdon.ifname, kif->ifname, sizeof(sdon.ifname)); sdon.depend_state = kif->depend_state; send_imsg_session(IMSG_SESSION_DEPENDON, 0, &sdon, sizeof(sdon)); } void kr_ifinfo(char *ifname) { struct kif *kif; RB_FOREACH(kif, kif_tree, &kit) if (!strcmp(ifname, kif->ifname)) { kr_send_dependon(kif); return; } } static int kr_net_redist_add(struct ktable *kt, struct network_config *net, struct filter_set_head *attr, int dynamic) { struct kredist_node *r, *xr; if ((r = calloc(1, sizeof(*r))) == NULL) fatal("%s", __func__); r->prefix = net->prefix; r->prefixlen = net->prefixlen; r->rd = net->rd; r->dynamic = dynamic; xr = RB_INSERT(kredist_tree, &kt->kredist, r); if (xr != NULL) { free(r); if (dynamic != xr->dynamic && dynamic) { /* * ignore update a non-dynamic announcement is * already present which has preference. */ return 0; } /* * only equal or non-dynamic announcement ends up here. * In both cases reset the dynamic flag (nop for equal) and * redistribute. */ xr->dynamic = dynamic; } if (send_network(IMSG_NETWORK_ADD, net, attr) == -1) log_warnx("%s: failed to send network update", __func__); return 1; } static void kr_net_redist_del(struct ktable *kt, struct network_config *net, int dynamic) { struct kredist_node *r, node; memset(&node, 0, sizeof(node)); node.prefix = net->prefix; node.prefixlen = net->prefixlen; node.rd = net->rd; r = RB_FIND(kredist_tree, &kt->kredist, &node); if (r == NULL || dynamic != r->dynamic) return; if (RB_REMOVE(kredist_tree, &kt->kredist, r) == NULL) { log_warnx("%s: failed to remove network %s/%u", __func__, log_addr(&node.prefix), node.prefixlen); return; } free(r); if (send_network(IMSG_NETWORK_REMOVE, net, NULL) == -1) log_warnx("%s: failed to send network removal", __func__); } int kr_net_match(struct ktable *kt, struct network_config *net, uint16_t flags, int loopback) { struct network *xn; TAILQ_FOREACH(xn, &kt->krn, entry) { if (xn->net.prefix.aid != net->prefix.aid) continue; switch (xn->net.type) { case NETWORK_DEFAULT: /* static match already redistributed */ continue; case NETWORK_STATIC: /* Skip networks with nexthop on loopback. */ if (loopback) continue; if (flags & F_STATIC) break; continue; case NETWORK_CONNECTED: /* Skip networks with nexthop on loopback. */ if (loopback) continue; if (flags & F_CONNECTED) break; continue; case NETWORK_RTLABEL: if (net->rtlabel == xn->net.rtlabel) break; continue; case NETWORK_PRIORITY: if (net->priority == xn->net.priority) break; continue; case NETWORK_MRTCLONE: case NETWORK_PREFIXSET: /* must not happen */ log_warnx("%s: found a NETWORK_PREFIXSET, " "please send a bug report", __func__); continue; } net->rd = xn->net.rd; if (kr_net_redist_add(kt, net, &xn->net.attrset, 1)) return (1); } return (0); } struct network * kr_net_find(struct ktable *kt, struct network *n) { struct network *xn; TAILQ_FOREACH(xn, &kt->krn, entry) { if (n->net.type != xn->net.type || n->net.prefixlen != xn->net.prefixlen || n->net.rd != xn->net.rd || n->net.rtlabel != xn->net.rtlabel || n->net.priority != xn->net.priority) continue; if (memcmp(&n->net.prefix, &xn->net.prefix, sizeof(n->net.prefix)) == 0) return (xn); } return (NULL); } void kr_net_reload(u_int rtableid, uint64_t rd, struct network_head *nh) { struct network *n, *xn; struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) fatalx("%s: non-existent rtableid %d", __func__, rtableid); while ((n = TAILQ_FIRST(nh)) != NULL) { TAILQ_REMOVE(nh, n, entry); n->net.old = 0; n->net.rd = rd; xn = kr_net_find(kt, n); if (xn) { xn->net.old = 0; filterset_free(&xn->net.attrset); filterset_move(&n->net.attrset, &xn->net.attrset); network_free(n); } else TAILQ_INSERT_TAIL(&kt->krn, n, entry); } } void kr_net_clear(struct ktable *kt) { struct network *n, *xn; TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { TAILQ_REMOVE(&kt->krn, n, entry); if (n->net.type == NETWORK_DEFAULT) kr_net_redist_del(kt, &n->net, 0); network_free(n); } } void kr_redistribute(int type, struct ktable *kt, struct kroute_full *kf) { struct network_config net; uint32_t a; int loflag = 0; memset(&net, 0, sizeof(net)); net.prefix = kf->prefix; net.prefixlen = kf->prefixlen; net.rtlabel = rtlabel_name2id(kf->label); rtlabel_unref(net.rtlabel); /* drop reference now, which is ok here */ net.priority = kf->priority; /* shortcut for removals */ if (type == IMSG_NETWORK_REMOVE) { kr_net_redist_del(kt, &net, 1); return; } if (kf->flags & F_BGPD) return; switch (kf->prefix.aid) { case AID_INET: /* * We consider the loopback net and multicast addresses * as not redistributable. */ a = ntohl(kf->prefix.v4.s_addr); if (IN_MULTICAST(a) || (a >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) return; /* Check if the nexthop is the loopback addr. */ if (kf->nexthop.v4.s_addr == htonl(INADDR_LOOPBACK)) loflag = 1; break; case AID_INET6: /* * We consider unspecified, loopback, multicast, * link- and site-local, IPv4 mapped and IPv4 compatible * addresses as not redistributable. */ if (IN6_IS_ADDR_UNSPECIFIED(&kf->prefix.v6) || IN6_IS_ADDR_LOOPBACK(&kf->prefix.v6) || IN6_IS_ADDR_MULTICAST(&kf->prefix.v6) || IN6_IS_ADDR_LINKLOCAL(&kf->prefix.v6) || IN6_IS_ADDR_SITELOCAL(&kf->prefix.v6) || IN6_IS_ADDR_V4MAPPED(&kf->prefix.v6) || IN6_IS_ADDR_V4COMPAT(&kf->prefix.v6)) return; /* Check if the nexthop is the loopback addr. */ if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) loflag = 1; break; default: /* unhandled AID cannot be redistributed */ return; } /* * never allow 0/0 or ::/0 the default route can only be redistributed * with announce default. */ if (kf->prefixlen == 0) return; if (kr_net_match(kt, &net, kf->flags, loflag) == 0) /* no longer matches, if still present remove it */ kr_net_redist_del(kt, &net, 1); } void ktable_preload(void) { struct ktable *kt; struct network *n; u_int i; for (i = 0; i < krt_size; i++) { if ((kt = ktable_get(i)) == NULL) continue; kt->state = RECONF_DELETE; /* mark all networks as old */ TAILQ_FOREACH(n, &kt->krn, entry) n->net.old = 1; } } void ktable_postload(void) { struct ktable *kt; struct network *n, *xn; u_int i; for (i = krt_size; i > 0; i--) { if ((kt = ktable_get(i - 1)) == NULL) continue; if (kt->state == RECONF_DELETE) { ktable_free(i - 1); continue; } else if (kt->state == RECONF_REINIT) kt->fib_sync = kt->fib_conf; /* cleanup old networks */ TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { if (n->net.old) { TAILQ_REMOVE(&kt->krn, n, entry); if (n->net.type == NETWORK_DEFAULT) kr_net_redist_del(kt, &n->net, 0); network_free(n); } } } } int kr_reload(void) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; struct knexthop *nh; struct network *n; u_int rid; int hasdyn = 0; for (rid = 0; rid < krt_size; rid++) { if ((kt = ktable_get(rid)) == NULL) continue; /* if this is the main nexthop table revalidate nexthops */ if (kt->rtableid == kt->nhtableid) RB_FOREACH(nh, knexthop_tree, KT2KNT(kt)) knexthop_validate(kt, nh); TAILQ_FOREACH(n, &kt->krn, entry) if (n->net.type == NETWORK_DEFAULT) { kr_net_redist_add(kt, &n->net, &n->net.attrset, 0); } else hasdyn = 1; if (hasdyn) { /* only evaluate the full tree if we need */ RB_FOREACH(kr, kroute_tree, &kt->krt) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); RB_FOREACH(kr6, kroute6_tree, &kt->krt6) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); } } return (0); } uint8_t kr_priority(struct kroute_full *kf) { if (kf->priority == RTP_MINE) return kr_state.fib_prio; return kf->priority; } struct kroute_full * kr_tofull(struct kroute *kr) { static struct kroute_full kf; memset(&kf, 0, sizeof(kf)); kf.prefix.aid = AID_INET; kf.prefix.v4.s_addr = kr->prefix.s_addr; kf.nexthop.aid = AID_INET; kf.nexthop.v4.s_addr = kr->nexthop.s_addr; strlcpy(kf.label, rtlabel_id2name(kr->labelid), sizeof(kf.label)); kf.flags = kr->flags; kf.ifindex = kr->ifindex; kf.prefixlen = kr->prefixlen; kf.priority = kr->priority; kf.mplslabel = kr->mplslabel; return (&kf); } struct kroute_full * kr6_tofull(struct kroute6 *kr6) { static struct kroute_full kf; memset(&kf, 0, sizeof(kf)); kf.prefix.aid = AID_INET6; kf.prefix.v6 = kr6->prefix; kf.prefix.scope_id = kr6->prefix_scope_id; kf.nexthop.aid = AID_INET6; kf.nexthop.v6 = kr6->nexthop; kf.nexthop.scope_id = kr6->nexthop_scope_id; strlcpy(kf.label, rtlabel_id2name(kr6->labelid), sizeof(kf.label)); kf.flags = kr6->flags; kf.ifindex = kr6->ifindex; kf.prefixlen = kr6->prefixlen; kf.priority = kr6->priority; kf.mplslabel = kr6->mplslabel; return (&kf); } /* * RB-tree compare functions */ int kroute_compare(struct kroute *a, struct kroute *b) { if (ntohl(a->prefix.s_addr) < ntohl(b->prefix.s_addr)) return (-1); if (ntohl(a->prefix.s_addr) > ntohl(b->prefix.s_addr)) return (1); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); /* if the priority is RTP_ANY finish on the first address hit */ if (a->priority == RTP_ANY || b->priority == RTP_ANY) return (0); if (a->priority < b->priority) return (-1); if (a->priority > b->priority) return (1); return (0); } int kroute6_compare(struct kroute6 *a, struct kroute6 *b) { int i; for (i = 0; i < 16; i++) { if (a->prefix.s6_addr[i] < b->prefix.s6_addr[i]) return (-1); if (a->prefix.s6_addr[i] > b->prefix.s6_addr[i]) return (1); } if (a->prefix_scope_id < b->prefix_scope_id) return (-1); if (a->prefix_scope_id > b->prefix_scope_id) return (1); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); /* if the priority is RTP_ANY finish on the first address hit */ if (a->priority == RTP_ANY || b->priority == RTP_ANY) return (0); if (a->priority < b->priority) return (-1); if (a->priority > b->priority) return (1); return (0); } int knexthop_compare(struct knexthop *a, struct knexthop *b) { int i; if (a->nexthop.aid != b->nexthop.aid) return (b->nexthop.aid - a->nexthop.aid); switch (a->nexthop.aid) { case AID_INET: if (ntohl(a->nexthop.v4.s_addr) < ntohl(b->nexthop.v4.s_addr)) return (-1); if (ntohl(a->nexthop.v4.s_addr) > ntohl(b->nexthop.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->nexthop.v6.s6_addr[i] < b->nexthop.v6.s6_addr[i]) return (-1); if (a->nexthop.v6.s6_addr[i] > b->nexthop.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } return (0); } int kredist_compare(struct kredist_node *a, struct kredist_node *b) { int i; if (a->prefix.aid != b->prefix.aid) return (b->prefix.aid - a->prefix.aid); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); switch (a->prefix.aid) { case AID_INET: if (ntohl(a->prefix.v4.s_addr) < ntohl(b->prefix.v4.s_addr)) return (-1); if (ntohl(a->prefix.v4.s_addr) > ntohl(b->prefix.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->prefix.v6.s6_addr[i] < b->prefix.v6.s6_addr[i]) return (-1); if (a->prefix.v6.s6_addr[i] > b->prefix.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } if (a->rd < b->rd) return (-1); if (a->rd > b->rd) return (1); return (0); } int kif_compare(struct kif *a, struct kif *b) { return (b->ifindex - a->ifindex); } /* * tree management functions */ struct kroute * kroute_find(struct ktable *kt, const struct bgpd_addr *prefix, uint8_t prefixlen, uint8_t prio) { struct kroute s; struct kroute *kn, *tmp; s.prefix = prefix->v4; s.prefixlen = prefixlen; s.priority = prio; kn = RB_FIND(kroute_tree, &kt->krt, &s); if (kn && prio == RTP_ANY) { tmp = RB_PREV(kroute_tree, &kt->krt, kn); while (tmp) { if (kroute_compare(&s, tmp) == 0) kn = tmp; else break; tmp = RB_PREV(kroute_tree, &kt->krt, kn); } } return (kn); } struct kroute * kroute_matchgw(struct kroute *kr, struct kroute_full *kf) { in_addr_t nexthop; if (kf->flags & F_CONNECTED) { do { if (kr->ifindex == kf->ifindex || kf->ifindex == 0) return (kr); kr = kr->next; } while (kr); return (NULL); } nexthop = kf->nexthop.v4.s_addr; do { if (kr->nexthop.s_addr == nexthop) return (kr); kr = kr->next; } while (kr); return (NULL); } int kroute_insert(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr, *krm; struct kroute6 *kr6, *kr6m; struct knexthop *n; uint32_t mplslabel = 0; int multipath = 0; if (kf->prefix.aid == AID_VPN_IPv4 || kf->prefix.aid == AID_VPN_IPv6) { /* only a single MPLS label is supported for now */ if (kf->prefix.labellen != 3) { log_warnx("%s/%u does not have a single label", log_addr(&kf->prefix), kf->prefixlen); return -1; } mplslabel = (kf->prefix.labelstack[0] << 24) | (kf->prefix.labelstack[1] << 16) | (kf->prefix.labelstack[2] << 8); } switch (kf->prefix.aid) { case AID_INET: case AID_VPN_IPv4: if ((kr = calloc(1, sizeof(*kr))) == NULL) { log_warn("%s", __func__); return (-1); } kr->flags = kf->flags; kr->prefix = kf->prefix.v4; kr->prefixlen = kf->prefixlen; if (kf->nexthop.aid == AID_INET) kr->nexthop = kf->nexthop.v4; if (kf->prefix.aid == AID_VPN_IPv4) { kr->flags |= F_MPLS; kr->mplslabel = htonl(mplslabel); } kr->ifindex = kf->ifindex; kr->priority = kf->priority; kr->labelid = rtlabel_name2id(kf->label); if ((krm = RB_INSERT(kroute_tree, &kt->krt, kr)) != NULL) { /* multipath route, add at end of list */ while (krm->next != NULL) krm = krm->next; krm->next = kr; multipath = 1; } /* check if a kernel route exists */ if ((kf->flags & F_BGPD) && kroute_find(kt, &kf->prefix, kf->prefixlen, RTP_KERN) == NULL) if (send_rtmsg(RTM_ADD, kt, kf)) kr->flags |= F_BGPD_INSERTED; break; case AID_INET6: case AID_VPN_IPv6: if ((kr6 = calloc(1, sizeof(*kr6))) == NULL) { log_warn("%s", __func__); return (-1); } kr6->flags = kf->flags; kr6->prefix = kf->prefix.v6; kr6->prefix_scope_id = kf->prefix.scope_id; kr6->prefixlen = kf->prefixlen; if (kf->nexthop.aid == AID_INET6) { kr6->nexthop = kf->nexthop.v6; kr6->nexthop_scope_id = kf->nexthop.scope_id; } else kr6->nexthop = in6addr_any; if (kf->prefix.aid == AID_VPN_IPv6) { kr6->flags |= F_MPLS; kr6->mplslabel = htonl(mplslabel); } kr6->ifindex = kf->ifindex; kr6->priority = kf->priority; kr6->labelid = rtlabel_name2id(kf->label); if ((kr6m = RB_INSERT(kroute6_tree, &kt->krt6, kr6)) != NULL) { /* multipath route, add at end of list */ while (kr6m->next != NULL) kr6m = kr6m->next; kr6m->next = kr6; multipath = 1; } /* check if a kernel route exists */ if ((kf->flags & F_BGPD) && kroute6_find(kt, &kf->prefix, kf->prefixlen, RTP_KERN) == NULL) if (send_rtmsg(RTM_ADD, kt, kf)) kr6->flags |= F_BGPD_INSERTED; break; } if (bgpd_has_bgpnh() || !(kf->flags & F_BGPD)) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) if (prefix_compare(&kf->prefix, &n->nexthop, kf->prefixlen) == 0) knexthop_validate(kt, n); } if (!(kf->flags & F_BGPD)) { /* redistribute multipath routes only once */ if (!multipath) kr_redistribute(IMSG_NETWORK_ADD, kt, kf); } return (0); } static int kroute4_remove(struct ktable *kt, struct kroute_full *kf, int any) { struct kroute *kr, *krm; struct knexthop *n; int multipath = 1; if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (-1); if ((kr->flags & F_BGPD) != (kf->flags & F_BGPD)) { log_warnx("%s: wrong type for %s/%u", __func__, log_addr(&kf->prefix), kf->prefixlen); if (!(kf->flags & F_BGPD)) kr->flags &= ~F_BGPD_INSERTED; return (-1); } /* get the correct route to remove */ krm = kr; if (!any) { if ((krm = kroute_matchgw(kr, kf)) == NULL) { log_warnx("delete %s/%u: route not found", log_addr(&kf->prefix), kf->prefixlen); return (-2); } } if (krm == kr) { /* head element */ RB_REMOVE(kroute_tree, &kt->krt, krm); if (krm->next != NULL) { kr = krm->next; if (RB_INSERT(kroute_tree, &kt->krt, kr) != NULL) { log_warnx("%s: failed to add %s/%u", __func__, inet_ntoa(kr->prefix), kr->prefixlen); return (-2); } } else { multipath = 0; } } else { /* somewhere in the list */ while (kr->next != krm && kr->next != NULL) kr = kr->next; if (kr->next == NULL) { log_warnx("%s: multipath list corrupted for %s/%u", __func__, inet_ntoa(kr->prefix), kr->prefixlen); return (-2); } kr->next = krm->next; } /* check whether a nexthop depends on this kroute */ if (krm->flags & F_NEXTHOP) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) { if (n->kroute == krm) knexthop_validate(kt, n); } } *kf = *kr_tofull(krm); rtlabel_unref(krm->labelid); free(krm); return (multipath); } static int kroute6_remove(struct ktable *kt, struct kroute_full *kf, int any) { struct kroute6 *kr, *krm; struct knexthop *n; int multipath = 1; if ((kr = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (-1); if ((kr->flags & F_BGPD) != (kf->flags & F_BGPD)) { log_warnx("%s: wrong type for %s/%u", __func__, log_addr(&kf->prefix), kf->prefixlen); if (!(kf->flags & F_BGPD)) kr->flags &= ~F_BGPD_INSERTED; return (-1); } /* get the correct route to remove */ krm = kr; if (!any) { if ((krm = kroute6_matchgw(kr, kf)) == NULL) { log_warnx("delete %s/%u: route not found", log_addr(&kf->prefix), kf->prefixlen); return (-2); } } if (krm == kr) { /* head element */ RB_REMOVE(kroute6_tree, &kt->krt6, krm); if (krm->next != NULL) { kr = krm->next; if (RB_INSERT(kroute6_tree, &kt->krt6, kr) != NULL) { log_warnx("%s: failed to add %s/%u", __func__, log_in6addr(&kr->prefix), kr->prefixlen); return (-2); } } else { multipath = 0; } } else { /* somewhere in the list */ while (kr->next != krm && kr->next != NULL) kr = kr->next; if (kr->next == NULL) { log_warnx("%s: multipath list corrupted for %s/%u", __func__, log_in6addr(&kr->prefix), kr->prefixlen); return (-2); } kr->next = krm->next; } /* check whether a nexthop depends on this kroute */ if (krm->flags & F_NEXTHOP) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) { if (n->kroute == krm) knexthop_validate(kt, n); } } *kf = *kr6_tofull(krm); rtlabel_unref(krm->labelid); free(krm); return (multipath); } int kroute_remove(struct ktable *kt, struct kroute_full *kf, int any) { int multipath; switch (kf->prefix.aid) { case AID_INET: multipath = kroute4_remove(kt, kf, any); break; case AID_INET6: multipath = kroute6_remove(kt, kf, any); break; default: log_warnx("%s: not handled AID", __func__); return (-1); } if (multipath < 0) return (multipath + 1); if (kf->flags & F_BGPD_INSERTED) send_rtmsg(RTM_DELETE, kt, kf); /* remove only once all multipath routes are gone */ if (!(kf->flags & F_BGPD) && !multipath) kr_redistribute(IMSG_NETWORK_REMOVE, kt, kf); return (0); } void kroute_clear(struct ktable *kt) { struct kroute *kr; while ((kr = RB_MIN(kroute_tree, &kt->krt)) != NULL) kroute_remove(kt, kr_tofull(kr), 1); } struct kroute6 * kroute6_find(struct ktable *kt, const struct bgpd_addr *prefix, uint8_t prefixlen, uint8_t prio) { struct kroute6 s; struct kroute6 *kn6, *tmp; s.prefix = prefix->v6; s.prefix_scope_id = prefix->scope_id; s.prefixlen = prefixlen; s.priority = prio; kn6 = RB_FIND(kroute6_tree, &kt->krt6, &s); if (kn6 && prio == RTP_ANY) { tmp = RB_PREV(kroute6_tree, &kt->krt6, kn6); while (tmp) { if (kroute6_compare(&s, tmp) == 0) kn6 = tmp; else break; tmp = RB_PREV(kroute6_tree, &kt->krt6, kn6); } } return (kn6); } struct kroute6 * kroute6_matchgw(struct kroute6 *kr, struct kroute_full *kf) { struct in6_addr nexthop; if (kf->flags & F_CONNECTED) { do { if (kr->ifindex == kf->ifindex || kf->ifindex == 0) return (kr); kr = kr->next; } while (kr); return (NULL); } nexthop = kf->nexthop.v6; do { if (memcmp(&kr->nexthop, &nexthop, sizeof(nexthop)) == 0 && kr->nexthop_scope_id == kf->nexthop.scope_id) return (kr); kr = kr->next; } while (kr); return (NULL); } void kroute6_clear(struct ktable *kt) { struct kroute6 *kr; while ((kr = RB_MIN(kroute6_tree, &kt->krt6)) != NULL) kroute_remove(kt, kr6_tofull(kr), 1); } struct knexthop * knexthop_find(struct ktable *kt, struct bgpd_addr *addr) { struct knexthop s; memset(&s, 0, sizeof(s)); memcpy(&s.nexthop, addr, sizeof(s.nexthop)); return (RB_FIND(knexthop_tree, KT2KNT(kt), &s)); } int knexthop_insert(struct ktable *kt, struct knexthop *kn) { if (RB_INSERT(knexthop_tree, KT2KNT(kt), kn) != NULL) { log_warnx("%s: failed for %s", __func__, log_addr(&kn->nexthop)); free(kn); return (-1); } knexthop_validate(kt, kn); return (0); } void knexthop_remove(struct ktable *kt, struct knexthop *kn) { kroute_detach_nexthop(kt, kn); RB_REMOVE(knexthop_tree, KT2KNT(kt), kn); free(kn); } void knexthop_clear(struct ktable *kt) { struct knexthop *kn; while ((kn = RB_MIN(knexthop_tree, KT2KNT(kt))) != NULL) knexthop_remove(kt, kn); } struct kif * kif_find(int ifindex) { struct kif s; memset(&s, 0, sizeof(s)); s.ifindex = ifindex; return (RB_FIND(kif_tree, &kit, &s)); } int kif_insert(struct kif *kif) { if (RB_INSERT(kif_tree, &kit, kif) != NULL) { log_warnx("RB_INSERT(kif_tree, &kit, kif)"); free(kif); return (-1); } return (0); } int kif_remove(struct kif *kif) { struct ktable *kt; kif->flags &= ~IFF_UP; /* * TODO, remove all kroutes using this interface, * the kernel does this for us but better to do it * here as well. */ if ((kt = ktable_get(kif->rdomain)) != NULL) knexthop_track(kt, kif->ifindex); RB_REMOVE(kif_tree, &kit, kif); free(kif); return (0); } void kif_clear(void) { struct kif *kif; while ((kif = RB_MIN(kif_tree, &kit)) != NULL) kif_remove(kif); } /* * nexthop validation */ static int kif_validate(struct kif *kif) { if (!(kif->flags & IFF_UP)) return (0); /* * we treat link_state == LINK_STATE_UNKNOWN as valid, * not all interfaces have a concept of "link state" and/or * do not report up */ if (kif->link_state == LINK_STATE_DOWN) return (0); return (1); } /* * return 1 when the interface is up and the link state is up or unknwown * except when this is a carp interface, then return 1 only when link state * is up */ static int kif_depend_state(struct kif *kif) { if (!(kif->flags & IFF_UP)) return (0); return LINK_STATE_IS_UP(kif->link_state); } int kroute_validate(struct kroute *kr) { struct kif *kif; if (kr->flags & (F_REJECT | F_BLACKHOLE)) return (0); if ((kif = kif_find(kr->ifindex)) == NULL) { if (kr->ifindex) log_warnx("%s: interface with index %d not found, " "referenced from route for %s/%u", __func__, kr->ifindex, inet_ntoa(kr->prefix), kr->prefixlen); return (1); } return (kif->nh_reachable); } int kroute6_validate(struct kroute6 *kr) { struct kif *kif; if (kr->flags & (F_REJECT | F_BLACKHOLE)) return (0); if ((kif = kif_find(kr->ifindex)) == NULL) { if (kr->ifindex) log_warnx("%s: interface with index %d not found, " "referenced from route for %s/%u", __func__, kr->ifindex, log_in6addr(&kr->prefix), kr->prefixlen); return (1); } return (kif->nh_reachable); } int knexthop_true_nexthop(struct ktable *kt, struct kroute_full *kf) { struct bgpd_addr gateway = { 0 }; struct knexthop *kn; struct kroute *kr; struct kroute6 *kr6; /* * Ignore the nexthop for VPN routes. The gateway is forced * to an mpe(4) interface route using an MPLS label. */ switch (kf->prefix.aid) { case AID_VPN_IPv4: case AID_VPN_IPv6: return 1; } kn = knexthop_find(kt, &kf->nexthop); if (kn == NULL) { log_warnx("%s: nexthop %s not found", __func__, log_addr(&kf->nexthop)); return 0; } if (kn->kroute == NULL) return 0; switch (kn->nexthop.aid) { case AID_INET: kr = kn->kroute; if (kr->flags & F_CONNECTED) return 1; gateway.aid = AID_INET; gateway.v4.s_addr = kr->nexthop.s_addr; break; case AID_INET6: kr6 = kn->kroute; if (kr6->flags & F_CONNECTED) return 1; gateway.aid = AID_INET6; gateway.v6 = kr6->nexthop; gateway.scope_id = kr6->nexthop_scope_id; break; } kf->nexthop = gateway; return 1; } void knexthop_validate(struct ktable *kt, struct knexthop *kn) { void *oldk; struct kroute *kr; struct kroute6 *kr6; oldk = kn->kroute; kroute_detach_nexthop(kt, kn); if ((kt = ktable_get(kt->nhtableid)) == NULL) fatalx("%s: lost nexthop routing table", __func__); switch (kn->nexthop.aid) { case AID_INET: kr = kroute_match(kt, &kn->nexthop, 0); if (kr != NULL) { kn->kroute = kr; kn->ifindex = kr->ifindex; kr->flags |= F_NEXTHOP; } /* * Send update if nexthop route changed under us if * the route remains the same then the NH state has not * changed. */ if (kr != oldk) knexthop_send_update(kn); break; case AID_INET6: kr6 = kroute6_match(kt, &kn->nexthop, 0); if (kr6 != NULL) { kn->kroute = kr6; kn->ifindex = kr6->ifindex; kr6->flags |= F_NEXTHOP; } if (kr6 != oldk) knexthop_send_update(kn); break; } } /* * Called on interface state change. */ void knexthop_track(struct ktable *kt, u_short ifindex) { struct knexthop *kn; RB_FOREACH(kn, knexthop_tree, KT2KNT(kt)) if (kn->ifindex == ifindex) knexthop_validate(kt, kn); } /* * Called on route change. */ void knexthop_update(struct ktable *kt, struct kroute_full *kf) { struct knexthop *kn; RB_FOREACH(kn, knexthop_tree, KT2KNT(kt)) if (prefix_compare(&kf->prefix, &kn->nexthop, kf->prefixlen) == 0) knexthop_send_update(kn); } void knexthop_send_update(struct knexthop *kn) { struct kroute_nexthop n; struct kroute *kr; struct kroute6 *kr6; memset(&n, 0, sizeof(n)); n.nexthop = kn->nexthop; if (kn->kroute == NULL) { n.valid = 0; /* NH is not valid */ send_nexthop_update(&n); return; } switch (kn->nexthop.aid) { case AID_INET: kr = kn->kroute; n.valid = kroute_validate(kr); n.connected = kr->flags & F_CONNECTED; if (!n.connected) { n.gateway.aid = AID_INET; n.gateway.v4.s_addr = kr->nexthop.s_addr; } else { n.gateway = n.nexthop; n.net.aid = AID_INET; n.net.v4.s_addr = kr->prefix.s_addr; n.netlen = kr->prefixlen; } break; case AID_INET6: kr6 = kn->kroute; n.valid = kroute6_validate(kr6); n.connected = kr6->flags & F_CONNECTED; if (!n.connected) { n.gateway.aid = AID_INET6; n.gateway.v6 = kr6->nexthop; n.gateway.scope_id = kr6->nexthop_scope_id; } else { n.gateway = n.nexthop; n.net.aid = AID_INET6; n.net.v6 = kr6->prefix; n.net.scope_id = kr6->prefix_scope_id; n.netlen = kr6->prefixlen; } break; } send_nexthop_update(&n); } struct kroute * kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchany) { int i; struct kroute *kr; struct bgpd_addr masked; for (i = 32; i >= 0; i--) { applymask(&masked, key, i); if ((kr = kroute_find(kt, &masked, i, RTP_ANY)) != NULL) if (matchany || bgpd_oknexthop(kr_tofull(kr))) return (kr); } return (NULL); } struct kroute6 * kroute6_match(struct ktable *kt, struct bgpd_addr *key, int matchany) { int i; struct kroute6 *kr6; struct bgpd_addr masked; for (i = 128; i >= 0; i--) { applymask(&masked, key, i); if ((kr6 = kroute6_find(kt, &masked, i, RTP_ANY)) != NULL) if (matchany || bgpd_oknexthop(kr6_tofull(kr6))) return (kr6); } return (NULL); } void kroute_detach_nexthop(struct ktable *kt, struct knexthop *kn) { struct knexthop *s; struct kroute *k; struct kroute6 *k6; if (kn->kroute == NULL) return; /* * check whether there's another nexthop depending on this kroute * if not remove the flag */ RB_FOREACH(s, knexthop_tree, KT2KNT(kt)) if (s->kroute == kn->kroute && s != kn) break; if (s == NULL) { switch (kn->nexthop.aid) { case AID_INET: k = kn->kroute; k->flags &= ~F_NEXTHOP; break; case AID_INET6: k6 = kn->kroute; k6->flags &= ~F_NEXTHOP; break; } } kn->kroute = NULL; kn->ifindex = 0; } /* * misc helpers */ uint8_t prefixlen_classful(in_addr_t ina) { /* it hurt to write this. */ if (ina >= 0xf0000000U) /* class E */ return (32); else if (ina >= 0xe0000000U) /* class D */ return (4); else if (ina >= 0xc0000000U) /* class C */ return (24); else if (ina >= 0x80000000U) /* class B */ return (16); else /* class A */ return (8); } static uint8_t mask2prefixlen4(struct sockaddr_in *sa_in) { in_addr_t ina; ina = sa_in->sin_addr.s_addr; if (ina == 0) return (0); else return (33 - ffs(ntohl(ina))); } static uint8_t mask2prefixlen6(struct sockaddr_in6 *sa_in6) { uint8_t *ap, *ep; u_int l = 0; /* * sin6_len is the size of the sockaddr so substract the offset of * the possibly truncated sin6_addr struct. */ ap = (uint8_t *)&sa_in6->sin6_addr; ep = (uint8_t *)sa_in6 + sa_in6->sin6_len; for (; ap < ep; ap++) { /* this "beauty" is adopted from sbin/route/show.c ... */ switch (*ap) { case 0xff: l += 8; break; case 0xfe: l += 7; goto done; case 0xfc: l += 6; goto done; case 0xf8: l += 5; goto done; case 0xf0: l += 4; goto done; case 0xe0: l += 3; goto done; case 0xc0: l += 2; goto done; case 0x80: l += 1; goto done; case 0x00: goto done; default: fatalx("non contiguous inet6 netmask"); } } done: if (l > sizeof(struct in6_addr) * 8) fatalx("%s: prefixlen %d out of bound", __func__, l); return (l); } uint8_t mask2prefixlen(sa_family_t af, struct sockaddr *mask) { switch (af) { case AF_INET: return mask2prefixlen4((struct sockaddr_in *)mask); case AF_INET6: return mask2prefixlen6((struct sockaddr_in6 *)mask); default: fatalx("%s: unsupported af", __func__); } } const struct ifmedia_status_description if_status_descriptions[] = IFM_STATUS_DESCRIPTIONS; const struct ifmedia_description ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS; int ift2ifm(uint8_t if_type) { switch (if_type) { case IFT_ETHER: return (IFM_ETHER); case IFT_IEEE80211: return (IFM_IEEE80211); /* TODO maybe add ATM (only other media type supported) */ default: return (0); } } const char * get_media_descr(int media_type) { const struct ifmedia_description *p; for (p = ifm_type_descriptions; p->ifmt_string != NULL; p++) if (media_type == p->ifmt_word) return (p->ifmt_string); return ("unknown media"); } const char * get_linkstate(uint8_t if_type, int link_state) { static char buf[8]; switch (link_state) { case LINK_STATE_DOWN: return "no network"; case LINK_STATE_UP: return "active"; case LINK_STATE_UNKNOWN: return "unknown"; default: snprintf(buf, sizeof(buf), "[#%d]", link_state); return (buf); } } #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) void get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) { int i; for (i = 0; i < RTAX_MAX; i++) { if (addrs & (1 << i)) { rti_info[i] = sa; sa = (struct sockaddr *)((char *)(sa) + ROUNDUP(sa->sa_len)); } else rti_info[i] = NULL; } } static int get_fib(const char *name) { struct ifreq ifr = { 0 }; int s, fib = RT_DEFAULT_FIB; if ((s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == -1) fatal("get_fib: socket"); strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); if (ioctl(s, SIOCGIFFIB, (caddr_t)&ifr) == 0) fib = ifr.ifr_fib; close(s); return fib; } void if_change(u_short ifindex, int flags, struct if_data *ifd) { struct ktable *kt; struct kif *kif; int fib; uint8_t reachable; if ((kif = kif_find(ifindex)) == NULL) { log_warnx("%s: interface with index %u not found", __func__, ifindex); return; } fib = get_fib(kif->ifname); log_info("%s: %s: rdomain %u %s, %s, %s, %s", __func__, kif->ifname, fib, flags & IFF_UP ? "UP" : "DOWN", get_media_descr(ift2ifm(ifd->ifi_type)), get_linkstate(ifd->ifi_type, ifd->ifi_link_state), get_baudrate(ifd->ifi_baudrate, "bps")); kif->flags = flags; kif->link_state = ifd->ifi_link_state; kif->if_type = ifd->ifi_type; kif->rdomain = fib; kif->baudrate = ifd->ifi_baudrate; kif->depend_state = kif_depend_state(kif); kr_send_dependon(kif); if ((reachable = kif_validate(kif)) == kif->nh_reachable) return; /* nothing changed wrt nexthop validity */ kif->nh_reachable = reachable; kt = ktable_get(kif->rdomain); if (kt == NULL) return; knexthop_track(kt, ifindex); } void if_announce(void *msg) { struct if_announcemsghdr *ifan; struct kif *kif; ifan = msg; switch (ifan->ifan_what) { case IFAN_ARRIVAL: if ((kif = calloc(1, sizeof(*kif))) == NULL) { log_warn("%s", __func__); return; } kif->ifindex = ifan->ifan_index; strlcpy(kif->ifname, ifan->ifan_name, sizeof(kif->ifname)); kif_insert(kif); break; case IFAN_DEPARTURE: kif = kif_find(ifan->ifan_index); if (kif != NULL) kif_remove(kif); break; } } int get_mpe_config(const char *name, u_int *rdomain, u_int *label) { return (-1); } static int prio2flags(uint8_t fib_prio) { switch (fib_prio) { case RTP_PROTO1: return RTF_PROTO1; case RTP_PROTO2: return RTF_PROTO2; default: case RTP_PROTO3: return RTF_PROTO3; } } static uint8_t flags2prio(int flags) { uint8_t prio = RTP_KERN; int prioflag; /* Everything from the kernel is one prio unless it is a bgpd route */ prioflag = prio2flags(kr_state.fib_prio); if ((flags & prioflag) == prioflag) prio = RTP_MINE; return prio; } /* * rtsock related functions */ int send_rtmsg(int action, struct ktable *kt, struct kroute_full *kf) { struct iovec iov[7]; struct rt_msghdr hdr; struct sockaddr_storage prefix, nexthop, mask; struct bgpd_addr netmask; struct sockaddr *sa; socklen_t salen; int iovcnt = 0; if (!kt->fib_sync) return (0); /* initialize header */ memset(&hdr, 0, sizeof(hdr)); hdr.rtm_version = RTM_VERSION; hdr.rtm_type = action; hdr.rtm_flags = prio2flags(kr_state.fib_prio); if (kf->flags & F_BLACKHOLE) hdr.rtm_flags |= RTF_BLACKHOLE; if (kf->flags & F_REJECT) hdr.rtm_flags |= RTF_REJECT; if (action == RTM_CHANGE) /* reset these flags on change */ hdr.rtm_fmask = RTF_REJECT|RTF_BLACKHOLE; hdr.rtm_seq = kr_state.rtseq++; /* overflow doesn't matter */ hdr.rtm_msglen = sizeof(hdr); /* adjust iovec */ iov[iovcnt].iov_base = &hdr; iov[iovcnt++].iov_len = sizeof(hdr); memset(&prefix, 0, sizeof(prefix)); sa = addr2sa(&kf->prefix, 0, &salen); sa->sa_len = salen; memcpy(&prefix, sa, salen); /* adjust header */ hdr.rtm_addrs |= RTA_DST; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &prefix; iov[iovcnt++].iov_len = ROUNDUP(salen); /* XXX can we even have no nexthop ??? */ if (kf->nexthop.aid != AID_UNSPEC) { memset(&nexthop, 0, sizeof(nexthop)); sa = addr2sa(&kf->nexthop, 0, &salen); sa->sa_len = salen; memcpy(&nexthop, sa, salen); /* adjust header */ hdr.rtm_flags |= RTF_GATEWAY; hdr.rtm_addrs |= RTA_GATEWAY; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &nexthop; iov[iovcnt++].iov_len = ROUNDUP(salen); } memset(&netmask, 0, sizeof(netmask)); memset(&netmask.v6, 0xff, sizeof(netmask.v6)); netmask.aid = kf->prefix.aid; applymask(&netmask, &netmask, kf->prefixlen); memset(&mask, 0, sizeof(mask)); sa = addr2sa(&netmask, 0, &salen); sa->sa_len = salen; memcpy(&mask, sa, salen); /* adjust header */ hdr.rtm_addrs |= RTA_NETMASK; hdr.rtm_msglen += ROUNDUP(salen); /* adjust iovec */ iov[iovcnt].iov_base = &mask; iov[iovcnt++].iov_len = ROUNDUP(salen); if (kf->flags & F_MPLS) { /* no MPLS support */ return (0); } /* Silently ignore set routing labels */ retry: if (writev(kr_state.fd, iov, iovcnt) == -1) { if (errno == ESRCH) { if (hdr.rtm_type == RTM_CHANGE) { hdr.rtm_type = RTM_ADD; goto retry; } else if (hdr.rtm_type == RTM_DELETE) { log_info("route %s/%u vanished before delete", log_addr(&kf->prefix), kf->prefixlen); return (1); } } log_warn("%s: action %u, prefix %s/%u", __func__, hdr.rtm_type, log_addr(&kf->prefix), kf->prefixlen); return (0); } return (1); } int fetchtable(struct ktable *kt) { size_t len; int mib[7]; char *buf = NULL, *next, *lim; struct rt_msghdr *rtm; struct kroute_full kf; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_DUMP; mib[5] = 0; mib[6] = kt->rtableid; if (sysctl(mib, 7, NULL, &len, NULL, 0) == -1) { if (kt->rtableid != 0 && errno == EINVAL) /* table nonexistent */ return (0); log_warn("%s: sysctl", __func__); return (-1); } if (len > 0) { if ((buf = malloc(len)) == NULL) { log_warn("%s", __func__); return (-1); } if (sysctl(mib, 7, buf, &len, NULL, 0) == -1) { log_warn("%s: sysctl2", __func__); free(buf); return (-1); } } lim = buf + len; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; if (rtm->rtm_version != RTM_VERSION) continue; if (dispatch_rtmsg_addr(rtm, &kf) == -1) continue; if (kf.priority == RTP_MINE) send_rtmsg(RTM_DELETE, kt, &kf); else kroute_insert(kt, &kf); } free(buf); return (0); } int fetchifs(int ifindex) { size_t len; int mib[6], fib; char *buf, *next, *lim; struct if_msghdr ifm; struct kif *kif; struct sockaddr *sa, *rti_info[RTAX_MAX]; struct sockaddr_dl *sdl; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = AF_INET; /* AF does not matter but AF_INET is shorter */ mib[4] = NET_RT_IFLIST; mib[5] = ifindex; if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) { log_warn("%s: sysctl", __func__); return (-1); } if ((buf = malloc(len)) == NULL) { log_warn("%s", __func__); return (-1); } if (sysctl(mib, 6, buf, &len, NULL, 0) == -1) { log_warn("%s: sysctl2", __func__); free(buf); return (-1); } lim = buf + len; for (next = buf; next < lim; next += ifm.ifm_msglen) { memcpy(&ifm, next, sizeof(ifm)); if (ifm.ifm_version != RTM_VERSION) continue; if (ifm.ifm_type != RTM_IFINFO) continue; sa = (struct sockaddr *)(next + sizeof(ifm)); get_rtaddrs(ifm.ifm_addrs, sa, rti_info); if ((kif = calloc(1, sizeof(*kif))) == NULL) { log_warn("%s", __func__); free(buf); return (-1); } kif->ifindex = ifm.ifm_index; kif->flags = ifm.ifm_flags; kif->link_state = ifm.ifm_data.ifi_link_state; kif->if_type = ifm.ifm_data.ifi_type; kif->baudrate = ifm.ifm_data.ifi_baudrate; kif->nh_reachable = kif_validate(kif); kif->depend_state = kif_depend_state(kif); if ((sa = rti_info[RTAX_IFP]) != NULL) if (sa->sa_family == AF_LINK) { sdl = (struct sockaddr_dl *)sa; if (sdl->sdl_nlen >= sizeof(kif->ifname)) memcpy(kif->ifname, sdl->sdl_data, sizeof(kif->ifname) - 1); else if (sdl->sdl_nlen > 0) memcpy(kif->ifname, sdl->sdl_data, sdl->sdl_nlen); /* string already terminated via calloc() */ } fib = get_fib(kif->ifname); kif->rdomain = fib; kif_insert(kif); } free(buf); return (0); } int dispatch_rtmsg(void) { char buf[RT_BUF_SIZE]; ssize_t n; char *next, *lim; struct rt_msghdr *rtm; struct if_msghdr ifm; struct kroute_full kf; struct ktable *kt; int mpath = 1; if ((n = read(kr_state.fd, &buf, sizeof(buf))) == -1) { if (errno == EAGAIN || errno == EINTR) return (0); log_warn("%s: read error", __func__); return (-1); } if (n == 0) { log_warnx("routing socket closed"); return (-1); } lim = buf + n; for (next = buf; next < lim; next += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)next; if (lim < next + sizeof(u_short) || lim < next + rtm->rtm_msglen) fatalx("%s: partial rtm in buffer", __func__); if (rtm->rtm_version != RTM_VERSION) continue; switch (rtm->rtm_type) { case RTM_ADD: case RTM_CHANGE: case RTM_DELETE: if (rtm->rtm_pid == kr_state.pid) /* cause by us */ continue; /* failed attempts */ if (rtm->rtm_errno || !(rtm->rtm_flags & RTF_DONE)) continue; if ((kt = ktable_get(getrtable())) == NULL) continue; if (dispatch_rtmsg_addr(rtm, &kf) == -1) continue; switch (rtm->rtm_type) { case RTM_ADD: case RTM_CHANGE: if (kr_fib_change(kt, &kf, rtm->rtm_type, mpath) == -1) return -1; break; case RTM_DELETE: if (kr_fib_delete(kt, &kf, mpath) == -1) return -1; break; } break; case RTM_IFINFO: memcpy(&ifm, next, sizeof(ifm)); if_change(ifm.ifm_index, ifm.ifm_flags, &ifm.ifm_data); break; case RTM_IFANNOUNCE: if_announce(next); break; default: /* ignore for now */ break; } } return (0); } int dispatch_rtmsg_addr(struct rt_msghdr *rtm, struct kroute_full *kf) { struct sockaddr *sa, *rti_info[RTAX_MAX]; struct sockaddr_in *sa_in; struct sockaddr_in6 *sa_in6; sa = (struct sockaddr *)(rtm + 1); get_rtaddrs(rtm->rtm_addrs, sa, rti_info); /* Skip ARP/ND cache, broadcast and dynamic routes. */ if (rtm->rtm_flags & (RTF_LLINFO|RTF_BROADCAST|RTF_DYNAMIC)) return (-1); if ((sa = rti_info[RTAX_DST]) == NULL) { log_warnx("route message without destination"); return (-1); } memset(kf, 0, sizeof(*kf)); if (rtm->rtm_flags & RTF_STATIC) kf->flags |= F_STATIC; if (rtm->rtm_flags & RTF_BLACKHOLE) kf->flags |= F_BLACKHOLE; if (rtm->rtm_flags & RTF_REJECT) kf->flags |= F_REJECT; kf->priority = flags2prio(rtm->rtm_flags); sa2addr(sa, &kf->prefix, NULL); switch (sa->sa_family) { case AF_INET: sa_in = (struct sockaddr_in *)rti_info[RTAX_NETMASK]; if (rtm->rtm_flags & RTF_HOST) kf->prefixlen = 32; else if (sa_in != NULL) kf->prefixlen = mask2prefixlen4(sa_in); else kf->prefixlen = prefixlen_classful(kf->prefix.v4.s_addr); break; case AF_INET6: sa_in6 = (struct sockaddr_in6 *)rti_info[RTAX_NETMASK]; if (rtm->rtm_flags & RTF_HOST) kf->prefixlen = 128; else if (sa_in6 != NULL) kf->prefixlen = mask2prefixlen6(sa_in6); else fatalx("in6 net addr without netmask"); break; default: return (-1); } if ((sa = rti_info[RTAX_GATEWAY]) == NULL) { log_warnx("route %s/%u without gateway", log_addr(&kf->prefix), kf->prefixlen); return (-1); } kf->ifindex = rtm->rtm_index; if (rtm->rtm_flags & RTF_GATEWAY) { switch (sa->sa_family) { case AF_LINK: kf->flags |= F_CONNECTED; break; case AF_INET: case AF_INET6: sa2addr(rti_info[RTAX_GATEWAY], &kf->nexthop, NULL); break; } } else { kf->flags |= F_CONNECTED; } return (0); } int kr_fib_delete(struct ktable *kt, struct kroute_full *kf, int mpath) { struct kroute *kr; struct kroute6 *kr6; int rv; rv = kroute_remove(kt, kf, !mpath); /* check if lower pref bgp route exists */ switch (kf->prefix.aid) { case AID_INET: if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, RTP_MINE)) != NULL) { if (send_rtmsg(RTM_ADD, kt, kf)) kr->flags |= F_BGPD_INSERTED; } break; case AID_INET6: if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, RTP_MINE)) != NULL) { if (send_rtmsg(RTM_ADD, kt, kf)) kr6->flags |= F_BGPD_INSERTED; } break; } return rv; } int kr_fib_change(struct ktable *kt, struct kroute_full *kf, int type, int mpath) { struct kroute *kr; struct kroute6 *kr6; int flags, oflags; int changed = 0, rtlabel_changed = 0; uint16_t new_labelid; flags = kf->flags; switch (kf->prefix.aid) { case AID_INET: if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { if (!(kf->flags & F_BGPD)) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr = kroute_matchgw(kr, kf)) == NULL) { log_warnx("%s[change]: " "mpath route not found", __func__); goto add4; } else if (mpath && type == RTM_ADD) goto add4; if (kf->nexthop.aid == AID_INET) { if (kr->nexthop.s_addr != kf->nexthop.v4.s_addr) changed = 1; kr->nexthop.s_addr = kf->nexthop.v4.s_addr; kr->ifindex = kf->ifindex; } else { if (kr->nexthop.s_addr != 0) changed = 1; kr->nexthop.s_addr = 0; kr->ifindex = kf->ifindex; } if (kr->flags & F_NEXTHOP) flags |= F_NEXTHOP; new_labelid = rtlabel_name2id(kf->label); if (kr->labelid != new_labelid) { rtlabel_unref(kr->labelid); kr->labelid = new_labelid; rtlabel_changed = 1; } oflags = kr->flags; if (flags != oflags) changed = 1; kr->flags = flags; if (rtlabel_changed) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if ((oflags & F_CONNECTED) && !(flags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if ((flags & F_CONNECTED) && !(oflags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if (kr->flags & F_NEXTHOP && changed) knexthop_update(kt, kf); } else { kr->flags &= ~F_BGPD_INSERTED; } } else { add4: kroute_insert(kt, kf); } break; case AID_INET6: if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { if (!(kf->flags & F_BGPD)) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr6 = kroute6_matchgw(kr6, kf)) == NULL) { log_warnx("%s[change]: IPv6 mpath " "route not found", __func__); goto add6; } else if (mpath && type == RTM_ADD) goto add6; if (kf->nexthop.aid == AID_INET6) { if (memcmp(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)) || kr6->nexthop_scope_id != kf->nexthop.scope_id) changed = 1; kr6->nexthop = kf->nexthop.v6; kr6->nexthop_scope_id = kf->nexthop.scope_id; kr6->ifindex = kf->ifindex; } else { if (memcmp(&kr6->nexthop, &in6addr_any, sizeof(struct in6_addr))) changed = 1; kr6->nexthop = in6addr_any; kr6->nexthop_scope_id = 0; kr6->ifindex = kf->ifindex; } if (kr6->flags & F_NEXTHOP) flags |= F_NEXTHOP; new_labelid = rtlabel_name2id(kf->label); if (kr6->labelid != new_labelid) { rtlabel_unref(kr6->labelid); kr6->labelid = new_labelid; rtlabel_changed = 1; } oflags = kr6->flags; if (flags != oflags) changed = 1; kr6->flags = flags; if (rtlabel_changed) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if ((oflags & F_CONNECTED) && !(flags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if ((flags & F_CONNECTED) && !(oflags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if (kr6->flags & F_NEXTHOP && changed) knexthop_update(kt, kf); } else { kr6->flags &= ~F_BGPD_INSERTED; } } else { add6: kroute_insert(kt, kf); } break; } return (0); } openbgpd-8.8/src/bgpd/kroute-linux.c100644 001750 001750 00000215364 14751151116 0013223/* $OpenBSD: kroute.c,v 1.299 2022/09/15 08:20:14 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2022 Claudio Jeker * Copyright (c) 2021 Ariadne Conill * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include "bgpd.h" #include "log.h" #include #include #include #define RTP_ANY 0x0 #define RTP_MINE 0xff enum { RTM_ADD=1, RTM_CHANGE, RTM_DELETE, }; enum { LINK_STATE_UNKNOWN, LINK_STATE_DOWN, LINK_STATE_UP, }; struct ktable **krt; u_int krt_size; struct { struct mnl_socket *nl; uint32_t pid; uint32_t nlmsg_seq; uint32_t query_seq; uint8_t fib_prio; } kr_state; struct kroute { RB_ENTRY(kroute) entry; struct kroute *next; struct in_addr prefix; struct in_addr nexthop; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct kroute6 { RB_ENTRY(kroute6) entry; struct kroute6 *next; struct in6_addr prefix; struct in6_addr nexthop; uint32_t prefix_scope_id; /* because ... */ uint32_t nexthop_scope_id; uint32_t mplslabel; uint16_t flags; uint16_t labelid; u_short ifindex; uint8_t prefixlen; uint8_t priority; }; struct knexthop { RB_ENTRY(knexthop) entry; struct bgpd_addr nexthop; void *kroute; u_short ifindex; }; struct kredist_node { RB_ENTRY(kredist_node) entry; struct bgpd_addr prefix; uint64_t rd; uint8_t prefixlen; uint8_t dynamic; }; struct kif { RB_ENTRY(kif) entry; char ifname[IFNAMSIZ]; uint64_t baudrate; u_int rdomain; int flags; u_short ifindex; uint8_t if_type; uint8_t link_state; uint8_t nh_reachable; /* for nexthop verification */ uint8_t depend_state; /* for session depend on */ }; int ktable_new(u_int, u_int, char *, int); void ktable_free(u_int); void ktable_destroy(struct ktable *); struct ktable *ktable_get(u_int); int kr4_change(struct ktable *, struct kroute_full *); int kr6_change(struct ktable *, struct kroute_full *); #ifdef NOTYET int krVPN4_change(struct ktable *, struct kroute_full *); int krVPN6_change(struct ktable *, struct kroute_full *); #endif int kr_net_match(struct ktable *, struct network_config *, uint16_t, int); struct network *kr_net_find(struct ktable *, struct network *); void kr_net_clear(struct ktable *); void kr_redistribute(int, struct ktable *, struct kroute_full *); uint8_t kr_priority(struct kroute_full *); struct kroute_full *kr_tofull(struct kroute *); struct kroute_full *kr6_tofull(struct kroute6 *); int kroute_compare(struct kroute *, struct kroute *); int kroute6_compare(struct kroute6 *, struct kroute6 *); int knexthop_compare(struct knexthop *, struct knexthop *); int kredist_compare(struct kredist_node *, struct kredist_node *); int kif_compare(struct kif *, struct kif *); struct kroute *kroute_find(struct ktable *, const struct bgpd_addr *, uint8_t, uint8_t); struct kroute *kroute_matchgw(struct kroute *, struct kroute_full *); int kroute_insert(struct ktable *, struct kroute_full *); int kroute_remove(struct ktable *, struct kroute_full *, int); void kroute_clear(struct ktable *); struct kroute6 *kroute6_find(struct ktable *, const struct bgpd_addr *, uint8_t, uint8_t); struct kroute6 *kroute6_matchgw(struct kroute6 *, struct kroute_full *); void kroute6_clear(struct ktable *); struct knexthop *knexthop_find(struct ktable *, struct bgpd_addr *); int knexthop_insert(struct ktable *, struct knexthop *); void knexthop_remove(struct ktable *, struct knexthop *); void knexthop_clear(struct ktable *); struct kif *kif_find(int); int kif_insert(struct kif *); int kif_remove(struct kif *); void kif_clear(void); int kroute_validate(struct kroute *); int kroute6_validate(struct kroute6 *); int knexthop_true_nexthop(struct ktable *, struct kroute_full *); void knexthop_validate(struct ktable *, struct knexthop *); void knexthop_track(struct ktable *, u_short); void knexthop_update(struct ktable *, struct kroute_full *); void knexthop_send_update(struct knexthop *); struct kroute *kroute_match(struct ktable *, struct bgpd_addr *, int); struct kroute6 *kroute6_match(struct ktable *, struct bgpd_addr *, int); void kroute_detach_nexthop(struct ktable *, struct knexthop *); uint8_t prefixlen_classful(in_addr_t); static uint8_t mask2prefixlen4(struct sockaddr_in *); static uint8_t mask2prefixlen6(struct sockaddr_in6 *); #ifdef NOTYET uint64_t ift2ifm(uint8_t); const char *get_media_descr(uint64_t); void if_change(u_short, int, struct if_data *); #endif const char *get_linkstate(uint8_t, int); int send_rtmsg(int, struct ktable *, struct kroute_full *); int dispatch_rtmsg(void); int fetchtable(struct ktable *); int fetchifs(int); int dispatch_rtmsg_addr(const struct nlmsghdr *, const struct rtmsg *, const struct nlattr **, struct kroute_full *); int kr_fib_delete(struct ktable *, struct kroute_full *, int); int kr_fib_change(struct ktable *, struct kroute_full *, int, int); RB_PROTOTYPE(kroute_tree, kroute, entry, kroute_compare) RB_GENERATE(kroute_tree, kroute, entry, kroute_compare) RB_PROTOTYPE(kroute6_tree, kroute6, entry, kroute6_compare) RB_GENERATE(kroute6_tree, kroute6, entry, kroute6_compare) RB_PROTOTYPE(knexthop_tree, knexthop, entry, knexthop_compare) RB_GENERATE(knexthop_tree, knexthop, entry, knexthop_compare) RB_PROTOTYPE(kredist_tree, kredist_node, entry, kredist_compare) RB_GENERATE(kredist_tree, kredist_node, entry, kredist_compare) RB_HEAD(kif_tree, kif) kit; RB_PROTOTYPE(kif_tree, kif, entry, kif_compare) RB_GENERATE(kif_tree, kif, entry, kif_compare) #define KT2KNT(x) (&(ktable_get((x)->nhtableid)->knt)) /* seq num 0 is special, so skip it */ static uint32_t kr_next_seq(void) { if (kr_state.nlmsg_seq == 0) kr_state.nlmsg_seq++; return kr_state.nlmsg_seq++; } /* * exported functions */ int kr_init(int *fd, uint8_t fib_prio) { kr_state.nl = mnl_socket_open2(NETLINK_ROUTE, SOCK_CLOEXEC | SOCK_NONBLOCK); if (kr_state.nl == NULL) fatal("mnl_socket_open"); if (mnl_socket_bind(kr_state.nl, RTMGRP_LINK | RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE, MNL_SOCKET_AUTOPID) < 0) fatal("mnl_socket_bind"); kr_state.pid = mnl_socket_get_portid(kr_state.nl); kr_state.nlmsg_seq = 1; kr_state.fib_prio = fib_prio; RB_INIT(&kit); if (fetchifs(0) == -1) return (-1); *fd = mnl_socket_get_fd(kr_state.nl); return (0); } int kr_default_prio(void) { return RTPROT_BGP; } int kr_check_prio(long long prio) { if (prio <= RTPROT_STATIC || prio >= UCHAR_MAX) return 0; return 1; } int ktable_new(u_int rtableid, u_int rdomid, char *name, int fs) { struct ktable **xkrt; struct ktable *kt; size_t oldsize; /* resize index table if needed */ if (rtableid >= krt_size) { oldsize = sizeof(struct ktable *) * krt_size; if ((xkrt = reallocarray(krt, rtableid + 1, sizeof(struct ktable *))) == NULL) { log_warn("%s", __func__); return (-1); } krt = xkrt; krt_size = rtableid + 1; memset((char *)krt + oldsize, 0, krt_size * sizeof(struct ktable *) - oldsize); } if (krt[rtableid]) fatalx("ktable_new: table already exists."); /* allocate new element */ kt = krt[rtableid] = calloc(1, sizeof(struct ktable)); if (kt == NULL) { log_warn("%s", __func__); return (-1); } /* initialize structure ... */ strlcpy(kt->descr, name, sizeof(kt->descr)); RB_INIT(&kt->krt); RB_INIT(&kt->krt6); RB_INIT(&kt->knt); TAILQ_INIT(&kt->krn); kt->fib_conf = kt->fib_sync = fs; kt->rtableid = rtableid; kt->nhtableid = rdomid; /* bump refcount of rdomain table for the nexthop lookups */ ktable_get(kt->nhtableid)->nhrefcnt++; /* ... and load it */ if (fetchtable(kt) == -1) return (-1); /* everything is up and running */ kt->state = RECONF_REINIT; log_debug("%s: %s with rtableid %d rdomain %d", __func__, name, rtableid, rdomid); return (0); } void ktable_free(u_int rtableid) { struct ktable *kt, *nkt; if ((kt = ktable_get(rtableid)) == NULL) return; /* decouple from kernel, no new routes will be entered from here */ kr_fib_decouple(kt->rtableid); /* first unhook from the nexthop table */ nkt = ktable_get(kt->nhtableid); nkt->nhrefcnt--; /* * Evil little details: * If kt->nhrefcnt > 0 then kt == nkt and nothing needs to be done. * If kt != nkt then kt->nhrefcnt must be 0 and kt must be killed. * If nkt is no longer referenced it must be killed (possible double * free so check that kt != nkt). */ if (kt != nkt && nkt->nhrefcnt <= 0) ktable_destroy(nkt); if (kt->nhrefcnt <= 0) ktable_destroy(kt); } void ktable_destroy(struct ktable *kt) { /* decouple just to be sure, does not hurt */ kr_fib_decouple(kt->rtableid); log_debug("%s: freeing ktable %s rtableid %u", __func__, kt->descr, kt->rtableid); /* only clear nexthop table if it is the main rdomain table */ if (kt->rtableid == kt->nhtableid) knexthop_clear(kt); kroute_clear(kt); kroute6_clear(kt); knexthop_clear(kt); kr_net_clear(kt); krt[kt->rtableid] = NULL; free(kt); } struct ktable * ktable_get(u_int rtableid) { if (rtableid >= krt_size) return (NULL); return (krt[rtableid]); } int ktable_update(u_int rtableid, char *name, int flags) { struct ktable *kt, *rkt; u_int rdomid; if (!ktable_exists(rtableid, &rdomid)) fatalx("King Bula lost a table"); /* may not happen */ if (rdomid != rtableid || flags & F_RIB_NOFIB) { rkt = ktable_get(rdomid); if (rkt == NULL) { char buf[32]; snprintf(buf, sizeof(buf), "rdomain_%d", rdomid); if (ktable_new(rdomid, rdomid, buf, 0)) return (-1); } else { /* there is no need for full fib synchronisation if * the table is only used for nexthop lookups. */ if (rkt->state == RECONF_DELETE) { rkt->fib_conf = 0; rkt->state = RECONF_KEEP; } } } if (flags & (F_RIB_NOFIB | F_RIB_NOEVALUATE)) /* only rdomain table must exist */ return (0); kt = ktable_get(rtableid); if (kt == NULL) { if (ktable_new(rtableid, rdomid, name, !(flags & F_RIB_NOFIBSYNC))) return (-1); } else { /* fib sync has higher preference then no sync */ if (kt->state == RECONF_DELETE) { kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); kt->state = RECONF_KEEP; } else if (!kt->fib_conf) kt->fib_conf = !(flags & F_RIB_NOFIBSYNC); strlcpy(kt->descr, name, sizeof(kt->descr)); } return (0); } int ktable_exists(u_int rtableid, u_int *rdomid) { if (rtableid != 0) return (0); if (rdomid) *rdomid = 0; return (1); } int kr_change(u_int rtableid, struct kroute_full *kf) { struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); kf->flags |= F_BGPD; kf->priority = RTP_MINE; if (!knexthop_true_nexthop(kt, kf)) return kroute_remove(kt, kf, 1); switch (kf->prefix.aid) { case AID_INET: return (kr4_change(kt, kf)); case AID_INET6: return (kr6_change(kt, kf)); #ifdef NOTYET case AID_VPN_IPv4: return (krVPN4_change(kt, kf)); case AID_VPN_IPv6: return (krVPN6_change(kt, kf)); #endif } log_warnx("%s: not handled AID", __func__); return (-1); } int kr4_change(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr; /* for blackhole and reject routes nexthop needs to be 127.0.0.1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) kf->nexthop.v4.s_addr = htonl(INADDR_LOOPBACK); /* nexthop within 127/8 -> ignore silently */ else if ((kf->nexthop.v4.s_addr & htonl(IN_CLASSA_NET)) == htonl(INADDR_LOOPBACK & IN_CLASSA_NET)) return (0); if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { kr->nexthop.s_addr = kf->nexthop.v4.s_addr; rtlabel_unref(kr->labelid); kr->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr->flags |= F_BLACKHOLE; else kr->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr->flags |= F_REJECT; else kr->flags &= ~F_REJECT; if (kr->flags & F_NEXTHOP) knexthop_update(kt, kf); if (send_rtmsg(RTM_CHANGE, kt, kf)) kr->flags |= F_BGPD_INSERTED; } return (0); } int kr6_change(struct ktable *kt, struct kroute_full *kf) { struct kroute6 *kr6; struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT; /* for blackhole and reject routes nexthop needs to be ::1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) memcpy(&kf->nexthop.v6, &lo6, sizeof(kf->nexthop.v6)); /* nexthop to loopback -> ignore silently */ else if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) return (0); if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { memcpy(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)); kr6->nexthop_scope_id = kf->nexthop.scope_id; rtlabel_unref(kr6->labelid); kr6->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr6->flags |= F_BLACKHOLE; else kr6->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr6->flags |= F_REJECT; else kr6->flags &= ~F_REJECT; if (kr6->flags & F_NEXTHOP) knexthop_update(kt, kf); if (send_rtmsg(RTM_CHANGE, kt, kf)) kr6->flags |= F_BGPD_INSERTED; } return (0); } #ifdef NOTYET int krVPN4_change(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr; uint32_t mplslabel = 0; /* nexthop within 127/8 -> ignore silently */ if ((kf->nexthop.v4.s_addr & htonl(IN_CLASSA_NET)) == htonl(INADDR_LOOPBACK & IN_CLASSA_NET)) return (0); /* only a single MPLS label is supported for now */ if (kf->prefix.labellen != 3) { log_warnx("%s: %s/%u has not a single label", __func__, log_addr(&kf->prefix), kf->prefixlen); return (0); } mplslabel = (kf->prefix.labelstack[0] << 24) | (kf->prefix.labelstack[1] << 16) | (kf->prefix.labelstack[2] << 8); mplslabel = htonl(mplslabel); /* for blackhole and reject routes nexthop needs to be 127.0.0.1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) kf->nexthop.v4.s_addr = htonl(INADDR_LOOPBACK); if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { kr->mplslabel = mplslabel; kr->ifindex = kf->ifindex; kr->nexthop.s_addr = kf->nexthop.v4.s_addr; rtlabel_unref(kr->labelid); kr->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr->flags |= F_BLACKHOLE; else kr->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr->flags |= F_REJECT; else kr->flags &= ~F_REJECT; if (send_rtmsg(RTM_CHANGE, kt, kf)) kr->flags |= F_BGPD_INSERTED; } return (0); } int krVPN6_change(struct ktable *kt, struct kroute_full *kf) { struct kroute6 *kr6; struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT; uint32_t mplslabel = 0; /* nexthop to loopback -> ignore silently */ if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) return (0); /* only a single MPLS label is supported for now */ if (kf->prefix.labellen != 3) { log_warnx("%s: %s/%u has not a single label", __func__, log_addr(&kf->prefix), kf->prefixlen); return (0); } mplslabel = (kf->prefix.labelstack[0] << 24) | (kf->prefix.labelstack[1] << 16) | (kf->prefix.labelstack[2] << 8); mplslabel = htonl(mplslabel); /* for blackhole and reject routes nexthop needs to be ::1 */ if (kf->flags & (F_BLACKHOLE|F_REJECT)) memcpy(&kf->nexthop.v6, &lo6, sizeof(kf->nexthop.v6)); if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) { if (kroute_insert(kt, kf) == -1) return (-1); } else { kr6->mplslabel = mplslabel; kr6->ifindex = kf->ifindex; memcpy(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)); kr6->nexthop_scope_id = kf->nexthop.scope_id; rtlabel_unref(kr6->labelid); kr6->labelid = rtlabel_name2id(kf->label); if (kf->flags & F_BLACKHOLE) kr6->flags |= F_BLACKHOLE; else kr6->flags &= ~F_BLACKHOLE; if (kf->flags & F_REJECT) kr6->flags |= F_REJECT; else kr6->flags &= ~F_REJECT; if (send_rtmsg(RTM_CHANGE, kt, kf)) kr6->flags |= F_BGPD_INSERTED; } return (0); } #endif int kr_delete(u_int rtableid, struct kroute_full *kf) { struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); kf->flags |= F_BGPD; kf->priority = RTP_MINE; return kroute_remove(kt, kf, 1); } int kr_flush(u_int rtableid) { struct ktable *kt; struct kroute *kr, *next; struct kroute6 *kr6, *next6; if ((kt = ktable_get(rtableid)) == NULL) /* too noisy during reloads, just ignore */ return (0); RB_FOREACH_SAFE(kr, kroute_tree, &kt->krt, next) if ((kr->flags & F_BGPD_INSERTED)) { if (kroute_remove(kt, kr_tofull(kr), 1) == -1) return (-1); } RB_FOREACH_SAFE(kr6, kroute6_tree, &kt->krt6, next6) if ((kr6->flags & F_BGPD_INSERTED)) { if (kroute_remove(kt, kr6_tofull(kr6), 1) == -1) return (-1); } kt->fib_sync = 0; return (0); } void kr_shutdown(void) { u_int i; for (i = krt_size; i > 0; i--) ktable_free(i - 1); kif_clear(); free(krt); mnl_socket_close(kr_state.nl); } void kr_fib_couple(u_int rtableid) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */ return; if (kt->fib_sync) /* already coupled */ return; kt->fib_sync = 1; RB_FOREACH(kr, kroute_tree, &kt->krt) if (kr->flags & F_BGPD) { if (send_rtmsg(RTM_ADD, kt, kr_tofull(kr))) kr->flags |= F_BGPD_INSERTED; } RB_FOREACH(kr6, kroute6_tree, &kt->krt6) if (kr6->flags & F_BGPD) { if (send_rtmsg(RTM_ADD, kt, kr6_tofull(kr6))) kr6->flags |= F_BGPD_INSERTED; } log_info("kernel routing table %u (%s) coupled", kt->rtableid, kt->descr); } void kr_fib_couple_all(void) { u_int i; for (i = krt_size; i > 0; i--) kr_fib_couple(i - 1); } void kr_fib_decouple(u_int rtableid) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; if ((kt = ktable_get(rtableid)) == NULL) /* table does not exist */ return; if (!kt->fib_sync) /* already decoupled */ return; RB_FOREACH(kr, kroute_tree, &kt->krt) if ((kr->flags & F_BGPD_INSERTED)) { if (send_rtmsg(RTM_DELETE, kt, kr_tofull(kr))) kr->flags &= ~F_BGPD_INSERTED; } RB_FOREACH(kr6, kroute6_tree, &kt->krt6) if ((kr6->flags & F_BGPD_INSERTED)) { if (send_rtmsg(RTM_DELETE, kt, kr6_tofull(kr6))) kr6->flags &= ~F_BGPD_INSERTED; } kt->fib_sync = 0; log_info("kernel routing table %u (%s) decoupled", kt->rtableid, kt->descr); } void kr_fib_decouple_all(void) { u_int i; for (i = krt_size; i > 0; i--) kr_fib_decouple(i - 1); } void kr_fib_prio_set(uint8_t prio) { kr_state.fib_prio = prio; } int kr_dispatch_msg(void) { return (dispatch_rtmsg()); } int kr_nexthop_add(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *h; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return (0); } if ((h = knexthop_find(kt, addr)) != NULL) { /* should not happen... this is actually an error path */ knexthop_send_update(h); } else { if ((h = calloc(1, sizeof(*h))) == NULL) { log_warn("%s", __func__); return (-1); } memcpy(&h->nexthop, addr, sizeof(h->nexthop)); if (knexthop_insert(kt, h) == -1) return (-1); } return (0); } void kr_nexthop_delete(u_int rtableid, struct bgpd_addr *addr) { struct ktable *kt; struct knexthop *kn; if ((kt = ktable_get(rtableid)) == NULL) { log_warnx("%s: non-existent rtableid %d", __func__, rtableid); return; } if ((kn = knexthop_find(kt, addr)) == NULL) return; knexthop_remove(kt, kn); } static struct ctl_show_interface * kr_show_interface(struct kif *kif) { static struct ctl_show_interface iface; #ifdef NOTYET uint64_t ifms_type; #endif memset(&iface, 0, sizeof(iface)); strlcpy(iface.ifname, kif->ifname, sizeof(iface.ifname)); snprintf(iface.linkstate, sizeof(iface.linkstate), "%s", get_linkstate(kif->if_type, kif->link_state)); #ifdef NOTYET if ((ifms_type = ift2ifm(kif->if_type)) != 0) snprintf(iface.media, sizeof(iface.media), "%s", get_media_descr(ifms_type)); #endif iface.baudrate = kif->baudrate; iface.rdomain = kif->rdomain; iface.nh_reachable = kif->nh_reachable; iface.is_up = (kif->flags & IFF_UP) == IFF_UP; return &iface; } void kr_show_route(struct imsg *imsg) { struct ktable *kt; struct kroute *kr, *kn; struct kroute6 *kr6, *kn6; struct kroute_full *kf; struct bgpd_addr addr; struct ctl_kroute_req req; struct ctl_show_nexthop snh; struct knexthop *h; struct kif *kif; uint32_t tableid; pid_t pid; u_int i; u_short ifindex = 0; tableid = imsg_get_id(imsg); pid = imsg_get_pid(imsg); switch (imsg_get_type(imsg)) { case IMSG_CTL_KROUTE: if (imsg_get_data(imsg, &req, sizeof(req)) == -1) { log_warnx("%s: wrong imsg len", __func__); break; } kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } if (!req.af || req.af == AF_INET) RB_FOREACH(kr, kroute_tree, &kt->krt) { if (req.flags && (kr->flags & req.flags) == 0) continue; kn = kr; do { kf = kr_tofull(kn); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } while ((kn = kn->next) != NULL); } if (!req.af || req.af == AF_INET6) RB_FOREACH(kr6, kroute6_tree, &kt->krt6) { if (req.flags && (kr6->flags & req.flags) == 0) continue; kn6 = kr6; do { kf = kr6_tofull(kn6); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } while ((kn6 = kn6->next) != NULL); } break; case IMSG_CTL_KROUTE_ADDR: if (imsg_get_data(imsg, &addr, sizeof(addr)) == -1) { log_warnx("%s: wrong imsg len", __func__); break; } kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } kr = NULL; switch (addr.aid) { case AID_INET: kr = kroute_match(kt, &addr, 1); if (kr != NULL) { kf = kr_tofull(kr); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } break; case AID_INET6: kr6 = kroute6_match(kt, &addr, 1); if (kr6 != NULL) { kf = kr6_tofull(kr6); kf->priority = kr_priority(kf); send_imsg_session(IMSG_CTL_KROUTE, pid, kf, sizeof(*kf)); } break; } break; case IMSG_CTL_SHOW_NEXTHOP: kt = ktable_get(tableid); if (kt == NULL) { log_warnx("%s: table %u does not exist", __func__, tableid); break; } RB_FOREACH(h, knexthop_tree, KT2KNT(kt)) { memset(&snh, 0, sizeof(snh)); memcpy(&snh.addr, &h->nexthop, sizeof(snh.addr)); if (h->kroute != NULL) { switch (h->nexthop.aid) { case AID_INET: kr = h->kroute; snh.valid = kroute_validate(kr); snh.krvalid = 1; snh.kr = *kr_tofull(kr); ifindex = kr->ifindex; break; case AID_INET6: kr6 = h->kroute; snh.valid = kroute6_validate(kr6); snh.krvalid = 1; snh.kr = *kr6_tofull(kr6); ifindex = kr6->ifindex; break; } snh.kr.priority = kr_priority(&snh.kr); if ((kif = kif_find(ifindex)) != NULL) memcpy(&snh.iface, kr_show_interface(kif), sizeof(snh.iface)); } send_imsg_session(IMSG_CTL_SHOW_NEXTHOP, pid, &snh, sizeof(snh)); } break; case IMSG_CTL_SHOW_INTERFACE: RB_FOREACH(kif, kif_tree, &kit) send_imsg_session(IMSG_CTL_SHOW_INTERFACE, pid, kr_show_interface(kif), sizeof(struct ctl_show_interface)); break; case IMSG_CTL_SHOW_FIB_TABLES: for (i = 0; i < krt_size; i++) { struct ktable ktab; if ((kt = ktable_get(i)) == NULL) continue; ktab = *kt; /* do not leak internal information */ RB_INIT(&ktab.krt); RB_INIT(&ktab.krt6); RB_INIT(&ktab.knt); TAILQ_INIT(&ktab.krn); send_imsg_session(IMSG_CTL_SHOW_FIB_TABLES, pid, &ktab, sizeof(ktab)); } break; default: /* nada */ break; } send_imsg_session(IMSG_CTL_END, pid, NULL, 0); } static void kr_send_dependon(struct kif *kif) { struct session_dependon sdon = { {0} }; strlcpy(sdon.ifname, kif->ifname, sizeof(sdon.ifname)); sdon.depend_state = kif->depend_state; send_imsg_session(IMSG_SESSION_DEPENDON, 0, &sdon, sizeof(sdon)); } void kr_ifinfo(char *ifname) { struct kif *kif; RB_FOREACH(kif, kif_tree, &kit) if (!strcmp(ifname, kif->ifname)) { kr_send_dependon(kif); return; } } static int kr_net_redist_add(struct ktable *kt, struct network_config *net, struct filter_set_head *attr, int dynamic) { struct kredist_node *r, *xr; if ((r = calloc(1, sizeof(*r))) == NULL) fatal("%s", __func__); r->prefix = net->prefix; r->prefixlen = net->prefixlen; r->rd = net->rd; r->dynamic = dynamic; xr = RB_INSERT(kredist_tree, &kt->kredist, r); if (xr != NULL) { free(r); if (dynamic != xr->dynamic && dynamic) { /* * ignore update a non-dynamic announcement is * already present which has preference. */ return 0; } /* * only equal or non-dynamic announcement ends up here. * In both cases reset the dynamic flag (nop for equal) and * redistribute. */ xr->dynamic = dynamic; } if (send_network(IMSG_NETWORK_ADD, net, attr) == -1) log_warnx("%s: failed to send network update", __func__); return 1; } static void kr_net_redist_del(struct ktable *kt, struct network_config *net, int dynamic) { struct kredist_node *r, node; memset(&node, 0, sizeof(node)); node.prefix = net->prefix; node.prefixlen = net->prefixlen; node.rd = net->rd; r = RB_FIND(kredist_tree, &kt->kredist, &node); if (r == NULL || dynamic != r->dynamic) return; if (RB_REMOVE(kredist_tree, &kt->kredist, r) == NULL) { log_warnx("%s: failed to remove network %s/%u", __func__, log_addr(&node.prefix), node.prefixlen); return; } free(r); if (send_network(IMSG_NETWORK_REMOVE, net, NULL) == -1) log_warnx("%s: failed to send network removal", __func__); } int kr_net_match(struct ktable *kt, struct network_config *net, uint16_t flags, int loopback) { struct network *xn; TAILQ_FOREACH(xn, &kt->krn, entry) { if (xn->net.prefix.aid != net->prefix.aid) continue; switch (xn->net.type) { case NETWORK_DEFAULT: /* static match already redistributed */ continue; case NETWORK_STATIC: /* Skip networks with nexthop on loopback. */ if (loopback) continue; if (flags & F_STATIC) break; continue; case NETWORK_CONNECTED: /* Skip networks with nexthop on loopback. */ if (loopback) continue; if (flags & F_CONNECTED) break; continue; case NETWORK_RTLABEL: if (net->rtlabel == xn->net.rtlabel) break; continue; case NETWORK_PRIORITY: if (net->priority == xn->net.priority) break; continue; case NETWORK_MRTCLONE: case NETWORK_PREFIXSET: /* must not happen */ log_warnx("%s: found a NETWORK_PREFIXSET, " "please send a bug report", __func__); continue; } net->rd = xn->net.rd; if (kr_net_redist_add(kt, net, &xn->net.attrset, 1)) return (1); } return (0); } struct network * kr_net_find(struct ktable *kt, struct network *n) { struct network *xn; TAILQ_FOREACH(xn, &kt->krn, entry) { if (n->net.type != xn->net.type || n->net.prefixlen != xn->net.prefixlen || n->net.rd != xn->net.rd || n->net.rtlabel != xn->net.rtlabel || n->net.priority != xn->net.priority) continue; if (memcmp(&n->net.prefix, &xn->net.prefix, sizeof(n->net.prefix)) == 0) return (xn); } return (NULL); } void kr_net_reload(u_int rtableid, uint64_t rd, struct network_head *nh) { struct network *n, *xn; struct ktable *kt; if ((kt = ktable_get(rtableid)) == NULL) fatalx("%s: non-existent rtableid %d", __func__, rtableid); while ((n = TAILQ_FIRST(nh)) != NULL) { TAILQ_REMOVE(nh, n, entry); n->net.old = 0; n->net.rd = rd; xn = kr_net_find(kt, n); if (xn) { xn->net.old = 0; filterset_free(&xn->net.attrset); filterset_move(&n->net.attrset, &xn->net.attrset); network_free(n); } else TAILQ_INSERT_TAIL(&kt->krn, n, entry); } } void kr_net_clear(struct ktable *kt) { struct network *n, *xn; TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { TAILQ_REMOVE(&kt->krn, n, entry); if (n->net.type == NETWORK_DEFAULT) kr_net_redist_del(kt, &n->net, 0); network_free(n); } } void kr_redistribute(int type, struct ktable *kt, struct kroute_full *kf) { struct network_config net; uint32_t a; int loflag = 0; memset(&net, 0, sizeof(net)); net.prefix = kf->prefix; net.prefixlen = kf->prefixlen; net.rtlabel = rtlabel_name2id(kf->label); rtlabel_unref(net.rtlabel); /* drop reference now, which is ok here */ net.priority = kf->priority; /* shortcut for removals */ if (type == IMSG_NETWORK_REMOVE) { kr_net_redist_del(kt, &net, 1); return; } if (kf->flags & F_BGPD) return; switch (kf->prefix.aid) { case AID_INET: /* * We consider the loopback net and multicast addresses * as not redistributable. */ a = ntohl(kf->prefix.v4.s_addr); if (IN_MULTICAST(a) || (a >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) return; /* Check if the nexthop is the loopback addr. */ if (kf->nexthop.v4.s_addr == htonl(INADDR_LOOPBACK)) loflag = 1; break; case AID_INET6: /* * We consider unspecified, loopback, multicast, * link- and site-local, IPv4 mapped and IPv4 compatible * addresses as not redistributable. */ if (IN6_IS_ADDR_UNSPECIFIED(&kf->prefix.v6) || IN6_IS_ADDR_LOOPBACK(&kf->prefix.v6) || IN6_IS_ADDR_MULTICAST(&kf->prefix.v6) || IN6_IS_ADDR_LINKLOCAL(&kf->prefix.v6) || IN6_IS_ADDR_SITELOCAL(&kf->prefix.v6) || IN6_IS_ADDR_V4MAPPED(&kf->prefix.v6) || IN6_IS_ADDR_V4COMPAT(&kf->prefix.v6)) return; /* Check if the nexthop is the loopback addr. */ if (IN6_IS_ADDR_LOOPBACK(&kf->nexthop.v6)) loflag = 1; break; default: /* unhandled AID cannot be redistributed */ return; } /* * never allow 0/0 or ::/0 the default route can only be redistributed * with announce default. */ if (kf->prefixlen == 0) return; if (kr_net_match(kt, &net, kf->flags, loflag) == 0) /* no longer matches, if still present remove it */ kr_net_redist_del(kt, &net, 1); } void ktable_preload(void) { struct ktable *kt; struct network *n; u_int i; for (i = 0; i < krt_size; i++) { if ((kt = ktable_get(i)) == NULL) continue; kt->state = RECONF_DELETE; /* mark all networks as old */ TAILQ_FOREACH(n, &kt->krn, entry) n->net.old = 1; } } void ktable_postload(void) { struct ktable *kt; struct network *n, *xn; u_int i; for (i = krt_size; i > 0; i--) { if ((kt = ktable_get(i - 1)) == NULL) continue; if (kt->state == RECONF_DELETE) { ktable_free(i - 1); continue; } else if (kt->state == RECONF_REINIT) kt->fib_sync = kt->fib_conf; /* cleanup old networks */ TAILQ_FOREACH_SAFE(n, &kt->krn, entry, xn) { if (n->net.old) { TAILQ_REMOVE(&kt->krn, n, entry); if (n->net.type == NETWORK_DEFAULT) kr_net_redist_del(kt, &n->net, 0); network_free(n); } } } } int kr_reload(void) { struct ktable *kt; struct kroute *kr; struct kroute6 *kr6; struct knexthop *nh; struct network *n; u_int rid; int hasdyn = 0; for (rid = 0; rid < krt_size; rid++) { if ((kt = ktable_get(rid)) == NULL) continue; /* if this is the main nexthop table revalidate nexthops */ if (kt->rtableid == kt->nhtableid) RB_FOREACH(nh, knexthop_tree, KT2KNT(kt)) knexthop_validate(kt, nh); TAILQ_FOREACH(n, &kt->krn, entry) if (n->net.type == NETWORK_DEFAULT) { kr_net_redist_add(kt, &n->net, &n->net.attrset, 0); } else hasdyn = 1; if (hasdyn) { /* only evaluate the full tree if we need */ RB_FOREACH(kr, kroute_tree, &kt->krt) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); RB_FOREACH(kr6, kroute6_tree, &kt->krt6) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); } } return (0); } uint8_t kr_priority(struct kroute_full *kf) { if (kf->priority == RTP_MINE) return kr_state.fib_prio; return kf->priority; } struct kroute_full * kr_tofull(struct kroute *kr) { static struct kroute_full kf; memset(&kf, 0, sizeof(kf)); kf.prefix.aid = AID_INET; kf.prefix.v4.s_addr = kr->prefix.s_addr; kf.nexthop.aid = AID_INET; kf.nexthop.v4.s_addr = kr->nexthop.s_addr; strlcpy(kf.label, rtlabel_id2name(kr->labelid), sizeof(kf.label)); kf.flags = kr->flags; kf.ifindex = kr->ifindex; kf.prefixlen = kr->prefixlen; kf.priority = kr->priority; kf.mplslabel = kr->mplslabel; return (&kf); } struct kroute_full * kr6_tofull(struct kroute6 *kr6) { static struct kroute_full kf; memset(&kf, 0, sizeof(kf)); kf.prefix.aid = AID_INET6; kf.prefix.v6 = kr6->prefix; kf.prefix.scope_id = kr6->prefix_scope_id; kf.nexthop.aid = AID_INET6; kf.nexthop.v6 = kr6->nexthop; kf.nexthop.scope_id = kr6->nexthop_scope_id; strlcpy(kf.label, rtlabel_id2name(kr6->labelid), sizeof(kf.label)); kf.flags = kr6->flags; kf.ifindex = kr6->ifindex; kf.prefixlen = kr6->prefixlen; kf.priority = kr6->priority; kf.mplslabel = kr6->mplslabel; return (&kf); } /* * RB-tree compare functions */ int kroute_compare(struct kroute *a, struct kroute *b) { if (ntohl(a->prefix.s_addr) < ntohl(b->prefix.s_addr)) return (-1); if (ntohl(a->prefix.s_addr) > ntohl(b->prefix.s_addr)) return (1); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); /* if the priority is RTP_ANY finish on the first address hit */ if (a->priority == RTP_ANY || b->priority == RTP_ANY) return (0); if (a->priority < b->priority) return (-1); if (a->priority > b->priority) return (1); return (0); } int kroute6_compare(struct kroute6 *a, struct kroute6 *b) { int i; for (i = 0; i < 16; i++) { if (a->prefix.s6_addr[i] < b->prefix.s6_addr[i]) return (-1); if (a->prefix.s6_addr[i] > b->prefix.s6_addr[i]) return (1); } if (a->prefix_scope_id < b->prefix_scope_id) return (-1); if (a->prefix_scope_id > b->prefix_scope_id) return (1); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); /* if the priority is RTP_ANY finish on the first address hit */ if (a->priority == RTP_ANY || b->priority == RTP_ANY) return (0); if (a->priority < b->priority) return (-1); if (a->priority > b->priority) return (1); return (0); } int knexthop_compare(struct knexthop *a, struct knexthop *b) { int i; if (a->nexthop.aid != b->nexthop.aid) return (b->nexthop.aid - a->nexthop.aid); switch (a->nexthop.aid) { case AID_INET: if (ntohl(a->nexthop.v4.s_addr) < ntohl(b->nexthop.v4.s_addr)) return (-1); if (ntohl(a->nexthop.v4.s_addr) > ntohl(b->nexthop.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->nexthop.v6.s6_addr[i] < b->nexthop.v6.s6_addr[i]) return (-1); if (a->nexthop.v6.s6_addr[i] > b->nexthop.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } return (0); } int kredist_compare(struct kredist_node *a, struct kredist_node *b) { int i; if (a->prefix.aid != b->prefix.aid) return (b->prefix.aid - a->prefix.aid); if (a->prefixlen < b->prefixlen) return (-1); if (a->prefixlen > b->prefixlen) return (1); switch (a->prefix.aid) { case AID_INET: if (ntohl(a->prefix.v4.s_addr) < ntohl(b->prefix.v4.s_addr)) return (-1); if (ntohl(a->prefix.v4.s_addr) > ntohl(b->prefix.v4.s_addr)) return (1); break; case AID_INET6: for (i = 0; i < 16; i++) { if (a->prefix.v6.s6_addr[i] < b->prefix.v6.s6_addr[i]) return (-1); if (a->prefix.v6.s6_addr[i] > b->prefix.v6.s6_addr[i]) return (1); } break; default: fatalx("%s: unknown AF", __func__); } if (a->rd < b->rd) return (-1); if (a->rd > b->rd) return (1); return (0); } int kif_compare(struct kif *a, struct kif *b) { return (b->ifindex - a->ifindex); } /* * tree management functions */ struct kroute * kroute_find(struct ktable *kt, const struct bgpd_addr *prefix, uint8_t prefixlen, uint8_t prio) { struct kroute s; struct kroute *kn, *tmp; s.prefix = prefix->v4; s.prefixlen = prefixlen; s.priority = prio; kn = RB_FIND(kroute_tree, &kt->krt, &s); if (kn && prio == RTP_ANY) { tmp = RB_PREV(kroute_tree, &kt->krt, kn); while (tmp) { if (kroute_compare(&s, tmp) == 0) kn = tmp; else break; tmp = RB_PREV(kroute_tree, &kt->krt, kn); } } return (kn); } struct kroute * kroute_matchgw(struct kroute *kr, struct kroute_full *kf) { in_addr_t nexthop; if (kf->flags & F_CONNECTED) { do { if (kr->ifindex == kf->ifindex) return (kr); kr = kr->next; } while (kr); return (NULL); } nexthop = kf->nexthop.v4.s_addr; do { if (kr->nexthop.s_addr == nexthop) return (kr); kr = kr->next; } while (kr); return (NULL); } int kroute_insert(struct ktable *kt, struct kroute_full *kf) { struct kroute *kr, *krm; struct kroute6 *kr6, *kr6m; struct knexthop *n; uint32_t mplslabel = 0; int multipath = 0; if (kf->prefix.aid == AID_VPN_IPv4 || kf->prefix.aid == AID_VPN_IPv6) { /* only a single MPLS label is supported for now */ if (kf->prefix.labellen != 3) { log_warnx("%s/%u does not have a single label", log_addr(&kf->prefix), kf->prefixlen); return -1; } mplslabel = (kf->prefix.labelstack[0] << 24) | (kf->prefix.labelstack[1] << 16) | (kf->prefix.labelstack[2] << 8); } switch (kf->prefix.aid) { case AID_INET: case AID_VPN_IPv4: if ((kr = calloc(1, sizeof(*kr))) == NULL) { log_warn("%s", __func__); return (-1); } kr->flags = kf->flags; kr->prefix = kf->prefix.v4; kr->prefixlen = kf->prefixlen; if (kf->nexthop.aid == AID_INET) kr->nexthop = kf->nexthop.v4; if (kf->prefix.aid == AID_VPN_IPv4) { kr->flags |= F_MPLS; kr->mplslabel = htonl(mplslabel); } kr->ifindex = kf->ifindex; kr->priority = kf->priority; kr->labelid = rtlabel_name2id(kf->label); if ((krm = RB_INSERT(kroute_tree, &kt->krt, kr)) != NULL) { /* multipath route, add at end of list */ while (krm->next != NULL) krm = krm->next; krm->next = kr; multipath = 1; } if (kf->flags & F_BGPD) if (send_rtmsg(RTM_ADD, kt, kf)) kr->flags |= F_BGPD_INSERTED; break; case AID_INET6: case AID_VPN_IPv6: if ((kr6 = calloc(1, sizeof(*kr6))) == NULL) { log_warn("%s", __func__); return (-1); } kr6->flags = kf->flags; kr6->prefix = kf->prefix.v6; kr6->prefix_scope_id = kf->prefix.scope_id; kr6->prefixlen = kf->prefixlen; if (kf->nexthop.aid == AID_INET6) { kr6->nexthop = kf->nexthop.v6; kr6->nexthop_scope_id = kf->nexthop.scope_id; } else kr6->nexthop = in6addr_any; if (kf->prefix.aid == AID_VPN_IPv6) { kr6->flags |= F_MPLS; kr6->mplslabel = htonl(mplslabel); } kr6->ifindex = kf->ifindex; kr6->priority = kf->priority; kr6->labelid = rtlabel_name2id(kf->label); if ((kr6m = RB_INSERT(kroute6_tree, &kt->krt6, kr6)) != NULL) { /* multipath route, add at end of list */ while (kr6m->next != NULL) kr6m = kr6m->next; kr6m->next = kr6; multipath = 1; } if (kf->flags & F_BGPD) if (send_rtmsg(RTM_ADD, kt, kf)) kr6->flags |= F_BGPD_INSERTED; break; } if (bgpd_has_bgpnh() || !(kf->flags & F_BGPD)) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) if (prefix_compare(&kf->prefix, &n->nexthop, kf->prefixlen) == 0) knexthop_validate(kt, n); } if (!(kf->flags & F_BGPD)) { /* redistribute multipath routes only once */ if (!multipath) kr_redistribute(IMSG_NETWORK_ADD, kt, kf); } return (0); } static int kroute4_remove(struct ktable *kt, struct kroute_full *kf, int any) { struct kroute *kr, *krm; struct knexthop *n; int multipath = 1; if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (-1); if ((kr->flags & F_BGPD) != (kf->flags & F_BGPD)) { log_warnx("%s: wrong type for %s/%u", __func__, log_addr(&kf->prefix), kf->prefixlen); if (!(kf->flags & F_BGPD)) kr->flags &= ~F_BGPD_INSERTED; return (-1); } /* get the correct route to remove */ krm = kr; if (!any) { if ((krm = kroute_matchgw(kr, kf)) == NULL) { log_warnx("delete %s/%u: route not found", log_addr(&kf->prefix), kf->prefixlen); return (-2); } } if (krm == kr) { /* head element */ RB_REMOVE(kroute_tree, &kt->krt, krm); if (krm->next != NULL) { kr = krm->next; if (RB_INSERT(kroute_tree, &kt->krt, kr) != NULL) { log_warnx("%s: failed to add %s/%u", __func__, inet_ntoa(kr->prefix), kr->prefixlen); return (-2); } } else { multipath = 0; } } else { /* somewhere in the list */ while (kr->next != krm && kr->next != NULL) kr = kr->next; if (kr->next == NULL) { log_warnx("%s: multipath list corrupted for %s/%u", __func__, inet_ntoa(kr->prefix), kr->prefixlen); return (-2); } kr->next = krm->next; } /* check whether a nexthop depends on this kroute */ if (krm->flags & F_NEXTHOP) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) { if (n->kroute == krm) knexthop_validate(kt, n); } } *kf = *kr_tofull(krm); rtlabel_unref(krm->labelid); free(krm); return (multipath); } static int kroute6_remove(struct ktable *kt, struct kroute_full *kf, int any) { struct kroute6 *kr, *krm; struct knexthop *n; int multipath = 1; if ((kr = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) == NULL) return (-1); if ((kr->flags & F_BGPD) != (kf->flags & F_BGPD)) { log_warnx("%s: wrong type for %s/%u", __func__, log_addr(&kf->prefix), kf->prefixlen); if (!(kf->flags & F_BGPD)) kr->flags &= ~F_BGPD_INSERTED; return (-1); } /* get the correct route to remove */ krm = kr; if (!any) { if ((krm = kroute6_matchgw(kr, kf)) == NULL) { log_warnx("delete %s/%u: route not found", log_addr(&kf->prefix), kf->prefixlen); return (-2); } } if (krm == kr) { /* head element */ RB_REMOVE(kroute6_tree, &kt->krt6, krm); if (krm->next != NULL) { kr = krm->next; if (RB_INSERT(kroute6_tree, &kt->krt6, kr) != NULL) { log_warnx("%s: failed to add %s/%u", __func__, log_in6addr(&kr->prefix), kr->prefixlen); return (-2); } } else { multipath = 0; } } else { /* somewhere in the list */ while (kr->next != krm && kr->next != NULL) kr = kr->next; if (kr->next == NULL) { log_warnx("%s: multipath list corrupted for %s/%u", __func__, log_in6addr(&kr->prefix), kr->prefixlen); return (-2); } kr->next = krm->next; } /* check whether a nexthop depends on this kroute */ if (krm->flags & F_NEXTHOP) { RB_FOREACH(n, knexthop_tree, KT2KNT(kt)) { if (n->kroute == krm) knexthop_validate(kt, n); } } *kf = *kr6_tofull(krm); rtlabel_unref(krm->labelid); free(krm); return (multipath); } int kroute_remove(struct ktable *kt, struct kroute_full *kf, int any) { int multipath; switch (kf->prefix.aid) { case AID_INET: multipath = kroute4_remove(kt, kf, any); break; case AID_INET6: multipath = kroute6_remove(kt, kf, any); break; default: log_warnx("%s: not handled AID", __func__); return (-1); } if (multipath < 0) return (multipath + 1); if (kf->flags & F_BGPD_INSERTED) send_rtmsg(RTM_DELETE, kt, kf); /* remove only once all multipath routes are gone */ if (!(kf->flags & F_BGPD) && !multipath) kr_redistribute(IMSG_NETWORK_REMOVE, kt, kf); return (0); } void kroute_clear(struct ktable *kt) { struct kroute *kr; while ((kr = RB_MIN(kroute_tree, &kt->krt)) != NULL) kroute_remove(kt, kr_tofull(kr), 1); } struct kroute6 * kroute6_find(struct ktable *kt, const struct bgpd_addr *prefix, uint8_t prefixlen, uint8_t prio) { struct kroute6 s; struct kroute6 *kn6, *tmp; s.prefix = prefix->v6; s.prefix_scope_id = prefix->scope_id; s.prefixlen = prefixlen; s.priority = prio; kn6 = RB_FIND(kroute6_tree, &kt->krt6, &s); if (kn6 && prio == RTP_ANY) { tmp = RB_PREV(kroute6_tree, &kt->krt6, kn6); while (tmp) { if (kroute6_compare(&s, tmp) == 0) kn6 = tmp; else break; tmp = RB_PREV(kroute6_tree, &kt->krt6, kn6); } } return (kn6); } struct kroute6 * kroute6_matchgw(struct kroute6 *kr, struct kroute_full *kf) { struct in6_addr nexthop; if (kf->flags & F_CONNECTED) { do { if (kr->ifindex == kf->ifindex) return (kr); kr = kr->next; } while (kr); return (NULL); } nexthop = kf->nexthop.v6; do { if (memcmp(&kr->nexthop, &nexthop, sizeof(nexthop)) == 0 && kr->nexthop_scope_id == kf->nexthop.scope_id) return (kr); kr = kr->next; } while (kr); return (NULL); } void kroute6_clear(struct ktable *kt) { struct kroute6 *kr; while ((kr = RB_MIN(kroute6_tree, &kt->krt6)) != NULL) kroute_remove(kt, kr6_tofull(kr), 1); } struct knexthop * knexthop_find(struct ktable *kt, struct bgpd_addr *addr) { struct knexthop s; memset(&s, 0, sizeof(s)); memcpy(&s.nexthop, addr, sizeof(s.nexthop)); return (RB_FIND(knexthop_tree, KT2KNT(kt), &s)); } int knexthop_insert(struct ktable *kt, struct knexthop *kn) { if (RB_INSERT(knexthop_tree, KT2KNT(kt), kn) != NULL) { log_warnx("%s: failed for %s", __func__, log_addr(&kn->nexthop)); free(kn); return (-1); } knexthop_validate(kt, kn); return (0); } void knexthop_remove(struct ktable *kt, struct knexthop *kn) { kroute_detach_nexthop(kt, kn); RB_REMOVE(knexthop_tree, KT2KNT(kt), kn); free(kn); } void knexthop_clear(struct ktable *kt) { struct knexthop *kn; if (kt == NULL) return; while ((kn = RB_MIN(knexthop_tree, KT2KNT(kt))) != NULL) knexthop_remove(kt, kn); } struct kif * kif_find(int ifindex) { struct kif s; memset(&s, 0, sizeof(s)); s.ifindex = ifindex; return (RB_FIND(kif_tree, &kit, &s)); } int kif_insert(struct kif *kif) { if (RB_INSERT(kif_tree, &kit, kif) != NULL) { log_warnx("RB_INSERT(kif_tree, &kit, kif)"); free(kif); return (-1); } return (0); } int kif_remove(struct kif *kif) { struct ktable *kt; kif->flags &= ~IFF_UP; /* * TODO, remove all kroutes using this interface, * the kernel does this for us but better to do it * here as well. */ if ((kt = ktable_get(kif->rdomain)) != NULL) knexthop_track(kt, kif->ifindex); RB_REMOVE(kif_tree, &kit, kif); free(kif); return (0); } void kif_clear(void) { struct kif *kif; while ((kif = RB_MIN(kif_tree, &kit)) != NULL) kif_remove(kif); } /* * nexthop validation */ static int kif_validate(struct kif *kif) { if (!(kif->flags & IFF_UP)) return (0); /* * we treat link_state == LINK_STATE_UNKNOWN as valid, * not all interfaces have a concept of "link state" and/or * do not report up */ if (kif->link_state == LINK_STATE_DOWN) return (0); return (1); } #ifdef NOTYET /* * return 1 when the interface is up and the link state is up or unknwown * except when this is a carp interface, then return 1 only when link state * is up */ static int kif_depend_state(struct kif *kif) { if (!(kif->flags & IFF_UP)) return (0); if (kif->if_type == IFT_CARP && kif->link_state == LINK_STATE_UNKNOWN) return (0); return LINK_STATE_IS_UP(kif->link_state); } #endif int kroute_validate(struct kroute *kr) { struct kif *kif; if (kr->flags & (F_REJECT | F_BLACKHOLE)) return (0); if ((kif = kif_find(kr->ifindex)) == NULL) { if (kr->ifindex) log_warnx("%s: interface with index %d not found, " "referenced from route for %s/%u", __func__, kr->ifindex, inet_ntoa(kr->prefix), kr->prefixlen); return (1); } return (kif->nh_reachable); } int kroute6_validate(struct kroute6 *kr) { struct kif *kif; if (kr->flags & (F_REJECT | F_BLACKHOLE)) return (0); if ((kif = kif_find(kr->ifindex)) == NULL) { if (kr->ifindex) log_warnx("%s: interface with index %d not found, " "referenced from route for %s/%u", __func__, kr->ifindex, log_in6addr(&kr->prefix), kr->prefixlen); return (1); } return (kif->nh_reachable); } int knexthop_true_nexthop(struct ktable *kt, struct kroute_full *kf) { struct bgpd_addr gateway = { 0 }; struct knexthop *kn; struct kroute *kr; struct kroute6 *kr6; /* * Ignore the nexthop for VPN routes. The gateway is forced * to an mpe(4) interface route using an MPLS label. */ switch (kf->prefix.aid) { case AID_VPN_IPv4: case AID_VPN_IPv6: return 1; } kn = knexthop_find(kt, &kf->nexthop); if (kn == NULL) { log_warnx("%s: nexthop %s not found", __func__, log_addr(&kf->nexthop)); return 0; } if (kn->kroute == NULL) return 0; switch (kn->nexthop.aid) { case AID_INET: kr = kn->kroute; if (kr->flags & F_CONNECTED) return 1; gateway.aid = AID_INET; gateway.v4.s_addr = kr->nexthop.s_addr; break; case AID_INET6: kr6 = kn->kroute; if (kr6->flags & F_CONNECTED) return 1; gateway.aid = AID_INET6; gateway.v6 = kr6->nexthop; gateway.scope_id = kr6->nexthop_scope_id; break; } kf->nexthop = gateway; return 1; } void knexthop_validate(struct ktable *kt, struct knexthop *kn) { void *oldk; struct kroute *kr; struct kroute6 *kr6; oldk = kn->kroute; kroute_detach_nexthop(kt, kn); if ((kt = ktable_get(kt->nhtableid)) == NULL) fatalx("%s: lost nexthop routing table", __func__); switch (kn->nexthop.aid) { case AID_INET: kr = kroute_match(kt, &kn->nexthop, 0); if (kr != NULL) { kn->kroute = kr; kn->ifindex = kr->ifindex; kr->flags |= F_NEXTHOP; } /* * Send update if nexthop route changed under us if * the route remains the same then the NH state has not * changed. */ if (kr != oldk) knexthop_send_update(kn); break; case AID_INET6: kr6 = kroute6_match(kt, &kn->nexthop, 0); if (kr6 != NULL) { kn->kroute = kr6; kn->ifindex = kr6->ifindex; kr6->flags |= F_NEXTHOP; } if (kr6 != oldk) knexthop_send_update(kn); break; } } /* * Called on interface state change. */ void knexthop_track(struct ktable *kt, u_short ifindex) { struct knexthop *kn; RB_FOREACH(kn, knexthop_tree, KT2KNT(kt)) if (kn->ifindex == ifindex) knexthop_validate(kt, kn); } /* * Called on route change. */ void knexthop_update(struct ktable *kt, struct kroute_full *kf) { struct knexthop *kn; RB_FOREACH(kn, knexthop_tree, KT2KNT(kt)) if (prefix_compare(&kf->prefix, &kn->nexthop, kf->prefixlen) == 0) knexthop_send_update(kn); } void knexthop_send_update(struct knexthop *kn) { struct kroute_nexthop n; struct kroute *kr; struct kroute6 *kr6; memset(&n, 0, sizeof(n)); n.nexthop = kn->nexthop; if (kn->kroute == NULL) { n.valid = 0; /* NH is not valid */ send_nexthop_update(&n); return; } switch (kn->nexthop.aid) { case AID_INET: kr = kn->kroute; n.valid = kroute_validate(kr); n.connected = kr->flags & F_CONNECTED; if (!n.connected) { n.gateway.aid = AID_INET; n.gateway.v4.s_addr = kr->nexthop.s_addr; } else { n.gateway = n.nexthop; n.net.aid = AID_INET; n.net.v4.s_addr = kr->prefix.s_addr; n.netlen = kr->prefixlen; } break; case AID_INET6: kr6 = kn->kroute; n.valid = kroute6_validate(kr6); n.connected = kr6->flags & F_CONNECTED; if (!n.connected) { n.gateway.aid = AID_INET6; n.gateway.v6 = kr6->nexthop; n.gateway.scope_id = kr6->nexthop_scope_id; } else { n.gateway = n.nexthop; n.net.aid = AID_INET6; n.net.v6 = kr6->prefix; n.net.scope_id = kr6->prefix_scope_id; n.netlen = kr6->prefixlen; } break; } send_nexthop_update(&n); } struct kroute * kroute_match(struct ktable *kt, struct bgpd_addr *key, int matchany) { int i; struct kroute *kr; struct bgpd_addr masked; for (i = 32; i >= 0; i--) { applymask(&masked, key, i); if ((kr = kroute_find(kt, &masked, i, RTP_ANY)) != NULL) if (matchany || bgpd_oknexthop(kr_tofull(kr))) return (kr); } return (NULL); } struct kroute6 * kroute6_match(struct ktable *kt, struct bgpd_addr *key, int matchany) { int i; struct kroute6 *kr6; struct bgpd_addr masked; for (i = 128; i >= 0; i--) { applymask(&masked, key, i); if ((kr6 = kroute6_find(kt, &masked, i, RTP_ANY)) != NULL) if (matchany || bgpd_oknexthop(kr6_tofull(kr6))) return (kr6); } return (NULL); } void kroute_detach_nexthop(struct ktable *kt, struct knexthop *kn) { struct knexthop *s; struct kroute *k; struct kroute6 *k6; if (kn->kroute == NULL) return; /* * check whether there's another nexthop depending on this kroute * if not remove the flag */ RB_FOREACH(s, knexthop_tree, KT2KNT(kt)) if (s->kroute == kn->kroute && s != kn) break; if (s == NULL) { switch (kn->nexthop.aid) { case AID_INET: k = kn->kroute; k->flags &= ~F_NEXTHOP; break; case AID_INET6: k6 = kn->kroute; k6->flags &= ~F_NEXTHOP; break; } } kn->kroute = NULL; kn->ifindex = 0; } /* * misc helpers */ uint8_t prefixlen_classful(in_addr_t ina) { /* it hurt to write this. */ if (ina >= 0xf0000000U) /* class E */ return (32); else if (ina >= 0xe0000000U) /* class D */ return (4); else if (ina >= 0xc0000000U) /* class C */ return (24); else if (ina >= 0x80000000U) /* class B */ return (16); else /* class A */ return (8); } static uint8_t mask2prefixlen4(struct sockaddr_in *sa_in) { in_addr_t ina; ina = sa_in->sin_addr.s_addr; if (ina == 0) return (0); else return (33 - ffs(ntohl(ina))); } static uint8_t mask2prefixlen6(struct sockaddr_in6 *sa_in6) { uint8_t *ap, *ep; u_int l = 0; /* * sin6_len is the size of the sockaddr so substract the offset of * the possibly truncated sin6_addr struct. */ ap = (uint8_t *)&sa_in6->sin6_addr; ep = (uint8_t *)sa_in6 + sizeof(struct in6_addr); for (; ap < ep; ap++) { /* this "beauty" is adopted from sbin/route/show.c ... */ switch (*ap) { case 0xff: l += 8; break; case 0xfe: l += 7; goto done; case 0xfc: l += 6; goto done; case 0xf8: l += 5; goto done; case 0xf0: l += 4; goto done; case 0xe0: l += 3; goto done; case 0xc0: l += 2; goto done; case 0x80: l += 1; goto done; case 0x00: goto done; default: fatalx("non contiguous inet6 netmask"); } } done: if (l > sizeof(struct in6_addr) * 8) fatalx("%s: prefixlen %d out of bound", __func__, l); return (l); } uint8_t mask2prefixlen(sa_family_t af, struct sockaddr *mask) { switch (af) { case AF_INET: return mask2prefixlen4((struct sockaddr_in *)mask); case AF_INET6: return mask2prefixlen6((struct sockaddr_in6 *)mask); default: fatalx("%s: unsupported af", __func__); } } #ifdef NOTYET const struct if_status_description if_status_descriptions[] = LINK_STATE_DESCRIPTIONS; const struct ifmedia_description ifm_type_descriptions[] = IFM_TYPE_DESCRIPTIONS; uint64_t ift2ifm(uint8_t if_type) { switch (if_type) { case IFT_ETHER: return (IFM_ETHER); case IFT_FDDI: return (IFM_FDDI); case IFT_CARP: return (IFM_CARP); case IFT_IEEE80211: return (IFM_IEEE80211); default: return (0); } } const char * get_media_descr(uint64_t media_type) { const struct ifmedia_description *p; for (p = ifm_type_descriptions; p->ifmt_string != NULL; p++) if (media_type == p->ifmt_word) return (p->ifmt_string); return ("unknown media"); } #endif const char * get_linkstate(uint8_t if_type, int link_state) { static char buf[8]; switch (link_state) { case LINK_STATE_UP: return "active"; case LINK_STATE_DOWN: return "down"; case LINK_STATE_UNKNOWN: return "unknown"; default: snprintf(buf, sizeof(buf), "[#%d]", link_state); return (buf); } } #ifdef NOTYET void if_change(u_short ifindex, int flags, struct if_data *ifd) { struct ktable *kt; struct kif *kif; uint8_t reachable; if ((kif = kif_find(ifindex)) == NULL) { log_warnx("%s: interface with index %u not found", __func__, ifindex); return; } log_info("%s: %s: rdomain %u %s, %s, %s, %s", __func__, kif->ifname, ifd->ifi_rdomain, flags & IFF_UP ? "UP" : "DOWN", get_media_descr(ift2ifm(ifd->ifi_type)), get_linkstate(ifd->ifi_type, ifd->ifi_link_state), get_baudrate(ifd->ifi_baudrate, "bps")); kif->flags = flags; kif->link_state = ifd->ifi_link_state; kif->if_type = ifd->ifi_type; kif->rdomain = ifd->ifi_rdomain; kif->baudrate = ifd->ifi_baudrate; kif->depend_state = kif_depend_state(kif); kr_send_dependon(kif); if ((reachable = kif_validate(kif)) == kif->nh_reachable) return; /* nothing changed wrt nexthop validity */ kif->nh_reachable = reachable; kt = ktable_get(kif->rdomain); if (kt == NULL) return; knexthop_track(kt, ifindex); } #endif static void if_announce(const struct nlmsghdr *nlh, const char *name) { struct ifinfomsg *ifi; struct ktable *kt; struct kif *kif; uint8_t reachable; ifi = mnl_nlmsg_get_payload(nlh); switch (nlh->nlmsg_type) { case RTM_NEWLINK: kif = kif_find(ifi->ifi_index); if (kif == NULL) { if ((kif = calloc(1, sizeof(*kif))) == NULL) { log_warn("%s", __func__); return; } kif->ifindex = ifi->ifi_index; kif_insert(kif); } if (name) strlcpy(kif->ifname, name, sizeof(kif->ifname)); kif->flags = ifi->ifi_flags; kif->if_type = ifi->ifi_type; if (ifi->ifi_flags & IFF_LOWER_UP) kif->link_state = LINK_STATE_UP; else kif->link_state = LINK_STATE_DOWN; if ((reachable = kif_validate(kif)) == kif->nh_reachable) return; /* nothing changed wrt nexthop validity */ kif->nh_reachable = reachable; kt = ktable_get(kif->rdomain); if (kt == NULL) return; knexthop_track(kt, kif->ifindex); break; case RTM_DELLINK: kif = kif_find(ifi->ifi_index); if (kif != NULL) kif_remove(kif); break; } } int get_mpe_config(const char *name, u_int *rdomain, u_int *label) { return (-1); } /* * rtsock related functions */ int send_rtmsg(int action, struct ktable *kt, struct kroute_full *kf) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; struct rtmsg *rtm; if (!kt->fib_sync) return (0); nlh = mnl_nlmsg_put_header(buf); nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK; switch (action) { case RTM_CHANGE: case RTM_ADD: nlh->nlmsg_type = RTM_NEWROUTE; nlh->nlmsg_flags |= NLM_F_CREATE | NLM_F_REPLACE; break; case RTM_DELETE: nlh->nlmsg_type = RTM_DELROUTE; break; } nlh->nlmsg_seq = kr_next_seq(); rtm = mnl_nlmsg_put_extra_header(nlh, sizeof *rtm); rtm->rtm_family = aid2af(kf->prefix.aid); rtm->rtm_dst_len = kf->prefixlen; rtm->rtm_src_len = 0; rtm->rtm_tos = 0; rtm->rtm_protocol = kr_state.fib_prio; rtm->rtm_table = kt->rtableid == 0 ? RT_TABLE_MAIN : kt->rtableid; rtm->rtm_type = RTN_UNICAST; if (kf->flags & F_BLACKHOLE) rtm->rtm_type = RTN_BLACKHOLE; if (kf->flags & F_REJECT) rtm->rtm_type = RTN_PROHIBIT; rtm->rtm_scope = RT_SCOPE_UNIVERSE; rtm->rtm_flags = 0; switch (kf->prefix.aid) { case AID_INET: mnl_attr_put_u32(nlh, RTA_DST, kf->prefix.v4.s_addr); if (kf->nexthop.aid != AID_UNSPEC) mnl_attr_put_u32(nlh, RTA_GATEWAY, kf->nexthop.v4.s_addr); break; case AID_INET6: mnl_attr_put(nlh, RTA_DST, sizeof(struct in6_addr), &kf->prefix.v6); if (kf->nexthop.aid != AID_UNSPEC) mnl_attr_put(nlh, RTA_GATEWAY, sizeof(struct in6_addr), &kf->nexthop.v6); break; default: log_warn("%s: unsupported address family %s", __func__, aid2str(kf->prefix.aid)); return (-1); } if (mnl_socket_sendto(kr_state.nl, nlh, nlh->nlmsg_len) < 0) { log_warn("%s: action %u, prefix %s/%u", __func__, nlh->nlmsg_type, log_addr(&kf->prefix), kf->prefixlen); return (0); } if (dispatch_rtmsg() == -1) return (0); return (1); } int fetchtable(struct ktable *kt) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; struct rtmsg *rtm; nlh = mnl_nlmsg_put_header(buf); nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; nlh->nlmsg_type = RTM_GETROUTE; nlh->nlmsg_seq = kr_state.query_seq = kr_next_seq(); rtm = mnl_nlmsg_put_extra_header(nlh, sizeof *rtm); rtm->rtm_family = AF_UNSPEC; rtm->rtm_table = kt->rtableid == 0 ? RT_TABLE_MAIN : kt->rtableid; if (mnl_socket_sendto(kr_state.nl, nlh, nlh->nlmsg_len) < 0) log_warn("%s: action %u", __func__, nlh->nlmsg_type); return dispatch_rtmsg(); } int fetchifs(int ifindex) { char buf[MNL_SOCKET_BUFFER_SIZE]; struct nlmsghdr *nlh; struct ifinfomsg *ifi; nlh = mnl_nlmsg_put_header(buf); nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; nlh->nlmsg_type = RTM_GETLINK; nlh->nlmsg_seq = kr_state.query_seq = kr_next_seq(); ifi = mnl_nlmsg_put_extra_header(nlh, sizeof *ifi); ifi->ifi_family = AF_UNSPEC; ifi->ifi_index = ifindex; if (mnl_socket_sendto(kr_state.nl, nlh, nlh->nlmsg_len) < 0) log_warn("%s: action %u", __func__, nlh->nlmsg_type); return dispatch_rtmsg(); } struct cb_attr { const struct nlattr **tb; unsigned char family; }; static const char * log_mnltype(int type, int islink) { static char buf[16]; if (islink == 0) { switch (type) { case RTA_TABLE: return "RTA_TABLE"; case RTA_OIF: return "RTA_OIF"; case RTA_FLOW: return "RTA_FLOW"; case RTA_PRIORITY: return "RTA_PRIORITY"; case RTA_METRICS: return "RTA_METRICS"; case RTA_DST: return "RTA_DST"; case RTA_SRC: return "RTA_SRC"; case RTA_PREFSRC: return "RTA_PREFSRC"; case RTA_GATEWAY: return "RTA_GATEWAY"; default: snprintf(buf, sizeof(buf), "#%d", type); return buf; } } else { switch (type) { case IFLA_MTU: return "IFLA_MTU"; case IFLA_LINK: return "IFLA_LINK"; case IFLA_IFNAME: return "IFLA_IFNAME"; default: snprintf(buf, sizeof(buf), "#%d", type); return buf; } } } static int rtmsg_attr_cb(const struct nlattr *attr, void *data) { struct cb_attr *my = data; int type = mnl_attr_get_type(attr); /* skip unsupported attribute in user-space */ if (mnl_attr_type_valid(attr, RTA_MAX) < 0) return MNL_CB_OK; switch(type) { case RTA_TABLE: case RTA_OIF: case RTA_FLOW: case RTA_PRIORITY: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { log_warnx("mnl_attr_validate for %s failed.", log_mnltype(type, 0)); return MNL_CB_ERROR; } break; case RTA_DST: case RTA_SRC: case RTA_PREFSRC: case RTA_GATEWAY: switch (my->family) { case AF_INET: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { log_warnx("mnl_attr_validate for %s failed.", log_mnltype(type, 0)); return MNL_CB_ERROR; } break; case AF_INET6: if (mnl_attr_validate2(attr, MNL_TYPE_BINARY, sizeof(struct in6_addr)) < 0) { log_warnx("mnl_attr_validate2 for %s failed.", log_mnltype(type, 0)); return MNL_CB_ERROR; } break; default: log_warnx("%s: unhandled routing family %d", __func__, my->family); return MNL_CB_ERROR; } break; case RTA_METRICS: /* ignored, also size is not fixed */ default: attr = NULL; break; } my->tb[type] = attr; return MNL_CB_OK; } static int link_attr_cb(const struct nlattr *attr, void *data) { struct cb_attr *my = data; int type = mnl_attr_get_type(attr); /* skip unsupported attribute in user-space */ if (mnl_attr_type_valid(attr, RTA_MAX) < 0) return MNL_CB_OK; switch(type) { case IFLA_MTU: case IFLA_LINK: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) { log_warnx("mnl_attr_validate for %s failed.", log_mnltype(type, 1)); return MNL_CB_ERROR; } break; case IFLA_IFNAME: if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) { log_warnx("mnl_attr_validate for %s failed.", log_mnltype(type, 1)); return MNL_CB_ERROR; } break; default: attr = NULL; break; } my->tb[type] = attr; return MNL_CB_OK; } static int mnl_callback(const struct nlmsghdr *nlh, void *data) { const struct nlattr *tb[RTA_MAX+1] = {}; struct rtmsg *rm; struct ktable *kt; struct cb_attr my = { .tb = tb }; struct kroute_full kf; unsigned int table; const char *name = NULL; int rv; /* ignore routes form us unless we queried for them */ if (nlh->nlmsg_pid == kr_state.pid && nlh->nlmsg_seq != kr_state.query_seq) return MNL_CB_OK; switch (nlh->nlmsg_type) { case RTM_NEWROUTE: case RTM_DELROUTE: rm = mnl_nlmsg_get_payload(nlh); my.family = rm->rtm_family; rv = mnl_attr_parse(nlh, sizeof(*rm), rtmsg_attr_cb, &my); if (rv != MNL_CB_OK) return rv; table = rm->rtm_table; if (tb[RTA_TABLE]) table = mnl_attr_get_u32(tb[RTA_TABLE]); if (table == RT_TABLE_MAIN) table = 0; else if (table == RT_TABLE_LOCAL) return MNL_CB_OK; if ((kt = ktable_get(table)) == NULL) return MNL_CB_OK; if (dispatch_rtmsg_addr(nlh, rm, tb, &kf) == -1) return MNL_CB_OK; switch (nlh->nlmsg_type) { case RTM_NEWROUTE: if (kr_fib_change(kt, &kf, rm->rtm_type, 0) == -1) return MNL_CB_ERROR; break; case RTM_DELROUTE: if (kr_fib_delete(kt, &kf, 0) == -1) return MNL_CB_ERROR; break; } break; case RTM_NEWLINK: case RTM_DELLINK: rv = mnl_attr_parse(nlh, sizeof(struct ifinfomsg), link_attr_cb, &my); if (rv != MNL_CB_OK) return rv; if (tb[IFLA_IFNAME]) name = mnl_attr_get_str(tb[IFLA_IFNAME]); if_announce(nlh, name); break; default: log_warnx("%s: unhandled routing message %d", __func__, nlh->nlmsg_type); break; } return MNL_CB_OK; } int dispatch_rtmsg(void) { char buf[MNL_SOCKET_BUFFER_SIZE]; int ret; ret = mnl_socket_recvfrom(kr_state.nl, buf, sizeof buf); while (ret > 0) { switch (mnl_cb_run(buf, ret, 0, 0, mnl_callback, NULL)) { case MNL_CB_STOP: return (0); case MNL_CB_ERROR: log_warnx("mnl_cb_run error"); return (-1); } ret = mnl_socket_recvfrom(kr_state.nl, buf, sizeof buf); } if (ret == -1) { if (errno == EAGAIN || errno == EINTR) return (0); log_warn("%s: read error", __func__); return (-1); } return (0); } int dispatch_rtmsg_addr(const struct nlmsghdr *nlh, const struct rtmsg *rm, const struct nlattr **tb, struct kroute_full *kf) { memset(kf, 0, sizeof(*kf)); if (rm->rtm_tos != 0) /* no support for TOS / DSCP */ return (0); if (rm->rtm_protocol == RTPROT_STATIC) kf->flags |= F_STATIC; if (rm->rtm_type == RTN_BLACKHOLE) kf->flags |= F_BLACKHOLE; if (rm->rtm_type == RTN_PROHIBIT) kf->flags |= F_REJECT; kf->priority = rm->rtm_protocol; switch (rm->rtm_family) { case AF_INET: kf->prefix.aid = AID_INET; if (tb[RTA_DST] != NULL) kf->prefix.v4.s_addr = mnl_attr_get_u32(tb[RTA_DST]); break; case AF_INET6: kf->prefix.aid = AID_INET6; if (tb[RTA_DST] != NULL) memcpy(&kf->prefix.v6, mnl_attr_get_payload(tb[RTA_DST]), sizeof(kf->prefix.v6)); break; default: log_warnx("route with unknown address family %d", rm->rtm_family); return (-1); } kf->prefixlen = rm->rtm_dst_len; if (tb[RTA_OIF] != NULL) kf->ifindex = mnl_attr_get_u32(tb[RTA_OIF]); if (tb[RTA_GATEWAY] != NULL) { switch (rm->rtm_family) { case AF_INET: kf->nexthop.aid = AID_INET; kf->nexthop.v4.s_addr = mnl_attr_get_u32(tb[RTA_GATEWAY]); break; case AF_INET6: kf->nexthop.aid = AID_INET6; memcpy(&kf->nexthop.v6, mnl_attr_get_payload(tb[RTA_GATEWAY]), sizeof(kf->nexthop.v6)); break; default: log_warnx("%s: unknown AF %u", __func__, rm->rtm_family); return (-1); } } else { kf->flags |= F_CONNECTED; } return (0); } int kr_fib_delete(struct ktable *kt, struct kroute_full *kf, int mpath) { return kroute_remove(kt, kf, !mpath); } int kr_fib_change(struct ktable *kt, struct kroute_full *kf, int type, int mpath) { struct kroute *kr; struct kroute6 *kr6; int flags, oflags; int changed = 0, rtlabel_changed = 0; uint16_t new_labelid; flags = kf->flags; switch (kf->prefix.aid) { case AID_INET: if ((kr = kroute_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { if (!(kf->flags & F_BGPD)) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr = kroute_matchgw(kr, kf)) == NULL) { log_warnx("%s[change]: " "mpath route not found", __func__); goto add4; } else if (mpath && type == RTM_ADD) goto add4; if (kf->nexthop.aid == AID_INET) { if (kr->nexthop.s_addr != kf->nexthop.v4.s_addr) changed = 1; kr->nexthop.s_addr = kf->nexthop.v4.s_addr; kr->ifindex = kf->ifindex; } else { if (kr->nexthop.s_addr != 0) changed = 1; kr->nexthop.s_addr = 0; kr->ifindex = kf->ifindex; } if (kr->flags & F_NEXTHOP) flags |= F_NEXTHOP; new_labelid = rtlabel_name2id(kf->label); if (kr->labelid != new_labelid) { rtlabel_unref(kr->labelid); kr->labelid = new_labelid; rtlabel_changed = 1; } oflags = kr->flags; if (flags != oflags) changed = 1; kr->flags = flags; if (rtlabel_changed) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if ((oflags & F_CONNECTED) && !(flags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if ((flags & F_CONNECTED) && !(oflags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr_tofull(kr)); if (kr->flags & F_NEXTHOP && changed) knexthop_update(kt, kf); } else { kr->flags &= ~F_BGPD_INSERTED; } } else { add4: kroute_insert(kt, kf); } break; case AID_INET6: if ((kr6 = kroute6_find(kt, &kf->prefix, kf->prefixlen, kf->priority)) != NULL) { if (!(kf->flags & F_BGPD)) { /* get the correct route */ if (mpath && type == RTM_CHANGE && (kr6 = kroute6_matchgw(kr6, kf)) == NULL) { log_warnx("%s[change]: IPv6 mpath " "route not found", __func__); goto add6; } else if (mpath && type == RTM_ADD) goto add6; if (kf->nexthop.aid == AID_INET6) { if (memcmp(&kr6->nexthop, &kf->nexthop.v6, sizeof(struct in6_addr)) || kr6->nexthop_scope_id != kf->nexthop.scope_id) changed = 1; kr6->nexthop = kf->nexthop.v6; kr6->nexthop_scope_id = kf->nexthop.scope_id; kr6->ifindex = kf->ifindex; } else { if (memcmp(&kr6->nexthop, &in6addr_any, sizeof(struct in6_addr))) changed = 1; kr6->nexthop = in6addr_any; kr6->nexthop_scope_id = 0; kr6->ifindex = kf->ifindex; } if (kr6->flags & F_NEXTHOP) flags |= F_NEXTHOP; new_labelid = rtlabel_name2id(kf->label); if (kr6->labelid != new_labelid) { rtlabel_unref(kr6->labelid); kr6->labelid = new_labelid; rtlabel_changed = 1; } oflags = kr6->flags; if (flags != oflags) changed = 1; kr6->flags = flags; if (rtlabel_changed) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if ((oflags & F_CONNECTED) && !(flags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if ((flags & F_CONNECTED) && !(oflags & F_CONNECTED)) kr_redistribute(IMSG_NETWORK_ADD, kt, kr6_tofull(kr6)); if (kr6->flags & F_NEXTHOP && changed) knexthop_update(kt, kf); } else { kr6->flags &= ~F_BGPD_INSERTED; } } else { add6: kroute_insert(kt, kf); } break; } return (0); } openbgpd-8.8/src/bgpd/control.c100644 001750 001750 00000033756 14730105010 0012225/* $OpenBSD: control.c,v 1.132 2024/12/02 15:03:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns = TAILQ_HEAD_INITIALIZER(ctl_conns); #define CONTROL_BACKLOG 5 struct ctl_conn *control_connbyfd(int); struct ctl_conn *control_connbypid(pid_t); int control_close(struct ctl_conn *); void control_result(struct ctl_conn *, u_int); int control_check(char *path) { struct sockaddr_un sa_un; int fd; memset(&sa_un, 0, sizeof(sa_un)); sa_un.sun_family = AF_UNIX; strlcpy(sa_un.sun_path, path, sizeof(sa_un.sun_path)); if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) == -1) { log_warn("%s: socket", __func__); return (-1); } if (connect(fd, (struct sockaddr *)&sa_un, sizeof(sa_un)) == 0) { log_warnx("control socket %s already in use", path); close(fd); return (-1); } close(fd); return (0); } int control_init(int restricted, char *path) { struct sockaddr_un sa_un; int fd; mode_t old_umask, mode; if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) == -1) { log_warn("control_init: socket"); return (-1); } memset(&sa_un, 0, sizeof(sa_un)); sa_un.sun_family = AF_UNIX; if (strlcpy(sa_un.sun_path, path, sizeof(sa_un.sun_path)) >= sizeof(sa_un.sun_path)) { log_warn("control_init: socket name too long"); close(fd); return (-1); } if (unlink(path) == -1) if (errno != ENOENT) { log_warn("control_init: unlink %s", path); close(fd); return (-1); } if (restricted) { old_umask = umask(S_IXUSR|S_IXGRP|S_IXOTH); mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; } else { old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH); mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP; } if (bind(fd, (struct sockaddr *)&sa_un, sizeof(sa_un)) == -1) { log_warn("control_init: bind: %s", path); close(fd); umask(old_umask); return (-1); } umask(old_umask); if (chmod(path, mode) == -1) { log_warn("control_init: chmod: %s", path); close(fd); unlink(path); return (-1); } return (fd); } int control_listen(int fd) { if (fd != -1 && listen(fd, CONTROL_BACKLOG) == -1) { log_warn("control_listen: listen"); return (-1); } return (0); } void control_shutdown(int fd) { close(fd); } size_t control_fill_pfds(struct pollfd *pfd, size_t size) { struct ctl_conn *ctl_conn; size_t i = 0; TAILQ_FOREACH(ctl_conn, &ctl_conns, entry) { pfd[i].fd = ctl_conn->imsgbuf.fd; pfd[i].events = POLLIN; if (imsgbuf_queuelen(&ctl_conn->imsgbuf) > 0) pfd[i].events |= POLLOUT; i++; } return i; } unsigned int control_accept(int listenfd, int restricted) { int connfd; socklen_t len; struct sockaddr_un sa_un; struct ctl_conn *ctl_conn; len = sizeof(sa_un); if ((connfd = accept4(listenfd, (struct sockaddr *)&sa_un, &len, SOCK_NONBLOCK | SOCK_CLOEXEC)) == -1) { if (errno == ENFILE || errno == EMFILE) { pauseaccept = getmonotime(); return (0); } else if (errno != EWOULDBLOCK && errno != EINTR && errno != ECONNABORTED) log_warn("control_accept: accept"); return (0); } if ((ctl_conn = calloc(1, sizeof(struct ctl_conn))) == NULL) { log_warn("control_accept"); close(connfd); return (0); } if (imsgbuf_init(&ctl_conn->imsgbuf, connfd) == -1 || imsgbuf_set_maxsize(&ctl_conn->imsgbuf, MAX_BGPD_IMSGSIZE) == -1) { log_warn("control_accept"); imsgbuf_clear(&ctl_conn->imsgbuf); close(connfd); free(ctl_conn); return (0); } ctl_conn->restricted = restricted; TAILQ_INSERT_TAIL(&ctl_conns, ctl_conn, entry); return (1); } struct ctl_conn * control_connbyfd(int fd) { struct ctl_conn *c; TAILQ_FOREACH(c, &ctl_conns, entry) { if (c->imsgbuf.fd == fd) break; } return (c); } struct ctl_conn * control_connbypid(pid_t pid) { struct ctl_conn *c; TAILQ_FOREACH(c, &ctl_conns, entry) { if (c->imsgbuf.pid == pid) break; } return (c); } int control_close(struct ctl_conn *c) { if (c->terminate && c->imsgbuf.pid) imsg_ctl_rde_msg(IMSG_CTL_TERMINATE, 0, c->imsgbuf.pid); imsgbuf_clear(&c->imsgbuf); TAILQ_REMOVE(&ctl_conns, c, entry); close(c->imsgbuf.fd); free(c); pauseaccept = 0; return (1); } int control_dispatch_msg(struct pollfd *pfd, struct peer_head *peers) { struct imsg imsg; struct ctl_neighbor neighbor; struct ctl_show_rib_request ribreq; struct ctl_conn *c; struct peer *p; ssize_t n; uint32_t type; pid_t pid; int verbose, matched; if ((c = control_connbyfd(pfd->fd)) == NULL) { log_warn("control_dispatch_msg: fd %d: not found", pfd->fd); return (0); } if (pfd->revents & POLLOUT) { if (imsgbuf_write(&c->imsgbuf) == -1) return control_close(c); if (c->throttled && imsgbuf_queuelen(&c->imsgbuf) < CTL_MSG_LOW_MARK) { if (imsg_ctl_rde_msg(IMSG_XON, 0, c->imsgbuf.pid) != -1) c->throttled = 0; } } if (!(pfd->revents & POLLIN)) return (0); if (imsgbuf_read(&c->imsgbuf) != 1) return control_close(c); for (;;) { if ((n = imsg_get(&c->imsgbuf, &imsg)) == -1) return control_close(c); if (n == 0) break; type = imsg_get_type(&imsg); pid = imsg_get_pid(&imsg); if (c->restricted) { switch (type) { case IMSG_CTL_SHOW_NEIGHBOR: case IMSG_CTL_SHOW_NEXTHOP: case IMSG_CTL_SHOW_INTERFACE: case IMSG_CTL_SHOW_RIB_MEM: case IMSG_CTL_SHOW_TERSE: case IMSG_CTL_SHOW_TIMER: case IMSG_CTL_SHOW_NETWORK: case IMSG_CTL_SHOW_FLOWSPEC: case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_RIB_PREFIX: case IMSG_CTL_SHOW_SET: case IMSG_CTL_SHOW_RTR: break; default: /* clear imsg type to prevent processing */ type = IMSG_NONE; control_result(c, CTL_RES_DENIED); break; } } /* * TODO: this is wrong and shoud work the other way around. * The imsg.hdr.pid is from the remote end and should not * be trusted. */ c->imsgbuf.pid = pid; switch (type) { case IMSG_NONE: /* message was filtered out, nothing to do */ break; case IMSG_CTL_FIB_COUPLE: case IMSG_CTL_FIB_DECOUPLE: imsg_ctl_parent(&imsg); break; case IMSG_CTL_SHOW_TERSE: RB_FOREACH(p, peer_head, peers) imsg_compose(&c->imsgbuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, p, sizeof(struct peer)); imsg_compose(&c->imsgbuf, IMSG_CTL_END, 0, 0, -1, NULL, 0); break; case IMSG_CTL_SHOW_NEIGHBOR: if (imsg_get_data(&imsg, &neighbor, sizeof(neighbor)) == -1) memset(&neighbor, 0, sizeof(neighbor)); matched = 0; RB_FOREACH(p, peer_head, peers) { if (!peer_matched(p, &neighbor)) continue; matched = 1; if (!neighbor.show_timers) { imsg_ctl_rde_msg(type, p->conf.id, pid); } else { u_int i; time_t d; struct ctl_timer ct; imsg_compose(&c->imsgbuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, p, sizeof(*p)); for (i = 1; i < Timer_Max; i++) { if (!timer_running(&p->timers, i, &d)) continue; ct.type = i; ct.val = d; imsg_compose(&c->imsgbuf, IMSG_CTL_SHOW_TIMER, 0, 0, -1, &ct, sizeof(ct)); } } } if (!matched && !RB_EMPTY(peers)) { control_result(c, CTL_RES_NOSUCHPEER); } else if (!neighbor.show_timers) { imsg_ctl_rde_msg(IMSG_CTL_END, 0, pid); } else { imsg_compose(&c->imsgbuf, IMSG_CTL_END, 0, 0, -1, NULL, 0); } break; case IMSG_CTL_NEIGHBOR_UP: case IMSG_CTL_NEIGHBOR_DOWN: case IMSG_CTL_NEIGHBOR_CLEAR: case IMSG_CTL_NEIGHBOR_RREFRESH: case IMSG_CTL_NEIGHBOR_DESTROY: if (imsg_get_data(&imsg, &neighbor, sizeof(neighbor)) == -1) { log_warnx("got IMSG_CTL_NEIGHBOR_ with " "wrong length"); break; } matched = 0; RB_FOREACH(p, peer_head, peers) { if (!peer_matched(p, &neighbor)) continue; matched = 1; switch (type) { case IMSG_CTL_NEIGHBOR_UP: bgp_fsm(p, EVNT_START, NULL); p->conf.down = 0; p->conf.reason[0] = '\0'; p->IdleHoldTime = INTERVAL_IDLE_HOLD_INITIAL; p->errcnt = 0; control_result(c, CTL_RES_OK); break; case IMSG_CTL_NEIGHBOR_DOWN: neighbor.reason[ sizeof(neighbor.reason) - 1] = '\0'; p->conf.down = 1; session_stop(p, ERR_CEASE_ADMIN_DOWN, neighbor.reason); control_result(c, CTL_RES_OK); break; case IMSG_CTL_NEIGHBOR_CLEAR: neighbor.reason[ sizeof(neighbor.reason) - 1] = '\0'; p->IdleHoldTime = INTERVAL_IDLE_HOLD_INITIAL; p->errcnt = 0; if (!p->conf.down) { session_stop(p, ERR_CEASE_ADMIN_RESET, neighbor.reason); timer_set(&p->timers, Timer_IdleHold, SESSION_CLEAR_DELAY); } else { session_stop(p, ERR_CEASE_ADMIN_DOWN, neighbor.reason); } control_result(c, CTL_RES_OK); break; case IMSG_CTL_NEIGHBOR_RREFRESH: if (session_neighbor_rrefresh(p)) control_result(c, CTL_RES_NOCAP); else control_result(c, CTL_RES_OK); break; case IMSG_CTL_NEIGHBOR_DESTROY: if (!p->template) control_result(c, CTL_RES_BADPEER); else if (p->state != STATE_IDLE) control_result(c, CTL_RES_BADSTATE); else { /* * Mark as deleted, will be * collected on next poll loop. */ p->reconf_action = RECONF_DELETE; control_result(c, CTL_RES_OK); } break; default: fatal("king bula wants more humppa"); } } if (!matched) control_result(c, CTL_RES_NOSUCHPEER); break; case IMSG_CTL_RELOAD: case IMSG_CTL_SHOW_INTERFACE: case IMSG_CTL_SHOW_FIB_TABLES: case IMSG_CTL_SHOW_RTR: imsg_ctl_parent(&imsg); break; case IMSG_CTL_KROUTE: case IMSG_CTL_KROUTE_ADDR: case IMSG_CTL_SHOW_NEXTHOP: imsg_ctl_parent(&imsg); break; case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_RIB_PREFIX: if (imsg_get_data(&imsg, &ribreq, sizeof(ribreq)) == -1) { log_warnx("got IMSG_CTL_SHOW_RIB with " "wrong length"); break; } /* check if at least one neighbor exists */ RB_FOREACH(p, peer_head, peers) if (peer_matched(p, &ribreq.neighbor)) break; if (p == NULL && !RB_EMPTY(peers)) { control_result(c, CTL_RES_NOSUCHPEER); break; } if (type == IMSG_CTL_SHOW_RIB_PREFIX && ribreq.prefix.aid == AID_UNSPEC) { /* malformed request, must specify af */ control_result(c, CTL_RES_PARSE_ERROR); break; } c->terminate = 1; imsg_ctl_rde(&imsg); break; case IMSG_CTL_SHOW_NETWORK: case IMSG_CTL_SHOW_FLOWSPEC: c->terminate = 1; /* FALLTHROUGH */ case IMSG_CTL_SHOW_RIB_MEM: case IMSG_CTL_SHOW_SET: imsg_ctl_rde(&imsg); break; case IMSG_NETWORK_ADD: case IMSG_NETWORK_ASPATH: case IMSG_NETWORK_ATTR: case IMSG_NETWORK_REMOVE: case IMSG_NETWORK_FLUSH: case IMSG_NETWORK_DONE: case IMSG_FLOWSPEC_ADD: case IMSG_FLOWSPEC_REMOVE: case IMSG_FLOWSPEC_DONE: case IMSG_FLOWSPEC_FLUSH: case IMSG_FILTER_SET: imsg_ctl_rde(&imsg); break; case IMSG_CTL_LOG_VERBOSE: if (imsg_get_data(&imsg, &verbose, sizeof(verbose)) == -1) break; /* forward to other processes */ imsg_ctl_parent(&imsg); imsg_ctl_rde(&imsg); log_setverbose(verbose); break; default: break; } imsg_free(&imsg); } return (0); } int control_imsg_relay(struct imsg *imsg, struct peer *p) { struct ctl_conn *c; uint32_t type; pid_t pid; type = imsg_get_type(imsg); pid = imsg_get_pid(imsg); if ((c = control_connbypid(pid)) == NULL) return (0); /* special handling for peers since only the stats are sent from RDE */ if (type == IMSG_CTL_SHOW_NEIGHBOR) { struct rde_peer_stats stats; struct peer peer; if (p == NULL) { log_warnx("%s: no such peer: id=%u", __func__, imsg_get_id(imsg)); return (0); } if (imsg_get_data(imsg, &stats, sizeof(stats)) == -1) { log_warnx("%s: imsg_get_data", __func__); return (0); } peer = *p; explicit_bzero(&peer.auth_conf, sizeof(peer.auth_conf)); peer.auth_conf.method = p->auth_conf.method; peer.stats.prefix_cnt = stats.prefix_cnt; peer.stats.prefix_out_cnt = stats.prefix_out_cnt; peer.stats.prefix_rcvd_update = stats.prefix_rcvd_update; peer.stats.prefix_rcvd_withdraw = stats.prefix_rcvd_withdraw; peer.stats.prefix_rcvd_eor = stats.prefix_rcvd_eor; peer.stats.prefix_sent_update = stats.prefix_sent_update; peer.stats.prefix_sent_withdraw = stats.prefix_sent_withdraw; peer.stats.prefix_sent_eor = stats.prefix_sent_eor; peer.stats.pending_update = stats.pending_update; peer.stats.pending_withdraw = stats.pending_withdraw; peer.stats.msg_queue_len = msgbuf_queuelen(p->wbuf); return imsg_compose(&c->imsgbuf, type, 0, pid, -1, &peer, sizeof(peer)); } /* if command finished no need to send exit message */ if (type == IMSG_CTL_END || type == IMSG_CTL_RESULT) c->terminate = 0; if (!c->throttled && imsgbuf_queuelen(&c->imsgbuf) > CTL_MSG_HIGH_MARK) { if (imsg_ctl_rde_msg(IMSG_XOFF, 0, pid) != -1) c->throttled = 1; } return (imsg_forward(&c->imsgbuf, imsg)); } void control_result(struct ctl_conn *c, u_int code) { imsg_compose(&c->imsgbuf, IMSG_CTL_RESULT, 0, c->imsgbuf.pid, -1, &code, sizeof(code)); } openbgpd-8.8/src/bgpd/pfkey.c100644 001750 001750 00000055100 14730105010 0011646/* $OpenBSD: pfkey.c,v 1.71 2024/10/02 09:45:29 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2003, 2004 Markus Friedl * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" extern struct bgpd_sysdep sysdep; #define PFKEY2_CHUNK sizeof(uint64_t) #define ROUNDUP(x) (((x) + (PFKEY2_CHUNK - 1)) & ~(PFKEY2_CHUNK - 1)) #define IOV_CNT 20 static uint32_t sadb_msg_seq = 0; static uint32_t pid = 0; /* should pid_t but pfkey needs uint32_t */ static int pfkey_fd; static int pfkey_reply(int, uint32_t *); static int pfkey_send(int, uint8_t, uint8_t, uint8_t, const struct bgpd_addr *, const struct bgpd_addr *, uint32_t, uint8_t, int, char *, uint8_t, int, char *, uint16_t, uint16_t); #define pfkey_flow(fd, satype, cmd, dir, from, to, sport, dport) \ pfkey_send(fd, satype, cmd, dir, from, to, \ 0, 0, 0, NULL, 0, 0, NULL, sport, dport) static int pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir, const struct bgpd_addr *src, const struct bgpd_addr *dst, uint32_t spi, uint8_t aalg, int alen, char *akey, uint8_t ealg, int elen, char *ekey, uint16_t sport, uint16_t dport) { struct sadb_msg smsg; struct sadb_sa sa; struct sadb_address sa_src, sa_dst, sa_peer, sa_smask, sa_dmask; struct sadb_key sa_akey, sa_ekey; struct sadb_spirange sa_spirange; struct sadb_protocol sa_flowtype, sa_protocol; struct iovec iov[IOV_CNT]; ssize_t n; int len = 0; int iov_cnt; struct sockaddr_storage ssrc, sdst, speer, smask, dmask; struct sockaddr *saptr; socklen_t salen; if (!pid) pid = getpid(); /* we need clean sockaddr... no ports set */ memset(&ssrc, 0, sizeof(ssrc)); memset(&smask, 0, sizeof(smask)); if ((saptr = addr2sa(src, 0, &salen))) { memcpy(&ssrc, saptr, salen); ssrc.ss_len = salen; } switch (src->aid) { case AID_INET: memset(&((struct sockaddr_in *)&smask)->sin_addr, 0xff, 32/8); break; case AID_INET6: memset(&((struct sockaddr_in6 *)&smask)->sin6_addr, 0xff, 128/8); break; case AID_UNSPEC: ssrc.ss_len = sizeof(struct sockaddr); break; default: return (-1); } smask.ss_family = ssrc.ss_family; smask.ss_len = ssrc.ss_len; memset(&sdst, 0, sizeof(sdst)); memset(&dmask, 0, sizeof(dmask)); if ((saptr = addr2sa(dst, 0, &salen))) { memcpy(&sdst, saptr, salen); sdst.ss_len = salen; } switch (dst->aid) { case AID_INET: memset(&((struct sockaddr_in *)&dmask)->sin_addr, 0xff, 32/8); break; case AID_INET6: memset(&((struct sockaddr_in6 *)&dmask)->sin6_addr, 0xff, 128/8); break; case AID_UNSPEC: sdst.ss_len = sizeof(struct sockaddr); break; default: return (-1); } dmask.ss_family = sdst.ss_family; dmask.ss_len = sdst.ss_len; memset(&smsg, 0, sizeof(smsg)); smsg.sadb_msg_version = PF_KEY_V2; smsg.sadb_msg_seq = ++sadb_msg_seq; smsg.sadb_msg_pid = pid; smsg.sadb_msg_len = sizeof(smsg) / 8; smsg.sadb_msg_type = mtype; smsg.sadb_msg_satype = satype; switch (mtype) { case SADB_GETSPI: memset(&sa_spirange, 0, sizeof(sa_spirange)); sa_spirange.sadb_spirange_exttype = SADB_EXT_SPIRANGE; sa_spirange.sadb_spirange_len = sizeof(sa_spirange) / 8; sa_spirange.sadb_spirange_min = 0x100; sa_spirange.sadb_spirange_max = 0xffffffff; sa_spirange.sadb_spirange_reserved = 0; break; case SADB_ADD: case SADB_UPDATE: case SADB_DELETE: memset(&sa, 0, sizeof(sa)); sa.sadb_sa_exttype = SADB_EXT_SA; sa.sadb_sa_len = sizeof(sa) / 8; sa.sadb_sa_replay = 0; sa.sadb_sa_spi = htonl(spi); sa.sadb_sa_state = SADB_SASTATE_MATURE; break; case SADB_X_ADDFLOW: case SADB_X_DELFLOW: memset(&sa_flowtype, 0, sizeof(sa_flowtype)); sa_flowtype.sadb_protocol_exttype = SADB_X_EXT_FLOW_TYPE; sa_flowtype.sadb_protocol_len = sizeof(sa_flowtype) / 8; sa_flowtype.sadb_protocol_direction = dir; sa_flowtype.sadb_protocol_proto = SADB_X_FLOW_TYPE_REQUIRE; memset(&sa_protocol, 0, sizeof(sa_protocol)); sa_protocol.sadb_protocol_exttype = SADB_X_EXT_PROTOCOL; sa_protocol.sadb_protocol_len = sizeof(sa_protocol) / 8; sa_protocol.sadb_protocol_direction = 0; sa_protocol.sadb_protocol_proto = 6; break; } memset(&sa_src, 0, sizeof(sa_src)); sa_src.sadb_address_exttype = SADB_EXT_ADDRESS_SRC; sa_src.sadb_address_len = (sizeof(sa_src) + ROUNDUP(ssrc.ss_len)) / 8; memset(&sa_dst, 0, sizeof(sa_dst)); sa_dst.sadb_address_exttype = SADB_EXT_ADDRESS_DST; sa_dst.sadb_address_len = (sizeof(sa_dst) + ROUNDUP(sdst.ss_len)) / 8; sa.sadb_sa_auth = aalg; sa.sadb_sa_encrypt = SADB_X_EALG_AES; /* XXX */ switch (mtype) { case SADB_ADD: case SADB_UPDATE: memset(&sa_akey, 0, sizeof(sa_akey)); sa_akey.sadb_key_exttype = SADB_EXT_KEY_AUTH; sa_akey.sadb_key_len = (sizeof(sa_akey) + ((alen + 7) / 8) * 8) / 8; sa_akey.sadb_key_bits = 8 * alen; memset(&sa_ekey, 0, sizeof(sa_ekey)); sa_ekey.sadb_key_exttype = SADB_EXT_KEY_ENCRYPT; sa_ekey.sadb_key_len = (sizeof(sa_ekey) + ((elen + 7) / 8) * 8) / 8; sa_ekey.sadb_key_bits = 8 * elen; break; case SADB_X_ADDFLOW: case SADB_X_DELFLOW: /* sa_peer always points to the remote machine */ if (dir == IPSP_DIRECTION_IN) { speer = ssrc; sa_peer = sa_src; } else { speer = sdst; sa_peer = sa_dst; } sa_peer.sadb_address_exttype = SADB_EXT_ADDRESS_DST; sa_peer.sadb_address_len = (sizeof(sa_peer) + ROUNDUP(speer.ss_len)) / 8; /* for addflow we also use src/dst as the flow destination */ sa_src.sadb_address_exttype = SADB_X_EXT_SRC_FLOW; sa_dst.sadb_address_exttype = SADB_X_EXT_DST_FLOW; memset(&smask, 0, sizeof(smask)); switch (src->aid) { case AID_INET: smask.ss_len = sizeof(struct sockaddr_in); smask.ss_family = AF_INET; memset(&((struct sockaddr_in *)&smask)->sin_addr, 0xff, 32/8); if (sport) { ((struct sockaddr_in *)&ssrc)->sin_port = htons(sport); ((struct sockaddr_in *)&smask)->sin_port = htons(0xffff); } break; case AID_INET6: smask.ss_len = sizeof(struct sockaddr_in6); smask.ss_family = AF_INET6; memset(&((struct sockaddr_in6 *)&smask)->sin6_addr, 0xff, 128/8); if (sport) { ((struct sockaddr_in6 *)&ssrc)->sin6_port = htons(sport); ((struct sockaddr_in6 *)&smask)->sin6_port = htons(0xffff); } break; } memset(&dmask, 0, sizeof(dmask)); switch (dst->aid) { case AID_INET: dmask.ss_len = sizeof(struct sockaddr_in); dmask.ss_family = AF_INET; memset(&((struct sockaddr_in *)&dmask)->sin_addr, 0xff, 32/8); if (dport) { ((struct sockaddr_in *)&sdst)->sin_port = htons(dport); ((struct sockaddr_in *)&dmask)->sin_port = htons(0xffff); } break; case AID_INET6: dmask.ss_len = sizeof(struct sockaddr_in6); dmask.ss_family = AF_INET6; memset(&((struct sockaddr_in6 *)&dmask)->sin6_addr, 0xff, 128/8); if (dport) { ((struct sockaddr_in6 *)&sdst)->sin6_port = htons(dport); ((struct sockaddr_in6 *)&dmask)->sin6_port = htons(0xffff); } break; } memset(&sa_smask, 0, sizeof(sa_smask)); sa_smask.sadb_address_exttype = SADB_X_EXT_SRC_MASK; sa_smask.sadb_address_len = (sizeof(sa_smask) + ROUNDUP(smask.ss_len)) / 8; memset(&sa_dmask, 0, sizeof(sa_dmask)); sa_dmask.sadb_address_exttype = SADB_X_EXT_DST_MASK; sa_dmask.sadb_address_len = (sizeof(sa_dmask) + ROUNDUP(dmask.ss_len)) / 8; break; } iov_cnt = 0; /* msghdr */ iov[iov_cnt].iov_base = &smsg; iov[iov_cnt].iov_len = sizeof(smsg); iov_cnt++; switch (mtype) { case SADB_ADD: case SADB_UPDATE: case SADB_DELETE: /* SA hdr */ iov[iov_cnt].iov_base = &sa; iov[iov_cnt].iov_len = sizeof(sa); smsg.sadb_msg_len += sa.sadb_sa_len; iov_cnt++; break; case SADB_GETSPI: /* SPI range */ iov[iov_cnt].iov_base = &sa_spirange; iov[iov_cnt].iov_len = sizeof(sa_spirange); smsg.sadb_msg_len += sa_spirange.sadb_spirange_len; iov_cnt++; break; case SADB_X_ADDFLOW: /* sa_peer always points to the remote machine */ iov[iov_cnt].iov_base = &sa_peer; iov[iov_cnt].iov_len = sizeof(sa_peer); iov_cnt++; iov[iov_cnt].iov_base = &speer; iov[iov_cnt].iov_len = ROUNDUP(speer.ss_len); smsg.sadb_msg_len += sa_peer.sadb_address_len; iov_cnt++; /* FALLTHROUGH */ case SADB_X_DELFLOW: /* add flow type */ iov[iov_cnt].iov_base = &sa_flowtype; iov[iov_cnt].iov_len = sizeof(sa_flowtype); smsg.sadb_msg_len += sa_flowtype.sadb_protocol_len; iov_cnt++; /* add protocol */ iov[iov_cnt].iov_base = &sa_protocol; iov[iov_cnt].iov_len = sizeof(sa_protocol); smsg.sadb_msg_len += sa_protocol.sadb_protocol_len; iov_cnt++; /* add flow masks */ iov[iov_cnt].iov_base = &sa_smask; iov[iov_cnt].iov_len = sizeof(sa_smask); iov_cnt++; iov[iov_cnt].iov_base = &smask; iov[iov_cnt].iov_len = ROUNDUP(smask.ss_len); smsg.sadb_msg_len += sa_smask.sadb_address_len; iov_cnt++; iov[iov_cnt].iov_base = &sa_dmask; iov[iov_cnt].iov_len = sizeof(sa_dmask); iov_cnt++; iov[iov_cnt].iov_base = &dmask; iov[iov_cnt].iov_len = ROUNDUP(dmask.ss_len); smsg.sadb_msg_len += sa_dmask.sadb_address_len; iov_cnt++; break; } /* dest addr */ iov[iov_cnt].iov_base = &sa_dst; iov[iov_cnt].iov_len = sizeof(sa_dst); iov_cnt++; iov[iov_cnt].iov_base = &sdst; iov[iov_cnt].iov_len = ROUNDUP(sdst.ss_len); smsg.sadb_msg_len += sa_dst.sadb_address_len; iov_cnt++; /* src addr */ iov[iov_cnt].iov_base = &sa_src; iov[iov_cnt].iov_len = sizeof(sa_src); iov_cnt++; iov[iov_cnt].iov_base = &ssrc; iov[iov_cnt].iov_len = ROUNDUP(ssrc.ss_len); smsg.sadb_msg_len += sa_src.sadb_address_len; iov_cnt++; switch (mtype) { case SADB_ADD: case SADB_UPDATE: if (alen) { /* auth key */ iov[iov_cnt].iov_base = &sa_akey; iov[iov_cnt].iov_len = sizeof(sa_akey); iov_cnt++; iov[iov_cnt].iov_base = akey; iov[iov_cnt].iov_len = ((alen + 7) / 8) * 8; smsg.sadb_msg_len += sa_akey.sadb_key_len; iov_cnt++; } if (elen) { /* encryption key */ iov[iov_cnt].iov_base = &sa_ekey; iov[iov_cnt].iov_len = sizeof(sa_ekey); iov_cnt++; iov[iov_cnt].iov_base = ekey; iov[iov_cnt].iov_len = ((elen + 7) / 8) * 8; smsg.sadb_msg_len += sa_ekey.sadb_key_len; iov_cnt++; } break; } len = smsg.sadb_msg_len * 8; do { n = writev(sd, iov, iov_cnt); } while (n == -1 && (errno == EAGAIN || errno == EINTR)); if (n == -1) { log_warn("%s: writev (%d/%d)", __func__, iov_cnt, len); return (-1); } return (0); } int pfkey_read(int sd, struct sadb_msg *h) { struct sadb_msg hdr; if (recv(sd, &hdr, sizeof(hdr), MSG_PEEK) != sizeof(hdr)) { if (errno == EAGAIN || errno == EINTR) return (1); log_warn("pfkey peek"); return (-1); } /* XXX: Only one message can be outstanding. */ if (hdr.sadb_msg_seq == sadb_msg_seq && hdr.sadb_msg_pid == pid) { if (h) memcpy(h, &hdr, sizeof(hdr)); return (0); } /* not ours, discard */ if (read(sd, &hdr, sizeof(hdr)) == -1) { if (errno == EAGAIN || errno == EINTR) return (1); log_warn("pfkey read"); return (-1); } return (1); } static int pfkey_reply(int sd, uint32_t *spi) { struct sadb_msg hdr, *msg; struct sadb_ext *ext; struct sadb_sa *sa; uint8_t *data; ssize_t len; int rv; do { rv = pfkey_read(sd, &hdr); if (rv == -1) return (-1); } while (rv); if (hdr.sadb_msg_errno != 0) { errno = hdr.sadb_msg_errno; if (errno == ESRCH) return (0); else { log_warn("pfkey"); /* discard error message */ if (read(sd, &hdr, sizeof(hdr)) == -1) log_warn("pfkey read"); return (-1); } } if ((data = reallocarray(NULL, hdr.sadb_msg_len, PFKEY2_CHUNK)) == NULL) { log_warn("pfkey malloc"); return (-1); } len = hdr.sadb_msg_len * PFKEY2_CHUNK; if (read(sd, data, len) != len) { log_warn("pfkey read"); freezero(data, len); return (-1); } if (hdr.sadb_msg_type == SADB_GETSPI) { if (spi == NULL) { freezero(data, len); return (0); } msg = (struct sadb_msg *)data; for (ext = (struct sadb_ext *)(msg + 1); (size_t)((uint8_t *)ext - (uint8_t *)msg) < msg->sadb_msg_len * PFKEY2_CHUNK; ext = (struct sadb_ext *)((uint8_t *)ext + ext->sadb_ext_len * PFKEY2_CHUNK)) { if (ext->sadb_ext_type == SADB_EXT_SA) { sa = (struct sadb_sa *) ext; *spi = ntohl(sa->sadb_sa_spi); break; } } } freezero(data, len); return (0); } static int pfkey_sa_add(const struct bgpd_addr *src, const struct bgpd_addr *dst, uint8_t keylen, char *key, uint32_t *spi) { if (pfkey_send(pfkey_fd, SADB_X_SATYPE_TCPSIGNATURE, SADB_GETSPI, 0, src, dst, 0, 0, 0, NULL, 0, 0, NULL, 0, 0) == -1) return (-1); if (pfkey_reply(pfkey_fd, spi) == -1) return (-1); if (pfkey_send(pfkey_fd, SADB_X_SATYPE_TCPSIGNATURE, SADB_UPDATE, 0, src, dst, *spi, 0, keylen, key, 0, 0, NULL, 0, 0) == -1) return (-1); if (pfkey_reply(pfkey_fd, NULL) == -1) return (-1); return (0); } static int pfkey_sa_remove(const struct bgpd_addr *src, const struct bgpd_addr *dst, uint32_t *spi) { if (pfkey_send(pfkey_fd, SADB_X_SATYPE_TCPSIGNATURE, SADB_DELETE, 0, src, dst, *spi, 0, 0, NULL, 0, 0, NULL, 0, 0) == -1) return (-1); if (pfkey_reply(pfkey_fd, NULL) == -1) return (-1); *spi = 0; return (0); } static int pfkey_md5sig_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { uint32_t spi_out = 0; uint32_t spi_in = 0; if (pfkey_sa_add(local_addr, remote_addr, auth->md5key_len, auth->md5key, &spi_out) == -1) goto fail; if (pfkey_sa_add(remote_addr, local_addr, auth->md5key_len, auth->md5key, &spi_in) == -1) goto fail; /* cleanup old flow if one was present */ if (pfkey_remove(as) == -1) return (-1); as->established = 1; as->method = auth->method; as->local_addr = *local_addr; as->remote_addr = *remote_addr; as->spi_out = spi_out; as->spi_in = spi_in; return (0); fail: return (-1); } static int pfkey_md5sig_remove(struct auth_state *as) { if (as->spi_out) if (pfkey_sa_remove(&as->local_addr, &as->remote_addr, &as->spi_out) == -1) goto fail; if (as->spi_in) if (pfkey_sa_remove(&as->remote_addr, &as->local_addr, &as->spi_in) == -1) goto fail; explicit_bzero(as, sizeof(*as)); return (0); fail: return (-1); } static uint8_t pfkey_auth_alg(enum auth_alg alg) { switch (alg) { case AUTH_AALG_SHA1HMAC: return SADB_AALG_SHA1HMAC; case AUTH_AALG_MD5HMAC: return SADB_AALG_MD5HMAC; default: return SADB_AALG_NONE; } } static uint8_t pfkey_enc_alg(enum auth_enc_alg alg) { switch (alg) { case AUTH_EALG_3DESCBC: return SADB_EALG_3DESCBC; case AUTH_EALG_AES: return SADB_X_EALG_AES; default: return SADB_AALG_NONE; } } static int pfkey_ipsec_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { uint8_t satype = SADB_SATYPE_ESP; /* cleanup first, unlike in the TCP MD5 case */ if (pfkey_remove(as) == -1) return (-1); switch (auth->method) { case AUTH_IPSEC_IKE_ESP: satype = SADB_SATYPE_ESP; break; case AUTH_IPSEC_IKE_AH: satype = SADB_SATYPE_AH; break; case AUTH_IPSEC_MANUAL_ESP: case AUTH_IPSEC_MANUAL_AH: satype = auth->method == AUTH_IPSEC_MANUAL_ESP ? SADB_SATYPE_ESP : SADB_SATYPE_AH; if (pfkey_send(pfkey_fd, satype, SADB_ADD, 0, local_addr, remote_addr, auth->spi_out, pfkey_auth_alg(auth->auth_alg_out), auth->auth_keylen_out, auth->auth_key_out, pfkey_enc_alg(auth->enc_alg_out), auth->enc_keylen_out, auth->enc_key_out, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; if (pfkey_send(pfkey_fd, satype, SADB_ADD, 0, remote_addr, local_addr, auth->spi_in, pfkey_auth_alg(auth->auth_alg_in), auth->auth_keylen_in, auth->auth_key_in, pfkey_enc_alg(auth->enc_alg_in), auth->enc_keylen_in, auth->enc_key_in, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; break; default: return (-1); } if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_OUT, local_addr, remote_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_OUT, local_addr, remote_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_IN, remote_addr, local_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_IN, remote_addr, local_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; /* save SPI so that they can be removed later on */ as->established = 1; as->method = auth->method; as->local_addr = *local_addr; as->remote_addr = *remote_addr; as->spi_in = auth->spi_in; as->spi_out = auth->spi_out; return (0); fail_key: log_warn("failed to insert ipsec key"); return (-1); fail_flow: log_warn("failed to insert ipsec flow"); return (-1); } static int pfkey_ipsec_remove(struct auth_state *as) { uint8_t satype; switch (as->method) { case AUTH_IPSEC_IKE_ESP: satype = SADB_SATYPE_ESP; break; case AUTH_IPSEC_IKE_AH: satype = SADB_SATYPE_AH; break; case AUTH_IPSEC_MANUAL_ESP: case AUTH_IPSEC_MANUAL_AH: satype = as->method == AUTH_IPSEC_MANUAL_ESP ? SADB_SATYPE_ESP : SADB_SATYPE_AH; if (pfkey_send(pfkey_fd, satype, SADB_DELETE, 0, &as->local_addr, &as->remote_addr, as->spi_out, 0, 0, NULL, 0, 0, NULL, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; if (pfkey_send(pfkey_fd, satype, SADB_DELETE, 0, &as->remote_addr, &as->local_addr, as->spi_in, 0, 0, NULL, 0, 0, NULL, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; break; default: return (-1); } if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_OUT, &as->local_addr, &as->remote_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_OUT, &as->local_addr, &as->remote_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_IN, &as->remote_addr, &as->local_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_IN, &as->remote_addr, &as->local_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; explicit_bzero(as, sizeof(*as)); return (0); fail_key: log_warn("failed to remove ipsec key"); return (-1); fail_flow: log_warn("failed to remove ipsec flow"); return (-1); } int pfkey_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { switch (auth->method) { case AUTH_NONE: return pfkey_remove(as); case AUTH_MD5SIG: return pfkey_md5sig_establish(as, auth, local_addr, remote_addr); default: return pfkey_ipsec_establish(as, auth, local_addr, remote_addr); } } int pfkey_remove(struct auth_state *as) { if (as->established == 0) return (0); switch (as->method) { case AUTH_NONE: return (0); case AUTH_MD5SIG: return (pfkey_md5sig_remove(as)); default: return (pfkey_ipsec_remove(as)); } } int pfkey_init(void) { if ((pfkey_fd = socket(PF_KEY, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, PF_KEY_V2)) == -1) { if (errno == EPROTONOSUPPORT) { log_warnx("PF_KEY not available, disabling ipsec"); return (-1); } else fatal("pfkey setup failed"); } return (pfkey_fd); } int pfkey_send_conf(struct imsgbuf *imsgbuf, uint32_t id, struct auth_config *auth) { /* SE only needs the auth method */ return imsg_compose(imsgbuf, IMSG_RECONF_PEER_AUTH, id, 0, -1, &auth->method, sizeof(auth->method)); } int pfkey_recv_conf(struct peer *p, struct imsg *imsg) { struct auth_config *auth = &p->auth_conf; return imsg_get_data(imsg, &auth->method, sizeof(auth->method)); } /* verify that connection is using TCP MD5SIG if required by config */ int tcp_md5_check(int fd, struct auth_config *auth) { socklen_t len; int opt; if (auth->method == AUTH_MD5SIG) { if (sysdep.no_md5sig) { errno = ENOPROTOOPT; return -1; } len = sizeof(opt); if (getsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, &len) == -1) return -1; if (!opt) { /* non-md5'd connection! */ errno = ECONNREFUSED; return -1; } } return 0; } /* enable or set TCP MD5SIG on a new client connection */ int tcp_md5_set(int fd, struct auth_config *auth, struct bgpd_addr *remote_addr) { int opt = 1; if (auth->method == AUTH_MD5SIG) { if (sysdep.no_md5sig) { errno = ENOPROTOOPT; return -1; } if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, sizeof(opt)) == -1) return -1; } return 0; } /* enable or prepare a new listening socket for TCP MD5SIG usage */ int tcp_md5_prep_listener(struct listen_addr *la, struct peer_head *p) { int opt = 1; if (setsockopt(la->fd, IPPROTO_TCP, TCP_MD5SIG, &opt, sizeof(opt)) == -1) { if (errno == ENOPROTOOPT) { /* system w/o md5sig */ log_warnx("md5sig not available, disabling"); sysdep.no_md5sig = 1; return 0; } return -1; } return 0; } /* add md5 key to all listening sockets, dummy function for portable */ void tcp_md5_add_listener(struct bgpd_config *conf, struct peer *p) { } /* delete md5 key form all listening sockets, dummy function for portable */ void tcp_md5_del_listener(struct bgpd_config *conf, struct peer *p) { } openbgpd-8.8/src/bgpd/pfkey-freebsd.c100644 001750 001750 00000055462 14730104726 0013306/* $OpenBSD: pfkey.c,v 1.70 2024/10/01 18:28:17 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2003, 2004 Markus Friedl * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" extern struct bgpd_sysdep sysdep; #define PFKEY2_CHUNK sizeof(uint64_t) #define ROUNDUP(x) (((x) + (PFKEY2_CHUNK - 1)) & ~(PFKEY2_CHUNK - 1)) #define IOV_CNT 20 static uint32_t sadb_msg_seq = 0; static uint32_t pid = 0; /* should pid_t but pfkey needs uint32_t */ static int pfkey_fd; static int pfkey_reply(int, uint32_t *); static int pfkey_send(int, uint8_t, uint8_t, uint8_t, const struct bgpd_addr *, const struct bgpd_addr *, uint32_t, uint8_t, int, char *, uint8_t, int, char *, uint16_t, uint16_t); #define pfkey_flow(fd, satype, cmd, dir, from, to, sport, dport) \ pfkey_send(fd, satype, cmd, dir, from, to, \ 0, 0, 0, NULL, 0, 0, NULL, sport, dport) static int pfkey_send(int sd, uint8_t satype, uint8_t mtype, uint8_t dir, const struct bgpd_addr *src, const struct bgpd_addr *dst, uint32_t spi, uint8_t aalg, int alen, char *akey, uint8_t ealg, int elen, char *ekey, uint16_t sport, uint16_t dport) { struct sadb_msg smsg; struct sadb_sa sa; struct sadb_address sa_src, sa_dst; struct sockaddr_storage ssrc, sdst, smask, dmask; struct sadb_key sa_akey, sa_ekey; struct sadb_spirange sa_spirange; #ifdef NOTYET struct sadb_address sa_peer, sa_smask, sa_dmask; struct sockaddr_storage speer; struct sadb_protocol sa_flowtype, sa_protocol; #endif struct iovec iov[IOV_CNT]; ssize_t n; int len = 0; int iov_cnt; struct sockaddr *saptr; socklen_t salen; if (!pid) pid = getpid(); /* we need clean sockaddr... no ports set */ memset(&ssrc, 0, sizeof(ssrc)); memset(&smask, 0, sizeof(smask)); if ((saptr = addr2sa(src, 0, &salen))) { memcpy(&ssrc, saptr, salen); ssrc.ss_len = salen; } switch (src->aid) { case AID_INET: memset(&((struct sockaddr_in *)&smask)->sin_addr, 0xff, 32/8); break; case AID_INET6: memset(&((struct sockaddr_in6 *)&smask)->sin6_addr, 0xff, 128/8); break; case AID_UNSPEC: ssrc.ss_len = sizeof(struct sockaddr); break; default: return (-1); } smask.ss_family = ssrc.ss_family; smask.ss_len = ssrc.ss_len; memset(&sdst, 0, sizeof(sdst)); memset(&dmask, 0, sizeof(dmask)); if ((saptr = addr2sa(dst, 0, &salen))) { memcpy(&sdst, saptr, salen); sdst.ss_len = salen; } switch (dst->aid) { case AID_INET: memset(&((struct sockaddr_in *)&dmask)->sin_addr, 0xff, 32/8); break; case AID_INET6: memset(&((struct sockaddr_in6 *)&dmask)->sin6_addr, 0xff, 128/8); break; case AID_UNSPEC: sdst.ss_len = sizeof(struct sockaddr); break; default: return (-1); } dmask.ss_family = sdst.ss_family; dmask.ss_len = sdst.ss_len; memset(&smsg, 0, sizeof(smsg)); smsg.sadb_msg_version = PF_KEY_V2; smsg.sadb_msg_seq = ++sadb_msg_seq; smsg.sadb_msg_pid = pid; smsg.sadb_msg_len = sizeof(smsg) / 8; smsg.sadb_msg_type = mtype; smsg.sadb_msg_satype = satype; switch (mtype) { case SADB_GETSPI: memset(&sa_spirange, 0, sizeof(sa_spirange)); sa_spirange.sadb_spirange_exttype = SADB_EXT_SPIRANGE; sa_spirange.sadb_spirange_len = sizeof(sa_spirange) / 8; sa_spirange.sadb_spirange_min = 0x100; sa_spirange.sadb_spirange_max = 0xffffffff; sa_spirange.sadb_spirange_reserved = 0; break; case SADB_ADD: case SADB_UPDATE: case SADB_DELETE: memset(&sa, 0, sizeof(sa)); sa.sadb_sa_exttype = SADB_EXT_SA; sa.sadb_sa_len = sizeof(sa) / 8; sa.sadb_sa_replay = 0; sa.sadb_sa_spi = htonl(spi); sa.sadb_sa_state = SADB_SASTATE_MATURE; break; #ifdef NOTYET case SADB_X_ADDFLOW: case SADB_X_DELFLOW: memset(&sa_flowtype, 0, sizeof(sa_flowtype)); sa_flowtype.sadb_protocol_exttype = SADB_X_EXT_FLOW_TYPE; sa_flowtype.sadb_protocol_len = sizeof(sa_flowtype) / 8; sa_flowtype.sadb_protocol_direction = dir; sa_flowtype.sadb_protocol_proto = SADB_X_FLOW_TYPE_REQUIRE; memset(&sa_protocol, 0, sizeof(sa_protocol)); sa_protocol.sadb_protocol_exttype = SADB_X_EXT_PROTOCOL; sa_protocol.sadb_protocol_len = sizeof(sa_protocol) / 8; sa_protocol.sadb_protocol_direction = 0; sa_protocol.sadb_protocol_proto = 6; break; #endif } memset(&sa_src, 0, sizeof(sa_src)); sa_src.sadb_address_exttype = SADB_EXT_ADDRESS_SRC; sa_src.sadb_address_len = (sizeof(sa_src) + ROUNDUP(ssrc.ss_len)) / 8; memset(&sa_dst, 0, sizeof(sa_dst)); sa_dst.sadb_address_exttype = SADB_EXT_ADDRESS_DST; sa_dst.sadb_address_len = (sizeof(sa_dst) + ROUNDUP(sdst.ss_len)) / 8; sa.sadb_sa_auth = aalg; sa.sadb_sa_encrypt = ealg; switch (mtype) { case SADB_ADD: case SADB_UPDATE: memset(&sa_akey, 0, sizeof(sa_akey)); sa_akey.sadb_key_exttype = SADB_EXT_KEY_AUTH; sa_akey.sadb_key_len = (sizeof(sa_akey) + ((alen + 7) / 8) * 8) / 8; sa_akey.sadb_key_bits = 8 * alen; memset(&sa_ekey, 0, sizeof(sa_ekey)); sa_ekey.sadb_key_exttype = SADB_EXT_KEY_ENCRYPT; sa_ekey.sadb_key_len = (sizeof(sa_ekey) + ((elen + 7) / 8) * 8) / 8; sa_ekey.sadb_key_bits = 8 * elen; break; #ifdef NOTYET case SADB_X_ADDFLOW: case SADB_X_DELFLOW: /* sa_peer always points to the remote machine */ if (dir == IPSP_DIRECTION_IN) { speer = ssrc; sa_peer = sa_src; } else { speer = sdst; sa_peer = sa_dst; } sa_peer.sadb_address_exttype = SADB_EXT_ADDRESS_DST; sa_peer.sadb_address_len = (sizeof(sa_peer) + ROUNDUP(speer.ss_len)) / 8; /* for addflow we also use src/dst as the flow destination */ sa_src.sadb_address_exttype = SADB_X_EXT_SRC_FLOW; sa_dst.sadb_address_exttype = SADB_X_EXT_DST_FLOW; memset(&smask, 0, sizeof(smask)); switch (src->aid) { case AID_INET: smask.ss_len = sizeof(struct sockaddr_in); smask.ss_family = AF_INET; memset(&((struct sockaddr_in *)&smask)->sin_addr, 0xff, 32/8); if (sport) { ((struct sockaddr_in *)&ssrc)->sin_port = htons(sport); ((struct sockaddr_in *)&smask)->sin_port = htons(0xffff); } break; case AID_INET6: smask.ss_len = sizeof(struct sockaddr_in6); smask.ss_family = AF_INET6; memset(&((struct sockaddr_in6 *)&smask)->sin6_addr, 0xff, 128/8); if (sport) { ((struct sockaddr_in6 *)&ssrc)->sin6_port = htons(sport); ((struct sockaddr_in6 *)&smask)->sin6_port = htons(0xffff); } break; } memset(&dmask, 0, sizeof(dmask)); switch (dst->aid) { case AID_INET: dmask.ss_len = sizeof(struct sockaddr_in); dmask.ss_family = AF_INET; memset(&((struct sockaddr_in *)&dmask)->sin_addr, 0xff, 32/8); if (dport) { ((struct sockaddr_in *)&sdst)->sin_port = htons(dport); ((struct sockaddr_in *)&dmask)->sin_port = htons(0xffff); } break; case AID_INET6: dmask.ss_len = sizeof(struct sockaddr_in6); dmask.ss_family = AF_INET6; memset(&((struct sockaddr_in6 *)&dmask)->sin6_addr, 0xff, 128/8); if (dport) { ((struct sockaddr_in6 *)&sdst)->sin6_port = htons(dport); ((struct sockaddr_in6 *)&dmask)->sin6_port = htons(0xffff); } break; } memset(&sa_smask, 0, sizeof(sa_smask)); sa_smask.sadb_address_exttype = SADB_X_EXT_SRC_MASK; sa_smask.sadb_address_len = (sizeof(sa_smask) + ROUNDUP(smask.ss_len)) / 8; memset(&sa_dmask, 0, sizeof(sa_dmask)); sa_dmask.sadb_address_exttype = SADB_X_EXT_DST_MASK; sa_dmask.sadb_address_len = (sizeof(sa_dmask) + ROUNDUP(dmask.ss_len)) / 8; break; #endif } iov_cnt = 0; /* msghdr */ iov[iov_cnt].iov_base = &smsg; iov[iov_cnt].iov_len = sizeof(smsg); iov_cnt++; switch (mtype) { case SADB_ADD: case SADB_UPDATE: case SADB_DELETE: /* SA hdr */ iov[iov_cnt].iov_base = &sa; iov[iov_cnt].iov_len = sizeof(sa); smsg.sadb_msg_len += sa.sadb_sa_len; iov_cnt++; break; case SADB_GETSPI: /* SPI range */ iov[iov_cnt].iov_base = &sa_spirange; iov[iov_cnt].iov_len = sizeof(sa_spirange); smsg.sadb_msg_len += sa_spirange.sadb_spirange_len; iov_cnt++; break; #ifdef NOTYET case SADB_X_ADDFLOW: /* sa_peer always points to the remote machine */ iov[iov_cnt].iov_base = &sa_peer; iov[iov_cnt].iov_len = sizeof(sa_peer); iov_cnt++; iov[iov_cnt].iov_base = &speer; iov[iov_cnt].iov_len = ROUNDUP(speer.ss_len); smsg.sadb_msg_len += sa_peer.sadb_address_len; iov_cnt++; /* FALLTHROUGH */ case SADB_X_DELFLOW: /* add flow type */ iov[iov_cnt].iov_base = &sa_flowtype; iov[iov_cnt].iov_len = sizeof(sa_flowtype); smsg.sadb_msg_len += sa_flowtype.sadb_protocol_len; iov_cnt++; /* add protocol */ iov[iov_cnt].iov_base = &sa_protocol; iov[iov_cnt].iov_len = sizeof(sa_protocol); smsg.sadb_msg_len += sa_protocol.sadb_protocol_len; iov_cnt++; /* add flow masks */ iov[iov_cnt].iov_base = &sa_smask; iov[iov_cnt].iov_len = sizeof(sa_smask); iov_cnt++; iov[iov_cnt].iov_base = &smask; iov[iov_cnt].iov_len = ROUNDUP(smask.ss_len); smsg.sadb_msg_len += sa_smask.sadb_address_len; iov_cnt++; iov[iov_cnt].iov_base = &sa_dmask; iov[iov_cnt].iov_len = sizeof(sa_dmask); iov_cnt++; iov[iov_cnt].iov_base = &dmask; iov[iov_cnt].iov_len = ROUNDUP(dmask.ss_len); smsg.sadb_msg_len += sa_dmask.sadb_address_len; iov_cnt++; break; #endif } /* dest addr */ iov[iov_cnt].iov_base = &sa_dst; iov[iov_cnt].iov_len = sizeof(sa_dst); iov_cnt++; iov[iov_cnt].iov_base = &sdst; iov[iov_cnt].iov_len = ROUNDUP(sdst.ss_len); smsg.sadb_msg_len += sa_dst.sadb_address_len; iov_cnt++; /* src addr */ iov[iov_cnt].iov_base = &sa_src; iov[iov_cnt].iov_len = sizeof(sa_src); iov_cnt++; iov[iov_cnt].iov_base = &ssrc; iov[iov_cnt].iov_len = ROUNDUP(ssrc.ss_len); smsg.sadb_msg_len += sa_src.sadb_address_len; iov_cnt++; switch (mtype) { case SADB_ADD: case SADB_UPDATE: if (alen) { /* auth key */ iov[iov_cnt].iov_base = &sa_akey; iov[iov_cnt].iov_len = sizeof(sa_akey); iov_cnt++; iov[iov_cnt].iov_base = akey; iov[iov_cnt].iov_len = ((alen + 7) / 8) * 8; smsg.sadb_msg_len += sa_akey.sadb_key_len; iov_cnt++; } if (elen) { /* encryption key */ iov[iov_cnt].iov_base = &sa_ekey; iov[iov_cnt].iov_len = sizeof(sa_ekey); iov_cnt++; iov[iov_cnt].iov_base = ekey; iov[iov_cnt].iov_len = ((elen + 7) / 8) * 8; smsg.sadb_msg_len += sa_ekey.sadb_key_len; iov_cnt++; } break; } len = smsg.sadb_msg_len * 8; do { n = writev(sd, iov, iov_cnt); } while (n == -1 && (errno == EAGAIN || errno == EINTR)); if (n == -1) { log_warn("%s: writev (%d/%d)", __func__, iov_cnt, len); return (-1); } return (0); } int pfkey_read(int sd, struct sadb_msg *h) { struct sadb_msg hdr; if (recv(sd, &hdr, sizeof(hdr), MSG_PEEK) != sizeof(hdr)) { if (errno == EAGAIN || errno == EINTR) return (1); log_warn("pfkey peek"); return (-1); } /* XXX: Only one message can be outstanding. */ if (hdr.sadb_msg_seq == sadb_msg_seq && hdr.sadb_msg_pid == pid) { if (h) memcpy(h, &hdr, sizeof(hdr)); return (0); } /* not ours, discard */ if (read(sd, &hdr, sizeof(hdr)) == -1) { if (errno == EAGAIN || errno == EINTR) return (1); log_warn("pfkey read"); return (-1); } return (1); } static int pfkey_reply(int sd, uint32_t *spi) { struct sadb_msg hdr, *msg; struct sadb_ext *ext; struct sadb_sa *sa; uint8_t *data; ssize_t len; int rv; do { rv = pfkey_read(sd, &hdr); if (rv == -1) return (-1); } while (rv); if (hdr.sadb_msg_errno != 0) { errno = hdr.sadb_msg_errno; if (errno == ESRCH || errno == EEXIST) return (0); else { log_warn("pfkey"); /* discard error message */ if (read(sd, &hdr, sizeof(hdr)) == -1) log_warn("pfkey read"); return (-1); } } if ((data = reallocarray(NULL, hdr.sadb_msg_len, PFKEY2_CHUNK)) == NULL) { log_warn("pfkey malloc"); return (-1); } len = hdr.sadb_msg_len * PFKEY2_CHUNK; if (read(sd, data, len) != len) { log_warn("pfkey read"); freezero(data, len); return (-1); } if (hdr.sadb_msg_type == SADB_GETSPI) { if (spi == NULL) { freezero(data, len); return (0); } msg = (struct sadb_msg *)data; for (ext = (struct sadb_ext *)(msg + 1); (size_t)((uint8_t *)ext - (uint8_t *)msg) < msg->sadb_msg_len * PFKEY2_CHUNK; ext = (struct sadb_ext *)((uint8_t *)ext + ext->sadb_ext_len * PFKEY2_CHUNK)) { if (ext->sadb_ext_type == SADB_EXT_SA) { sa = (struct sadb_sa *) ext; *spi = ntohl(sa->sadb_sa_spi); break; } } } freezero(data, len); return (0); } static int pfkey_sa_add(const struct bgpd_addr *src, const struct bgpd_addr *dst, uint8_t keylen, char *key, uint32_t *spi) { /* * From setkey(8): * TCP-MD5 associations must use 0x1000 and therefore only * have per-host granularity at this time. */ *spi = 0x1000; if (pfkey_send(pfkey_fd, SADB_X_SATYPE_TCPSIGNATURE, SADB_ADD, 0, src, dst, *spi, SADB_X_AALG_TCP_MD5, keylen, key, SADB_EALG_NONE, 0, NULL, 0, 0) == -1) return (-1); if (pfkey_reply(pfkey_fd, NULL) == -1) return (-1); return (0); } static int pfkey_sa_remove(const struct bgpd_addr *src, const struct bgpd_addr *dst, uint32_t *spi) { if (pfkey_send(pfkey_fd, SADB_X_SATYPE_TCPSIGNATURE, SADB_DELETE, 0, src, dst, *spi, SADB_X_AALG_TCP_MD5, 0, NULL, 0, 0, NULL, 0, 0) == -1) return (-1); if (pfkey_reply(pfkey_fd, NULL) == -1) return (-1); *spi = 0; return (0); } static int pfkey_md5sig_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { uint32_t spi_out = 0; uint32_t spi_in = 0; /* cleanup old flow if one was present */ if (pfkey_remove(as) == -1) return (-1); if (pfkey_sa_add(local_addr, remote_addr, auth->md5key_len, auth->md5key, &spi_out) == -1) goto fail; if (pfkey_sa_add(remote_addr, local_addr, auth->md5key_len, auth->md5key, &spi_in) == -1) goto fail; as->established = 1; as->method = auth->method; as->local_addr = *local_addr; as->remote_addr = *remote_addr; as->spi_out = spi_out; as->spi_in = spi_in; return (0); fail: return (-1); } static int pfkey_md5sig_remove(struct auth_state *as) { if (as->spi_out) if (pfkey_sa_remove(&as->local_addr, &as->remote_addr, &as->spi_out) == -1) goto fail; if (as->spi_in) if (pfkey_sa_remove(&as->remote_addr, &as->local_addr, &as->spi_in) == -1) goto fail; explicit_bzero(as, sizeof(*as)); return (0); fail: return (-1); } #ifdef NOTYET static uint8_t pfkey_auth_alg(enum auth_alg alg) { switch (alg) { case AUTH_AALG_SHA1HMAC: return SADB_AALG_SHA1HMAC; case AUTH_AALG_MD5HMAC: return SADB_AALG_MD5HMAC; default: return SADB_AALG_NONE; } } static uint8_t pfkey_enc_alg(enum auth_enc_alg alg) { switch (alg) { case AUTH_EALG_3DESCBC: return SADB_EALG_3DESCBC; case AUTH_EALG_AES: return SADB_X_EALG_AES; default: return SADB_AALG_NONE; } } static int pfkey_ipsec_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { uint8_t satype = SADB_SATYPE_ESP; /* cleanup first, unlike in the TCP MD5 case */ if (pfkey_remove(as) == -1) return (-1); switch (auth->method) { case AUTH_IPSEC_IKE_ESP: satype = SADB_SATYPE_ESP; break; case AUTH_IPSEC_IKE_AH: satype = SADB_SATYPE_AH; break; case AUTH_IPSEC_MANUAL_ESP: case AUTH_IPSEC_MANUAL_AH: satype = auth->method == AUTH_IPSEC_MANUAL_ESP ? SADB_SATYPE_ESP : SADB_SATYPE_AH; if (pfkey_send(pfkey_fd, satype, SADB_ADD, 0, local_addr, remote_addr, auth->spi_out, pfkey_auth_alg(auth->auth_alg_out), auth->auth_keylen_out, auth->auth_key_out, pfkey_enc_alg(auth->enc_alg_out), auth->enc_keylen_out, auth->enc_key_out, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; if (pfkey_send(pfkey_fd, satype, SADB_ADD, 0, remote_addr, local_addr, auth->spi_in, pfkey_auth_alg(auth->auth_alg_in), auth->auth_keylen_in, auth->auth_key_in, pfkey_enc_alg(auth->enc_alg_in), auth->enc_keylen_in, auth->enc_key_in, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; break; default: return (-1); } if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_OUT, local_addr, remote_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_OUT, local_addr, remote_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_IN, remote_addr, local_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_ADDFLOW, IPSP_DIRECTION_IN, remote_addr, local_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; /* save SPI so that they can be removed later on */ as->established = 1; as->method = auth->method; as->local_addr = *local_addr; as->remote_addr = *remote_addr; as->spi_in = auth->spi_in; as->spi_out = auth->spi_out; return (0); fail_key: log_warn("failed to insert ipsec key"); return (-1); fail_flow: log_warn("failed to insert ipsec flow"); return (-1); } static int pfkey_ipsec_remove(struct auth_state *as) { uint8_t satype; switch (as->method) { case AUTH_IPSEC_IKE_ESP: satype = SADB_SATYPE_ESP; break; case AUTH_IPSEC_IKE_AH: satype = SADB_SATYPE_AH; break; case AUTH_IPSEC_MANUAL_ESP: case AUTH_IPSEC_MANUAL_AH: satype = as->method == AUTH_IPSEC_MANUAL_ESP ? SADB_SATYPE_ESP : SADB_SATYPE_AH; if (pfkey_send(pfkey_fd, satype, SADB_DELETE, 0, &as->local_addr, &as->remote_addr, as->spi_out, 0, 0, NULL, 0, 0, NULL, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; if (pfkey_send(pfkey_fd, satype, SADB_DELETE, 0, &as->remote_addr, &as->local_addr, as->spi_in, 0, 0, NULL, 0, 0, NULL, 0, 0) == -1) goto fail_key; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_key; break; default: return (-1); } if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_OUT, &as->local_addr, &as->remote_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_OUT, &as->local_addr, &as->remote_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_IN, &as->remote_addr, &as->local_addr, 0, BGP_PORT) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; if (pfkey_flow(pfkey_fd, satype, SADB_X_DELFLOW, IPSP_DIRECTION_IN, &as->remote_addr, &as->local_addr, BGP_PORT, 0) == -1) goto fail_flow; if (pfkey_reply(pfkey_fd, NULL) == -1) goto fail_flow; explicit_bzero(as, sizeof(*as)); return (0); fail_key: log_warn("failed to remove ipsec key"); return (-1); fail_flow: log_warn("failed to remove flow"); return (-1); } #endif int pfkey_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { switch (auth->method) { case AUTH_NONE: return pfkey_remove(as); case AUTH_MD5SIG: return pfkey_md5sig_establish(as, auth, local_addr, remote_addr); default: #ifdef NOTYET return pfkey_ipsec_establish(as, auth, local_addr, remote_addr); #else return (-1); #endif } } int pfkey_remove(struct auth_state *as) { if (as->established == 0) return (0); switch (as->method) { case AUTH_NONE: return (0); case AUTH_MD5SIG: return (pfkey_md5sig_remove(as)); default: #ifdef NOTYET return (pfkey_ipsec_remove(as)); #else return (-1); #endif } } int pfkey_init(void) { if ((pfkey_fd = socket(PF_KEY, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, PF_KEY_V2)) == -1) { if (errno == EPROTONOSUPPORT) { log_warnx("PF_KEY not available, disabling ipsec"); return (-1); } else fatal("pfkey setup failed"); } return (pfkey_fd); } int pfkey_send_conf(struct imsgbuf *imsgbuf, uint32_t id, struct auth_config *auth) { /* SE only needs the auth method */ return imsg_compose(imsgbuf, IMSG_RECONF_PEER_AUTH, id, 0, -1, &auth->method, sizeof(auth->method)); } int pfkey_recv_conf(struct peer *p, struct imsg *imsg) { struct auth_config *auth = &p->auth_conf; return imsg_get_data(imsg, &auth->method, sizeof(auth->method)); } /* verify that connection is using TCP MD5SIG if required by config */ int tcp_md5_check(int fd, struct auth_config *auth) { socklen_t len; int opt; if (auth->method == AUTH_MD5SIG) { if (sysdep.no_md5sig) { errno = ENOPROTOOPT; return -1; } len = sizeof(opt); if (getsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, &len) == -1) return -1; if (!opt) { /* non-md5'd connection! */ errno = ECONNREFUSED; return -1; } } return 0; } /* enable or set TCP MD5SIG on a new client connection */ int tcp_md5_set(int fd, struct auth_config *auth, struct bgpd_addr *remote_addr) { int opt = 1; if (auth->method == AUTH_MD5SIG) { if (sysdep.no_md5sig) { errno = ENOPROTOOPT; return -1; } if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &opt, sizeof(opt)) == -1) return -1; } return 0; } /* enable or prepare a new listening socket for TCP MD5SIG usage */ int tcp_md5_prep_listener(struct listen_addr *la, struct peer_head *p) { int opt = 1; if (setsockopt(la->fd, IPPROTO_TCP, TCP_MD5SIG, &opt, sizeof(opt)) == -1) { if (errno == ENOPROTOOPT) { /* system w/o md5sig */ log_warnx("md5sig not available, disabling"); sysdep.no_md5sig = 1; return 0; } return -1; } return 0; } /* add md5 key to all listening sockets, dummy function for portable */ void tcp_md5_add_listener(struct bgpd_config *conf, struct peer *p) { } /* delete md5 key form all listening sockets, dummy function for portable */ void tcp_md5_del_listener(struct bgpd_config *conf, struct peer *p) { } openbgpd-8.8/src/bgpd/pfkey-linux.c100644 001750 001750 00000012652 14730104726 0013025/* $OpenBSD$ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" int pfkey_read(int sd, struct sadb_msg *h) { log_warnx("pfkey read disabled"); return (-1); } int pfkey_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { switch (auth->method) { case AUTH_NONE: case AUTH_MD5SIG: return (0); default: return (-1); } } int pfkey_remove(struct auth_state *as) { if (as->established == 0) return (0); else return (-1); } int pfkey_init(void) { log_warnx("PF_KEY not available, disabling ipsec"); return (-1); } int pfkey_send_conf(struct imsgbuf *imsgbuf, uint32_t id, struct auth_config *auth) { /* SE needs the full md5 data (and there is no IPSec) */ return imsg_compose(imsgbuf, IMSG_RECONF_PEER_AUTH, id, 0, -1, auth, sizeof(*auth)); } int pfkey_recv_conf(struct peer *p, struct imsg *imsg) { struct auth_config *auth = &p->auth_conf; return imsg_get_data(imsg, auth, sizeof(*auth)); } int tcp_md5_check(int fd, struct auth_config *auth) { /* * No need to do the check on Linux. * Only two options get us here: * - the session has no md5 and the SYN had no md5 option * - the session has md5 and the SYN had a valid md5 hash */ return (0); } /* * Add the TCP MD5SUM key to the kernel to enable TCP MD5SUM. */ static int install_tcp_md5(int fd, struct bgpd_addr *addr, char *key, uint8_t key_len) { struct tcp_md5sig md5; struct sockaddr *sa; socklen_t sa_len; if (key_len > TCP_MD5SIG_MAXKEYLEN) { /* not be possible unless TCP_MD5_KEY_LEN changes */ errno = EINVAL; return -1; } memset(&md5, 0, sizeof(md5)); if (key_len != 0) { md5.tcpm_keylen = key_len; memcpy(&md5.tcpm_key, key, md5.tcpm_keylen); } sa = addr2sa(addr, 0, &sa_len); memcpy(&md5.tcpm_addr, sa, sa_len); if (setsockopt(fd, IPPROTO_TCP, TCP_MD5SIG, &md5, sizeof(md5)) == -1) { /* ignore removals that fail because addr is not present */ if (errno == ENOENT && key_len == 0) return 0; return -1; } return 0; } int tcp_md5_set(int fd, struct auth_config *auth, struct bgpd_addr *remote_addr) { if (auth->method == AUTH_MD5SIG) { if (install_tcp_md5(fd, remote_addr, auth->md5key, auth->md5key_len) == -1) return -1; } return 0; } static int listener_match_peer(struct listen_addr *la, struct peer *p) { struct bgpd_addr listen_addr, *local_addr; sa2addr((struct sockaddr *)&la->sa, &listen_addr, NULL); /* first check remote_addr to be in same address family as socket */ if (p->conf.remote_addr.aid != listen_addr.aid) return 0; /* check if listening socket uses "wildcard" address */ switch (listen_addr.aid) { case AID_INET: if (listen_addr.v4.s_addr == htonl(INADDR_ANY)) return 1; break; case AID_INET6: if (IN6_IS_ADDR_UNSPECIFIED(&listen_addr.v6)) return 1; break; default: fatalx("%s: %s is unsupported", __func__, aid2str(listen_addr.aid)); } switch (p->conf.remote_addr.aid) { case AID_INET: local_addr = &p->conf.local_addr_v4; break; case AID_INET6: local_addr = &p->conf.local_addr_v6; break; default: fatalx("%s: %s is unsupported", __func__, aid2str(p->conf.remote_addr.aid)); } if (local_addr->aid == AID_UNSPEC) /* undefined bind address will match any listener */ return 1; if (memcmp(&listen_addr, local_addr, sizeof(listen_addr)) == 0) return 1; return 0; } int tcp_md5_prep_listener(struct listen_addr *la, struct peer_head *peers) { struct peer *p; RB_FOREACH(p, peer_head, peers) { if (p->auth_conf.method == AUTH_MD5SIG) { if (listener_match_peer(la, p) == 0) continue; if (install_tcp_md5(la->fd, &p->conf.remote_addr, p->auth_conf.md5key, p->auth_conf.md5key_len) == -1) { log_peer_warn(&p->conf, "setsockopt md5sig on listening socket"); return -1; } } } return 0; } void tcp_md5_add_listener(struct bgpd_config *conf, struct peer *p) { struct listen_addr *la; TAILQ_FOREACH(la, conf->listen_addrs, entry) { if (listener_match_peer(la, p) == 0) continue; if (install_tcp_md5(la->fd, &p->conf.remote_addr, p->auth_conf.md5key, p->auth_conf.md5key_len) == -1) log_peer_warn(&p->conf, "failed deletion of md5sig on listening socket"); } } void tcp_md5_del_listener(struct bgpd_config *conf, struct peer *p) { struct listen_addr *la; TAILQ_FOREACH(la, conf->listen_addrs, entry) { if (listener_match_peer(la, p) == 0) continue; if (install_tcp_md5(la->fd, &p->conf.remote_addr, NULL, 0) == -1) log_peer_warn(&p->conf, "failed deletion of md5sig on listening socket"); } } openbgpd-8.8/src/bgpd/pfkey-disabled.c100644 001750 001750 00000004071 14730104726 0013431/* $OpenBSD$ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "bgpd.h" #include "session.h" #include "log.h" int pfkey_read(int sd, struct sadb_msg *h) { log_warnx("pfkey read disabled"); return (-1); } int pfkey_establish(struct auth_state *as, struct auth_config *auth, const struct bgpd_addr *local_addr, const struct bgpd_addr *remote_addr) { if (auth->method == AUTH_NONE) return (0); else return (-1); } int pfkey_remove(struct auth_state *as) { if (as->established == 0) return (0); return (-1); } int pfkey_init(void) { log_warnx("PF_KEY not available, disabling ipsec"); return (-1); } int pfkey_send_conf(struct imsgbuf *imsgbuf, uint32_t id, struct auth_config *auth) { return (0); } int pfkey_recv_conf(struct peer *p, struct imsg *imsg) { return (0); } int tcp_md5_check(int fd, struct auth_config *auth) { return (0); } int tcp_md5_set(int fd, struct auth_config *auth, struct bgpd_addr *remote_addr) { return (0); } int tcp_md5_prep_listener(struct listen_addr *la, struct peer_head *p) { return (0); } /* add md5 key to all listening sockets, dummy function for portable */ void tcp_md5_add_listener(struct bgpd_config *conf, struct peer *p) { } /* delete md5 key form all listening sockets, dummy function for portable */ void tcp_md5_del_listener(struct bgpd_config *conf, struct peer *p) { } openbgpd-8.8/src/bgpd/rde_update.c100644 001750 001750 00000101340 14751151130 0012651/* $OpenBSD: rde_update.c,v 1.175 2025/02/04 18:16:56 denis Exp $ */ /* * Copyright (c) 2004 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "log.h" enum up_state { UP_OK, UP_ERR_LIMIT, UP_FILTERED, UP_EXCLUDED, }; static struct community comm_no_advertise = { .flags = COMMUNITY_TYPE_BASIC, .data1 = COMMUNITY_WELLKNOWN, .data2 = COMMUNITY_NO_ADVERTISE }; static struct community comm_no_export = { .flags = COMMUNITY_TYPE_BASIC, .data1 = COMMUNITY_WELLKNOWN, .data2 = COMMUNITY_NO_EXPORT }; static struct community comm_no_expsubconfed = { .flags = COMMUNITY_TYPE_BASIC, .data1 = COMMUNITY_WELLKNOWN, .data2 = COMMUNITY_NO_EXPSUBCONFED }; static void up_prep_adjout(struct rde_peer *, struct filterstate *, uint8_t); static int up_test_update(struct rde_peer *peer, struct prefix *p) { struct rde_aspath *asp; struct rde_community *comm; struct rde_peer *frompeer; frompeer = prefix_peer(p); asp = prefix_aspath(p); comm = prefix_communities(p); if (asp == NULL || asp->flags & F_ATTR_PARSE_ERR) fatalx("try to send out a botched path"); if (asp->flags & (F_ATTR_LOOP | F_ATTR_OTC_LEAK)) fatalx("try to send out a looped path"); if (peer == frompeer) /* Do not send routes back to sender */ return (0); if (!frompeer->conf.ebgp && !peer->conf.ebgp) { /* * route reflector redistribution rules: * 1. if announce is set -> announce * 2. from non-client, to non-client -> no * 3. from client, to non-client -> yes * 4. from non-client, to client -> yes * 5. from client, to client -> yes */ if (frompeer->conf.reflector_client == 0 && peer->conf.reflector_client == 0 && (asp->flags & F_PREFIX_ANNOUNCED) == 0) /* Do not redistribute updates to ibgp peers */ return (0); } /* * With "transparent-as yes" set do not filter based on * well-known communities. Instead pass them on to the client. */ if (peer->flags & PEERFLAG_TRANS_AS) return (1); /* well-known communities */ if (community_match(comm, &comm_no_advertise, NULL)) return (0); if (peer->conf.ebgp) { if (community_match(comm, &comm_no_export, NULL)) return (0); if (community_match(comm, &comm_no_expsubconfed, NULL)) return (0); } return (1); } /* RFC9234 open policy handling */ static int up_enforce_open_policy(struct rde_peer *peer, struct filterstate *state, uint8_t aid) { /* only for IPv4 and IPv6 unicast */ if (aid != AID_INET && aid != AID_INET6) return 0; /* * do not propagate (consider it filtered) if OTC is present and * local role is peer, customer or rs-client. */ if (peer->role == ROLE_PEER || peer->role == ROLE_CUSTOMER || peer->role == ROLE_RS_CLIENT) if (state->aspath.flags & F_ATTR_OTC) return 1; /* * add OTC attribute if not present towards peers, customers and * rs-clients (local roles peer, provider, rs). */ if (peer->role == ROLE_PEER || peer->role == ROLE_PROVIDER || peer->role == ROLE_RS) if ((state->aspath.flags & F_ATTR_OTC) == 0) { uint32_t tmp; tmp = htonl(peer->conf.local_as); if (attr_optadd(&state->aspath, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_OTC, &tmp, sizeof(tmp)) == -1) log_peer_warnx(&peer->conf, "failed to add OTC attribute"); state->aspath.flags |= F_ATTR_OTC; } return 0; } /* * Process a single prefix by passing it through the various filter stages * and if not filtered out update the Adj-RIB-Out. Returns: * - UP_OK if prefix was added * - UP_ERR_LIMIT if the peer outbound prefix limit was reached * - UP_FILTERED if prefix was filtered out * - UP_EXCLUDED if prefix was excluded because of up_test_update() */ static enum up_state up_process_prefix(struct rde_peer *peer, struct prefix *new, struct prefix *p) { struct filterstate state; struct bgpd_addr addr; int excluded = 0; /* * up_test_update() needs to run before the output filters * else the well-known communities won't work properly. * The output filters would not be able to add well-known * communities. */ if (!up_test_update(peer, new)) excluded = 1; rde_filterstate_prep(&state, new); pt_getaddr(new->pt, &addr); if (rde_filter(peer->out_rules, peer, prefix_peer(new), &addr, new->pt->prefixlen, &state) == ACTION_DENY) { rde_filterstate_clean(&state); return UP_FILTERED; } /* Open Policy Check: acts like an output filter */ if (up_enforce_open_policy(peer, &state, new->pt->aid)) { rde_filterstate_clean(&state); return UP_FILTERED; } if (excluded) { rde_filterstate_clean(&state); return UP_EXCLUDED; } /* from here on we know this is an update */ if (p == (void *)-1) p = prefix_adjout_get(peer, new->path_id_tx, new->pt); up_prep_adjout(peer, &state, new->pt->aid); prefix_adjout_update(p, peer, &state, new->pt, new->path_id_tx); rde_filterstate_clean(&state); /* max prefix checker outbound */ if (peer->conf.max_out_prefix && peer->stats.prefix_out_cnt > peer->conf.max_out_prefix) { log_peer_warnx(&peer->conf, "outbound prefix limit reached (>%u/%u)", peer->stats.prefix_out_cnt, peer->conf.max_out_prefix); rde_update_err(peer, ERR_CEASE, ERR_CEASE_MAX_SENT_PREFIX, NULL); return UP_ERR_LIMIT; } return UP_OK; } void up_generate_updates(struct rde_peer *peer, struct rib_entry *re) { struct prefix *new, *p; p = prefix_adjout_first(peer, re->prefix); new = prefix_best(re); while (new != NULL) { switch (up_process_prefix(peer, new, p)) { case UP_OK: case UP_ERR_LIMIT: return; case UP_FILTERED: if (peer->flags & PEERFLAG_EVALUATE_ALL) { new = TAILQ_NEXT(new, entry.list.rib); if (new != NULL && prefix_eligible(new)) continue; } goto done; case UP_EXCLUDED: goto done; } } done: /* withdraw prefix */ if (p != NULL) prefix_adjout_withdraw(p); } /* * Generate updates for the add-path send case. Depending on the * peer eval settings prefixes are selected and distributed. * This highly depends on the Adj-RIB-Out to handle prefixes with no * changes gracefully. It may be possible to improve the API so that * less churn is needed. */ void up_generate_addpath(struct rde_peer *peer, struct rib_entry *re) { struct prefix *head, *new, *p; int maxpaths = 0, extrapaths = 0, extra; int checkmode = 1; head = prefix_adjout_first(peer, re->prefix); /* mark all paths as stale */ for (p = head; p != NULL; p = prefix_adjout_next(peer, p)) p->flags |= PREFIX_FLAG_STALE; /* update paths */ new = prefix_best(re); while (new != NULL) { /* check limits and stop when a limit is reached */ if (peer->eval.maxpaths != 0 && maxpaths >= peer->eval.maxpaths) break; if (peer->eval.extrapaths != 0 && extrapaths >= peer->eval.extrapaths) break; extra = 1; if (checkmode) { switch (peer->eval.mode) { case ADDPATH_EVAL_BEST: if (new->dmetric == PREFIX_DMETRIC_BEST) extra = 0; else checkmode = 0; break; case ADDPATH_EVAL_ECMP: if (new->dmetric == PREFIX_DMETRIC_BEST || new->dmetric == PREFIX_DMETRIC_ECMP) extra = 0; else checkmode = 0; break; case ADDPATH_EVAL_AS_WIDE: if (new->dmetric == PREFIX_DMETRIC_BEST || new->dmetric == PREFIX_DMETRIC_ECMP || new->dmetric == PREFIX_DMETRIC_AS_WIDE) extra = 0; else checkmode = 0; break; case ADDPATH_EVAL_ALL: /* nothing to check */ checkmode = 0; break; default: fatalx("unknown add-path eval mode"); } } switch (up_process_prefix(peer, new, (void *)-1)) { case UP_OK: maxpaths++; extrapaths += extra; break; case UP_FILTERED: case UP_EXCLUDED: break; case UP_ERR_LIMIT: /* just give up */ return; } /* only allow valid prefixes */ new = TAILQ_NEXT(new, entry.list.rib); if (new == NULL || !prefix_eligible(new)) break; } /* withdraw stale paths */ for (p = head; p != NULL; p = prefix_adjout_next(peer, p)) { if (p->flags & PREFIX_FLAG_STALE) prefix_adjout_withdraw(p); } } /* * Generate updates for the add-path send all case. Since all prefixes * are distributed just remove old and add new. */ void up_generate_addpath_all(struct rde_peer *peer, struct rib_entry *re, struct prefix *new, struct prefix *old) { struct prefix *p, *head = NULL; int all = 0; /* * if old and new are NULL then insert all prefixes from best, * clearing old routes in the process */ if (old == NULL && new == NULL) { /* mark all paths as stale */ head = prefix_adjout_first(peer, re->prefix); for (p = head; p != NULL; p = prefix_adjout_next(peer, p)) p->flags |= PREFIX_FLAG_STALE; new = prefix_best(re); all = 1; } if (new != NULL && !prefix_eligible(new)) { /* only allow valid prefixes */ new = NULL; } if (old != NULL) { /* withdraw stale paths */ p = prefix_adjout_get(peer, old->path_id_tx, old->pt); if (p != NULL) prefix_adjout_withdraw(p); } /* add new path (or multiple if all is set) */ while (new != NULL) { switch (up_process_prefix(peer, new, (void *)-1)) { case UP_OK: case UP_FILTERED: case UP_EXCLUDED: break; case UP_ERR_LIMIT: /* just give up */ return; } if (!all) break; /* only allow valid prefixes */ new = TAILQ_NEXT(new, entry.list.rib); if (new == NULL || !prefix_eligible(new)) break; } if (all) { /* withdraw stale paths */ for (p = head; p != NULL; p = prefix_adjout_next(peer, p)) { if (p->flags & PREFIX_FLAG_STALE) prefix_adjout_withdraw(p); } } } /* send a default route to the specified peer */ void up_generate_default(struct rde_peer *peer, uint8_t aid) { extern struct rde_peer *peerself; struct filterstate state; struct rde_aspath *asp; struct prefix *p; struct pt_entry *pte; struct bgpd_addr addr; if (peer->capa.mp[aid] == 0) return; rde_filterstate_init(&state); asp = &state.aspath; asp->aspath = aspath_get(NULL, 0); asp->origin = ORIGIN_IGP; rde_filterstate_set_vstate(&state, ROA_NOTFOUND, ASPA_NEVER_KNOWN); /* the other default values are OK, nexthop is once again NULL */ /* * XXX apply default overrides. Not yet possible, mainly a parse.y * problem. */ /* rde_apply_set(asp, peerself, peerself, set, af); */ memset(&addr, 0, sizeof(addr)); addr.aid = aid; p = prefix_adjout_lookup(peer, &addr, 0); /* outbound filter as usual */ if (rde_filter(peer->out_rules, peer, peerself, &addr, 0, &state) == ACTION_DENY) { rde_filterstate_clean(&state); return; } up_prep_adjout(peer, &state, addr.aid); /* can't use pt_fill here since prefix_adjout_update keeps a ref */ pte = pt_get(&addr, 0); if (pte == NULL) pte = pt_add(&addr, 0); prefix_adjout_update(p, peer, &state, pte, 0); rde_filterstate_clean(&state); /* max prefix checker outbound */ if (peer->conf.max_out_prefix && peer->stats.prefix_out_cnt > peer->conf.max_out_prefix) { log_peer_warnx(&peer->conf, "outbound prefix limit reached (>%u/%u)", peer->stats.prefix_out_cnt, peer->conf.max_out_prefix); rde_update_err(peer, ERR_CEASE, ERR_CEASE_MAX_SENT_PREFIX, NULL); } } static struct bgpd_addr * up_get_nexthop(struct rde_peer *peer, struct filterstate *state, uint8_t aid) { struct bgpd_addr *peer_local = NULL; switch (aid) { case AID_INET: case AID_VPN_IPv4: if (peer_has_ext_nexthop(peer, aid) && peer->remote_addr.aid == AID_INET6) peer_local = &peer->local_v6_addr; else if (peer->local_v4_addr.aid == AID_INET) peer_local = &peer->local_v4_addr; break; case AID_INET6: case AID_VPN_IPv6: if (peer->local_v6_addr.aid == AID_INET6) peer_local = &peer->local_v6_addr; break; case AID_EVPN: if (peer->local_v4_addr.aid == AID_INET) peer_local = &peer->local_v4_addr; else if (peer->local_v6_addr.aid == AID_INET6) peer_local = &peer->local_v6_addr; break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: /* flowspec has no nexthop */ return (NULL); default: fatalx("%s, bad AID %s", __func__, aid2str(aid)); } if (state->nhflags & NEXTHOP_SELF) { /* * Forcing the nexthop to self is always possible * and has precedence over other flags. */ return (peer_local); } else if (!peer->conf.ebgp) { /* * in the ibgp case the nexthop is normally not * modified unless it points at the peer itself. */ if (state->nexthop == NULL) { /* announced networks without explicit nexthop set */ return (peer_local); } /* * per RFC: if remote peer address is equal to the nexthop set * the nexthop to our local address. This reduces the risk of * routing loops. This overrides NEXTHOP_NOMODIFY. */ if (memcmp(&state->nexthop->exit_nexthop, &peer->remote_addr, sizeof(peer->remote_addr)) == 0) { return (peer_local); } return (&state->nexthop->exit_nexthop); } else if (peer->conf.distance == 1) { /* * In the ebgp directly connected case never send * out a nexthop that is outside of the connected * network of the peer. No matter what flags are * set. This follows section 5.1.3 of RFC 4271. * So just check if the nexthop is in the same net * is enough here. */ if (state->nexthop != NULL && state->nexthop->flags & NEXTHOP_CONNECTED && prefix_compare(&peer->remote_addr, &state->nexthop->nexthop_net, state->nexthop->nexthop_netlen) == 0) { /* nexthop and peer are in the same net */ return (&state->nexthop->exit_nexthop); } return (peer_local); } else { /* * For ebgp multihop make it possible to overrule * the sent nexthop by setting NEXTHOP_NOMODIFY. * Similar to the ibgp case there is no same net check * needed but still ensure that the nexthop is not * pointing to the peer itself. */ if (state->nhflags & NEXTHOP_NOMODIFY && state->nexthop != NULL && memcmp(&state->nexthop->exit_nexthop, &peer->remote_addr, sizeof(peer->remote_addr)) != 0) { /* no modify flag set and nexthop not peer addr */ return (&state->nexthop->exit_nexthop); } return (peer_local); } } static void up_prep_adjout(struct rde_peer *peer, struct filterstate *state, uint8_t aid) { struct bgpd_addr *nexthop; struct nexthop *nh = NULL; u_char *np; uint16_t nl; /* prepend local AS number for eBGP sessions. */ if (peer->conf.ebgp && (peer->flags & PEERFLAG_TRANS_AS) == 0) { uint32_t prep_as = peer->conf.local_as; np = aspath_prepend(state->aspath.aspath, prep_as, 1, &nl); aspath_put(state->aspath.aspath); state->aspath.aspath = aspath_get(np, nl); free(np); } /* update nexthop */ nexthop = up_get_nexthop(peer, state, aid); if (nexthop != NULL) nh = nexthop_get(nexthop); nexthop_unref(state->nexthop); state->nexthop = nh; state->nhflags = 0; } static int up_generate_attr(struct ibuf *buf, struct rde_peer *peer, struct rde_aspath *asp, struct rde_community *comm, struct nexthop *nh, uint8_t aid) { struct attr *oa = NULL, *newaggr = NULL; u_char *pdata; uint32_t tmp32; int flags, neednewpath = 0, rv; uint16_t plen; uint8_t oalen = 0, type; if (asp->others_len > 0) oa = asp->others[oalen++]; /* dump attributes in ascending order */ for (type = ATTR_ORIGIN; type < 255; type++) { while (oa && oa->type < type) { if (oalen < asp->others_len) oa = asp->others[oalen++]; else oa = NULL; } switch (type) { /* * Attributes stored in rde_aspath */ case ATTR_ORIGIN: if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_ORIGIN, &asp->origin, 1) == -1) return -1; break; case ATTR_ASPATH: plen = aspath_length(asp->aspath); pdata = aspath_dump(asp->aspath); if (!peer_has_as4byte(peer)) pdata = aspath_deflate(pdata, &plen, &neednewpath); rv = attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_ASPATH, pdata, plen); if (!peer_has_as4byte(peer)) free(pdata); if (rv == -1) return -1; break; case ATTR_NEXTHOP: switch (aid) { case AID_INET: if (nh == NULL) return -1; if (nh->exit_nexthop.aid != AID_INET) { if (peer_has_ext_nexthop(peer, aid)) break; return -1; } if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_NEXTHOP, &nh->exit_nexthop.v4, sizeof(nh->exit_nexthop.v4)) == -1) return -1; break; default: break; } break; case ATTR_MED: /* * The old MED from other peers MUST not be announced * to others unless the MED is originating from us or * the peer is an IBGP one. Only exception are routers * with "transparent-as yes" set. */ if (asp->flags & F_ATTR_MED && (!peer->conf.ebgp || asp->flags & F_ATTR_MED_ANNOUNCE || peer->flags & PEERFLAG_TRANS_AS)) { tmp32 = htonl(asp->med); if (attr_writebuf(buf, ATTR_OPTIONAL, ATTR_MED, &tmp32, 4) == -1) return -1; } break; case ATTR_LOCALPREF: if (!peer->conf.ebgp) { /* local preference, only valid for ibgp */ tmp32 = htonl(asp->lpref); if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_LOCALPREF, &tmp32, 4) == -1) return -1; } break; /* * Communities are stored in struct rde_community */ case ATTR_COMMUNITIES: case ATTR_EXT_COMMUNITIES: case ATTR_LARGE_COMMUNITIES: if (community_writebuf(comm, type, peer->conf.ebgp, buf) == -1) return -1; break; /* * NEW to OLD conversion when sending stuff to a 2byte AS peer */ case ATTR_AS4_PATH: if (neednewpath) { plen = aspath_length(asp->aspath); pdata = aspath_dump(asp->aspath); flags = ATTR_OPTIONAL|ATTR_TRANSITIVE; if (!(asp->flags & F_PREFIX_ANNOUNCED)) flags |= ATTR_PARTIAL; if (plen != 0) if (attr_writebuf(buf, flags, ATTR_AS4_PATH, pdata, plen) == -1) return -1; } break; case ATTR_AS4_AGGREGATOR: if (newaggr) { flags = ATTR_OPTIONAL|ATTR_TRANSITIVE; if (!(asp->flags & F_PREFIX_ANNOUNCED)) flags |= ATTR_PARTIAL; if (attr_writebuf(buf, flags, ATTR_AS4_AGGREGATOR, newaggr->data, newaggr->len) == -1) return -1; } break; /* * multiprotocol attributes are handled elsewhere */ case ATTR_MP_REACH_NLRI: case ATTR_MP_UNREACH_NLRI: break; /* * dump all other path attributes. Following rules apply: * 1. well-known attrs: ATTR_ATOMIC_AGGREGATE and * ATTR_AGGREGATOR pass unmodified (enforce flags * to correct values). Actually ATTR_AGGREGATOR may be * deflated for OLD 2-byte peers. * 2. non-transitive attrs: don't re-announce to ebgp peers * 3. transitive known attrs: announce unmodified * 4. transitive unknown attrs: set partial bit and re-announce */ case ATTR_ATOMIC_AGGREGATE: if (oa == NULL || oa->type != type) break; if (attr_writebuf(buf, ATTR_WELL_KNOWN, ATTR_ATOMIC_AGGREGATE, NULL, 0) == -1) return -1; break; case ATTR_AGGREGATOR: if (oa == NULL || oa->type != type) break; if ((!(oa->flags & ATTR_TRANSITIVE)) && peer->conf.ebgp) break; if (!peer_has_as4byte(peer)) { /* need to deflate the aggregator */ uint8_t t[6]; uint16_t tas; if ((!(oa->flags & ATTR_TRANSITIVE)) && peer->conf.ebgp) break; memcpy(&tmp32, oa->data, sizeof(tmp32)); if (ntohl(tmp32) > USHRT_MAX) { tas = htons(AS_TRANS); newaggr = oa; } else tas = htons(ntohl(tmp32)); memcpy(t, &tas, sizeof(tas)); memcpy(t + sizeof(tas), oa->data + sizeof(tmp32), oa->len - sizeof(tmp32)); if (attr_writebuf(buf, oa->flags, oa->type, &t, sizeof(t)) == -1) return -1; } else { if (attr_writebuf(buf, oa->flags, oa->type, oa->data, oa->len) == -1) return -1; } break; case ATTR_ORIGINATOR_ID: case ATTR_CLUSTER_LIST: case ATTR_OTC: if (oa == NULL || oa->type != type) break; if ((!(oa->flags & ATTR_TRANSITIVE)) && peer->conf.ebgp) break; if (attr_writebuf(buf, oa->flags, oa->type, oa->data, oa->len) == -1) return -1; break; default: if (oa == NULL && type >= ATTR_FIRST_UNKNOWN) /* there is no attribute left to dump */ return (0); if (oa == NULL || oa->type != type) break; /* unknown attribute */ if (!(oa->flags & ATTR_TRANSITIVE)) { /* * RFC 1771: * Unrecognized non-transitive optional * attributes must be quietly ignored and * not passed along to other BGP peers. */ break; } if (attr_writebuf(buf, oa->flags | ATTR_PARTIAL, oa->type, oa->data, oa->len) == -1) return -1; } } return 0; } /* * Check if the pending element is a EoR marker. If so remove it from the * tree and return 1. */ int up_is_eor(struct rde_peer *peer, uint8_t aid) { struct prefix *p; p = RB_MIN(prefix_tree, &peer->updates[aid]); if (p != NULL && (p->flags & PREFIX_FLAG_EOR)) { /* * Need to remove eor from update tree because * prefix_adjout_destroy() can't handle that. */ RB_REMOVE(prefix_tree, &peer->updates[aid], p); p->flags &= ~PREFIX_FLAG_UPDATE; prefix_adjout_destroy(p); return 1; } return 0; } /* minimal buffer size > withdraw len + attr len + attr hdr + afi/safi */ #define MIN_UPDATE_LEN 16 static void up_prefix_free(struct prefix_tree *prefix_head, struct prefix *p, struct rde_peer *peer, int withdraw) { if (withdraw) { /* prefix no longer needed, remove it */ prefix_adjout_destroy(p); peer->stats.prefix_sent_withdraw++; } else { /* prefix still in Adj-RIB-Out, keep it */ RB_REMOVE(prefix_tree, prefix_head, p); p->flags &= ~PREFIX_FLAG_UPDATE; peer->stats.pending_update--; peer->stats.prefix_sent_update++; } } /* * Write prefixes to buffer until either there is no more space or * the next prefix has no longer the same ASPATH attributes. * Returns -1 if no prefix was written else 0. */ static int up_dump_prefix(struct ibuf *buf, struct prefix_tree *prefix_head, struct rde_peer *peer, int withdraw) { struct prefix *p, *np; int done = 0, has_ap = -1, rv = -1; RB_FOREACH_SAFE(p, prefix_tree, prefix_head, np) { if (has_ap == -1) has_ap = peer_has_add_path(peer, p->pt->aid, CAPA_AP_SEND); if (pt_writebuf(buf, p->pt, withdraw, has_ap, p->path_id_tx) == -1) break; /* make sure we only dump prefixes which belong together */ if (np == NULL || np->aspath != p->aspath || np->communities != p->communities || np->nexthop != p->nexthop || np->nhflags != p->nhflags || (np->flags & PREFIX_FLAG_EOR)) done = 1; rv = 0; up_prefix_free(prefix_head, p, peer, withdraw); if (done) break; } return rv; } static int up_generate_mp_reach(struct ibuf *buf, struct rde_peer *peer, struct nexthop *nh, uint8_t aid) { struct bgpd_addr *nexthop; size_t off, nhoff; uint16_t len, afi; uint8_t safi; /* attribute header, defaulting to extended length one */ if (ibuf_add_n8(buf, ATTR_OPTIONAL | ATTR_EXTLEN) == -1) return -1; if (ibuf_add_n8(buf, ATTR_MP_REACH_NLRI) == -1) return -1; off = ibuf_size(buf); if (ibuf_add_zero(buf, sizeof(len)) == -1) return -1; if (aid2afi(aid, &afi, &safi)) fatalx("up_generate_mp_reach: bad AID"); /* AFI + SAFI + NH LEN + NH + Reserved */ if (ibuf_add_n16(buf, afi) == -1) return -1; if (ibuf_add_n8(buf, safi) == -1) return -1; nhoff = ibuf_size(buf); if (ibuf_add_zero(buf, 1) == -1) return -1; if (aid == AID_VPN_IPv4 || aid == AID_VPN_IPv6) { /* write zero rd */ if (ibuf_add_zero(buf, sizeof(uint64_t)) == -1) return -1; } switch (aid) { case AID_INET: case AID_VPN_IPv4: if (nh == NULL) return -1; nexthop = &nh->exit_nexthop; /* AID_INET must only use this path with an IPv6 nexthop */ if (nexthop->aid == AID_INET && aid != AID_INET) { if (ibuf_add(buf, &nexthop->v4, sizeof(nexthop->v4)) == -1) return -1; break; } else if (nexthop->aid == AID_INET6 && peer_has_ext_nexthop(peer, aid)) { if (ibuf_add(buf, &nexthop->v6, sizeof(nexthop->v6)) == -1) return -1; } else { /* can't encode nexthop, give up and withdraw prefix */ return -1; } break; case AID_INET6: case AID_VPN_IPv6: if (nh == NULL) return -1; nexthop = &nh->exit_nexthop; if (ibuf_add(buf, &nexthop->v6, sizeof(nexthop->v6)) == -1) return -1; break; case AID_EVPN: if (nh == NULL) return -1; nexthop = &nh->exit_nexthop; if (nexthop->aid == AID_INET) { if (ibuf_add(buf, &nexthop->v4, sizeof(nexthop->v4)) == -1) return -1; break; } else if (nexthop->aid == AID_INET6) { if (ibuf_add(buf, &nexthop->v6, sizeof(nexthop->v6)) == -1) return -1; } else { /* can't encode nexthop, give up and withdraw prefix */ return -1; } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: /* no NH */ break; default: fatalx("up_generate_mp_reach: unknown AID"); } /* update nexthop len */ len = ibuf_size(buf) - nhoff - 1; if (ibuf_set_n8(buf, nhoff, len) == -1) return -1; if (ibuf_add_zero(buf, 1) == -1) /* Reserved must be 0 */ return -1; if (up_dump_prefix(buf, &peer->updates[aid], peer, 0) == -1) /* no prefixes written, fail update */ return -1; /* update MP_REACH attribute length field */ len = ibuf_size(buf) - off - sizeof(len); if (ibuf_set_n16(buf, off, len) == -1) return -1; return 0; } /* * Generate UPDATE message containing either just withdraws or updates. * UPDATE messages are contructed like this: * * +-----------------------------------------------------+ * | Withdrawn Routes Length (2 octets) | * +-----------------------------------------------------+ * | Withdrawn Routes (variable) | * +-----------------------------------------------------+ * | Total Path Attribute Length (2 octets) | * +-----------------------------------------------------+ * | Path Attributes (variable) | * +-----------------------------------------------------+ * | Network Layer Reachability Information (variable) | * +-----------------------------------------------------+ * * Multiprotocol messages use MP_REACH_NLRI and MP_UNREACH_NLRI * the latter will be the only path attribute in a message. */ /* * Write UPDATE message for withdrawn routes. The size of buf limits * how may routes can be added. Return 0 on success -1 on error which * includes generating an empty withdraw message. */ struct ibuf * up_dump_withdraws(struct rde_peer *peer, uint8_t aid) { struct ibuf *buf; size_t off, pkgsize = MAX_PKTSIZE; uint16_t afi, len; uint8_t safi; if (peer_has_ext_msg(peer)) pkgsize = MAX_EXT_PKTSIZE; if ((buf = ibuf_dynamic(4, pkgsize - MSGSIZE_HEADER)) == NULL) goto fail; /* reserve space for the withdrawn routes length field */ off = ibuf_size(buf); if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; if (aid != AID_INET) { /* reserve space for 2-byte path attribute length */ off = ibuf_size(buf); if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; /* attribute header, defaulting to extended length one */ if (ibuf_add_n8(buf, ATTR_OPTIONAL | ATTR_EXTLEN) == -1) goto fail; if (ibuf_add_n8(buf, ATTR_MP_UNREACH_NLRI) == -1) goto fail; if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; /* afi & safi */ if (aid2afi(aid, &afi, &safi)) fatalx("%s: bad AID", __func__); if (ibuf_add_n16(buf, afi) == -1) goto fail; if (ibuf_add_n8(buf, safi) == -1) goto fail; } if (up_dump_prefix(buf, &peer->withdraws[aid], peer, 1) == -1) goto fail; /* update length field (either withdrawn routes or attribute length) */ len = ibuf_size(buf) - off - sizeof(len); if (ibuf_set_n16(buf, off, len) == -1) goto fail; if (aid != AID_INET) { /* write MP_UNREACH_NLRI attribute length (always extended) */ len -= 4; /* skip attribute header */ if (ibuf_set_n16(buf, off + sizeof(len) + 2, len) == -1) goto fail; } else { /* no extra attributes so set attribute len to 0 */ if (ibuf_add_zero(buf, sizeof(len)) == -1) { goto fail; } } return buf; fail: /* something went horribly wrong */ log_peer_warn(&peer->conf, "generating withdraw failed, peer desynced"); ibuf_free(buf); return NULL; } /* * Withdraw a single prefix after an error. */ static struct ibuf * up_dump_withdraw_one(struct rde_peer *peer, struct prefix *p, struct ibuf *buf) { size_t off; int has_ap; uint16_t afi, len; uint8_t safi; /* reset the buffer and start fresh */ ibuf_truncate(buf, 0); /* reserve space for the withdrawn routes length field */ off = ibuf_size(buf); if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; if (p->pt->aid != AID_INET) { /* reserve space for 2-byte path attribute length */ off = ibuf_size(buf); if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; /* attribute header, defaulting to extended length one */ if (ibuf_add_n8(buf, ATTR_OPTIONAL | ATTR_EXTLEN) == -1) goto fail; if (ibuf_add_n8(buf, ATTR_MP_UNREACH_NLRI) == -1) goto fail; if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; /* afi & safi */ if (aid2afi(p->pt->aid, &afi, &safi)) fatalx("%s: bad AID", __func__); if (ibuf_add_n16(buf, afi) == -1) goto fail; if (ibuf_add_n8(buf, safi) == -1) goto fail; } has_ap = peer_has_add_path(peer, p->pt->aid, CAPA_AP_SEND); if (pt_writebuf(buf, p->pt, 1, has_ap, p->path_id_tx) == -1) goto fail; /* update length field (either withdrawn routes or attribute length) */ len = ibuf_size(buf) - off - sizeof(len); if (ibuf_set_n16(buf, off, len) == -1) goto fail; if (p->pt->aid != AID_INET) { /* write MP_UNREACH_NLRI attribute length (always extended) */ len -= 4; /* skip attribute header */ if (ibuf_set_n16(buf, off + sizeof(len) + 2, len) == -1) goto fail; } else { /* no extra attributes so set attribute len to 0 */ if (ibuf_add_zero(buf, sizeof(len)) == -1) { goto fail; } } return buf; fail: /* something went horribly wrong */ log_peer_warn(&peer->conf, "generating withdraw failed, peer desynced"); ibuf_free(buf); return NULL; } /* * Write UPDATE message for changed and added routes. The size of buf limits * how may routes can be added. The function first dumps the path attributes * and then tries to add as many prefixes using these attributes. * Return 0 on success -1 on error which includes producing an empty message. */ struct ibuf * up_dump_update(struct rde_peer *peer, uint8_t aid) { struct ibuf *buf; struct bgpd_addr addr; struct prefix *p; size_t off, pkgsize = MAX_PKTSIZE; uint16_t len; int force_ip4mp = 0; p = RB_MIN(prefix_tree, &peer->updates[aid]); if (p == NULL) return NULL; if (peer_has_ext_msg(peer)) pkgsize = MAX_EXT_PKTSIZE; if (aid == AID_INET && peer_has_ext_nexthop(peer, AID_INET)) { struct nexthop *nh = prefix_nexthop(p); if (nh != NULL && nh->exit_nexthop.aid == AID_INET6) force_ip4mp = 1; } if ((buf = ibuf_dynamic(4, pkgsize - MSGSIZE_HEADER)) == NULL) goto fail; /* withdrawn routes length field is 0 */ if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; /* reserve space for 2-byte path attribute length */ off = ibuf_size(buf); if (ibuf_add_zero(buf, sizeof(len)) == -1) goto fail; if (up_generate_attr(buf, peer, prefix_aspath(p), prefix_communities(p), prefix_nexthop(p), aid) == -1) goto drop; if (aid != AID_INET || force_ip4mp) { /* write mp attribute including nlri */ /* * RFC 7606 wants this to be first but then we need * to use multiple buffers with adjusted length to * merge the attributes together in reverse order of * creation. */ if (up_generate_mp_reach(buf, peer, prefix_nexthop(p), aid) == -1) goto drop; } /* update attribute length field */ len = ibuf_size(buf) - off - sizeof(len); if (ibuf_set_n16(buf, off, len) == -1) goto fail; if (aid == AID_INET && !force_ip4mp) { /* last but not least dump the IPv4 nlri */ if (up_dump_prefix(buf, &peer->updates[aid], peer, 0) == -1) goto drop; } return buf; drop: /* Not enough space. Drop current prefix, it will never fit. */ p = RB_MIN(prefix_tree, &peer->updates[aid]); pt_getaddr(p->pt, &addr); log_peer_warnx(&peer->conf, "generating update failed, " "prefix %s/%d dropped", log_addr(&addr), p->pt->prefixlen); up_prefix_free(&peer->updates[aid], p, peer, 0); return up_dump_withdraw_one(peer, p, buf); fail: /* something went horribly wrong */ log_peer_warn(&peer->conf, "generating update failed, peer desynced"); ibuf_free(buf); return NULL; } openbgpd-8.8/src/bgpd/rde_attr.c100644 001750 001750 00000047255 14673014240 0012362/* $OpenBSD: rde_attr.c,v 1.135 2024/09/10 09:38:45 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker * Copyright (c) 2016 Job Snijders * Copyright (c) 2016 Peter Hessler * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" int attr_writebuf(struct ibuf *buf, uint8_t flags, uint8_t type, void *data, uint16_t data_len) { u_char hdr[4]; flags &= ~ATTR_DEFMASK; if (data_len > 255) { flags |= ATTR_EXTLEN; hdr[2] = (data_len >> 8) & 0xff; hdr[3] = data_len & 0xff; } else { hdr[2] = data_len & 0xff; } hdr[0] = flags; hdr[1] = type; if (ibuf_add(buf, hdr, flags & ATTR_EXTLEN ? 4 : 3) == -1) return (-1); if (data != NULL && ibuf_add(buf, data, data_len) == -1) return (-1); return (0); } /* optional attribute specific functions */ struct attr *attr_alloc(uint8_t, uint8_t, void *, uint16_t); struct attr *attr_lookup(uint8_t, uint8_t, void *, uint16_t); void attr_put(struct attr *); static inline int attr_diff(struct attr *, struct attr *); RB_HEAD(attr_tree, attr) attrtable = RB_INITIALIZER(&attr); RB_GENERATE_STATIC(attr_tree, attr, entry, attr_diff); void attr_shutdown(void) { if (!RB_EMPTY(&attrtable)) log_warnx("%s: free non-free attr table", __func__); } int attr_optadd(struct rde_aspath *asp, uint8_t flags, uint8_t type, void *data, uint16_t len) { uint8_t l; struct attr *a, *t; void *p; /* known optional attributes were validated previously */ if ((a = attr_lookup(flags, type, data, len)) == NULL) a = attr_alloc(flags, type, data, len); /* attribute allowed only once */ for (l = 0; l < asp->others_len; l++) { if (asp->others[l] == NULL) break; if (type == asp->others[l]->type) { if (a->refcnt == 0) attr_put(a); return (-1); } } /* add attribute to the table but first bump refcnt */ a->refcnt++; rdemem.attr_refs++; for (l = 0; l < asp->others_len; l++) { if (asp->others[l] == NULL) { asp->others[l] = a; return (0); } /* list is sorted */ if (a->type < asp->others[l]->type) { t = asp->others[l]; asp->others[l] = a; a = t; } } /* no empty slot found, need to realloc */ if (asp->others_len == UCHAR_MAX) fatalx("attr_optadd: others_len overflow"); asp->others_len++; if ((p = reallocarray(asp->others, asp->others_len, sizeof(struct attr *))) == NULL) fatal("%s", __func__); asp->others = p; /* l stores the size of others before resize */ asp->others[l] = a; return (0); } struct attr * attr_optget(const struct rde_aspath *asp, uint8_t type) { uint8_t l; for (l = 0; l < asp->others_len; l++) { if (asp->others[l] == NULL) break; if (type == asp->others[l]->type) return (asp->others[l]); if (type < asp->others[l]->type) break; } return (NULL); } void attr_copy(struct rde_aspath *t, const struct rde_aspath *s) { uint8_t l; if (t->others != NULL) attr_freeall(t); t->others_len = s->others_len; if (t->others_len == 0) { t->others = NULL; return; } if ((t->others = calloc(s->others_len, sizeof(struct attr *))) == 0) fatal("%s", __func__); for (l = 0; l < t->others_len; l++) { if (s->others[l] == NULL) break; s->others[l]->refcnt++; rdemem.attr_refs++; t->others[l] = s->others[l]; } } static inline int attr_diff(struct attr *oa, struct attr *ob) { int r; if (ob == NULL) return (1); if (oa == NULL) return (-1); if (oa->flags > ob->flags) return (1); if (oa->flags < ob->flags) return (-1); if (oa->type > ob->type) return (1); if (oa->type < ob->type) return (-1); if (oa->len > ob->len) return (1); if (oa->len < ob->len) return (-1); r = memcmp(oa->data, ob->data, oa->len); if (r > 0) return (1); if (r < 0) return (-1); return (0); } int attr_compare(struct rde_aspath *a, struct rde_aspath *b) { uint8_t l, min; min = a->others_len < b->others_len ? a->others_len : b->others_len; for (l = 0; l < min; l++) if (a->others[l] != b->others[l]) return (attr_diff(a->others[l], b->others[l])); if (a->others_len < b->others_len) { for (; l < b->others_len; l++) if (b->others[l] != NULL) return (-1); } else if (a->others_len > b->others_len) { for (; l < a->others_len; l++) if (a->others[l] != NULL) return (1); } return (0); } void attr_free(struct rde_aspath *asp, struct attr *attr) { uint8_t l; for (l = 0; l < asp->others_len; l++) if (asp->others[l] == attr) { attr_put(asp->others[l]); for (++l; l < asp->others_len; l++) asp->others[l - 1] = asp->others[l]; asp->others[asp->others_len - 1] = NULL; return; } /* no realloc() because the slot may be reused soon */ } void attr_freeall(struct rde_aspath *asp) { uint8_t l; for (l = 0; l < asp->others_len; l++) attr_put(asp->others[l]); free(asp->others); asp->others = NULL; asp->others_len = 0; } struct attr * attr_alloc(uint8_t flags, uint8_t type, void *data, uint16_t len) { struct attr *a; a = calloc(1, sizeof(struct attr)); if (a == NULL) fatal("%s", __func__); rdemem.attr_cnt++; flags &= ~ATTR_DEFMASK; /* normalize mask */ a->flags = flags; a->type = type; a->len = len; if (len != 0) { if ((a->data = malloc(len)) == NULL) fatal("%s", __func__); rdemem.attr_dcnt++; rdemem.attr_data += len; memcpy(a->data, data, len); } else a->data = NULL; if (RB_INSERT(attr_tree, &attrtable, a) != NULL) fatalx("corrupted attr tree"); return (a); } struct attr * attr_lookup(uint8_t flags, uint8_t type, void *data, uint16_t len) { struct attr needle; flags &= ~ATTR_DEFMASK; /* normalize mask */ needle.flags = flags; needle.type = type; needle.len = len; needle.data = data; return RB_FIND(attr_tree, &attrtable, &needle); } void attr_put(struct attr *a) { if (a == NULL) return; rdemem.attr_refs--; if (--a->refcnt > 0) /* somebody still holds a reference */ return; /* unlink */ RB_REMOVE(attr_tree, &attrtable, a); if (a->len != 0) rdemem.attr_dcnt--; rdemem.attr_data -= a->len; rdemem.attr_cnt--; free(a->data); free(a); } /* aspath specific functions */ static uint16_t aspath_count(const void *, uint16_t); static uint32_t aspath_extract_origin(const void *, uint16_t); static uint16_t aspath_countlength(struct aspath *, uint16_t, int); static void aspath_countcopy(struct aspath *, uint16_t, uint8_t *, uint16_t, int); int aspath_compare(struct aspath *a1, struct aspath *a2) { int r; if (a1->len > a2->len) return (1); if (a1->len < a2->len) return (-1); r = memcmp(a1->data, a2->data, a1->len); if (r > 0) return (1); if (r < 0) return (-1); return (0); } struct aspath * aspath_get(void *data, uint16_t len) { struct aspath *aspath; aspath = malloc(ASPATH_HEADER_SIZE + len); if (aspath == NULL) fatal("%s", __func__); rdemem.aspath_cnt++; rdemem.aspath_size += ASPATH_HEADER_SIZE + len; aspath->len = len; aspath->ascnt = aspath_count(data, len); aspath->source_as = aspath_extract_origin(data, len); if (len != 0) memcpy(aspath->data, data, len); return (aspath); } struct aspath * aspath_copy(struct aspath *a) { struct aspath *aspath; aspath = malloc(ASPATH_HEADER_SIZE + a->len); if (aspath == NULL) fatal("%s", __func__); rdemem.aspath_cnt++; rdemem.aspath_size += ASPATH_HEADER_SIZE + a->len; memcpy(aspath, a, ASPATH_HEADER_SIZE + a->len); return (aspath); } void aspath_put(struct aspath *aspath) { if (aspath == NULL) return; rdemem.aspath_cnt--; rdemem.aspath_size -= ASPATH_HEADER_SIZE + aspath->len; free(aspath); } /* * convert a 4 byte aspath to a 2 byte one. */ u_char * aspath_deflate(u_char *data, uint16_t *len, int *flagnew) { uint8_t *seg, *nseg, *ndata = NULL; uint32_t as; int i; uint16_t seg_size, olen, nlen; uint8_t seg_len; /* first calculate the length of the aspath */ nlen = 0; seg = data; olen = *len; for (; olen > 0; olen -= seg_size, seg += seg_size) { seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; nlen += 2 + sizeof(uint16_t) * seg_len; if (seg_size > olen) fatalx("%s: would overflow", __func__); } if (nlen == 0) goto done; if ((ndata = malloc(nlen)) == NULL) fatal("%s", __func__); /* then copy the aspath */ seg = data; olen = *len; for (nseg = ndata; seg < data + olen; seg += seg_size) { *nseg++ = seg[0]; *nseg++ = seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; for (i = 0; i < seg_len; i++) { as = aspath_extract(seg, i); if (as > USHRT_MAX) { as = AS_TRANS; *flagnew = 1; } *nseg++ = (as >> 8) & 0xff; *nseg++ = as & 0xff; } } done: *len = nlen; return (ndata); } void aspath_merge(struct rde_aspath *a, struct attr *attr) { uint8_t *np; uint16_t ascnt, diff, nlen, difflen; int hroom = 0; ascnt = aspath_count(attr->data, attr->len); if (ascnt > a->aspath->ascnt) { /* ASPATH is shorter then AS4_PATH no way to merge */ attr_free(a, attr); return; } diff = a->aspath->ascnt - ascnt; if (diff && attr->len > 2 && attr->data[0] == AS_SEQUENCE) hroom = attr->data[1]; difflen = aspath_countlength(a->aspath, diff, hroom); nlen = attr->len + difflen; if ((np = malloc(nlen)) == NULL) fatal("%s", __func__); /* copy head from old aspath */ aspath_countcopy(a->aspath, diff, np, difflen, hroom); /* copy tail from new aspath */ if (hroom > 0) memcpy(np + nlen - attr->len + 2, attr->data + 2, attr->len - 2); else memcpy(np + nlen - attr->len, attr->data, attr->len); aspath_put(a->aspath); a->aspath = aspath_get(np, nlen); free(np); attr_free(a, attr); } uint32_t aspath_neighbor(struct aspath *aspath) { /* * Empty aspath is OK -- internal AS route. * Additionally the RFC specifies that if the path starts with an * AS_SET the neighbor AS is also the local AS. */ if (aspath->len == 0 || aspath->data[0] != AS_SEQUENCE) return (rde_local_as()); return (aspath_extract(aspath->data, 0)); } static uint16_t aspath_count(const void *data, uint16_t len) { const uint8_t *seg; uint16_t cnt, seg_size; uint8_t seg_type, seg_len; cnt = 0; seg = data; for (; len > 0; len -= seg_size, seg += seg_size) { seg_type = seg[0]; seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; if (seg_type == AS_SET) cnt += 1; else cnt += seg_len; if (seg_size > len) fatalx("%s: would overflow", __func__); } return (cnt); } /* * The origin AS number derived from a Route as follows: * o the rightmost AS in the final segment of the AS_PATH attribute * in the Route if that segment is of type AS_SEQUENCE, or * o the BGP speaker's own AS number if that segment is of type * AS_CONFED_SEQUENCE or AS_CONFED_SET or if the AS_PATH is empty, * o the distinguished value "NONE" if the final segment of the * AS_PATH attribute is of any other type. */ static uint32_t aspath_extract_origin(const void *data, uint16_t len) { const uint8_t *seg; uint32_t as = AS_NONE; uint16_t seg_size; uint8_t seg_len; /* AS_PATH is empty */ if (len == 0) return (rde_local_as()); seg = data; for (; len > 0; len -= seg_size, seg += seg_size) { seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; if (len == seg_size && seg[0] == AS_SEQUENCE) { as = aspath_extract(seg, seg_len - 1); } if (seg_size > len) fatalx("%s: would overflow", __func__); } return (as); } static uint16_t aspath_countlength(struct aspath *aspath, uint16_t cnt, int headcnt) { const uint8_t *seg; uint16_t seg_size, len, clen; uint8_t seg_type = 0, seg_len = 0; seg = aspath->data; clen = 0; for (len = aspath->len; len > 0 && cnt > 0; len -= seg_size, seg += seg_size) { seg_type = seg[0]; seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; if (seg_type == AS_SET) cnt -= 1; else if (seg_len > cnt) { seg_len = cnt; clen += 2 + sizeof(uint32_t) * cnt; break; } else cnt -= seg_len; clen += seg_size; if (seg_size > len) fatalx("%s: would overflow", __func__); } if (headcnt > 0 && seg_type == AS_SEQUENCE && headcnt + seg_len < 256) /* no need for additional header from the new aspath. */ clen -= 2; return (clen); } static void aspath_countcopy(struct aspath *aspath, uint16_t cnt, uint8_t *buf, uint16_t size, int headcnt) { const uint8_t *seg; uint16_t seg_size, len; uint8_t seg_type, seg_len; if (headcnt > 0) /* * additional room because we steal the segment header * from the other aspath */ size += 2; seg = aspath->data; for (len = aspath->len; len > 0 && cnt > 0; len -= seg_size, seg += seg_size) { seg_type = seg[0]; seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; if (seg_type == AS_SET) cnt -= 1; else if (seg_len > cnt) { seg_len = cnt + headcnt; seg_size = 2 + sizeof(uint32_t) * cnt; cnt = 0; } else { cnt -= seg_len; if (cnt == 0) seg_len += headcnt; } memcpy(buf, seg, seg_size); buf[0] = seg_type; buf[1] = seg_len; buf += seg_size; if (size < seg_size) fatalx("%s: would overflow", __func__); size -= seg_size; } } int aspath_loopfree(struct aspath *aspath, uint32_t myAS) { uint8_t *seg; uint16_t len, seg_size; uint8_t i, seg_len; seg = aspath->data; for (len = aspath->len; len > 0; len -= seg_size, seg += seg_size) { seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; for (i = 0; i < seg_len; i++) { if (myAS == aspath_extract(seg, i)) return (0); } if (seg_size > len) fatalx("%s: would overflow", __func__); } return (1); } static int as_compare(struct filter_as *f, uint32_t as, uint32_t neighas) { uint32_t match; if (f->flags & AS_FLAG_AS_SET_NAME) /* should not happen */ return (0); if (f->flags & AS_FLAG_AS_SET) return (as_set_match(f->aset, as)); if (f->flags & AS_FLAG_NEIGHBORAS) match = neighas; else match = f->as_min; switch (f->op) { case OP_NONE: case OP_EQ: if (as == match) return (1); break; case OP_NE: if (as != match) return (1); break; case OP_RANGE: if (as >= f->as_min && as <= f->as_max) return (1); break; case OP_XRANGE: if (as < f->as_min || as > f->as_max) return (1); break; } return (0); } /* we need to be able to search more than one as */ int aspath_match(struct aspath *aspath, struct filter_as *f, uint32_t neighas) { const uint8_t *seg; int final; uint16_t len, seg_size; uint8_t i, seg_len; uint32_t as = AS_NONE; if (f->type == AS_EMPTY) { if (aspath_length(aspath) == 0) return (1); else return (0); } /* just check the leftmost AS */ if (f->type == AS_PEER) { as = aspath_neighbor(aspath); if (as_compare(f, as, neighas)) return (1); else return (0); } seg = aspath->data; len = aspath->len; for (; len >= 6; len -= seg_size, seg += seg_size) { seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; final = (len == seg_size); if (f->type == AS_SOURCE) { /* * Just extract the rightmost AS * but if that segment is an AS_SET then the rightmost * AS of a previous AS_SEQUENCE segment should be used. * Because of that just look at AS_SEQUENCE segments. */ if (seg[0] == AS_SEQUENCE) as = aspath_extract(seg, seg_len - 1); /* not yet in the final segment */ if (!final) continue; if (as_compare(f, as, neighas)) return (1); else return (0); } /* AS_TRANSIT or AS_ALL */ for (i = 0; i < seg_len; i++) { /* * the source (rightmost) AS is excluded from * AS_TRANSIT matches. */ if (final && i == seg_len - 1 && f->type == AS_TRANSIT) return (0); as = aspath_extract(seg, i); if (as_compare(f, as, neighas)) return (1); } if (seg_size > len) fatalx("%s: would overflow", __func__); } return (0); } /* * Returns a new prepended aspath. Old needs to be freed by caller. */ u_char * aspath_prepend(struct aspath *asp, uint32_t as, int quantum, uint16_t *len) { u_char *p; int l, overflow = 0, shift = 0, size, wpos = 0; uint8_t type; /* lunatic prepends are blocked in the parser and limited */ /* first calculate new size */ if (asp->len > 0) { if (asp->len < 2) fatalx("aspath_prepend: bad aspath length"); type = asp->data[0]; size = asp->data[1]; } else { /* empty as path */ type = AS_SET; size = 0; } if (quantum > 255) fatalx("aspath_prepend: preposterous prepend"); if (quantum == 0) { /* no change needed but return a copy */ if (asp->len == 0) { *len = 0; return (NULL); } p = malloc(asp->len); if (p == NULL) fatal("%s", __func__); memcpy(p, asp->data, asp->len); *len = asp->len; return (p); } else if (type == AS_SET || size + quantum > 255) { /* need to attach a new AS_SEQUENCE */ l = 2 + quantum * sizeof(uint32_t) + asp->len; if (type == AS_SET) overflow = quantum; else overflow = size + quantum - 255; } else l = quantum * sizeof(uint32_t) + asp->len; quantum -= overflow; p = malloc(l); if (p == NULL) fatal("%s", __func__); /* first prepends */ as = htonl(as); if (overflow > 0) { p[wpos++] = AS_SEQUENCE; p[wpos++] = overflow; for (; overflow > 0; overflow--) { memcpy(p + wpos, &as, sizeof(uint32_t)); wpos += sizeof(uint32_t); } } if (quantum > 0) { shift = 2; p[wpos++] = AS_SEQUENCE; p[wpos++] = quantum + size; for (; quantum > 0; quantum--) { memcpy(p + wpos, &as, sizeof(uint32_t)); wpos += sizeof(uint32_t); } } if (asp->len > shift) memcpy(p + wpos, asp->data + shift, asp->len - shift); *len = l; return (p); } /* * Returns a new aspath where neighbor_as is replaced by local_as. */ u_char * aspath_override(struct aspath *asp, uint32_t neighbor_as, uint32_t local_as, uint16_t *len) { u_char *p, *seg, *nseg; uint32_t as; uint16_t l, seg_size; uint8_t i, seg_len, seg_type; if (asp->len == 0) { *len = 0; return (NULL); } p = malloc(asp->len); if (p == NULL) fatal("%s", __func__); seg = asp->data; nseg = p; for (l = asp->len; l > 0; l -= seg_size, seg += seg_size) { *nseg++ = seg_type = seg[0]; *nseg++ = seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; for (i = 0; i < seg_len; i++) { as = aspath_extract(seg, i); if (as == neighbor_as) as = local_as; as = htonl(as); memcpy(nseg, &as, sizeof(as)); nseg += sizeof(as); } if (seg_size > l) fatalx("%s: would overflow", __func__); } *len = asp->len; return (p); } int aspath_lenmatch(struct aspath *a, enum aslen_spec type, u_int aslen) { uint8_t *seg; uint32_t as, lastas = 0; u_int count = 0; uint16_t len, seg_size; uint8_t i, seg_len, seg_type; if (type == ASLEN_MAX) { if (aslen < aspath_count(a->data, a->len)) return (1); else return (0); } /* type == ASLEN_SEQ */ seg = a->data; for (len = a->len; len > 0; len -= seg_size, seg += seg_size) { seg_type = seg[0]; seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; for (i = 0; i < seg_len; i++) { as = aspath_extract(seg, i); if (as == lastas) { if (aslen < ++count) return (1); } else if (seg_type == AS_SET) { /* AS path 3 { 4 3 7 } 3 will have count = 3 */ continue; } else count = 1; lastas = as; } if (seg_size > len) fatalx("%s: would overflow", __func__); } return (0); } openbgpd-8.8/src/bgpd/rde_community.c100644 001750 001750 00000043500 14673014240 0013421/* $OpenBSD: rde_community.c,v 1.16 2024/09/10 08:53:20 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" static int apply_flag(uint32_t in, uint8_t flag, struct rde_peer *peer, uint32_t *out, uint32_t *mask) { switch (flag) { case COMMUNITY_ANY: if (mask == NULL) return -1; *out = 0; *mask = 0; return 0; case COMMUNITY_NEIGHBOR_AS: if (peer == NULL) return -1; *out = peer->conf.remote_as; break; case COMMUNITY_LOCAL_AS: if (peer == NULL) return -1; *out = peer->conf.local_as; break; default: *out = in; break; } if (mask) *mask = UINT32_MAX; return 0; } static int fc2c(struct community *fc, struct rde_peer *peer, struct community *c, struct community *m) { int type; uint8_t subtype; memset(c, 0, sizeof(*c)); if (m) memset(m, 0xff, sizeof(*m)); c->flags = (uint8_t)fc->flags; switch ((uint8_t)c->flags) { case COMMUNITY_TYPE_BASIC: if (apply_flag(fc->data1, fc->flags >> 8, peer, &c->data1, m ? &m->data1 : NULL)) return -1; if (apply_flag(fc->data2, fc->flags >> 16, peer, &c->data2, m ? &m->data2 : NULL)) return -1; /* check that values fit */ if (c->data1 > USHRT_MAX || c->data2 > USHRT_MAX) return -1; return 0; case COMMUNITY_TYPE_LARGE: if (apply_flag(fc->data1, fc->flags >> 8, peer, &c->data1, m ? &m->data1 : NULL)) return -1; if (apply_flag(fc->data2, fc->flags >> 16, peer, &c->data2, m ? &m->data2 : NULL)) return -1; if (apply_flag(fc->data3, fc->flags >> 24, peer, &c->data3, m ? &m->data3 : NULL)) return -1; return 0; case COMMUNITY_TYPE_EXT: type = (int32_t)fc->data3 >> 8; subtype = fc->data3 & 0xff; if ((fc->flags >> 24 & 0xff) == COMMUNITY_ANY) { /* special case for 'ext-community * *' */ if (m == NULL) return -1; m->data1 = 0; m->data2 = 0; m->data3 = 0; return 0; } if (type == -1) { /* special case for 'ext-community rt *' */ if ((fc->flags >> 8 & 0xff) != COMMUNITY_ANY || m == NULL) return -1; c->data3 = subtype; m->data1 = 0; m->data2 = 0; m->data3 = 0xff; return 0; } c->data3 = type << 8 | subtype; switch (type & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_FOUR_AS: if ((fc->flags >> 8 & 0xff) == COMMUNITY_ANY) break; if (apply_flag(fc->data1, fc->flags >> 8, peer, &c->data1, m ? &m->data1 : NULL)) return -1; if (apply_flag(fc->data2, fc->flags >> 16, peer, &c->data2, m ? &m->data2 : NULL)) return -1; if (m) m->data3 &= ~(EXT_COMMUNITY_TRANS_FOUR_AS << 8); return 0; case EXT_COMMUNITY_TRANS_IPV4: if ((fc->flags >> 8 & 0xff) == COMMUNITY_ANY) break; if (apply_flag(fc->data1, fc->flags >> 8, peer, &c->data1, m ? &m->data1 : NULL)) return -1; if (apply_flag(fc->data2, fc->flags >> 16, peer, &c->data2, m ? &m->data2 : NULL)) return -1; /* check that values fit */ if (c->data2 > USHRT_MAX) return -1; return 0; case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: if ((fc->flags >> 8 & 0xff) == COMMUNITY_ANY) break; c->data1 = fc->data1; c->data2 = fc->data2; return 0; } /* this is for 'ext-community subtype *' */ if (m == NULL) return -1; m->data1 = 0; m->data2 = 0; return 0; default: fatalx("%s: unknown type %d", __func__, (uint8_t)c->flags); } } static int fast_match(const void *va, const void *vb) { const struct community *a = va; const struct community *b = vb; if ((uint8_t)a->flags != (uint8_t)b->flags) return (uint8_t)a->flags > (uint8_t)b->flags ? 1 : -1; if (a->data1 != b->data1) return a->data1 > b->data1 ? 1 : -1; if (a->data2 != b->data2) return a->data2 > b->data2 ? 1 : -1; if (a->data3 != b->data3) return a->data3 > b->data3 ? 1 : -1; return 0; } static int mask_match(struct community *a, struct community *b, struct community *m) { if ((uint8_t)a->flags != (uint8_t)b->flags) return (uint8_t)a->flags > (uint8_t)b->flags ? 1 : -1; if ((a->data1 & m->data1) != (b->data1 & m->data1)) { if ((a->data1 & m->data1) > (b->data1 & m->data1)) return 1; return -1; } if ((a->data2 & m->data2) != (b->data2 & m->data2)) { if ((a->data2 & m->data2) > (b->data2 & m->data2)) return 1; return -1; } if ((a->data3 & m->data3) != (b->data3 & m->data3)) { if ((a->data3 & m->data3) > (b->data3 & m->data3)) return 1; return -1; } return 0; } /* * Insert a community keeping the list sorted. Don't add if already present. */ static void insert_community(struct rde_community *comm, struct community *c) { int l; int r; if (comm->nentries + 1 > comm->size) { struct community *new; int newsize = comm->size + 8; if ((new = recallocarray(comm->communities, comm->size, newsize, sizeof(struct community))) == NULL) fatal(__func__); comm->communities = new; comm->size = newsize; } /* XXX can be made faster by binary search */ for (l = 0; l < comm->nentries; l++) { r = fast_match(comm->communities + l, c); if (r == 0) { /* already present, nothing to do */ return; } else if (r > 0) { /* shift reminder by one slot */ memmove(comm->communities + l + 1, comm->communities + l, (comm->nentries - l) * sizeof(*c)); break; } } /* insert community at slot l */ comm->communities[l] = *c; comm->nentries++; } static int non_transitive_ext_community(struct community *c) { if ((uint8_t)c->flags != COMMUNITY_TYPE_EXT) return 0; if ((c->data3 >> 8) & EXT_COMMUNITY_NON_TRANSITIVE) return 1; return 0; } /* * Check if a community is present. This function will expand local-as and * neighbor-as and also mask of bits to support partial matches. */ int community_match(struct rde_community *comm, struct community *fc, struct rde_peer *peer) { struct community test, mask; int l; if (fc->flags >> 8 == 0) { /* fast path */ return (bsearch(fc, comm->communities, comm->nentries, sizeof(*fc), fast_match) != NULL); } else { /* slow path */ if (fc2c(fc, peer, &test, &mask) == -1) return 0; for (l = 0; l < comm->nentries; l++) { if (mask_match(&comm->communities[l], &test, &mask) == 0) return 1; } return 0; } } /* * Count the number of communities of type type. */ int community_count(struct rde_community *comm, uint8_t type) { int l; int count = 0; /* use the fact that the array is ordered by type */ switch (type) { case COMMUNITY_TYPE_BASIC: for (l = 0; l < comm->nentries; l++) { if ((uint8_t)comm->communities[l].flags == type) count++; else break; } break; case COMMUNITY_TYPE_EXT: for (l = 0; l < comm->nentries; l++) { if ((uint8_t)comm->communities[l].flags == type) count++; else if ((uint8_t)comm->communities[l].flags > type) break; } break; case COMMUNITY_TYPE_LARGE: for (l = comm->nentries; l > 0; l--) { if ((uint8_t)comm->communities[l - 1].flags == type) count++; else break; } break; } return count; } /* * Insert a community, expanding local-as and neighbor-as if needed. */ int community_set(struct rde_community *comm, struct community *fc, struct rde_peer *peer) { struct community set; if (fc->flags >> 8 == 0) { /* fast path */ insert_community(comm, fc); } else { if (fc2c(fc, peer, &set, NULL) == -1) return 0; if ((uint8_t)set.flags == COMMUNITY_TYPE_EXT) { int type = (int)set.data3 >> 8; switch (type & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_FOUR_AS: /* check that values fit */ if (set.data1 > USHRT_MAX && set.data2 > USHRT_MAX) return 0; if (set.data1 > USHRT_MAX) set.data3 = (set.data3 & 0xff) | EXT_COMMUNITY_TRANS_FOUR_AS << 8; else set.data3 = (set.data3 & 0xff) | EXT_COMMUNITY_TRANS_TWO_AS << 8; break; } } insert_community(comm, &set); } return 1; } /* * Remove a community if present, This function will expand local-as and * neighbor-as and also mask of bits to support partial matches. */ void community_delete(struct rde_community *comm, struct community *fc, struct rde_peer *peer) { struct community test, mask; struct community *match; int l = 0; if (fc->flags >> 8 == 0) { /* fast path */ match = bsearch(fc, comm->communities, comm->nentries, sizeof(*fc), fast_match); if (match == NULL) return; /* move everything after match down by 1 */ memmove(match, match + 1, (char *)(comm->communities + comm->nentries) - (char *)(match + 1)); comm->nentries--; return; } else { if (fc2c(fc, peer, &test, &mask) == -1) return; while (l < comm->nentries) { if (mask_match(&comm->communities[l], &test, &mask) == 0) { memmove(comm->communities + l, comm->communities + l + 1, (comm->nentries - l - 1) * sizeof(test)); comm->nentries--; continue; } l++; } } } /* * Internalize communities from the wireformat. * Store the partial flag in struct rde_community so it is not lost. * - community_add for ATTR_COMMUNITUES * - community_large_add for ATTR_LARGE_COMMUNITIES * - community_ext_add for ATTR_EXT_COMMUNITIES */ int community_add(struct rde_community *comm, int flags, struct ibuf *buf) { struct community set = { .flags = COMMUNITY_TYPE_BASIC }; uint16_t data1, data2; if (ibuf_size(buf) == 0 || ibuf_size(buf) % 4 != 0) return -1; if (flags & ATTR_PARTIAL) comm->flags |= PARTIAL_COMMUNITIES; while (ibuf_size(buf) > 0) { if (ibuf_get_n16(buf, &data1) == -1 || ibuf_get_n16(buf, &data2) == -1) return -1; set.data1 = data1; set.data2 = data2; insert_community(comm, &set); } return 0; } int community_large_add(struct rde_community *comm, int flags, struct ibuf *buf) { struct community set = { .flags = COMMUNITY_TYPE_LARGE }; if (ibuf_size(buf) == 0 || ibuf_size(buf) % 12 != 0) return -1; if (flags & ATTR_PARTIAL) comm->flags |= PARTIAL_LARGE_COMMUNITIES; while (ibuf_size(buf) > 0) { if (ibuf_get_n32(buf, &set.data1) == -1 || ibuf_get_n32(buf, &set.data2) == -1 || ibuf_get_n32(buf, &set.data3) == -1) return -1; insert_community(comm, &set); } return 0; } int community_ext_add(struct rde_community *comm, int flags, int ebgp, struct ibuf *buf) { struct community set = { .flags = COMMUNITY_TYPE_EXT }; uint64_t c; uint8_t type; if (ibuf_size(buf) == 0 || ibuf_size(buf) % 8 != 0) return -1; if (flags & ATTR_PARTIAL) comm->flags |= PARTIAL_EXT_COMMUNITIES; while (ibuf_size(buf) > 0) { if (ibuf_get_n64(buf, &c) == -1) return (-1); type = c >> 56; /* filter out non-transitive ext communuties from ebgp peers */ if (ebgp && (type & EXT_COMMUNITY_NON_TRANSITIVE)) continue; switch (type & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: set.data1 = c >> 32 & 0xffff; set.data2 = c; break; case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: set.data1 = c >> 16; set.data2 = c & 0xffff; break; } set.data3 = c >> 48; insert_community(comm, &set); } return 0; } /* * Convert communities back to the wireformat. * When writing ATTR_EXT_COMMUNITIES non-transitive communities need to * be skipped if they are sent to an ebgp peer. */ int community_writebuf(struct rde_community *comm, uint8_t type, int ebgp, struct ibuf *buf) { struct community *cp; uint64_t ext; int l, size, start, end, num; int flags = ATTR_OPTIONAL | ATTR_TRANSITIVE; uint8_t t; switch (type) { case ATTR_COMMUNITIES: if (comm->flags & PARTIAL_COMMUNITIES) flags |= ATTR_PARTIAL; size = 4; t = COMMUNITY_TYPE_BASIC; break; case ATTR_EXT_COMMUNITIES: if (comm->flags & PARTIAL_EXT_COMMUNITIES) flags |= ATTR_PARTIAL; size = 8; t = COMMUNITY_TYPE_EXT; break; case ATTR_LARGE_COMMUNITIES: if (comm->flags & PARTIAL_LARGE_COMMUNITIES) flags |= ATTR_PARTIAL; size = 12; t = COMMUNITY_TYPE_LARGE; break; default: return -1; } /* first count how many communities will be written */ num = 0; start = -1; for (l = 0; l < comm->nentries; l++) { cp = &comm->communities[l]; if ((uint8_t)cp->flags == t) { if (ebgp && non_transitive_ext_community(cp)) continue; num++; if (start == -1) start = l; } if ((uint8_t)cp->flags > t) break; } end = l; /* no communities for this type present */ if (num == 0) return 0; if (num > INT16_MAX / size) return -1; /* write attribute header */ if (attr_writebuf(buf, flags, type, NULL, num * size) == -1) return -1; /* write out the communities */ for (l = start; l < end; l++) { cp = &comm->communities[l]; switch (type) { case ATTR_COMMUNITIES: if (ibuf_add_n16(buf, cp->data1) == -1) return -1; if (ibuf_add_n16(buf, cp->data2) == -1) return -1; break; case ATTR_EXT_COMMUNITIES: if (ebgp && non_transitive_ext_community(cp)) continue; ext = (uint64_t)cp->data3 << 48; switch ((cp->data3 >> 8) & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: ext |= ((uint64_t)cp->data1 & 0xffff) << 32; ext |= (uint64_t)cp->data2; break; case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: ext |= (uint64_t)cp->data1 << 16; ext |= (uint64_t)cp->data2 & 0xffff; break; } if (ibuf_add_n64(buf, ext) == -1) return -1; break; case ATTR_LARGE_COMMUNITIES: if (ibuf_add_n32(buf, cp->data1) == -1) return -1; if (ibuf_add_n32(buf, cp->data2) == -1) return -1; if (ibuf_add_n32(buf, cp->data3) == -1) return -1; break; } } return 0; } /* * Global RIB cache for communities */ static inline int communities_compare(struct rde_community *a, struct rde_community *b) { if (a->nentries != b->nentries) return a->nentries > b->nentries ? 1 : -1; if (a->flags != b->flags) return a->flags > b->flags ? 1 : -1; return memcmp(a->communities, b->communities, a->nentries * sizeof(struct community)); } RB_HEAD(comm_tree, rde_community) commtable = RB_INITIALIZER(&commtable); RB_GENERATE_STATIC(comm_tree, rde_community, entry, communities_compare); void communities_shutdown(void) { if (!RB_EMPTY(&commtable)) log_warnx("%s: free non-free table", __func__); } struct rde_community * communities_lookup(struct rde_community *comm) { return RB_FIND(comm_tree, &commtable, comm); } struct rde_community * communities_link(struct rde_community *comm) { struct rde_community *n, *f; if ((n = malloc(sizeof(*n))) == NULL) fatal(__func__); communities_copy(n, comm); if ((f = RB_INSERT(comm_tree, &commtable, n)) != NULL) { log_warnx("duplicate communities collection inserted"); free(n->communities); free(n); return f; } n->refcnt = 1; /* initial reference by the cache */ rdemem.comm_size += n->size; rdemem.comm_nmemb += n->nentries; rdemem.comm_cnt++; return n; } void communities_unlink(struct rde_community *comm) { if (comm->refcnt != 1) fatalx("%s: unlinking still referenced communities", __func__); RB_REMOVE(comm_tree, &commtable, comm); rdemem.comm_size -= comm->size; rdemem.comm_nmemb -= comm->nentries; rdemem.comm_cnt--; free(comm->communities); free(comm); } /* * Return true/1 if the two communities collections are identical, * otherwise returns zero. */ int communities_equal(struct rde_community *a, struct rde_community *b) { if (a->nentries != b->nentries) return 0; if (a->flags != b->flags) return 0; return (memcmp(a->communities, b->communities, a->nentries * sizeof(struct community)) == 0); } /* * Copy communities to a new unreferenced struct. Needs to call * communities_clean() when done. to can be statically allocated, * it will be cleaned first. */ void communities_copy(struct rde_community *to, struct rde_community *from) { memset(to, 0, sizeof(*to)); /* ignore from->size and allocate the perfect amount */ to->size = from->nentries; to->nentries = from->nentries; to->flags = from->flags; if (to->nentries == 0) return; if ((to->communities = reallocarray(NULL, to->size, sizeof(struct community))) == NULL) fatal(__func__); memcpy(to->communities, from->communities, to->nentries * sizeof(struct community)); } /* * Clean up the communities by freeing any dynamically allocated memory. */ void communities_clean(struct rde_community *comm) { if (comm->refcnt != 0) fatalx("%s: cleaning still referenced communities", __func__); free(comm->communities); memset(comm, 0, sizeof(*comm)); } int community_to_rd(struct community *fc, uint64_t *community) { struct community c; uint64_t rd; if (fc2c(fc, NULL, &c, NULL) == -1) return -1; switch ((c.data3 >> 8) & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: rd = (0ULL << 48); rd |= ((uint64_t)c.data1 & 0xffff) << 32; rd |= (uint64_t)c.data2; break; case EXT_COMMUNITY_TRANS_IPV4: rd = (1ULL << 48); rd |= (uint64_t)c.data1 << 16; rd |= (uint64_t)c.data2 & 0xffff; break; case EXT_COMMUNITY_TRANS_FOUR_AS: rd = (2ULL << 48); rd |= (uint64_t)c.data1 << 16; rd |= (uint64_t)c.data2 & 0xffff; break; default: return -1; } *community = htobe64(rd); return 0; } openbgpd-8.8/src/bgpd/printconf.c100644 001750 001750 00000077422 14751151130 0012554/* $OpenBSD: printconf.c,v 1.181 2025/01/27 15:22:11 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2016 Job Snijders * Copyright (c) 2016 Peter Hessler * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA, PROFITS OR MIND, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "log.h" void print_prefix(struct filter_prefix *p); const char *community_type(struct community *c); void print_community(struct community *c); void print_origin(uint8_t); void print_set(struct filter_set_head *); void print_mainconf(struct bgpd_config *); void print_l3vpn_targets(struct filter_set_head *, const char *); void print_l3vpn(struct l3vpn *); const char *print_af(uint8_t); void print_network(struct network_config *, const char *); void print_flowspec(struct flowspec_config *, const char *); void print_as_sets(struct as_set_head *); void print_prefixsets(struct prefixset_head *); void print_originsets(struct prefixset_head *); void print_roa(struct roa_tree *); void print_aspa(struct aspa_tree *); void print_rtrs(struct rtr_config_head *); void print_peer(struct peer *, struct bgpd_config *, const char *); const char *print_auth_alg(enum auth_alg); const char *print_enc_alg(enum auth_enc_alg); void print_announce(struct peer_config *, const char *); void print_as(struct filter_rule *); void print_rule(struct bgpd_config *, struct filter_rule *); const char *mrt_type(enum mrt_type); void print_mrt(struct bgpd_config *, uint32_t, uint32_t, const char *, const char *); void print_groups(struct bgpd_config *); int peer_compare(const void *, const void *); void print_prefix(struct filter_prefix *p) { uint8_t max_len = 0; switch (p->addr.aid) { case AID_INET: case AID_VPN_IPv4: max_len = 32; break; case AID_INET6: case AID_VPN_IPv6: max_len = 128; break; case AID_UNSPEC: /* no prefix to print */ return; } printf("%s/%u", log_addr(&p->addr), p->len); switch (p->op) { case OP_NONE: break; case OP_NE: printf(" prefixlen != %u", p->len_min); break; case OP_XRANGE: printf(" prefixlen %u >< %u ", p->len_min, p->len_max); break; case OP_RANGE: if (p->len_min == p->len_max && p->len != p->len_min) printf(" prefixlen = %u", p->len_min); else if (p->len == p->len_min && p->len_max == max_len) printf(" or-longer"); else if (p->len == p->len_min && p->len != p->len_max) printf(" maxlen %u", p->len_max); else if (p->len_max == max_len) printf(" prefixlen >= %u", p->len_min); else printf(" prefixlen %u - %u", p->len_min, p->len_max); break; default: printf(" prefixlen %u ??? %u", p->len_min, p->len_max); break; } } const char * community_type(struct community *c) { switch ((uint8_t)c->flags) { case COMMUNITY_TYPE_BASIC: return "community"; case COMMUNITY_TYPE_LARGE: return "large-community"; case COMMUNITY_TYPE_EXT: return "ext-community"; default: return "???"; } } void print_community(struct community *c) { struct in_addr addr; int type; uint8_t subtype; switch ((uint8_t)c->flags) { case COMMUNITY_TYPE_BASIC: switch ((c->flags >> 8) & 0xff) { case COMMUNITY_ANY: printf("*:"); break; case COMMUNITY_NEIGHBOR_AS: printf("neighbor-as:"); break; case COMMUNITY_LOCAL_AS: printf("local-as:"); break; default: printf("%u:", c->data1); break; } switch ((c->flags >> 16) & 0xff) { case COMMUNITY_ANY: printf("* "); break; case COMMUNITY_NEIGHBOR_AS: printf("neighbor-as "); break; case COMMUNITY_LOCAL_AS: printf("local-as "); break; default: printf("%u ", c->data2); break; } break; case COMMUNITY_TYPE_LARGE: switch ((c->flags >> 8) & 0xff) { case COMMUNITY_ANY: printf("*:"); break; case COMMUNITY_NEIGHBOR_AS: printf("neighbor-as:"); break; case COMMUNITY_LOCAL_AS: printf("local-as:"); break; default: printf("%u:", c->data1); break; } switch ((c->flags >> 16) & 0xff) { case COMMUNITY_ANY: printf("*:"); break; case COMMUNITY_NEIGHBOR_AS: printf("neighbor-as:"); break; case COMMUNITY_LOCAL_AS: printf("local-as:"); break; default: printf("%u:", c->data2); break; } switch ((c->flags >> 24) & 0xff) { case COMMUNITY_ANY: printf("* "); break; case COMMUNITY_NEIGHBOR_AS: printf("neighbor-as "); break; case COMMUNITY_LOCAL_AS: printf("local-as "); break; default: printf("%u ", c->data3); break; } break; case COMMUNITY_TYPE_EXT: if ((c->flags >> 24 & 0xff) == COMMUNITY_ANY) { printf("* * "); break; } type = (int32_t)c->data3 >> 8; subtype = c->data3; printf("%s ", log_ext_subtype(type, subtype)); if ((c->flags >> 8 & 0xff) == COMMUNITY_ANY) { printf("* "); break; } switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_GEN_TWO_AS: case EXT_COMMUNITY_GEN_FOUR_AS: if ((c->flags >> 8 & 0xff) == COMMUNITY_NEIGHBOR_AS) printf("neighbor-as:"); else if ((c->flags >> 8 & 0xff) == COMMUNITY_LOCAL_AS) printf("local-as:"); else printf("%s:", log_as(c->data1)); break; case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_GEN_IPV4: addr.s_addr = htonl(c->data1); printf("%s:", inet_ntoa(addr)); break; } switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_GEN_TWO_AS: case EXT_COMMUNITY_GEN_FOUR_AS: case EXT_COMMUNITY_GEN_IPV4: if ((c->flags >> 16 & 0xff) == COMMUNITY_ANY) printf("* "); else if ((c->flags >> 16 & 0xff) == COMMUNITY_NEIGHBOR_AS) printf("neighbor-as "); else if ((c->flags >> 16 & 0xff) == COMMUNITY_LOCAL_AS) printf("local-as "); else printf("%u ", c->data2); break; case EXT_COMMUNITY_NON_TRANS_OPAQUE: if (subtype == EXT_COMMUNITY_SUBTYPE_OVS) { switch (c->data2) { case EXT_COMMUNITY_OVS_VALID: printf("valid "); break; case EXT_COMMUNITY_OVS_NOTFOUND: printf("not-found "); break; case EXT_COMMUNITY_OVS_INVALID: printf("invalid "); break; } break; } printf("0x%x%08x ", c->data1 & 0xffff, c->data2); break; case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: default: printf("0x%x%08x ", c->data1 & 0xffff, c->data2); break; } } } void print_origin(uint8_t o) { if (o == ORIGIN_IGP) printf("igp "); else if (o == ORIGIN_EGP) printf("egp "); else if (o == ORIGIN_INCOMPLETE) printf("incomplete "); else printf("%u ", o); } void print_set(struct filter_set_head *set) { struct filter_set *s; if (TAILQ_EMPTY(set)) return; printf("set { "); TAILQ_FOREACH(s, set, entry) { switch (s->type) { case ACTION_SET_LOCALPREF: printf("localpref %u ", s->action.metric); break; case ACTION_SET_RELATIVE_LOCALPREF: printf("localpref %+d ", s->action.relative); break; case ACTION_SET_MED: printf("metric %u ", s->action.metric); break; case ACTION_SET_RELATIVE_MED: printf("metric %+d ", s->action.relative); break; case ACTION_SET_WEIGHT: printf("weight %u ", s->action.metric); break; case ACTION_SET_RELATIVE_WEIGHT: printf("weight %+d ", s->action.relative); break; case ACTION_SET_NEXTHOP: printf("nexthop %s ", log_addr(&s->action.nexthop)); break; case ACTION_SET_NEXTHOP_REJECT: printf("nexthop reject "); break; case ACTION_SET_NEXTHOP_BLACKHOLE: printf("nexthop blackhole "); break; case ACTION_SET_NEXTHOP_NOMODIFY: printf("nexthop no-modify "); break; case ACTION_SET_NEXTHOP_SELF: printf("nexthop self "); break; case ACTION_SET_PREPEND_SELF: printf("prepend-self %u ", s->action.prepend); break; case ACTION_SET_PREPEND_PEER: printf("prepend-neighbor %u ", s->action.prepend); break; case ACTION_SET_AS_OVERRIDE: printf("as-override "); break; case ACTION_DEL_COMMUNITY: printf("%s delete ", community_type(&s->action.community)); print_community(&s->action.community); break; case ACTION_SET_COMMUNITY: printf("%s ", community_type(&s->action.community)); print_community(&s->action.community); break; case ACTION_PFTABLE: printf("pftable %s ", s->action.pftable); break; case ACTION_RTLABEL: printf("rtlabel %s ", s->action.rtlabel); break; case ACTION_SET_ORIGIN: printf("origin "); print_origin(s->action.origin); break; case ACTION_RTLABEL_ID: case ACTION_PFTABLE_ID: case ACTION_SET_NEXTHOP_REF: /* not possible */ printf("king bula saiz: config broken"); break; } } printf("}"); } void print_mainconf(struct bgpd_config *conf) { struct in_addr ina; struct listen_addr *la; printf("AS %s", log_as(conf->as)); if (conf->as > USHRT_MAX && conf->short_as != AS_TRANS) printf(" %u", conf->short_as); ina.s_addr = htonl(conf->bgpid); printf("\nrouter-id %s\n", inet_ntoa(ina)); printf("socket \"%s\"\n", conf->csock); if (conf->rcsock) printf("socket \"%s\" restricted\n", conf->rcsock); if (conf->holdtime != INTERVAL_HOLD) printf("holdtime %u\n", conf->holdtime); if (conf->min_holdtime != MIN_HOLDTIME) printf("holdtime min %u\n", conf->min_holdtime); if (conf->connectretry != INTERVAL_CONNECTRETRY) printf("connect-retry %u\n", conf->connectretry); if (conf->staletime != INTERVAL_STALE) printf("staletime %u\n", conf->staletime); if (conf->flags & BGPD_FLAG_DECISION_ROUTEAGE) printf("rde route-age evaluate\n"); if (conf->flags & BGPD_FLAG_DECISION_MED_ALWAYS) printf("rde med compare always\n"); if (conf->flags & BGPD_FLAG_DECISION_ALL_PATHS) printf("rde evaluate all\n"); if (conf->flags & BGPD_FLAG_PERMIT_AS_SET) printf("reject as-set no\n"); if (conf->log & BGPD_LOG_UPDATES) printf("log updates\n"); TAILQ_FOREACH(la, conf->listen_addrs, entry) { struct bgpd_addr addr; uint16_t port; sa2addr((struct sockaddr *)&la->sa, &addr, &port); printf("listen on %s", log_sockaddr((struct sockaddr *)&la->sa, la->sa_len)); if (port != BGP_PORT) printf(" port %hu", port); printf("\n"); } if (conf->flags & BGPD_FLAG_NEXTHOP_BGP) printf("nexthop qualify via bgp\n"); if (conf->flags & BGPD_FLAG_NEXTHOP_DEFAULT) printf("nexthop qualify via default\n"); if (conf->fib_priority != kr_default_prio()) printf("fib-priority %hhu\n", conf->fib_priority); printf("\n"); } void print_l3vpn_targets(struct filter_set_head *set, const char *tgt) { struct filter_set *s; TAILQ_FOREACH(s, set, entry) { printf("\t%s ", tgt); print_community(&s->action.community); printf("\n"); } } void print_l3vpn(struct l3vpn *vpn) { struct network *n; printf("vpn \"%s\" on %s {\n", vpn->descr, vpn->ifmpe); printf("\t%s\n", log_rd(vpn->rd)); print_l3vpn_targets(&vpn->export, "export-target"); print_l3vpn_targets(&vpn->import, "import-target"); if (vpn->flags & F_RIB_NOFIBSYNC) printf("\tfib-update no\n"); else printf("\tfib-update yes\n"); TAILQ_FOREACH(n, &vpn->net_l, entry) print_network(&n->net, "\t"); printf("}\n"); } const char * print_af(uint8_t aid) { /* * Hack around the fact that aid2str() will return "IPv4 unicast" * for AID_INET. AID_INET, AID_INET6 and the flowspec AID need * special handling and the other AID should never end up here. */ if (aid == AID_INET || aid == AID_FLOWSPECv4) return ("inet"); if (aid == AID_INET6 || aid == AID_FLOWSPECv6) return ("inet6"); return (aid2str(aid)); } void print_network(struct network_config *n, const char *c) { switch (n->type) { case NETWORK_STATIC: printf("%snetwork %s static", c, print_af(n->prefix.aid)); break; case NETWORK_CONNECTED: printf("%snetwork %s connected", c, print_af(n->prefix.aid)); break; case NETWORK_RTLABEL: printf("%snetwork %s rtlabel \"%s\"", c, print_af(n->prefix.aid), rtlabel_id2name(n->rtlabel)); break; case NETWORK_PRIORITY: printf("%snetwork %s priority %d", c, print_af(n->prefix.aid), n->priority); break; case NETWORK_PREFIXSET: printf("%snetwork prefix-set %s", c, n->psname); break; default: printf("%snetwork %s/%u", c, log_addr(&n->prefix), n->prefixlen); break; } if (!TAILQ_EMPTY(&n->attrset)) printf(" "); print_set(&n->attrset); printf("\n"); } static void print_flowspec_list(struct flowspec *f, int type, int is_v6) { const uint8_t *comp; const char *fmt; int complen, off = 0; if (flowspec_get_component(f->data, f->len, type, is_v6, &comp, &complen) != 1) return; printf("%s ", flowspec_fmt_label(type)); fmt = flowspec_fmt_num_op(comp, complen, &off); if (off == -1) { printf("%s ", fmt); } else { printf("{ %s ", fmt); do { fmt = flowspec_fmt_num_op(comp, complen, &off); printf("%s ", fmt); } while (off != -1); printf("} "); } } static void print_flowspec_flags(struct flowspec *f, int type, int is_v6) { const uint8_t *comp; const char *fmt, *flags; int complen, off = 0; switch (type) { case FLOWSPEC_TYPE_TCP_FLAGS: flags = FLOWSPEC_TCP_FLAG_STRING; break; case FLOWSPEC_TYPE_FRAG: if (!is_v6) flags = FLOWSPEC_FRAG_STRING4; else flags = FLOWSPEC_FRAG_STRING6; break; default: printf("??? "); return; } if (flowspec_get_component(f->data, f->len, type, is_v6, &comp, &complen) != 1) return; printf("%s ", flowspec_fmt_label(type)); fmt = flowspec_fmt_bin_op(comp, complen, &off, flags); if (off == -1) { printf("%s ", fmt); } else { printf("{ %s ", fmt); do { fmt = flowspec_fmt_bin_op(comp, complen, &off, flags); printf("%s ", fmt); } while (off != -1); printf("} "); } } static void print_flowspec_addr(struct flowspec *f, int type, int is_v6) { struct bgpd_addr addr; uint8_t plen; flowspec_get_addr(f->data, f->len, type, is_v6, &addr, &plen, NULL); if (plen == 0) printf("%s any ", flowspec_fmt_label(type)); else printf("%s %s/%u ", flowspec_fmt_label(type), log_addr(&addr), plen); } void print_flowspec(struct flowspec_config *fconf, const char *c) { struct flowspec *f = fconf->flow; int is_v6 = (f->aid == AID_FLOWSPECv6); printf("%sflowspec %s ", c, print_af(f->aid)); print_flowspec_list(f, FLOWSPEC_TYPE_PROTO, is_v6); print_flowspec_addr(f, FLOWSPEC_TYPE_SOURCE, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_SRC_PORT, is_v6); print_flowspec_addr(f, FLOWSPEC_TYPE_DEST, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_DST_PORT, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_DSCP, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_PKT_LEN, is_v6); print_flowspec_flags(f, FLOWSPEC_TYPE_TCP_FLAGS, is_v6); print_flowspec_flags(f, FLOWSPEC_TYPE_FRAG, is_v6); /* TODO: fixup the code handling to be like in the parser */ print_flowspec_list(f, FLOWSPEC_TYPE_ICMP_TYPE, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_ICMP_CODE, is_v6); print_set(&fconf->attrset); printf("\n"); } void print_as_sets(struct as_set_head *as_sets) { struct as_set *aset; uint32_t *as; size_t i, n; int len; SIMPLEQ_FOREACH(aset, as_sets, entry) { printf("as-set \"%s\" {\n\t", aset->name); as = set_get(aset->set, &n); for (i = 0, len = 8; i < n; i++) { if (len > 72) { printf("\n\t"); len = 8; } len += printf("%u ", as[i]); } printf("\n}\n\n"); } } void print_prefixsets(struct prefixset_head *psh) { struct prefixset *ps; struct prefixset_item *psi; SIMPLEQ_FOREACH(ps, psh, entry) { int count = 0; printf("prefix-set \"%s\" {", ps->name); RB_FOREACH(psi, prefixset_tree, &ps->psitems) { if (count++ % 2 == 0) printf("\n\t"); else printf(", "); print_prefix(&psi->p); } printf("\n}\n\n"); } } void print_originsets(struct prefixset_head *psh) { struct prefixset *ps; struct roa *roa; struct bgpd_addr addr; SIMPLEQ_FOREACH(ps, psh, entry) { printf("origin-set \"%s\" {", ps->name); RB_FOREACH(roa, roa_tree, &ps->roaitems) { printf("\n\t"); addr.aid = roa->aid; addr.v6 = roa->prefix.inet6; printf("%s/%u", log_addr(&addr), roa->prefixlen); if (roa->prefixlen != roa->maxlen) printf(" maxlen %u", roa->maxlen); printf(" source-as %u", roa->asnum); } printf("\n}\n\n"); } } void print_roa(struct roa_tree *r) { struct roa *roa; if (RB_EMPTY(r)) return; printf("roa-set {"); RB_FOREACH(roa, roa_tree, r) { printf("\n\t%s", log_roa(roa)); } printf("\n}\n\n"); } void print_aspa(struct aspa_tree *a) { struct aspa_set *aspa; if (RB_EMPTY(a)) return; printf("aspa-set {"); RB_FOREACH(aspa, aspa_tree, a) { printf("\n\t%s", log_aspa(aspa)); } printf("\n}\n\n"); } static void print_auth(struct auth_config *auth, const char *c) { char *method; if (auth->method == AUTH_MD5SIG) printf("%s\ttcp md5sig\n", c); else if (auth->method == AUTH_IPSEC_MANUAL_ESP || auth->method == AUTH_IPSEC_MANUAL_AH) { if (auth->method == AUTH_IPSEC_MANUAL_ESP) method = "esp"; else method = "ah"; printf("%s\tipsec %s in spi %u %s XXXXXX", c, method, auth->spi_in, print_auth_alg(auth->auth_alg_in)); if (auth->enc_alg_in) printf(" %s XXXXXX", print_enc_alg(auth->enc_alg_in)); printf("\n"); printf("%s\tipsec %s out spi %u %s XXXXXX", c, method, auth->spi_out, print_auth_alg(auth->auth_alg_out)); if (auth->enc_alg_out) printf(" %s XXXXXX", print_enc_alg(auth->enc_alg_out)); printf("\n"); } else if (auth->method == AUTH_IPSEC_IKE_AH) printf("%s\tipsec ah ike\n", c); else if (auth->method == AUTH_IPSEC_IKE_ESP) printf("%s\tipsec esp ike\n", c); } void print_rtrs(struct rtr_config_head *rh) { struct rtr_config *r; SIMPLEQ_FOREACH(r, rh, entry) { printf("rtr %s {\n", log_addr(&r->remote_addr)); printf("\tdescr \"%s\"\n", r->descr); printf("\tport %u\n", r->remote_port); if (r->local_addr.aid != AID_UNSPEC) printf("local-addr %s\n", log_addr(&r->local_addr)); print_auth(&r->auth, ""); printf("}\n\n"); } } void print_peer(struct peer *peer, struct bgpd_config *conf, const char *c) { struct in_addr ina; struct peer_config *p = &peer->conf; if ((p->remote_addr.aid == AID_INET && p->remote_masklen != 32) || (p->remote_addr.aid == AID_INET6 && p->remote_masklen != 128)) printf("%sneighbor %s/%u {\n", c, log_addr(&p->remote_addr), p->remote_masklen); else printf("%sneighbor %s {\n", c, log_addr(&p->remote_addr)); if (p->descr[0]) printf("%s\tdescr \"%s\"\n", c, p->descr); if (p->rib[0]) printf("%s\trib \"%s\"\n", c, p->rib); if (p->remote_as) printf("%s\tremote-as %s\n", c, log_as(p->remote_as)); if (p->local_as != conf->as) { printf("%s\tlocal-as %s", c, log_as(p->local_as)); if (p->local_as > USHRT_MAX && p->local_short_as != AS_TRANS) printf(" %u", p->local_short_as); printf("\n"); } if (p->down) printf("%s\tdown\n", c); if (p->distance > 1) printf("%s\tmultihop %u\n", c, p->distance); if (p->passive) printf("%s\tpassive\n", c); if (p->local_addr_v4.aid) printf("%s\tlocal-address %s\n", c, log_addr(&p->local_addr_v4)); if (p->local_addr_v6.aid) printf("%s\tlocal-address %s\n", c, log_addr(&p->local_addr_v6)); if (p->remote_port != BGP_PORT) printf("%s\tport %hu\n", c, p->remote_port); if (p->role != ROLE_NONE) printf("%s\trole %s\n", c, log_policy(p->role)); if (p->max_prefix) { printf("%s\tmax-prefix %u", c, p->max_prefix); if (p->max_prefix_restart) printf(" restart %u", p->max_prefix_restart); printf("\n"); } if (p->max_out_prefix) { printf("%s\tmax-prefix %u out", c, p->max_out_prefix); if (p->max_out_prefix_restart) printf(" restart %u", p->max_out_prefix_restart); printf("\n"); } if (p->holdtime) printf("%s\tholdtime %u\n", c, p->holdtime); if (p->min_holdtime) printf("%s\tholdtime min %u\n", c, p->min_holdtime); if (p->staletime) printf("%s\tstaletime %u\n", c, p->staletime); if (p->export_type == EXPORT_NONE) printf("%s\texport none\n", c); else if (p->export_type == EXPORT_DEFAULT_ROUTE) printf("%s\texport default-route\n", c); if (p->enforce_as == ENFORCE_AS_ON) printf("%s\tenforce neighbor-as yes\n", c); else printf("%s\tenforce neighbor-as no\n", c); if (p->enforce_local_as == ENFORCE_AS_ON) printf("%s\tenforce local-as yes\n", c); else printf("%s\tenforce local-as no\n", c); if (p->reflector_client) { if (conf->clusterid == 0) printf("%s\troute-reflector\n", c); else { ina.s_addr = htonl(conf->clusterid); printf("%s\troute-reflector %s\n", c, inet_ntoa(ina)); } } if (p->demote_group[0]) printf("%s\tdemote %s\n", c, p->demote_group); if (p->if_depend[0]) printf("%s\tdepend on \"%s\"\n", c, p->if_depend); if (p->flags & PEERFLAG_TRANS_AS) printf("%s\ttransparent-as yes\n", c); if (conf->flags & BGPD_FLAG_DECISION_ALL_PATHS) { if (!(p->flags & PEERFLAG_EVALUATE_ALL)) printf("%s\trde evaluate default\n", c); } else { if (p->flags & PEERFLAG_EVALUATE_ALL) printf("%s\trde evaluate all\n", c); } if (conf->flags & BGPD_FLAG_PERMIT_AS_SET) { if (!(p->flags & PEERFLAG_PERMIT_AS_SET)) printf("%s\treject as-set yes\n", c); } else { if (p->flags & PEERFLAG_PERMIT_AS_SET) printf("%s\treject as-set no\n", c); } if (p->flags & PEERFLAG_LOG_UPDATES) printf("%s\tlog updates\n", c); print_auth(&peer->auth_conf, c); if (p->ttlsec) printf("%s\tttl-security yes\n", c); print_announce(p, c); print_mrt(conf, p->id, p->groupid, c, "\t"); printf("%s}\n", c); } const char * print_auth_alg(enum auth_alg alg) { switch (alg) { case AUTH_AALG_SHA1HMAC: return ("sha1"); case AUTH_AALG_MD5HMAC: return ("md5"); default: return ("???"); } } const char * print_enc_alg(enum auth_enc_alg alg) { switch (alg) { case AUTH_EALG_3DESCBC: return ("3des"); case AUTH_EALG_AES: return ("aes"); default: return ("???"); } } static const char * print_addpath_mode(enum addpath_mode mode) { switch (mode) { case ADDPATH_EVAL_NONE: return "none"; case ADDPATH_EVAL_BEST: return "best"; case ADDPATH_EVAL_ECMP: return "ecmp"; case ADDPATH_EVAL_AS_WIDE: return "as-wide-best"; case ADDPATH_EVAL_ALL: return "all"; default: return "???"; } } void print_announce(struct peer_config *p, const char *c) { uint8_t aid; int match = 0; for (aid = AID_MIN; aid < AID_MAX; aid++) if (p->capabilities.mp[aid] == 2) { printf("%s\tannounce %s enforce\n", c, aid2str(aid)); match = 1; } else if (p->capabilities.mp[aid]) { printf("%s\tannounce %s\n", c, aid2str(aid)); match = 1; } if (!match) { printf("%s\tannounce IPv4 none\n", c); printf("%s\tannounce IPv6 none\n", c); } if (p->capabilities.refresh == 2) printf("%s\tannounce refresh enforce\n", c); else if (p->capabilities.refresh == 0) printf("%s\tannounce refresh no\n", c); if (p->capabilities.enhanced_rr == 2) printf("%s\tannounce enhanced refresh enforce\n", c); else if (p->capabilities.enhanced_rr == 1) printf("%s\tannounce enhanced refresh yes\n", c); if (p->capabilities.grestart.restart == 2) printf("%s\tannounce restart enforce\n", c); else if (p->capabilities.grestart.restart == 0) printf("%s\tannounce restart no\n", c); if (p->capabilities.grestart.restart != 0 && p->capabilities.grestart.grnotification) printf("%s\tannounce graceful notification yes\n", c); if (p->capabilities.as4byte == 2) printf("%s\tannounce as4byte enforce\n", c); else if (p->capabilities.as4byte == 0) printf("%s\tannounce as4byte no\n", c); if (p->capabilities.ext_msg == 2) printf("%s\tannounce extended message enforce\n", c); else if (p->capabilities.ext_msg == 1) printf("%s\tannounce extended message yes\n", c); if (p->capabilities.ext_nh[AID_INET] == 2) printf("%s\tannounce extended nexthop enforce\n", c); else if (p->capabilities.ext_nh[AID_INET] == 1) printf("%s\tannounce extended nexthop yes\n", c); if (p->capabilities.add_path[AID_MIN] & CAPA_AP_RECV_ENFORCE) printf("%s\tannounce add-path recv enforce\n", c); else if (p->capabilities.add_path[AID_MIN] & CAPA_AP_RECV) printf("%s\tannounce add-path recv yes\n", c); if (p->capabilities.add_path[AID_MIN] & CAPA_AP_SEND) { printf("%s\tannounce add-path send %s", c, print_addpath_mode(p->eval.mode)); if (p->eval.extrapaths != 0) printf(" plus %d", p->eval.extrapaths); if (p->eval.maxpaths != 0) printf(" max %d", p->eval.maxpaths); if (p->capabilities.add_path[AID_MIN] & CAPA_AP_SEND_ENFORCE) printf(" enforce"); printf("\n"); } if (p->capabilities.policy == 2) printf("%s\tannounce policy enforce\n", c); else if (p->capabilities.policy == 1) printf("%s\tannounce policy yes\n", c); else printf("%s\tannounce policy no\n", c); } void print_as(struct filter_rule *r) { if (r->match.as.flags & AS_FLAG_AS_SET_NAME) { printf("as-set \"%s\" ", r->match.as.name); return; } switch (r->match.as.op) { case OP_RANGE: printf("%s - ", log_as(r->match.as.as_min)); printf("%s ", log_as(r->match.as.as_max)); break; case OP_XRANGE: printf("%s >< ", log_as(r->match.as.as_min)); printf("%s ", log_as(r->match.as.as_max)); break; case OP_NE: printf("!= %s ", log_as(r->match.as.as_min)); break; default: printf("%s ", log_as(r->match.as.as_min)); break; } } void print_rule(struct bgpd_config *conf, struct filter_rule *r) { struct peer *p; int i; if (r->action == ACTION_ALLOW) printf("allow "); else if (r->action == ACTION_DENY) printf("deny "); else printf("match "); if (r->quick) printf("quick "); if (r->rib[0]) printf("rib %s ", r->rib); if (r->dir == DIR_IN) printf("from "); else if (r->dir == DIR_OUT) printf("to "); else printf("eeeeeeeps. "); if (r->peer.peerid) { RB_FOREACH(p, peer_head, &conf->peers) if (p->conf.id == r->peer.peerid) break; if (p == NULL) printf("? "); else printf("%s ", log_addr(&p->conf.remote_addr)); } else if (r->peer.groupid) { RB_FOREACH(p, peer_head, &conf->peers) if (p->conf.groupid == r->peer.groupid) break; if (p == NULL) printf("group ? "); else printf("group \"%s\" ", p->conf.group); } else if (r->peer.remote_as) { printf("AS %s ", log_as(r->peer.remote_as)); } else if (r->peer.ebgp) { printf("ebgp "); } else if (r->peer.ibgp) { printf("ibgp "); } else printf("any "); if (r->match.ovs.is_set) { switch (r->match.ovs.validity) { case ROA_VALID: printf("ovs valid "); break; case ROA_INVALID: printf("ovs invalid "); break; case ROA_NOTFOUND: printf("ovs not-found "); break; default: printf("ovs ??? %d ??? ", r->match.ovs.validity); } } if (r->match.avs.is_set) { switch (r->match.avs.validity) { case ASPA_VALID: printf("avs valid "); break; case ASPA_INVALID: printf("avs invalid "); break; case ASPA_UNKNOWN: printf("avs unknown "); break; default: printf("avs ??? %d ??? ", r->match.avs.validity); } } if (r->match.prefix.addr.aid != AID_UNSPEC) { printf("prefix "); print_prefix(&r->match.prefix); printf(" "); } if (r->match.prefixset.name[0] != '\0') printf("prefix-set \"%s\" ", r->match.prefixset.name); if (r->match.prefixset.flags & PREFIXSET_FLAG_LONGER) printf("or-longer "); if (r->match.originset.name[0] != '\0') printf("origin-set \"%s\" ", r->match.originset.name); if (r->match.nexthop.flags) { if (r->match.nexthop.flags == FILTER_NEXTHOP_NEIGHBOR) printf("nexthop neighbor "); else printf("nexthop %s ", log_addr(&r->match.nexthop.addr)); } if (r->match.as.type) { if (r->match.as.type == AS_ALL) printf("AS "); else if (r->match.as.type == AS_SOURCE) printf("source-as "); else if (r->match.as.type == AS_TRANSIT) printf("transit-as "); else if (r->match.as.type == AS_PEER) printf("peer-as "); else printf("unfluffy-as "); print_as(r); } if (r->match.aslen.type) { printf("%s %u ", r->match.aslen.type == ASLEN_MAX ? "max-as-len" : "max-as-seq", r->match.aslen.aslen); } for (i = 0; i < MAX_COMM_MATCH; i++) { struct community *c = &r->match.community[i]; if (c->flags != 0) { printf("%s ", community_type(c)); print_community(c); } } if (r->match.maxcomm != 0) printf("max-communities %d ", r->match.maxcomm - 1); if (r->match.maxextcomm != 0) printf("max-ext-communities %d ", r->match.maxextcomm - 1); if (r->match.maxlargecomm != 0) printf("max-large-communities %d ", r->match.maxlargecomm - 1); print_set(&r->set); printf("\n"); } const char * mrt_type(enum mrt_type t) { switch (t) { case MRT_NONE: break; case MRT_TABLE_DUMP: return "table"; case MRT_TABLE_DUMP_MP: return "table-mp"; case MRT_TABLE_DUMP_V2: return "table-v2"; case MRT_ALL_IN: return "all in"; case MRT_ALL_OUT: return "all out"; case MRT_UPDATE_IN: return "updates in"; case MRT_UPDATE_OUT: return "updates out"; } return "unfluffy MRT"; } void print_mrt(struct bgpd_config *conf, uint32_t pid, uint32_t gid, const char *prep, const char *prep2) { struct mrt *m; if (conf->mrt == NULL) return; LIST_FOREACH(m, conf->mrt, entry) if ((gid != 0 && m->group_id == gid) || (m->peer_id == pid && m->group_id == gid)) { printf("%s%sdump ", prep, prep2); if (m->rib[0]) printf("rib %s ", m->rib); printf("%s \"%s\"", mrt_type(m->type), MRT2MC(m)->name); if (MRT2MC(m)->ReopenTimerInterval == 0) printf("\n"); else printf(" %d\n", MRT2MC(m)->ReopenTimerInterval); } if (!LIST_EMPTY(conf->mrt)) printf("\n"); } void print_groups(struct bgpd_config *conf) { struct peer **peerlist; struct peer *p; u_int peer_cnt, i; uint32_t prev_groupid; const char *c; peer_cnt = 0; RB_FOREACH(p, peer_head, &conf->peers) peer_cnt++; if ((peerlist = calloc(peer_cnt, sizeof(*peerlist))) == NULL) fatal("print_groups calloc"); i = 0; RB_FOREACH(p, peer_head, &conf->peers) peerlist[i++] = p; qsort(peerlist, peer_cnt, sizeof(*peerlist), peer_compare); prev_groupid = 0; for (i = 0; i < peer_cnt; i++) { if (peerlist[i]->conf.groupid) { c = "\t"; if (peerlist[i]->conf.groupid != prev_groupid) { if (prev_groupid) printf("}\n\n"); printf("group \"%s\" {\n", peerlist[i]->conf.group); prev_groupid = peerlist[i]->conf.groupid; } } else c = ""; print_peer(peerlist[i], conf, c); } if (prev_groupid) printf("}\n\n"); free(peerlist); } int peer_compare(const void *aa, const void *bb) { const struct peer * const *a; const struct peer * const *b; a = aa; b = bb; return ((*a)->conf.groupid - (*b)->conf.groupid); } void print_config(struct bgpd_config *conf, struct rib_names *rib_l) { struct filter_rule *r; struct network *n; struct flowspec_config *f; struct rde_rib *rr; struct l3vpn *vpn; print_mainconf(conf); print_rtrs(&conf->rtrs); print_roa(&conf->roa); print_aspa(&conf->aspa); print_as_sets(&conf->as_sets); print_prefixsets(&conf->prefixsets); print_originsets(&conf->originsets); TAILQ_FOREACH(n, &conf->networks, entry) print_network(&n->net, ""); RB_FOREACH(f, flowspec_tree, &conf->flowspecs) print_flowspec(f, ""); if (!SIMPLEQ_EMPTY(&conf->l3vpns)) printf("\n"); SIMPLEQ_FOREACH(vpn, &conf->l3vpns, entry) print_l3vpn(vpn); printf("\n"); if (conf->filtered_in_locrib) printf("rde rib Loc-RIB include filtered\n"); SIMPLEQ_FOREACH(rr, rib_l, entry) { if (rr->flags & F_RIB_NOEVALUATE) printf("rde rib %s no evaluate\n", rr->name); else if (rr->flags & F_RIB_NOFIB) printf("rde rib %s\n", rr->name); else printf("rde rib %s rtable %u fib-update %s\n", rr->name, rr->rtableid, rr->flags & F_RIB_NOFIBSYNC ? "no" : "yes"); } printf("\n"); print_mrt(conf, 0, 0, "", ""); print_groups(conf); TAILQ_FOREACH(r, conf->filters, entry) print_rule(conf, r); } openbgpd-8.8/src/bgpd/rde_filter.c100644 001750 001750 00000056346 14453465437 0012714/* $OpenBSD: rde_filter.c,v 1.136 2023/05/09 13:11:19 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker * Copyright (c) 2016 Job Snijders * Copyright (c) 2016 Peter Hessler * Copyright (c) 2018 Sebastian Benoit * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" int filterset_equal(struct filter_set_head *, struct filter_set_head *); void rde_apply_set(struct filter_set_head *sh, struct rde_peer *peer, struct rde_peer *from, struct filterstate *state, uint8_t aid) { struct filter_set *set; u_char *np; uint32_t prep_as; uint16_t nl; uint8_t prepend; TAILQ_FOREACH(set, sh, entry) { switch (set->type) { case ACTION_SET_LOCALPREF: state->aspath.lpref = set->action.metric; break; case ACTION_SET_RELATIVE_LOCALPREF: if (set->action.relative > 0) { if (state->aspath.lpref > UINT_MAX - set->action.relative) state->aspath.lpref = UINT_MAX; else state->aspath.lpref += set->action.relative; } else { if (state->aspath.lpref < 0U - set->action.relative) state->aspath.lpref = 0; else state->aspath.lpref += set->action.relative; } break; case ACTION_SET_MED: state->aspath.flags |= F_ATTR_MED | F_ATTR_MED_ANNOUNCE; state->aspath.med = set->action.metric; break; case ACTION_SET_RELATIVE_MED: state->aspath.flags |= F_ATTR_MED | F_ATTR_MED_ANNOUNCE; if (set->action.relative > 0) { if (state->aspath.med > UINT_MAX - set->action.relative) state->aspath.med = UINT_MAX; else state->aspath.med += set->action.relative; } else { if (state->aspath.med < 0U - set->action.relative) state->aspath.med = 0; else state->aspath.med += set->action.relative; } break; case ACTION_SET_WEIGHT: state->aspath.weight = set->action.metric; break; case ACTION_SET_RELATIVE_WEIGHT: if (set->action.relative > 0) { if (state->aspath.weight > UINT_MAX - set->action.relative) state->aspath.weight = UINT_MAX; else state->aspath.weight += set->action.relative; } else { if (state->aspath.weight < 0U - set->action.relative) state->aspath.weight = 0; else state->aspath.weight += set->action.relative; } break; case ACTION_SET_PREPEND_SELF: prep_as = peer->conf.local_as; prepend = set->action.prepend; np = aspath_prepend(state->aspath.aspath, prep_as, prepend, &nl); aspath_put(state->aspath.aspath); state->aspath.aspath = aspath_get(np, nl); free(np); break; case ACTION_SET_PREPEND_PEER: if (from == NULL) break; prep_as = from->conf.remote_as; prepend = set->action.prepend; np = aspath_prepend(state->aspath.aspath, prep_as, prepend, &nl); aspath_put(state->aspath.aspath); state->aspath.aspath = aspath_get(np, nl); free(np); break; case ACTION_SET_AS_OVERRIDE: if (from == NULL) break; np = aspath_override(state->aspath.aspath, from->conf.remote_as, from->conf.local_as, &nl); aspath_put(state->aspath.aspath); state->aspath.aspath = aspath_get(np, nl); free(np); break; case ACTION_SET_NEXTHOP: fatalx("unexpected filter action in RDE"); case ACTION_SET_NEXTHOP_REF: case ACTION_SET_NEXTHOP_REJECT: case ACTION_SET_NEXTHOP_BLACKHOLE: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: nexthop_modify(set->action.nh_ref, set->type, aid, &state->nexthop, &state->nhflags); break; case ACTION_SET_COMMUNITY: community_set(&state->communities, &set->action.community, peer); break; case ACTION_DEL_COMMUNITY: community_delete(&state->communities, &set->action.community, peer); break; case ACTION_PFTABLE: /* convert pftable name to an id */ set->action.id = pftable_name2id(set->action.pftable); set->type = ACTION_PFTABLE_ID; /* FALLTHROUGH */ case ACTION_PFTABLE_ID: pftable_unref(state->aspath.pftableid); state->aspath.pftableid = pftable_ref(set->action.id); break; case ACTION_RTLABEL: /* convert the route label to an id for faster access */ set->action.id = rtlabel_name2id(set->action.rtlabel); set->type = ACTION_RTLABEL_ID; /* FALLTHROUGH */ case ACTION_RTLABEL_ID: rtlabel_unref(state->aspath.rtlabelid); state->aspath.rtlabelid = rtlabel_ref(set->action.id); break; case ACTION_SET_ORIGIN: state->aspath.origin = set->action.origin; break; } } } /* return 1 when prefix matches filter_prefix, 0 if not */ static int rde_prefix_match(struct filter_prefix *fp, struct bgpd_addr *prefix, uint8_t plen) { if (fp->addr.aid != prefix->aid) /* don't use IPv4 rules for IPv6 and vice versa */ return (0); if (prefix_compare(prefix, &fp->addr, fp->len)) return (0); /* test prefixlen stuff too */ switch (fp->op) { case OP_NONE: /* perfect match */ return (plen == fp->len); case OP_EQ: return (plen == fp->len_min); case OP_NE: return (plen != fp->len_min); case OP_RANGE: return ((plen >= fp->len_min) && (plen <= fp->len_max)); case OP_XRANGE: return ((plen < fp->len_min) || (plen > fp->len_max)); default: log_warnx("%s: unsupported prefix operation", __func__); return (0); } } static int rde_filter_match(struct filter_rule *f, struct rde_peer *peer, struct rde_peer *from, struct filterstate *state, struct bgpd_addr *prefix, uint8_t plen) { struct rde_aspath *asp = &state->aspath; int i; if (f->peer.ebgp && !peer->conf.ebgp) return (0); if (f->peer.ibgp && peer->conf.ebgp) return (0); if (f->match.ovs.is_set) { if ((state->vstate & ROA_MASK) != f->match.ovs.validity) return (0); } if (f->match.avs.is_set) { if (((state->vstate >> 4) & ASPA_MASK) != f->match.avs.validity) return (0); } if (asp != NULL && f->match.as.type != AS_UNDEF) { if (aspath_match(asp->aspath, &f->match.as, peer->conf.remote_as) == 0) return (0); } if (asp != NULL && f->match.aslen.type != ASLEN_NONE) if (aspath_lenmatch(asp->aspath, f->match.aslen.type, f->match.aslen.aslen) == 0) return (0); for (i = 0; i < MAX_COMM_MATCH; i++) { if (f->match.community[i].flags == 0) break; if (community_match(&state->communities, &f->match.community[i], peer) == 0) return (0); } if (f->match.maxcomm != 0) { if (f->match.maxcomm > community_count(&state->communities, COMMUNITY_TYPE_BASIC)) return (0); } if (f->match.maxextcomm != 0) { if (f->match.maxextcomm > community_count(&state->communities, COMMUNITY_TYPE_EXT)) return (0); } if (f->match.maxlargecomm != 0) { if (f->match.maxlargecomm > community_count(&state->communities, COMMUNITY_TYPE_LARGE)) return (0); } if (f->match.nexthop.flags != 0) { struct bgpd_addr *nexthop, *cmpaddr; if (state->nexthop == NULL) /* no nexthop, skip */ return (0); nexthop = &state->nexthop->exit_nexthop; if (f->match.nexthop.flags == FILTER_NEXTHOP_ADDR) cmpaddr = &f->match.nexthop.addr; else cmpaddr = &from->remote_addr; if (cmpaddr->aid != nexthop->aid) /* don't use IPv4 rules for IPv6 and vice versa */ return (0); switch (cmpaddr->aid) { case AID_INET: if (cmpaddr->v4.s_addr != nexthop->v4.s_addr) return (0); break; case AID_INET6: if (memcmp(&cmpaddr->v6, &nexthop->v6, sizeof(struct in6_addr))) return (0); break; default: fatalx("King Bula lost in address space"); } } /* origin-set lookups match only on ROA_VALID */ if (asp != NULL && f->match.originset.ps != NULL) { if (trie_roa_check(&f->match.originset.ps->th, prefix, plen, aspath_origin(asp->aspath)) != ROA_VALID) return (0); } /* * prefixset and prefix filter rules are mutual exclusive */ if (f->match.prefixset.flags != 0) { if (f->match.prefixset.ps == NULL || !trie_match(&f->match.prefixset.ps->th, prefix, plen, (f->match.prefixset.flags & PREFIXSET_FLAG_LONGER))) return (0); } else if (f->match.prefix.addr.aid != 0) return (rde_prefix_match(&f->match.prefix, prefix, plen)); /* matched somewhen or is anymatch rule */ return (1); } /* return true when the rule f can never match for this peer */ int rde_filter_skip_rule(struct rde_peer *peer, struct filter_rule *f) { /* if any of the two is unset then rule can't be skipped */ if (peer == NULL || f == NULL) return (0); if (f->peer.groupid != 0 && f->peer.groupid != peer->conf.groupid) return (1); if (f->peer.peerid != 0 && f->peer.peerid != peer->conf.id) return (1); if (f->peer.remote_as != 0 && f->peer.remote_as != peer->conf.remote_as) return (1); if (f->peer.ebgp != 0 && f->peer.ebgp != peer->conf.ebgp) return (1); if (f->peer.ibgp != 0 && f->peer.ibgp != !peer->conf.ebgp) return (1); return (0); } int rde_filter_equal(struct filter_head *a, struct filter_head *b) { struct filter_rule *fa, *fb; struct rde_prefixset *psa, *psb, *osa, *osb; struct as_set *asa, *asb; int r; fa = a ? TAILQ_FIRST(a) : NULL; fb = b ? TAILQ_FIRST(b) : NULL; while (fa != NULL || fb != NULL) { /* compare the two rules */ if ((fa == NULL && fb != NULL) || (fa != NULL && fb == NULL)) /* new rule added or removed */ return (0); if (fa->action != fb->action || fa->quick != fb->quick) return (0); if (memcmp(&fa->peer, &fb->peer, sizeof(fa->peer))) return (0); /* compare filter_rule.match without the prefixset pointer */ psa = fa->match.prefixset.ps; psb = fb->match.prefixset.ps; osa = fa->match.originset.ps; osb = fb->match.originset.ps; asa = fa->match.as.aset; asb = fb->match.as.aset; fa->match.prefixset.ps = fb->match.prefixset.ps = NULL; fa->match.originset.ps = fb->match.originset.ps = NULL; fa->match.as.aset = fb->match.as.aset = NULL; r = memcmp(&fa->match, &fb->match, sizeof(fa->match)); /* fixup the struct again */ fa->match.prefixset.ps = psa; fb->match.prefixset.ps = psb; fa->match.originset.ps = osa; fb->match.originset.ps = osb; fa->match.as.aset = asa; fb->match.as.aset = asb; if (r != 0) return (0); if (fa->match.prefixset.ps != NULL && fa->match.prefixset.ps->dirty) { log_debug("%s: prefixset %s has changed", __func__, fa->match.prefixset.name); return (0); } if (fa->match.originset.ps != NULL && fa->match.originset.ps->dirty) { log_debug("%s: originset %s has changed", __func__, fa->match.originset.name); return (0); } if ((fa->match.as.flags & AS_FLAG_AS_SET) && fa->match.as.aset->dirty) { log_debug("%s: as-set %s has changed", __func__, fa->match.as.name); return (0); } if (!filterset_equal(&fa->set, &fb->set)) return (0); fa = TAILQ_NEXT(fa, entry); fb = TAILQ_NEXT(fb, entry); } return (1); } void rde_filterstate_init(struct filterstate *state) { memset(state, 0, sizeof(*state)); path_prep(&state->aspath); } static void rde_filterstate_set(struct filterstate *state, struct rde_aspath *asp, struct rde_community *communities, struct nexthop *nh, uint8_t nhflags, uint8_t vstate) { rde_filterstate_init(state); if (asp) path_copy(&state->aspath, asp); if (communities) communities_copy(&state->communities, communities); state->nexthop = nexthop_ref(nh); state->nhflags = nhflags; state->vstate = vstate; } /* * Build a filterstate based on the prefix p. */ void rde_filterstate_prep(struct filterstate *state, struct prefix *p) { rde_filterstate_set(state, prefix_aspath(p), prefix_communities(p), prefix_nexthop(p), prefix_nhflags(p), p->validation_state); } /* * Copy a filterstate to a new filterstate. */ void rde_filterstate_copy(struct filterstate *state, struct filterstate *src) { rde_filterstate_set(state, &src->aspath, &src->communities, src->nexthop, src->nhflags, src->vstate); } /* * Set the vstate based on the aspa_state and the supplied roa vstate. * This function must be called after rde_filterstate_init(). * rde_filterstate_prep() and rde_filterstate_copy() set the right vstate. */ void rde_filterstate_set_vstate(struct filterstate *state, uint8_t roa_vstate, uint8_t aspa_state) { state->vstate = aspa_state << 4; state->vstate |= roa_vstate & ROA_MASK; } void rde_filterstate_clean(struct filterstate *state) { path_clean(&state->aspath); communities_clean(&state->communities); nexthop_unref(state->nexthop); state->nexthop = NULL; } void filterlist_free(struct filter_head *fh) { struct filter_rule *r; if (fh == NULL) return; while ((r = TAILQ_FIRST(fh)) != NULL) { TAILQ_REMOVE(fh, r, entry); filterset_free(&r->set); free(r); } free(fh); } /* free a filterset and take care of possible name2id references */ void filterset_free(struct filter_set_head *sh) { struct filter_set *s; if (sh == NULL) return; while ((s = TAILQ_FIRST(sh)) != NULL) { TAILQ_REMOVE(sh, s, entry); if (s->type == ACTION_RTLABEL_ID) rtlabel_unref(s->action.id); else if (s->type == ACTION_PFTABLE_ID) pftable_unref(s->action.id); else if (s->type == ACTION_SET_NEXTHOP_REF) nexthop_unref(s->action.nh_ref); free(s); } } /* * this function is a bit more complicated than a memcmp() because there are * types that need to be considered equal e.g. ACTION_SET_MED and * ACTION_SET_RELATIVE_MED. Also ACTION_SET_COMMUNITY and ACTION_SET_NEXTHOP * need some special care. It only checks the types and not the values so * it does not do a real compare. */ int filterset_cmp(struct filter_set *a, struct filter_set *b) { if (strcmp(filterset_name(a->type), filterset_name(b->type))) return (a->type - b->type); if (a->type == ACTION_SET_COMMUNITY || a->type == ACTION_DEL_COMMUNITY) { /* a->type == b->type */ return (memcmp(&a->action.community, &b->action.community, sizeof(a->action.community))); } if (a->type == ACTION_SET_NEXTHOP && b->type == ACTION_SET_NEXTHOP) { /* * This is the only interesting case, all others are considered * equal. It does not make sense to e.g. set a nexthop and * reject it at the same time. Allow one IPv4 and one IPv6 * per filter set or only one of the other nexthop modifiers. */ return (a->action.nexthop.aid - b->action.nexthop.aid); } /* equal */ return (0); } /* * move filterset from source to dest. dest will be initialized first. * After the move source is an empty list. */ void filterset_move(struct filter_set_head *source, struct filter_set_head *dest) { TAILQ_INIT(dest); if (source == NULL) return; TAILQ_CONCAT(dest, source, entry); } /* * copy filterset from source to dest. dest will be initialized first. */ void filterset_copy(struct filter_set_head *source, struct filter_set_head *dest) { struct filter_set *s, *t; TAILQ_INIT(dest); if (source == NULL) return; TAILQ_FOREACH(s, source, entry) { if ((t = malloc(sizeof(struct filter_set))) == NULL) fatal(NULL); memcpy(t, s, sizeof(struct filter_set)); if (t->type == ACTION_RTLABEL_ID) rtlabel_ref(t->action.id); else if (t->type == ACTION_PFTABLE_ID) pftable_ref(t->action.id); else if (t->type == ACTION_SET_NEXTHOP_REF) nexthop_ref(t->action.nh_ref); TAILQ_INSERT_TAIL(dest, t, entry); } } int filterset_equal(struct filter_set_head *ah, struct filter_set_head *bh) { struct filter_set *a, *b; const char *as, *bs; for (a = TAILQ_FIRST(ah), b = TAILQ_FIRST(bh); a != NULL && b != NULL; a = TAILQ_NEXT(a, entry), b = TAILQ_NEXT(b, entry)) { switch (a->type) { case ACTION_SET_PREPEND_SELF: case ACTION_SET_PREPEND_PEER: if (a->type == b->type && a->action.prepend == b->action.prepend) continue; break; case ACTION_SET_AS_OVERRIDE: if (a->type == b->type) continue; break; case ACTION_SET_LOCALPREF: case ACTION_SET_MED: case ACTION_SET_WEIGHT: if (a->type == b->type && a->action.metric == b->action.metric) continue; break; case ACTION_SET_RELATIVE_LOCALPREF: case ACTION_SET_RELATIVE_MED: case ACTION_SET_RELATIVE_WEIGHT: if (a->type == b->type && a->action.relative == b->action.relative) continue; break; case ACTION_SET_NEXTHOP: if (a->type == b->type && memcmp(&a->action.nexthop, &b->action.nexthop, sizeof(a->action.nexthop)) == 0) continue; break; case ACTION_SET_NEXTHOP_REF: if (a->type == b->type && a->action.nh_ref == b->action.nh_ref) continue; break; case ACTION_SET_NEXTHOP_BLACKHOLE: case ACTION_SET_NEXTHOP_REJECT: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: if (a->type == b->type) continue; break; case ACTION_DEL_COMMUNITY: case ACTION_SET_COMMUNITY: if (a->type == b->type && memcmp(&a->action.community, &b->action.community, sizeof(a->action.community)) == 0) continue; break; case ACTION_PFTABLE: case ACTION_PFTABLE_ID: if (b->type == ACTION_PFTABLE) bs = b->action.pftable; else if (b->type == ACTION_PFTABLE_ID) bs = pftable_id2name(b->action.id); else break; if (a->type == ACTION_PFTABLE) as = a->action.pftable; else as = pftable_id2name(a->action.id); if (strcmp(as, bs) == 0) continue; break; case ACTION_RTLABEL: case ACTION_RTLABEL_ID: if (b->type == ACTION_RTLABEL) bs = b->action.rtlabel; else if (b->type == ACTION_RTLABEL_ID) bs = rtlabel_id2name(b->action.id); else break; if (a->type == ACTION_RTLABEL) as = a->action.rtlabel; else as = rtlabel_id2name(a->action.id); if (strcmp(as, bs) == 0) continue; break; case ACTION_SET_ORIGIN: if (a->type == b->type && a->action.origin == b->action.origin) continue; break; } /* compare failed */ return (0); } if (a != NULL || b != NULL) return (0); return (1); } const char * filterset_name(enum action_types type) { switch (type) { case ACTION_SET_LOCALPREF: case ACTION_SET_RELATIVE_LOCALPREF: return ("localpref"); case ACTION_SET_MED: case ACTION_SET_RELATIVE_MED: return ("metric"); case ACTION_SET_WEIGHT: case ACTION_SET_RELATIVE_WEIGHT: return ("weight"); case ACTION_SET_PREPEND_SELF: return ("prepend-self"); case ACTION_SET_PREPEND_PEER: return ("prepend-peer"); case ACTION_SET_AS_OVERRIDE: return ("as-override"); case ACTION_SET_NEXTHOP: case ACTION_SET_NEXTHOP_REF: case ACTION_SET_NEXTHOP_REJECT: case ACTION_SET_NEXTHOP_BLACKHOLE: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: return ("nexthop"); case ACTION_SET_COMMUNITY: return ("community"); case ACTION_DEL_COMMUNITY: return ("community delete"); case ACTION_PFTABLE: case ACTION_PFTABLE_ID: return ("pftable"); case ACTION_RTLABEL: case ACTION_RTLABEL_ID: return ("rtlabel"); case ACTION_SET_ORIGIN: return ("origin"); } fatalx("filterset_name: got lost"); } /* * Copyright (c) 2001 Daniel Hartmeier * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Effort sponsored in part by the Defense Advanced Research Projects * Agency (DARPA) and Air Force Research Laboratory, Air Force * Materiel Command, USAF, under agreement number F30602-01-2-0537. * */ #define RDE_FILTER_SET_SKIP_STEPS(i) \ do { \ while (head[i] != cur) { \ head[i]->skip[i] = cur; \ head[i] = TAILQ_NEXT(head[i], entry); \ } \ } while (0) void rde_filter_calc_skip_steps(struct filter_head *rules) { struct filter_rule *cur, *prev, *head[RDE_FILTER_SKIP_COUNT]; int i; if (rules == NULL) return; cur = TAILQ_FIRST(rules); prev = cur; for (i = 0; i < RDE_FILTER_SKIP_COUNT; ++i) head[i] = cur; while (cur != NULL) { if (cur->peer.peerid != prev->peer.peerid) RDE_FILTER_SET_SKIP_STEPS(RDE_FILTER_SKIP_PEERID); if (cur->peer.groupid != prev->peer.groupid) RDE_FILTER_SET_SKIP_STEPS(RDE_FILTER_SKIP_GROUPID); if (cur->peer.remote_as != prev->peer.remote_as) RDE_FILTER_SET_SKIP_STEPS(RDE_FILTER_SKIP_REMOTE_AS); prev = cur; cur = TAILQ_NEXT(cur, entry); } for (i = 0; i < RDE_FILTER_SKIP_COUNT; ++i) RDE_FILTER_SET_SKIP_STEPS(i); } #define RDE_FILTER_TEST_ATTRIB(t, a) \ do { \ if (t) { \ f = a; \ goto nextrule; \ } \ } while (0) enum filter_actions rde_filter(struct filter_head *rules, struct rde_peer *peer, struct rde_peer *from, struct bgpd_addr *prefix, uint8_t plen, struct filterstate *state) { struct filter_rule *f; enum filter_actions action = ACTION_DENY; /* default deny */ if (state->aspath.flags & F_ATTR_PARSE_ERR) /* * don't try to filter bad updates just deny them * so they act as implicit withdraws */ return (ACTION_DENY); if (rules == NULL) return (action); if (prefix->aid == AID_FLOWSPECv4 || prefix->aid == AID_FLOWSPECv6) return (ACTION_ALLOW); f = TAILQ_FIRST(rules); while (f != NULL) { RDE_FILTER_TEST_ATTRIB( (f->peer.peerid && f->peer.peerid != peer->conf.id), f->skip[RDE_FILTER_SKIP_PEERID]); RDE_FILTER_TEST_ATTRIB( (f->peer.groupid && f->peer.groupid != peer->conf.groupid), f->skip[RDE_FILTER_SKIP_GROUPID]); RDE_FILTER_TEST_ATTRIB( (f->peer.remote_as && f->peer.remote_as != peer->conf.remote_as), f->skip[RDE_FILTER_SKIP_REMOTE_AS]); if (rde_filter_match(f, peer, from, state, prefix, plen)) { rde_apply_set(&f->set, peer, from, state, prefix->aid); if (f->action != ACTION_NONE) action = f->action; if (f->quick) return (action); } f = TAILQ_NEXT(f, entry); nextrule: ; } return (action); } openbgpd-8.8/src/bgpd/rde_sets.c100644 001750 001750 00000011346 14673014240 0012356/* $OpenBSD: rde_sets.c,v 1.13 2024/09/10 09:38:45 claudio Exp $ */ /* * Copyright (c) 2018 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include "rde.h" struct set_table { void *set; size_t nmemb; size_t size; size_t max; }; struct as_set * as_sets_new(struct as_set_head *as_sets, const char *name, size_t nmemb, size_t size) { struct as_set *aset; size_t len; aset = calloc(1, sizeof(*aset)); if (aset == NULL) return NULL; len = strlcpy(aset->name, name, sizeof(aset->name)); assert(len < sizeof(aset->name)); aset->set = set_new(nmemb, size); if (aset->set == NULL) { free(aset); return NULL; } SIMPLEQ_INSERT_TAIL(as_sets, aset, entry); return aset; } struct as_set * as_sets_lookup(struct as_set_head *as_sets, const char *name) { struct as_set *aset; SIMPLEQ_FOREACH(aset, as_sets, entry) { if (strcmp(aset->name, name) == 0) return aset; } return NULL; } void as_sets_free(struct as_set_head *as_sets) { struct as_set *aset; if (as_sets == NULL) return; while (!SIMPLEQ_EMPTY(as_sets)) { aset = SIMPLEQ_FIRST(as_sets); SIMPLEQ_REMOVE_HEAD(as_sets, entry); set_free(aset->set); free(aset); } } void as_sets_mark_dirty(struct as_set_head *old, struct as_set_head *new) { struct as_set *n, *o; SIMPLEQ_FOREACH(n, new, entry) { if (old == NULL || (o = as_sets_lookup(old, n->name)) == NULL || !set_equal(n->set, o->set)) { n->dirty = 1; n->lastchange = getmonotime(); } else n->lastchange = o->lastchange; } } int as_set_match(const struct as_set *aset, uint32_t asnum) { return set_match(aset->set, asnum) != NULL; } struct set_table * set_new(size_t nmemb, size_t size) { struct set_table *set; set = calloc(1, sizeof(*set)); if (set == NULL) return NULL; if (nmemb == 0) nmemb = 4; set->size = size; set->max = nmemb; set->set = calloc(nmemb, set->size); if (set->set == NULL) { free(set); return NULL; } rdemem.aset_cnt++; rdemem.aset_size += sizeof(*set); rdemem.aset_size += set->size * set->max; return set; } void set_free(struct set_table *set) { if (set == NULL) return; rdemem.aset_cnt--; rdemem.aset_size -= sizeof(*set); rdemem.aset_size -= set->size * set->max; rdemem.aset_nmemb -= set->nmemb; free(set->set); free(set); } int set_add(struct set_table *set, void *elms, size_t nelms) { if (nelms == 0) /* nothing todo */ return 0; if (set->max < nelms || set->max - nelms < set->nmemb) { uint32_t *s; size_t new_size; if (set->nmemb >= SIZE_MAX - 4096 - nelms) { errno = ENOMEM; return -1; } for (new_size = set->max; new_size < set->nmemb + nelms; ) new_size += (new_size < 4096 ? new_size : 4096); s = reallocarray(set->set, new_size, set->size); if (s == NULL) return -1; rdemem.aset_size += set->size * (new_size - set->max); set->set = s; set->max = new_size; } memcpy((uint8_t *)set->set + set->nmemb * set->size, elms, nelms * set->size); set->nmemb += nelms; rdemem.aset_nmemb += nelms; return 0; } void * set_get(struct set_table *set, size_t *nelms) { *nelms = set->nmemb; return set->set; } static int set_cmp(const void *ap, const void *bp) { const uint32_t *a = ap; const uint32_t *b = bp; if (*a > *b) return 1; else if (*a < *b) return -1; return 0; } void set_prep(struct set_table *set) { if (set == NULL) return; qsort(set->set, set->nmemb, set->size, set_cmp); } void * set_match(const struct set_table *a, uint32_t asnum) { if (a == NULL) return NULL; return bsearch(&asnum, a->set, a->nmemb, a->size, set_cmp); } int set_equal(const struct set_table *a, const struct set_table *b) { /* allow NULL pointers to be passed */ if (a == NULL && b == NULL) return 1; if (a == NULL || b == NULL) return 0; if (a->nmemb != b->nmemb) return 0; if (memcmp(a->set, b->set, a->nmemb * a->size) != 0) return 0; return 1; } size_t set_nmemb(const struct set_table *set) { return set->nmemb; } openbgpd-8.8/src/bgpd/rde_trie.c100644 001750 001750 00000045156 14403051271 0012345/* $OpenBSD: rde_trie.c,v 1.17 2022/12/28 21:30:16 jmc Exp $ */ /* * Copyright (c) 2018 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgpd.h" #include "rde.h" /* * Bitwise compressed trie for prefix-sets. * Since the trie is path compressed the traversing function needs to check * that the lookup is still on path before taking a branch. * There are two types of nodes in the trie. Internal branch nodes and real * nodes. Internal nodes are added when needed because off path nodes are being * inserted and are just used for branching. * During lookup every node defines which bit is checked for branching. This * offset is strictly increasing. For IPv4 the maximum is therefore 32 levels. * Every node checks the bit at position plen to decide which branch to take. * The real nodes also include a prefixlen mask which represents the prefixlen * range that was defined. The prefixlen mask for IPv4 only has 32 bits but * the prefixlen range is from 0 - 32 which needs 33bits. Now prefixlen 0 is * special and only one element -- the default route -- can have prefixlen 0. * So this default route is added as a flag to the trie_head and needs to be * checked independent of the trie when doing a lookup. * On insertion a prefix is added with its prefixlen plen and a min & max * for the prefixlen range. The following precondition needs to hold * plen <= min <= max * To only match the prefix itself min and max are set to plen. * If a same prefix (addr/plen) is added to the trie but with different * min & max values then the masks of both nodes are merged with a binary OR. * The match function returns true the moment the first node is found which * covers the looked up prefix and where the prefixlen mask matches for the * looked up prefixlen. The moment the plen of a node is bigger than the * prefixlen of the looked up prefix the search can be stopped since * there will be no match. */ struct tentry_v4 { struct tentry_v4 *trie[2]; struct set_table *set; /* for roa source-as set */ struct in_addr addr; struct in_addr plenmask; uint8_t plen; uint8_t node; }; struct tentry_v6 { struct tentry_v6 *trie[2]; struct set_table *set; /* for roa source-as set */ struct in6_addr addr; struct in6_addr plenmask; uint8_t plen; uint8_t node; }; /* * Find first different bit between a & b starting from the MSB, * a & b have to be different. */ static int inet4findmsb(struct in_addr *a, struct in_addr *b) { int r = 0; uint32_t v; v = ntohl(a->s_addr ^ b->s_addr); if (v > 0xffff) { r += 16; v >>= 16; } if (v > 0x00ff) { r += 8; v >>= 8; } if (v > 0x000f) { r += 4; v >>= 4; } if (v > 0x0003) { r += 2; v >>= 2; } if (v > 0x0001) { r += 1; } return 31 - r; } /* * Find first different bit between a & b starting from the MSB, * a & b have to be different. */ static int inet6findmsb(struct in6_addr *a, struct in6_addr *b) { int r = 0; uint8_t i, x; for (i = 0; i < sizeof(*a) && a->s6_addr[i] == b->s6_addr[i]; i++) ; /* first different octet */ x = a->s6_addr[i] ^ b->s6_addr[i]; /* first different bit */ if (x > 0xf) { r += 4; x >>= 4; } if (x > 0x3) { r += 2; x >>= 2; } if (x > 0x1) { r += 1; } return i * 8 + 7 - r; } static int inet4isset(struct in_addr *addr, uint8_t bit) { return addr->s_addr & htonl(1U << (31 - bit)); } static int inet6isset(struct in6_addr *addr, uint8_t bit) { return addr->s6_addr[bit / 8] & (0x80 >> (bit % 8)); } static void inet4setbit(struct in_addr *addr, uint8_t bit) { /* bit 0 sets the MSB and 31 sets the LSB */ addr->s_addr |= htonl(1U << (31 - bit)); } static void inet6setbit(struct in6_addr *addr, uint8_t bit) { addr->s6_addr[bit / 8] |= (0x80 >> (bit % 8)); } static struct tentry_v4 * trie_add_v4(struct trie_head *th, struct in_addr *prefix, uint8_t plen) { struct tentry_v4 *n, *new, *b, **prev; struct in_addr p; inet4applymask(&p, prefix, plen); /* walk tree finding spot to insert */ prev = &th->root_v4; n = *prev; while (n) { struct in_addr mp; uint8_t minlen; minlen = n->plen > plen ? plen : n->plen; inet4applymask(&mp, &p, minlen); if (n->addr.s_addr != mp.s_addr) { /* * out of path, insert intermediary node between * np and n, then insert n and new node there */ if ((b = calloc(1, sizeof(*b))) == NULL) return NULL; rdemem.pset_cnt++; rdemem.pset_size += sizeof(*b); b->plen = inet4findmsb(&n->addr, &mp); inet4applymask(&b->addr, &n->addr, b->plen); *prev = b; if (inet4isset(&n->addr, b->plen)) { b->trie[1] = n; prev = &b->trie[0]; } else { b->trie[0] = n; prev = &b->trie[1]; } n = NULL; break; } if (n->plen > plen) { /* n is more specific, just insert new in between */ break; } if (n->plen == plen) { /* matching node, adjust */ if (n->node == 0) th->v4_cnt++; n->node = 1; return n; } /* no need to check for n->plen == 32 because of above if */ if (inet4isset(&p, n->plen)) prev = &n->trie[1]; else prev = &n->trie[0]; n = *prev; } /* create new node */ if ((new = calloc(1, sizeof(*new))) == NULL) return NULL; th->v4_cnt++; rdemem.pset_cnt++; rdemem.pset_size += sizeof(*new); new->addr = p; new->plen = plen; new->node = 1; /* link node */ *prev = new; if (n) { if (inet4isset(&n->addr, new->plen)) new->trie[1] = n; else new->trie[0] = n; } return new; } static struct tentry_v6 * trie_add_v6(struct trie_head *th, struct in6_addr *prefix, uint8_t plen) { struct tentry_v6 *n, *new, *b, **prev; struct in6_addr p; inet6applymask(&p, prefix, plen); /* walk tree finding spot to insert */ prev = &th->root_v6; n = *prev; while (n) { struct in6_addr mp; uint8_t minlen; minlen = n->plen > plen ? plen : n->plen; inet6applymask(&mp, &p, minlen); if (memcmp(&n->addr, &mp, sizeof(mp)) != 0) { /* * out of path, insert intermediary node between * np and n, then insert n and new node there */ if ((b = calloc(1, sizeof(*b))) == NULL) return NULL; rdemem.pset_cnt++; rdemem.pset_size += sizeof(*b); b->plen = inet6findmsb(&n->addr, &mp); inet6applymask(&b->addr, &n->addr, b->plen); *prev = b; if (inet6isset(&n->addr, b->plen)) { b->trie[1] = n; prev = &b->trie[0]; } else { b->trie[0] = n; prev = &b->trie[1]; } n = NULL; break; } if (n->plen > plen) { /* n is more specific, just insert new in between */ break; } if (n->plen == plen) { /* matching node, adjust */ if (n->node == 0) th->v6_cnt++; n->node = 1; return n; } /* no need to check for n->plen == 128 because of above if */ if (inet6isset(&p, n->plen)) prev = &n->trie[1]; else prev = &n->trie[0]; n = *prev; } /* create new node */ if ((new = calloc(1, sizeof(*new))) == NULL) return NULL; th->v6_cnt++; rdemem.pset_cnt++; rdemem.pset_size += sizeof(*new); new->addr = p; new->plen = plen; new->node = 1; /* link node */ *prev = new; if (n) { if (inet6isset(&n->addr, new->plen)) new->trie[1] = n; else new->trie[0] = n; } return new; } /* * Insert prefix/plen into the trie with a prefixlen mask covering min - max. * If plen == min == max then only the prefix/plen will match and no longer * match is possible. Else all prefixes under prefix/plen with a prefixlen * between min and max will match. */ int trie_add(struct trie_head *th, struct bgpd_addr *prefix, uint8_t plen, uint8_t min, uint8_t max) { struct tentry_v4 *n4; struct tentry_v6 *n6; uint8_t i; /* precondition plen <= min <= max */ if (plen > min || min > max) return -1; if (prefix->aid != AID_INET && prefix->aid != AID_INET6) return -1; /* * Check for default route, this is special cased since prefixlen 0 * can't be checked in the prefixlen mask plenmask. Also there is * only one default route so using a flag for this works. */ if (min == 0) { if (prefix->aid == AID_INET) th->match_default_v4 = 1; else th->match_default_v6 = 1; if (max == 0) /* just the default route */ return 0; min = 1; } switch (prefix->aid) { case AID_INET: if (max > 32) return -1; n4 = trie_add_v4(th, &prefix->v4, plen); if (n4 == NULL) return -1; /* * The prefixlen min - max goes from 1 to 32 but the bitmask * starts at 0 and so all bits are set with an offset of -1. * The default /0 route is handled specially above. */ for (i = min; i <= max; i++) inet4setbit(&n4->plenmask, i - 1); break; case AID_INET6: if (max > 128) return -1; n6 = trie_add_v6(th, &prefix->v6, plen); if (n6 == NULL) return -1; /* See above for the - 1 reason. */ for (i = min; i <= max; i++) inet6setbit(&n6->plenmask, i - 1); break; } return 0; } /* * Insert a ROA entry for prefix/plen. The prefix will insert a set with * source_as and the maxlen as data. This makes it possible to validate if a * prefix is matching this ROA record. It is possible to insert prefixes with * source_as = 0. These entries will never return ROA_VALID on check and can * be used to cover a large prefix as ROA_INVALID unless a more specific route * is a match. */ int trie_roa_add(struct trie_head *th, struct roa *roa) { struct tentry_v4 *n4; struct tentry_v6 *n6; struct set_table **stp; struct roa_set rs, *rsp; /* ignore possible default route since it does not make sense */ switch (roa->aid) { case AID_INET: if (roa->prefixlen > 32) return -1; n4 = trie_add_v4(th, &roa->prefix.inet, roa->prefixlen); if (n4 == NULL) return -1; stp = &n4->set; break; case AID_INET6: if (roa->prefixlen > 128) return -1; n6 = trie_add_v6(th, &roa->prefix.inet6, roa->prefixlen); if (n6 == NULL) return -1; stp = &n6->set; break; default: /* anything else fails */ return -1; } if (*stp == NULL) if ((*stp = set_new(1, sizeof(rs))) == NULL) return -1; /* merge sets with same key, longer maxlen wins */ if ((rsp = set_match(*stp, roa->asnum)) != NULL) { if (rsp->maxlen < roa->maxlen) rsp->maxlen = roa->maxlen; } else { rs.as = roa->asnum; rs.maxlen = roa->maxlen; if (set_add(*stp, &rs, 1) != 0) return -1; /* prep data so that set_match works */ set_prep(*stp); } return 0; } static void trie_free_v4(struct tentry_v4 *n) { if (n == NULL) return; trie_free_v4(n->trie[0]); trie_free_v4(n->trie[1]); set_free(n->set); free(n); rdemem.pset_cnt--; rdemem.pset_size -= sizeof(*n); } static void trie_free_v6(struct tentry_v6 *n) { if (n == NULL) return; trie_free_v6(n->trie[0]); trie_free_v6(n->trie[1]); set_free(n->set); free(n); rdemem.pset_cnt--; rdemem.pset_size -= sizeof(*n); } void trie_free(struct trie_head *th) { trie_free_v4(th->root_v4); trie_free_v6(th->root_v6); memset(th, 0, sizeof(*th)); } static int trie_match_v4(struct trie_head *th, struct in_addr *prefix, uint8_t plen, int orlonger) { struct tentry_v4 *n; if (plen == 0) { /* special handling for default route */ return th->match_default_v4; } n = th->root_v4; while (n) { struct in_addr mp; if (n->plen > plen) break; /* too specific, no match possible */ inet4applymask(&mp, prefix, n->plen); if (n->addr.s_addr != mp.s_addr) break; /* off path, no match possible */ /* the match covers all larger prefixlens */ if (n->node && orlonger) return 1; /* plen is from 1 - 32 but the bitmask starts with 0 */ if (n->node && inet4isset(&n->plenmask, plen - 1)) return 1; /* prefixlen allowed, match */ if (n->plen == 32) break; /* can't go deeper */ if (inet4isset(prefix, n->plen)) n = n->trie[1]; else n = n->trie[0]; } return 0; } static int trie_match_v6(struct trie_head *th, struct in6_addr *prefix, uint8_t plen, int orlonger) { struct tentry_v6 *n; if (plen == 0) { /* special handling for default route */ return th->match_default_v6; } n = th->root_v6; while (n) { struct in6_addr mp; if (n->plen > plen) break; /* too specific, no match possible */ inet6applymask(&mp, prefix, n->plen); if (memcmp(&n->addr, &mp, sizeof(mp)) != 0) break; /* off path, no match possible */ /* the match covers all larger prefixlens */ if (n->node && orlonger) return 1; /* plen is from 1 - 128 but the bitmask starts with 0 */ if (n->node && inet6isset(&n->plenmask, plen - 1)) return 1; /* prefixlen allowed, match */ if (n->plen == 128) break; /* can't go deeper */ if (inet6isset(prefix, n->plen)) n = n->trie[1]; else n = n->trie[0]; } return 0; } /* find first matching element in the trie for prefix "prefix/plen" */ int trie_match(struct trie_head *th, struct bgpd_addr *prefix, uint8_t plen, int orlonger) { switch (prefix->aid) { case AID_INET: return trie_match_v4(th, &prefix->v4, plen, orlonger); case AID_INET6: return trie_match_v6(th, &prefix->v6, plen, orlonger); default: /* anything else is no match */ return 0; } } static int trie_roa_check_v4(struct trie_head *th, struct in_addr *prefix, uint8_t plen, uint32_t as) { struct tentry_v4 *n; struct roa_set *rs; int validity = ROA_NOTFOUND; /* ignore possible default route since it does not make sense */ n = th->root_v4; while (n) { struct in_addr mp; if (n->plen > plen) break; /* too specific, no match possible */ inet4applymask(&mp, prefix, n->plen); if (n->addr.s_addr != mp.s_addr) break; /* off path, no other match possible */ if (n->node) { /* * The prefix is covered by this roa node * therefore invalid unless roa_set matches. */ validity = ROA_INVALID; /* AS_NONE can never match, so don't try */ if (as != AS_NONE) { if ((rs = set_match(n->set, as)) != NULL) { if (plen == n->plen || plen <= rs->maxlen) return ROA_VALID; } } } if (n->plen == 32) break; /* can't go deeper */ if (inet4isset(prefix, n->plen)) n = n->trie[1]; else n = n->trie[0]; } return validity; } static int trie_roa_check_v6(struct trie_head *th, struct in6_addr *prefix, uint8_t plen, uint32_t as) { struct tentry_v6 *n; struct roa_set *rs; int validity = ROA_NOTFOUND; /* ignore possible default route since it does not make sense */ n = th->root_v6; while (n) { struct in6_addr mp; if (n->plen > plen) break; /* too specific, no match possible */ inet6applymask(&mp, prefix, n->plen); if (memcmp(&n->addr, &mp, sizeof(mp)) != 0) break; /* off path, no other match possible */ if (n->node) { /* * This prefix is covered by this roa node. * Therefore invalid unless proven otherwise. */ validity = ROA_INVALID; /* AS_NONE can never match, so don't try */ if (as != AS_NONE) { if ((rs = set_match(n->set, as)) != NULL) if (plen == n->plen || plen <= rs->maxlen) return ROA_VALID; } } if (n->plen == 128) break; /* can't go deeper */ if (inet6isset(prefix, n->plen)) n = n->trie[1]; else n = n->trie[0]; } return validity; } /* * Do a ROA (Route Origin Validation) check. Look for elements in the trie * which cover prefix "prefix/plen" and match the source-as as. * AS_NONE can be used when the source-as is unknown (e.g. AS_SET). * The check will then only return ROA_NOTFOUND or ROA_INVALID depending if * the prefix is covered by the ROA. */ int trie_roa_check(struct trie_head *th, struct bgpd_addr *prefix, uint8_t plen, uint32_t as) { /* valid, invalid, unknown */ switch (prefix->aid) { case AID_INET: return trie_roa_check_v4(th, &prefix->v4, plen, as); case AID_INET6: return trie_roa_check_v6(th, &prefix->v6, plen, as); default: /* anything else is not-found */ return ROA_NOTFOUND; } } static int trie_equal_v4(struct tentry_v4 *a, struct tentry_v4 *b) { if (a == NULL && b == NULL) return 1; if (a == NULL || b == NULL) return 0; if (a->addr.s_addr != b->addr.s_addr || a->plen != b->plen || a->node != b->node || a->plenmask.s_addr != b->plenmask.s_addr) return 0; if (set_equal(a->set, b->set) == 0) return 0; if (trie_equal_v4(a->trie[0], b->trie[0]) == 0 || trie_equal_v4(a->trie[1], b->trie[1]) == 0) return 0; return 1; } static int trie_equal_v6(struct tentry_v6 *a, struct tentry_v6 *b) { if (a == NULL && b == NULL) return 1; if (a == NULL || b == NULL) return 0; if (memcmp(&a->addr, &b->addr, sizeof(a->addr)) != 0 || a->plen != b->plen || a->node != b->node || memcmp(&a->plenmask, &b->plenmask, sizeof(a->plenmask)) != 0) return 0; if (set_equal(a->set, b->set) == 0) return 0; if (trie_equal_v6(a->trie[0], b->trie[0]) == 0 || trie_equal_v6(a->trie[1], b->trie[1]) == 0) return 0; return 1; } /* Compare two tries and return 1 if they are the same else 0. */ int trie_equal(struct trie_head *a, struct trie_head *b) { if (a->match_default_v4 != b->match_default_v4 || a->match_default_v6 != b->match_default_v6) return 0; if (trie_equal_v4(a->root_v4, b->root_v4) == 0) return 0; if (trie_equal_v6(a->root_v6, b->root_v6) == 0) return 0; return 1; } /* debugging functions for printing the trie */ static void trie_dump_v4(struct tentry_v4 *n) { if (n == NULL) return; if (n->node) fprintf(stderr, "%s/%u plenmask %08x\n", inet_ntoa(n->addr), n->plen, n->plenmask.s_addr); else fprintf(stderr, " %s/%u\n", inet_ntoa(n->addr), n->plen); trie_dump_v4(n->trie[0]); trie_dump_v4(n->trie[1]); } static void trie_dump_v6(struct tentry_v6 *n) { char buf[48]; unsigned int i; if (n == NULL) return; if (n->node) { fprintf(stderr, "%s/%u plenmask ", inet_ntop(AF_INET6, &n->addr, buf, sizeof(buf)), n->plen); for (i = 0; i < sizeof(n->plenmask); i++) fprintf(stderr, "%02x", n->plenmask.s6_addr[i]); fprintf(stderr, "\n"); } else fprintf(stderr, " %s/%u\n", inet_ntop(AF_INET6, &n->addr, buf, sizeof(buf)), n->plen); trie_dump_v6(n->trie[0]); trie_dump_v6(n->trie[1]); } void trie_dump(struct trie_head *th) { if (th->match_default_v4) fprintf(stderr, "0.0.0.0/0 plenmask 0\n"); trie_dump_v4(th->root_v4); if (th->match_default_v6) fprintf(stderr, "::/0 plenmask 0\n"); trie_dump_v6(th->root_v6); } openbgpd-8.8/src/bgpd/rde_aspa.c100644 001750 001750 00000025667 14505476542 0012352/* $OpenBSD: rde_aspa.c,v 1.5 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include "bgpd.h" #include "rde.h" enum cp_state { UNKNOWN, NOT_PROVIDER, PROVIDER, }; struct rde_aspa_set { uint32_t as; uint32_t num; uint32_t *pas; int next; }; /* * Power of 2 hash table * The nodes are stored in the sets array. * Additonal data for the rde_aspa_set are stored in data. * For lookups only table and mask need to be accessed. */ struct rde_aspa { struct rde_aspa_set **table; uint32_t mask; uint32_t maxset; struct rde_aspa_set *sets; uint32_t *data; size_t maxdata; size_t curdata; uint32_t curset; time_t lastchange; }; struct aspa_state { int nhops; int nup_p; int nup_u; int nup_np; int ndown_p; int ndown_u; int ndown_np; }; /* * Use fmix32() the finalization mix of MurmurHash3 as a 32bit hash function. */ static inline uint32_t hash(uint32_t h) { h ^= h >> 16; h *= 0x85ebca6b; h ^= h >> 13; h *= 0xc2b2ae35; h ^= h >> 16; return h; } /* * Lookup an asnum in the aspa hash table. */ static struct rde_aspa_set * aspa_lookup(struct rde_aspa *ra, uint32_t asnum) { struct rde_aspa_set *aspa; uint32_t h; h = hash(asnum) & ra->mask; aspa = ra->table[h]; if (aspa == NULL) return NULL; while (aspa->as < asnum) { if (!aspa->next) break; aspa++; } if (aspa->as == asnum) return aspa; return NULL; } /* * Lookup if there is a customer - provider relation between cas and pas. * Returns UNKNOWN if cas is not in the ra table or the aid is out of range. * Returns PROVIDER if pas is registered for cas for the specified aid. * Retruns NOT_PROVIDER otherwise. * This function is called very frequently and needs to be fast. */ static enum cp_state aspa_cp_lookup(struct rde_aspa *ra, uint32_t cas, uint32_t pas) { struct rde_aspa_set *aspa; uint32_t i; aspa = aspa_lookup(ra, cas); if (aspa == NULL) return UNKNOWN; if (aspa->num < 16) { for (i = 0; i < aspa->num; i++) { if (aspa->pas[i] == pas) break; if (aspa->pas[i] > pas) return NOT_PROVIDER; } if (i == aspa->num) return NOT_PROVIDER; } else { uint32_t lim, x; for (i = 0, lim = aspa->num; lim != 0; lim /= 2) { x = lim / 2; i += x; if (aspa->pas[i] == pas) { break; } else if (aspa->pas[i] < pas) { /* move right */ i++; lim--; } else { /* move left */ i -= x; } } if (lim == 0) return NOT_PROVIDER; } return PROVIDER; } /* * Calculate the various indexes of an aspath. * The up-ramp starts at the source-as which is the right-most / last element * in the aspath. The down-ramp starts at index 1. * nhops: number of unique hops in the path * nup_p: smallest index after which all aspath hops are provider valid * nup_u: The biggest index of an unknown aspath hop. * nup_np: The biggest index of a not-provider aspath hop. * ndown_p: biggest index before which all aspath hops are provider valid * ndown_u: The smallest index of an unknown aspath hop. * ndown_np: The smallest index of a not-provider aspath hop. * Returns 0 on success and -1 if a AS_SET is encountered. */ static int aspa_check_aspath(struct rde_aspa *ra, struct aspath *a, struct aspa_state *s) { uint8_t *seg; uint32_t as, prevas = 0; uint16_t len, seg_size; uint8_t i, seg_type, seg_len; /* the neighbor-as itself is by definition valid */ s->ndown_p = 1; /* * Walk aspath and validate if necessary both up- and down-ramp. * If an AS_SET is found return -1 to indicate failure. */ seg = aspath_dump(a); len = aspath_length(a); for (; len > 0; len -= seg_size, seg += seg_size) { seg_type = seg[0]; seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; if (seg_type != AS_SEQUENCE) return -1; for (i = 0; i < seg_len; i++) { as = aspath_extract(seg, i); if (as == prevas) continue; /* skip prepends */ s->nhops++; if (prevas == 0) { prevas = as; /* skip left-most AS */ continue; } /* * down-ramp check, remember the * left-most unknown or not-provider * node and the right-most provider node * for which all nodes before are valid. */ switch (aspa_cp_lookup(ra, prevas, as)) { case UNKNOWN: if (s->ndown_u == 0) s->ndown_u = s->nhops; break; case PROVIDER: if (s->ndown_p + 1 == s->nhops) s->ndown_p = s->nhops; break; case NOT_PROVIDER: if (s->ndown_np == 0) s->ndown_np = s->nhops; break; } /* * up-ramp check, remember the right-most * unknown and not-provider node and the * left-most provider node for which all nodes * after are valid. * We recorde the nhops value of prevas, * that's why the use of nhops - 1. */ switch (aspa_cp_lookup(ra, as, prevas)) { case UNKNOWN: s->nup_p = 0; s->nup_u = s->nhops - 1; break; case PROVIDER: if (s->nup_p == 0) s->nup_p = s->nhops - 1; break; case NOT_PROVIDER: s->nup_p = 0; s->nup_np = s->nhops - 1; break; } prevas = as; } } /* the source-as itself is by definition valid */ if (s->nup_p == 0) s->nup_p = s->nhops; return 0; } /* * Set the two possible aspa outcomes for up-ramp only and up/down ramp * in the vstate array. */ static void aspa_check_finalize(struct aspa_state *state, uint8_t *onlyup, uint8_t *downup) { /* * Just an up-ramp: * if a check returned NOT_PROVIDER then the result is invalid. * if a check returned UNKNOWN then the result is unknown. * else path is valid. */ if (state->nup_np != 0) *onlyup = ASPA_INVALID; else if (state->nup_u != 0) *onlyup = ASPA_UNKNOWN; else *onlyup = ASPA_VALID; /* * Both up-ramp and down-ramp: * if nhops <= 2 the result is valid. * if there is less than one AS hop between up-ramp and * down-ramp then the result is valid. * if not-provider nodes for both ramps exist and they * do not overlap the path is invalid. * else the path is unknown. */ if (state->nhops <= 2) *downup = ASPA_VALID; else if (state->nup_p - state->ndown_p <= 1) *downup = ASPA_VALID; else if (state->nup_np != 0 && state->ndown_np != 0 && state->nup_np - state->ndown_np >= 0) *downup = ASPA_INVALID; else *downup = ASPA_UNKNOWN; } /* * Validate an aspath against the aspa_set *ra. * Returns ASPA_VALID if the aspath is valid, ASPA_UNKNOWN if the * aspath contains hops with unknown relation and ASPA_INVALID for * empty aspaths, aspath with AS_SET and aspaths that fail validation. */ void aspa_validation(struct rde_aspa *ra, struct aspath *a, struct rde_aspa_state *vstate) { struct aspa_state state = { 0 }; /* no aspa table, evrything is unknown */ if (ra == NULL) { memset(vstate, ASPA_UNKNOWN, sizeof(*vstate)); return; } /* empty ASPATHs are always invalid */ if (aspath_length(a) == 0) { memset(vstate, ASPA_INVALID, sizeof(*vstate)); return; } if (aspa_check_aspath(ra, a, &state) == -1) { memset(vstate, ASPA_INVALID, sizeof(*vstate)); return; } aspa_check_finalize(&state, &vstate->onlyup, &vstate->downup); } /* * Preallocate all data structures needed for the aspa table. * There are entries number of rde_aspa_sets with data_size bytes of * extra data (used to store SPAS and optional AFI bitmasks). */ struct rde_aspa * aspa_table_prep(uint32_t entries, size_t datasize) { struct rde_aspa *ra; uint32_t hsize = 1024; if (entries == 0) return NULL; if (entries > UINT32_MAX / 2) fatalx("aspa_table_prep overflow"); while (hsize < entries) hsize *= 2; if ((ra = calloc(1, sizeof(*ra))) == NULL) fatal("aspa table prep"); if ((ra->table = calloc(hsize, sizeof(ra->table[0]))) == NULL) fatal("aspa table prep"); if ((ra->sets = calloc(entries, sizeof(ra->sets[0]))) == NULL) fatal("aspa table prep"); if ((ra->data = malloc(datasize)) == NULL) fatal("aspa table prep"); ra->mask = hsize - 1; ra->maxset = entries; ra->maxdata = datasize / sizeof(ra->data[0]); ra->lastchange = getmonotime(); return ra; } /* * Insert an aspa customer/provider set into the hash table. * For hash conflict resulution insertion must happen in reverse order (biggest * customer asnum first). On conflict objects in the sets array are moved * around so that conflicting elements are direct neighbors. * The per AID information is (if required) stored as 2bits per provider. */ void aspa_add_set(struct rde_aspa *ra, uint32_t cas, const uint32_t *pas, uint32_t pascnt) { struct rde_aspa_set *aspa; uint32_t h, i; if (ra->curset >= ra->maxset) fatalx("aspa set overflow"); h = hash(cas) & ra->mask; aspa = ra->table[h]; if (aspa == NULL) { aspa = &ra->sets[ra->curset++]; } else { if (aspa->as <= cas) fatalx("%s: bad order of adds", __func__); /* insert before aspa */ memmove(aspa + 1, aspa, (ra->sets + ra->curset - aspa) * sizeof(*aspa)); ra->curset++; memset(aspa, 0, sizeof(*aspa)); aspa->next = 1; /* adjust hashtable after shift of elements */ for (i = 0; i <= ra->mask; i++) { if (ra->table[i] > aspa) ra->table[i]++; } } aspa->as = cas; ra->table[h] = aspa; if (ra->maxdata - ra->curdata < pascnt) fatalx("aspa set data overflow"); aspa->num = pascnt; aspa->pas = ra->data + ra->curdata; for (i = 0; i < pascnt; i++) ra->data[ra->curdata++] = pas[i]; } void aspa_table_free(struct rde_aspa *ra) { if (ra == NULL) return; free(ra->table); free(ra->sets); free(ra->data); free(ra); } void aspa_table_stats(const struct rde_aspa *ra, struct ctl_show_set *cset) { if (ra == NULL) return; cset->lastchange = ra->lastchange; cset->as_cnt = ra->maxset; } /* * Return true if the two rde_aspa tables contain the same data. */ int aspa_table_equal(const struct rde_aspa *ra, const struct rde_aspa *rb) { uint32_t i; /* allow NULL pointers to be passed */ if (ra == NULL && rb == NULL) return 1; if (ra == NULL || rb == NULL) return 0; if (ra->maxset != rb->maxset || ra->maxdata != rb->maxdata) return 0; for (i = 0; i < ra->maxset; i++) if (ra->sets[i].as != rb->sets[i].as) return 0; if (memcmp(ra->data, rb->data, ra->maxdata * sizeof(ra->data[0])) != 0) return 0; return 1; } void aspa_table_unchanged(struct rde_aspa *ra, const struct rde_aspa *old) { if (ra == NULL || old == NULL) return; ra->lastchange = old->lastchange; } openbgpd-8.8/src/bgpd/pftable.c100644 001750 001750 00000013005 14571326703 0012164/* $OpenBSD: pftable.c,v 1.18 2024/02/13 16:35:43 claudio Exp $ */ /* * Copyright (c) 2004 Damien Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include "log.h" /* Namespace collision: these are defined in pfvar.h and bgpd.h */ #undef v4 #undef v6 #include "bgpd.h" static int devpf = -1; struct pf_table { LIST_ENTRY(pf_table) entry; char name[PFTABLE_LEN]; unsigned long what; struct pfr_addr *worklist; int naddrs; int nalloc; }; /* List of tables under management */ LIST_HEAD(, pf_table) tables = LIST_HEAD_INITIALIZER(tables); static int pftable_change(struct pf_table *pft) { struct pfioc_table tio; int ret; if (pft->naddrs == 0 || pft->what == 0) return (0); if (devpf == -1 && ((devpf = open("/dev/pf", O_RDWR|O_CLOEXEC)) == -1)) fatal("open(/dev/pf)"); memset(&tio, 0, sizeof(tio)); strlcpy(tio.pfrio_table.pfrt_name, pft->name, sizeof(tio.pfrio_table.pfrt_name)); tio.pfrio_buffer = pft->worklist; tio.pfrio_esize = sizeof(*pft->worklist); tio.pfrio_size = pft->naddrs; ret = ioctl(devpf, pft->what, &tio); /* bad prefixes shouldn't cause us to die */ if (ret == -1) { if (errno == EINVAL) return (0); log_warn("pftable_change ioctl"); } return (ret); } static int pftable_clear(const char *name) { struct pfioc_table tio; if (devpf == -1 && ((devpf = open("/dev/pf", O_RDWR|O_CLOEXEC)) == -1)) fatal("open(/dev/pf)"); memset(&tio, 0, sizeof(tio)); strlcpy(tio.pfrio_table.pfrt_name, name, sizeof(tio.pfrio_table.pfrt_name)); if (ioctl(devpf, DIOCRCLRADDRS, &tio) == -1) { log_warn("pftable_clear ioctl"); return (-1); } return (0); } int pftable_exists(const char *name) { struct pfioc_table tio; struct pfr_astats dummy; if (devpf == -1 && ((devpf = open("/dev/pf", O_RDWR|O_CLOEXEC)) == -1)) fatal("open(/dev/pf)"); memset(&tio, 0, sizeof(tio)); strlcpy(tio.pfrio_table.pfrt_name, name, sizeof(tio.pfrio_table.pfrt_name)); tio.pfrio_buffer = &dummy; tio.pfrio_esize = sizeof(dummy); tio.pfrio_size = 1; if (ioctl(devpf, DIOCRGETASTATS, &tio) == -1) return (-1); return (0); } int pftable_add(const char *name) { struct pf_table *pft; /* Ignore duplicates */ LIST_FOREACH(pft, &tables, entry) if (strcmp(pft->name, name) == 0) return (0); if ((pft = calloc(1, sizeof(*pft))) == NULL) { log_warn("pftable malloc"); return (-1); } if (strlcpy(pft->name, name, sizeof(pft->name)) >= sizeof(pft->name)) { log_warn("pf_table name too long"); free(pft); return (-1); } LIST_INSERT_HEAD(&tables, pft, entry); return (0); } int pftable_clear_all(void) { struct pf_table *pft; LIST_FOREACH(pft, &tables, entry) { if (pftable_clear(pft->name) != 0) return (-1); free(pft->worklist); pft->worklist = NULL; pft->nalloc = pft->naddrs = 0; pft->what = 0; } return (0); } static int pftable_add_work(const char *table, struct bgpd_addr *addr, uint8_t len, int del) { struct pf_table *pft; struct pfr_addr *pfa, *tmp; unsigned long what; if (*table == '\0' || len > 128) fatal("pftable_add_work: insane"); /* Find table */ LIST_FOREACH(pft, &tables, entry) if (strcmp(pft->name, table) == 0) break; if (pft == NULL) { log_warn("pf table %s not found", table); return (-1); } /* * Only one type of work on the list at a time, * commit pending work first before adding new work */ what = del ? DIOCRDELADDRS : DIOCRADDADDRS; if (pft->naddrs != 0 && pft->what != what) pftable_commit(); if (pft->nalloc <= pft->naddrs) pft->nalloc = pft->nalloc == 0 ? 1 : pft->nalloc * 2; tmp = reallocarray(pft->worklist, pft->nalloc, sizeof(*tmp)); if (tmp == NULL) { if (pft->worklist != NULL) { log_warn("pftable_add_work: malloc"); free(pft->worklist); pft->worklist = NULL; } pft->nalloc = pft->naddrs = 0; pft->what = 0; return (-1); } pft->worklist = tmp; pfa = &pft->worklist[pft->naddrs]; memset(pfa, 0, sizeof(*pfa)); memcpy(&pfa->pfra_u, &addr->v6, (len + 7U) / 8); pfa->pfra_af = aid2af(addr->aid); pfa->pfra_net = len; pft->naddrs++; pft->what = what; /* Don't let the list grow too large */ if (pft->naddrs >= 1024) pftable_commit(); return (0); } /* imsg handlers */ int pftable_addr_add(struct pftable_msg *m) { return (pftable_add_work(m->pftable, &m->addr, m->len, 0)); } int pftable_addr_remove(struct pftable_msg *m) { return (pftable_add_work(m->pftable, &m->addr, m->len, 1)); } int pftable_commit(void) { struct pf_table *pft; int ret = 0; LIST_FOREACH(pft, &tables, entry) { if (pft->what != 0 && pftable_change(pft) != 0) ret = -1; free(pft->worklist); pft->worklist = NULL; pft->nalloc = pft->naddrs = 0; pft->what = 0; } return (ret); } openbgpd-8.8/src/bgpd/pftable-disabled.c100644 001750 001750 00000002451 13453650226 0013732/* $OpenBSD$ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "bgpd.h" #include "log.h" int pftable_exists(const char *name) { log_warnx("pftable not supported"); return (-1); } int pftable_add(const char *name) { log_warnx("pftable not supported"); return (-1); } int pftable_clear_all(void) { return (0); } /* imsg handlers */ int pftable_addr_add(struct pftable_msg *m) { return (-1); } int pftable_addr_remove(struct pftable_msg *m) { return (-1); } int pftable_commit(void) { /* is called on session shutdown so fake success */ return (0); } openbgpd-8.8/src/bgpd/name2id.c100644 001750 001750 00000010061 14264017711 0012060/* $OpenBSD: name2id.c,v 1.12 2022/06/16 15:30:12 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgpd.h" #define IDVAL_MAX 50000 struct n2id_label { TAILQ_ENTRY(n2id_label) entry; char *name; uint16_t id; int ref; }; TAILQ_HEAD(n2id_labels, n2id_label); uint16_t _name2id(struct n2id_labels *, const char *); const char *_id2name(struct n2id_labels *, uint16_t); void _unref(struct n2id_labels *, uint16_t); uint16_t _ref(struct n2id_labels *, uint16_t); struct n2id_labels rt_labels = TAILQ_HEAD_INITIALIZER(rt_labels); struct n2id_labels pftable_labels = TAILQ_HEAD_INITIALIZER(pftable_labels); uint16_t rtlabel_name2id(const char *name) { return (_name2id(&rt_labels, name)); } const char * rtlabel_id2name(uint16_t id) { return (_id2name(&rt_labels, id)); } void rtlabel_unref(uint16_t id) { _unref(&rt_labels, id); } uint16_t rtlabel_ref(uint16_t id) { return (_ref(&rt_labels, id)); } uint16_t pftable_name2id(const char *name) { return (_name2id(&pftable_labels, name)); } const char * pftable_id2name(uint16_t id) { return (_id2name(&pftable_labels, id)); } void pftable_unref(uint16_t id) { _unref(&pftable_labels, id); } uint16_t pftable_ref(uint16_t id) { return (_ref(&pftable_labels, id)); } /* * Try to convert a name into id. If something fails 0 is returned which * is the ID of the empty label. */ uint16_t _name2id(struct n2id_labels *head, const char *name) { struct n2id_label *label, *p = NULL; uint16_t new_id = 1; if (!name[0]) return (0); TAILQ_FOREACH(label, head, entry) if (strcmp(name, label->name) == 0) { label->ref++; return (label->id); } /* * to avoid fragmentation, we do a linear search from the beginning * and take the first free slot we find. if there is none or the list * is empty, append a new entry at the end. */ if (!TAILQ_EMPTY(head)) for (p = TAILQ_FIRST(head); p != NULL && p->id == new_id; p = TAILQ_NEXT(p, entry)) new_id = p->id + 1; if (new_id > IDVAL_MAX) return (0); if ((label = calloc(1, sizeof(struct n2id_label))) == NULL) return (0); if ((label->name = strdup(name)) == NULL) { free(label); return (0); } label->id = new_id; label->ref++; if (p != NULL) /* insert new entry before p */ TAILQ_INSERT_BEFORE(p, label, entry); else /* either list empty or no free slot in between */ TAILQ_INSERT_TAIL(head, label, entry); return (label->id); } const char * _id2name(struct n2id_labels *head, uint16_t id) { struct n2id_label *label; if (id == 0) return (""); TAILQ_FOREACH(label, head, entry) if (label->id == id) return (label->name); return (""); } void _unref(struct n2id_labels *head, uint16_t id) { struct n2id_label *p, *next; if (id == 0) return; for (p = TAILQ_FIRST(head); p != NULL; p = next) { next = TAILQ_NEXT(p, entry); if (id == p->id) { if (--p->ref == 0) { TAILQ_REMOVE(head, p, entry); free(p->name); free(p); } break; } } } uint16_t _ref(struct n2id_labels *head, uint16_t id) { struct n2id_label *label; if (id == 0) return (0); TAILQ_FOREACH(label, head, entry) if (label->id == id) { ++label->ref; return (id); } /* id not found, treat like no id */ return (0); } openbgpd-8.8/src/bgpd/util.c100644 001750 001750 00000070320 14751151130 0011515/* $OpenBSD: util.c,v 1.93 2025/02/04 18:16:56 denis Exp $ */ /* * Copyright (c) 2006 Claudio Jeker * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" const char * log_addr(const struct bgpd_addr *addr) { static char buf[74]; struct sockaddr *sa; socklen_t len; sa = addr2sa(addr, 0, &len); switch (addr->aid) { case AID_INET: case AID_INET6: return log_sockaddr(sa, len); case AID_VPN_IPv4: case AID_VPN_IPv6: snprintf(buf, sizeof(buf), "%s %s", log_rd(addr->rd), log_sockaddr(sa, len)); return (buf); case AID_EVPN: return log_evpnaddr(addr, sa, len); break; } return ("???"); } static const char * log_mac(const uint8_t mac[ETHER_ADDR_LEN]) { static char buf[18]; snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return (buf); } static const uint8_t zero_esi[ESI_ADDR_LEN]; static const char * log_esi(const uint8_t esi[ESI_ADDR_LEN]) { static char buf[30]; if (memcmp(esi, zero_esi, sizeof(zero_esi)) == 0) return (""); snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", esi[0], esi[1], esi[2], esi[3], esi[4], esi[5], esi[6], esi[7], esi[8], esi[9]); return (buf); } const char * log_evpnaddr(const struct bgpd_addr *addr, struct sockaddr *sa, socklen_t salen) { static char buf[138]; uint32_t vni; uint8_t len; switch(addr->evpn.type) { case EVPN_ROUTE_TYPE_2: memcpy(&vni, addr->labelstack, addr->labellen); snprintf(buf, sizeof(buf), "[2]:[%s]:[%s]:[%d]:[48]:[%s]", log_rd(addr->rd),log_esi(addr->evpn.esi), htonl(vni)>>8, log_mac(addr->evpn.mac)); if (sa != NULL) { len = strlen(buf); snprintf(buf+len, sizeof(buf)-len, ":[%d]:[%s]", sa->sa_family == AF_INET ? 32 : 128, log_sockaddr(sa, salen)); } break; case EVPN_ROUTE_TYPE_3: if (sa != NULL) { memcpy(&vni, addr->labelstack, addr->labellen); snprintf(buf, sizeof(buf), "[3]:[%s]:[%d]:[%s]", log_rd(addr->rd), sa->sa_family == AF_INET ? 32 : 128, log_sockaddr(sa, salen)); } break; default: break; } return (buf); } const char * log_in6addr(const struct in6_addr *addr) { struct sockaddr_in6 sa_in6; memset(&sa_in6, 0, sizeof(sa_in6)); sa_in6.sin6_family = AF_INET6; memcpy(&sa_in6.sin6_addr, addr, sizeof(sa_in6.sin6_addr)); #ifdef __KAME__ /* XXX thanks, KAME, for this ugliness... adopted from route/show.c */ if ((IN6_IS_ADDR_LINKLOCAL(&sa_in6.sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&sa_in6.sin6_addr) || IN6_IS_ADDR_MC_NODELOCAL(&sa_in6.sin6_addr)) && sa_in6.sin6_scope_id == 0) { uint16_t tmp16; memcpy(&tmp16, &sa_in6.sin6_addr.s6_addr[2], sizeof(tmp16)); sa_in6.sin6_scope_id = ntohs(tmp16); sa_in6.sin6_addr.s6_addr[2] = 0; sa_in6.sin6_addr.s6_addr[3] = 0; } #endif return (log_sockaddr((struct sockaddr *)&sa_in6, sizeof(sa_in6))); } const char * log_sockaddr(struct sockaddr *sa, socklen_t len) { static char buf[4][NI_MAXHOST]; static int bufidx; bufidx = (bufidx + 1) % 4; if (sa == NULL || getnameinfo(sa, len, buf[bufidx], sizeof(buf[0]), NULL, 0, NI_NUMERICHOST)) return ("(unknown)"); else return (buf[bufidx]); } const char * log_as(uint32_t as) { static char buf[11]; /* "4294967294\0" */ if (snprintf(buf, sizeof(buf), "%u", as) < 0) return ("?"); return (buf); } const char * log_rd(uint64_t rd) { static char buf[32]; struct in_addr addr; uint32_t u32; uint16_t u16; rd = be64toh(rd); switch (rd >> 48) { case EXT_COMMUNITY_TRANS_TWO_AS: u32 = rd & 0xffffffff; u16 = (rd >> 32) & 0xffff; snprintf(buf, sizeof(buf), "rd %hu:%u", u16, u32); break; case EXT_COMMUNITY_TRANS_FOUR_AS: u32 = (rd >> 16) & 0xffffffff; u16 = rd & 0xffff; snprintf(buf, sizeof(buf), "rd %s:%hu", log_as(u32), u16); break; case EXT_COMMUNITY_TRANS_IPV4: u32 = (rd >> 16) & 0xffffffff; u16 = rd & 0xffff; addr.s_addr = htonl(u32); snprintf(buf, sizeof(buf), "rd %s:%hu", inet_ntoa(addr), u16); break; default: snprintf(buf, sizeof(buf), "rd #%016llx", (unsigned long long)rd); break; } return (buf); } const struct ext_comm_pairs iana_ext_comms[] = IANA_EXT_COMMUNITIES; /* NOTE: this function does not check if the type/subtype combo is * actually valid. */ const char * log_ext_subtype(int type, uint8_t subtype) { static char etype[16]; const struct ext_comm_pairs *cp; for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if ((type == cp->type || type == -1) && subtype == cp->subtype) return (cp->subname); } if (type == -1) return ("???"); snprintf(etype, sizeof(etype), "[%hhx:%hhx]", (uint8_t)type, subtype); return (etype); } const char * log_reason(const char *communication) { static char buf[(REASON_LEN - 1) * 4 + 1]; strnvis(buf, communication, sizeof(buf), VIS_NL | VIS_OCTAL); return buf; } static const char * log_expires(time_t expires) { static char buf[32]; buf[0] = '\0'; if (expires != 0) snprintf(buf, sizeof(buf), " expires %lld", (long long)expires); return buf; } const char * log_roa(struct roa *roa) { static char buf[256]; char maxbuf[32]; #if defined(__GNUC__) && __GNUC__ < 4 struct bgpd_addr addr = { .aid = roa->aid }; addr.v6 = roa->prefix.inet6; #else struct bgpd_addr addr = { .aid = roa->aid, .v6 = roa->prefix.inet6 }; #endif maxbuf[0] = '\0'; if (roa->prefixlen != roa->maxlen) snprintf(maxbuf, sizeof(maxbuf), " maxlen %u", roa->maxlen); snprintf(buf, sizeof(buf), "%s/%u%s source-as %u%s", log_addr(&addr), roa->prefixlen, maxbuf, roa->asnum, log_expires(roa->expires)); return buf; } const char * log_aspa(struct aspa_set *aspa) { static char errbuf[256]; static char *buf; static size_t len; char asbuf[16]; size_t needed; uint32_t i; /* include enough space for header and trailer */ if ((uint64_t)aspa->num > (SIZE_MAX / sizeof(asbuf) - 72)) goto fail; needed = aspa->num * sizeof(asbuf) + 72; if (needed > len) { char *nbuf; if ((nbuf = realloc(buf, needed)) == NULL) goto fail; len = needed; buf = nbuf; } snprintf(buf, len, "customer-as %s%s provider-as { ", log_as(aspa->as), log_expires(aspa->expires)); for (i = 0; i < aspa->num; i++) { snprintf(asbuf, sizeof(asbuf), "%s ", log_as(aspa->tas[i])); if (strlcat(buf, asbuf, len) >= len) goto fail; } if (strlcat(buf, "}", len) >= len) goto fail; return buf; fail: free(buf); buf = NULL; len = 0; snprintf(errbuf, sizeof(errbuf), "customer-as %s%s provider-as { ... }", log_as(aspa->as), log_expires(aspa->expires)); return errbuf; } const char * log_aspath_error(int error) { static char buf[20]; switch (error) { case AS_ERR_LEN: return "inconsistent length"; case AS_ERR_TYPE: return "unknown segment type"; case AS_ERR_BAD: return "invalid encoding"; case AS_ERR_SOFT: return "soft failure"; default: snprintf(buf, sizeof(buf), "unknown %d", error); return buf; } } const char * log_rtr_error(enum rtr_error err) { static char buf[20]; switch (err) { case NO_ERROR: return "No Error"; case CORRUPT_DATA: return "Corrupt Data"; case INTERNAL_ERROR: return "Internal Error"; case NO_DATA_AVAILABLE: return "No Data Available"; case INVALID_REQUEST: return "Invalid Request"; case UNSUPP_PROTOCOL_VERS: return "Unsupported Protocol Version"; case UNSUPP_PDU_TYPE: return "Unsupported PDU Type"; case UNK_REC_WDRAWL: return "Withdrawal of Unknown Record"; case DUP_REC_RECV: return "Duplicate Announcement Received"; case UNEXP_PROTOCOL_VERS: return "Unexpected Protocol Version"; default: snprintf(buf, sizeof(buf), "unknown %u", err); return buf; } } const char * log_policy(enum role role) { switch (role) { case ROLE_PROVIDER: return "provider"; case ROLE_RS: return "rs"; case ROLE_RS_CLIENT: return "rs-client"; case ROLE_CUSTOMER: return "customer"; case ROLE_PEER: return "peer"; default: return "unknown"; } } const char * log_capability(uint8_t capa) { static char buf[20]; switch (capa) { case CAPA_MP: return "Multiprotocol Extensions"; case CAPA_REFRESH: return "Route Refresh"; case CAPA_EXT_NEXTHOP: return "Extended Nexhop Encoding"; case CAPA_EXT_MSG: return "Extended Message"; case CAPA_ROLE: return "BGP Role"; case CAPA_RESTART: return "Graceful Restart"; case CAPA_AS4BYTE: return "4-octet AS number"; case CAPA_ADD_PATH: return "ADD-PATH"; case CAPA_ENHANCED_RR: return "Enhanced Route Refresh"; default: snprintf(buf, sizeof(buf), "unknown %u", capa); return buf; } } static const char * aspath_delim(uint8_t seg_type, int closing) { static char db[8]; switch (seg_type) { case AS_SET: if (!closing) return ("{ "); else return (" }"); case AS_SEQUENCE: return (""); case AS_CONFED_SEQUENCE: if (!closing) return ("( "); else return (" )"); case AS_CONFED_SET: if (!closing) return ("[ "); else return (" ]"); default: if (!closing) snprintf(db, sizeof(db), "!%u ", seg_type); else snprintf(db, sizeof(db), " !%u", seg_type); return (db); } } static int aspath_snprint(char *buf, size_t size, struct ibuf *in) { #define UPDATE() \ do { \ if (r < 0 || (unsigned int)r >= size) \ return (-1); \ size -= r; \ buf += r; \ } while (0) struct ibuf data; uint32_t as; int r, n = 0; uint8_t i, seg_type, seg_len; ibuf_from_ibuf(&data, in); while (ibuf_size(&data) > 0) { if (ibuf_get_n8(&data, &seg_type) == -1 || ibuf_get_n8(&data, &seg_len) == -1 || seg_len == 0) return (-1); r = snprintf(buf, size, "%s%s", n++ != 0 ? " " : "", aspath_delim(seg_type, 0)); UPDATE(); for (i = 0; i < seg_len; i++) { if (ibuf_get_n32(&data, &as) == -1) return -1; r = snprintf(buf, size, "%s", log_as(as)); UPDATE(); if (i + 1 < seg_len) { r = snprintf(buf, size, " "); UPDATE(); } } r = snprintf(buf, size, "%s", aspath_delim(seg_type, 1)); UPDATE(); } /* ensure that we have a valid C-string especially for empty as path */ *buf = '\0'; return (0); #undef UPDATE } static ssize_t aspath_strsize(struct ibuf *in) { struct ibuf buf; ssize_t total_size = 0; uint32_t as; uint8_t i, seg_type, seg_len; ibuf_from_ibuf(&buf, in); while (ibuf_size(&buf) > 0) { if (ibuf_get_n8(&buf, &seg_type) == -1 || ibuf_get_n8(&buf, &seg_len) == -1 || seg_len == 0) return (-1); if (total_size != 0) total_size += 1; total_size += strlen(aspath_delim(seg_type, 0)); for (i = 0; i < seg_len; i++) { if (ibuf_get_n32(&buf, &as) == -1) return (-1); do { total_size++; } while ((as = as / 10) != 0); } total_size += seg_len - 1; total_size += strlen(aspath_delim(seg_type, 1)); } return (total_size + 1); } int aspath_asprint(char **ret, struct ibuf *data) { ssize_t slen; if ((slen = aspath_strsize(data)) == -1) { *ret = NULL; errno = EINVAL; return (-1); } *ret = malloc(slen); if (*ret == NULL) return (-1); if (aspath_snprint(*ret, slen, data) == -1) { free(*ret); *ret = NULL; errno = EINVAL; return (-1); } return (0); } /* * Extract the asnum out of the as segment at the specified position. * Direct access is not possible because of non-aligned reads. * Only works on verified 4-byte AS paths. */ uint32_t aspath_extract(const void *seg, int pos) { const u_char *ptr = seg; uint32_t as; /* minimal pos check, return 0 since that is an invalid ASN */ if (pos < 0 || pos >= ptr[1]) return (0); ptr += 2 + sizeof(uint32_t) * pos; memcpy(&as, ptr, sizeof(uint32_t)); return (ntohl(as)); } /* * Verify that the aspath is correctly encoded. */ int aspath_verify(struct ibuf *in, int as4byte, int permit_set) { struct ibuf buf; int pos, error = 0; uint8_t seg_len, seg_type; ibuf_from_ibuf(&buf, in); if (ibuf_size(&buf) & 1) { /* odd length aspath are invalid */ error = AS_ERR_BAD; goto done; } while (ibuf_size(&buf) > 0) { if (ibuf_get_n8(&buf, &seg_type) == -1 || ibuf_get_n8(&buf, &seg_len) == -1) { error = AS_ERR_LEN; goto done; } if (seg_len == 0) { /* empty aspath segments are not allowed */ error = AS_ERR_BAD; goto done; } /* * BGP confederations should not show up but consider them * as a soft error which invalidates the path but keeps the * bgp session running. */ if (seg_type == AS_CONFED_SEQUENCE || seg_type == AS_CONFED_SET) error = AS_ERR_SOFT; /* * If AS_SET filtering (RFC6472) is on, error out on AS_SET * as well. */ if (!permit_set && seg_type == AS_SET) error = AS_ERR_SOFT; if (seg_type != AS_SET && seg_type != AS_SEQUENCE && seg_type != AS_CONFED_SEQUENCE && seg_type != AS_CONFED_SET) { error = AS_ERR_TYPE; goto done; } /* RFC 7607 - AS 0 is considered malformed */ for (pos = 0; pos < seg_len; pos++) { uint32_t as; if (as4byte) { if (ibuf_get_n32(&buf, &as) == -1) { error = AS_ERR_LEN; goto done; } } else { uint16_t tmp; if (ibuf_get_n16(&buf, &tmp) == -1) { error = AS_ERR_LEN; goto done; } as = tmp; } if (as == 0) error = AS_ERR_SOFT; } } done: return (error); /* aspath is valid but probably not loop free */ } /* * convert a 2 byte aspath to a 4 byte one. */ struct ibuf * aspath_inflate(struct ibuf *in) { struct ibuf *out; uint16_t short_as; uint8_t seg_type, seg_len; /* * Allocate enough space for the worst case. * XXX add 1 byte for the empty ASPATH case since we can't * allocate an ibuf of 0 length. */ if ((out = ibuf_open(ibuf_size(in) * 2 + 1)) == NULL) return (NULL); /* then copy the aspath */ while (ibuf_size(in) > 0) { if (ibuf_get_n8(in, &seg_type) == -1 || ibuf_get_n8(in, &seg_len) == -1 || seg_len == 0) goto fail; if (ibuf_add_n8(out, seg_type) == -1 || ibuf_add_n8(out, seg_len) == -1) goto fail; for (; seg_len > 0; seg_len--) { if (ibuf_get_n16(in, &short_as) == -1) goto fail; if (ibuf_add_n32(out, short_as) == -1) goto fail; } } return (out); fail: ibuf_free(out); return (NULL); } static const u_char addrmask[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; /* NLRI functions to extract prefixes from the NLRI blobs */ int extract_prefix(const u_char *p, int len, void *va, uint8_t pfxlen, uint8_t max) { u_char *a = va; int plen; plen = PREFIX_SIZE(pfxlen) - 1; if (len < plen || max < plen) return -1; while (pfxlen > 0) { if (pfxlen < 8) { *a++ = *p++ & addrmask[pfxlen]; break; } else { *a++ = *p++; pfxlen -= 8; } } return (plen); } static int extract_prefix_buf(struct ibuf *buf, void *va, uint8_t pfxlen, uint8_t max) { u_char *a = va; unsigned int plen; uint8_t tmp; plen = PREFIX_SIZE(pfxlen) - 1; if (ibuf_size(buf) < plen || max < plen) return -1; while (pfxlen > 0) { if (ibuf_get_n8(buf, &tmp) == -1) return -1; if (pfxlen < 8) { *a++ = tmp & addrmask[pfxlen]; break; } else { *a++ = tmp; pfxlen -= 8; } } return (0); } int nlri_get_prefix(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen) { uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); if (pfxlen > 32) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_INET; if (extract_prefix_buf(buf, &prefix->v4, pfxlen, sizeof(prefix->v4)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_prefix6(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen) { uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); if (pfxlen > 128) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_INET6; if (extract_prefix_buf(buf, &prefix->v6, pfxlen, sizeof(prefix->v6)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_vpn4(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen, int withdraw) { int done = 0; uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_VPN_IPv4; /* label stack */ do { if (prefix->labellen + 3U > sizeof(prefix->labelstack) || pfxlen < 3 * 8) return (-1); if (withdraw) { /* on withdraw ignore the labelstack all together */ if (ibuf_skip(buf, 3) == -1) return (-1); pfxlen -= 3 * 8; break; } if (ibuf_get(buf, &prefix->labelstack[prefix->labellen], 3) == -1) return -1; if (prefix->labelstack[prefix->labellen + 2] & BGP_MPLS_BOS) done = 1; prefix->labellen += 3; pfxlen -= 3 * 8; } while (!done); /* RD */ if (pfxlen < sizeof(uint64_t) * 8 || ibuf_get_h64(buf, &prefix->rd) == -1) return (-1); pfxlen -= sizeof(uint64_t) * 8; /* prefix */ if (pfxlen > 32) return (-1); if (extract_prefix_buf(buf, &prefix->v4, pfxlen, sizeof(prefix->v4)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_vpn6(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen, int withdraw) { int done = 0; uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_VPN_IPv6; /* label stack */ do { if (prefix->labellen + 3U > sizeof(prefix->labelstack) || pfxlen < 3 * 8) return (-1); if (withdraw) { /* on withdraw ignore the labelstack all together */ if (ibuf_skip(buf, 3) == -1) return (-1); pfxlen -= 3 * 8; break; } if (ibuf_get(buf, &prefix->labelstack[prefix->labellen], 3) == -1) return (-1); if (prefix->labelstack[prefix->labellen + 2] & BGP_MPLS_BOS) done = 1; prefix->labellen += 3; pfxlen -= 3 * 8; } while (!done); /* RD */ if (pfxlen < sizeof(uint64_t) * 8 || ibuf_get_h64(buf, &prefix->rd) == -1) return (-1); pfxlen -= sizeof(uint64_t) * 8; /* prefix */ if (pfxlen > 128) return (-1); if (extract_prefix_buf(buf, &prefix->v6, pfxlen, sizeof(prefix->v6)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_evpn(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen) { struct ibuf evpnbuf; uint8_t nlrilen, type, pfxlen = 0, maclen = 0; if (ibuf_get_n8(buf, &type) == -1) return (-1); if (ibuf_get_n8(buf, &nlrilen) == -1) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_EVPN; switch (type) { case EVPN_ROUTE_TYPE_2: if (ibuf_get_ibuf(buf, nlrilen, &evpnbuf) == -1) return (-1); prefix->evpn.type = EVPN_ROUTE_TYPE_2; /* RD */ if (ibuf_get_h64(&evpnbuf, &prefix->rd) == -1) return (-1); /* ESI */ if (ibuf_get(&evpnbuf, &prefix->evpn.esi, sizeof(prefix->evpn.esi)) == -1) return (-1); /* Ethernet Tag */ if (ibuf_get_h32(&evpnbuf, &prefix->evpn.ethtag) == -1) return (-1); /* MAC length */ if (ibuf_get_n8(&evpnbuf, &maclen) == -1) return (-1); if (maclen != 48) return (-1); /* MAC address */ if (ibuf_get(&evpnbuf, &prefix->evpn.mac, sizeof(prefix->evpn.mac)) == -1) return (-1); /* Prefix length */ if (ibuf_get_n8(&evpnbuf, &pfxlen) == -1) return (-1); /* Destination */ if (pfxlen == 0) { /* nothing */ } else if (pfxlen == 32) { prefix->evpn.aid = AID_INET; if (ibuf_get(&evpnbuf, &prefix->evpn.v4, sizeof(prefix->evpn.v4)) == -1) return (-1); } else if (pfxlen == 128) { prefix->evpn.aid = AID_INET6; if (ibuf_get(&evpnbuf, &prefix->evpn.v6, sizeof(prefix->evpn.v6)) == -1) return (-1); } else return (-1); /* VNI */ if (ibuf_size(&evpnbuf) != 3 && ibuf_size(&evpnbuf) != 6) return (-1); prefix->labellen = ibuf_size(&evpnbuf); if (ibuf_get(&evpnbuf, prefix->labelstack, prefix->labellen) == -1) return (-1); break; case EVPN_ROUTE_TYPE_3: if (ibuf_get_ibuf(buf, nlrilen, &evpnbuf) == -1) return (-1); prefix->evpn.type = EVPN_ROUTE_TYPE_3; /* RD */ if (ibuf_get_h64(&evpnbuf, &prefix->rd) == -1) return (-1); /* Ethernet Tag */ if (ibuf_get_h32(&evpnbuf, &prefix->evpn.ethtag) == -1) return (-1); /* Prefix length */ if (ibuf_get_n8(&evpnbuf, &pfxlen) == -1) return (-1); /* Destination */ if (pfxlen == 32) { prefix->evpn.aid = AID_INET; if (ibuf_get(&evpnbuf, &prefix->evpn.v4, sizeof(prefix->evpn.v4)) == -1) return (-1); } else if (pfxlen == 128) { prefix->evpn.aid = AID_INET6; if (ibuf_get(&evpnbuf, &prefix->evpn.v6, sizeof(prefix->evpn.v6)) == -1) return (-1); } else return (-1); if (ibuf_size(&evpnbuf) != 0) return (-1); break; default: return (-1); } *prefixlen = pfxlen; return (0); } static in_addr_t prefixlen2mask(uint8_t prefixlen) { if (prefixlen == 0) return (0); return (0xffffffff << (32 - prefixlen)); } /* * This function will have undefined behaviour if the passed in prefixlen is * too large for the respective bgpd_addr address family. */ int prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, int prefixlen) { in_addr_t mask, aa, ba; int i; uint8_t m; if (a->aid != b->aid) return (a->aid - b->aid); switch (a->aid) { case AID_VPN_IPv4: if (be64toh(a->rd) > be64toh(b->rd)) return (1); if (be64toh(a->rd) < be64toh(b->rd)) return (-1); /* FALLTHROUGH */ case AID_INET: if (prefixlen == 0) return (0); if (prefixlen > 32) return (-1); mask = htonl(prefixlen2mask(prefixlen)); aa = ntohl(a->v4.s_addr & mask); ba = ntohl(b->v4.s_addr & mask); if (aa > ba) return (1); if (aa < ba) return (-1); break; case AID_VPN_IPv6: if (be64toh(a->rd) > be64toh(b->rd)) return (1); if (be64toh(a->rd) < be64toh(b->rd)) return (-1); /* FALLTHROUGH */ case AID_INET6: if (prefixlen == 0) return (0); if (prefixlen > 128) return (-1); for (i = 0; i < prefixlen / 8; i++) if (a->v6.s6_addr[i] != b->v6.s6_addr[i]) return (a->v6.s6_addr[i] - b->v6.s6_addr[i]); i = prefixlen % 8; if (i) { m = 0xff00 >> i; if ((a->v6.s6_addr[prefixlen / 8] & m) != (b->v6.s6_addr[prefixlen / 8] & m)) return ((a->v6.s6_addr[prefixlen / 8] & m) - (b->v6.s6_addr[prefixlen / 8] & m)); } break; default: return (-1); } if (a->aid == AID_VPN_IPv4 || a->aid == AID_VPN_IPv6) { if (a->labellen > b->labellen) return (1); if (a->labellen < b->labellen) return (-1); return (memcmp(a->labelstack, b->labelstack, a->labellen)); } return (0); } void inet4applymask(struct in_addr *dest, const struct in_addr *src, int prefixlen) { struct in_addr mask; mask.s_addr = htonl(prefixlen2mask(prefixlen)); dest->s_addr = src->s_addr & mask.s_addr; } void inet6applymask(struct in6_addr *dest, const struct in6_addr *src, int prefixlen) { struct in6_addr mask; int i; memset(&mask, 0, sizeof(mask)); for (i = 0; i < prefixlen / 8; i++) mask.s6_addr[i] = 0xff; i = prefixlen % 8; if (i) mask.s6_addr[prefixlen / 8] = 0xff00 >> i; for (i = 0; i < 16; i++) dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i]; } void applymask(struct bgpd_addr *dest, const struct bgpd_addr *src, int prefixlen) { *dest = *src; switch (src->aid) { case AID_INET: case AID_VPN_IPv4: inet4applymask(&dest->v4, &src->v4, prefixlen); break; case AID_INET6: case AID_VPN_IPv6: inet6applymask(&dest->v6, &src->v6, prefixlen); break; } } /* address family translation functions */ const struct aid aid_vals[AID_MAX] = AID_VALS; const char * aid2str(uint8_t aid) { if (aid < AID_MAX) return (aid_vals[aid].name); return ("unknown AID"); } int aid2afi(uint8_t aid, uint16_t *afi, uint8_t *safi) { if (aid != AID_UNSPEC && aid < AID_MAX) { *afi = aid_vals[aid].afi; *safi = aid_vals[aid].safi; return (0); } return (-1); } int afi2aid(uint16_t afi, uint8_t safi, uint8_t *aid) { uint8_t i; for (i = AID_MIN; i < AID_MAX; i++) if (aid_vals[i].afi == afi && aid_vals[i].safi == safi) { *aid = i; return (0); } return (-1); } sa_family_t aid2af(uint8_t aid) { if (aid < AID_MAX) return (aid_vals[aid].af); return (AF_UNSPEC); } int af2aid(sa_family_t af, uint8_t safi, uint8_t *aid) { uint8_t i; if (safi == 0) /* default to unicast subclass */ safi = SAFI_UNICAST; for (i = AID_UNSPEC; i < AID_MAX; i++) if (aid_vals[i].af == af && aid_vals[i].safi == safi) { *aid = i; return (0); } return (-1); } static socklen_t addr2sa_in6(struct sockaddr_in6 *sin6, struct in6_addr in6, uint16_t port, uint32_t scope_id) { sin6->sin6_family = AF_INET6; memcpy(&sin6->sin6_addr, &in6, sizeof(sin6->sin6_addr)); sin6->sin6_port = htons(port); sin6->sin6_scope_id = scope_id; return (sizeof(struct sockaddr_in6)); } static socklen_t addr2sa_in(struct sockaddr_in *sin, struct in_addr in, uint16_t port) { sin->sin_family = AF_INET; sin->sin_addr.s_addr = in.s_addr; sin->sin_port = htons(port); return (sizeof(struct sockaddr_in)); } /* * Convert a struct bgpd_addr into a struct sockaddr. For VPN addresses * the included label stack is ignored and needs to be handled by the caller. */ struct sockaddr * addr2sa(const struct bgpd_addr *addr, uint16_t port, socklen_t *len) { static struct sockaddr_storage ss; struct sockaddr_in *sa_in = (struct sockaddr_in *)&ss; struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)&ss; if (addr == NULL || addr->aid == AID_UNSPEC) return (NULL); memset(&ss, 0, sizeof(ss)); switch (addr->aid) { case AID_INET: case AID_VPN_IPv4: *len = addr2sa_in(sa_in, addr->v4, port); break; case AID_INET6: case AID_VPN_IPv6: *len = addr2sa_in6(sa_in6, addr->v6, port, addr->scope_id); break; case AID_EVPN: if (addr->evpn.aid == AID_INET) *len = addr2sa_in(sa_in, addr->evpn.v4, port); else if (addr->evpn.aid == AID_INET6) *len = addr2sa_in6(sa_in6, addr->evpn.v6, port, addr->scope_id); else { *len = 0; return (NULL); } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: default: return (NULL); } return ((struct sockaddr *)&ss); } void sa2addr(struct sockaddr *sa, struct bgpd_addr *addr, uint16_t *port) { struct sockaddr_in *sa_in = (struct sockaddr_in *)sa; struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa; memset(addr, 0, sizeof(*addr)); switch (sa->sa_family) { case AF_INET: addr->aid = AID_INET; memcpy(&addr->v4, &sa_in->sin_addr, sizeof(addr->v4)); if (port) *port = ntohs(sa_in->sin_port); break; case AF_INET6: addr->aid = AID_INET6; #ifdef __KAME__ /* * XXX thanks, KAME, for this ugliness... * adopted from route/show.c */ if ((IN6_IS_ADDR_LINKLOCAL(&sa_in6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&sa_in6->sin6_addr) || IN6_IS_ADDR_MC_NODELOCAL(&sa_in6->sin6_addr)) && sa_in6->sin6_scope_id == 0) { uint16_t tmp16; memcpy(&tmp16, &sa_in6->sin6_addr.s6_addr[2], sizeof(tmp16)); sa_in6->sin6_scope_id = ntohs(tmp16); sa_in6->sin6_addr.s6_addr[2] = 0; sa_in6->sin6_addr.s6_addr[3] = 0; } #endif memcpy(&addr->v6, &sa_in6->sin6_addr, sizeof(addr->v6)); addr->scope_id = sa_in6->sin6_scope_id; /* I hate v6 */ if (port) *port = ntohs(sa_in6->sin6_port); break; } } const char * get_baudrate(unsigned long long baudrate, char *unit) { static char bbuf[16]; const unsigned long long kilo = 1000; const unsigned long long mega = 1000ULL * kilo; const unsigned long long giga = 1000ULL * mega; if (baudrate > giga) snprintf(bbuf, sizeof(bbuf), "%llu G%s", baudrate / giga, unit); else if (baudrate > mega) snprintf(bbuf, sizeof(bbuf), "%llu M%s", baudrate / mega, unit); else if (baudrate > kilo) snprintf(bbuf, sizeof(bbuf), "%llu K%s", baudrate / kilo, unit); else snprintf(bbuf, sizeof(bbuf), "%llu %s", baudrate, unit); return (bbuf); } openbgpd-8.8/src/bgpd/carp.c100644 001750 001750 00000010212 14310313154 0011454/* $OpenBSD: carp.c,v 1.11 2022/08/17 15:15:25 claudio Exp $ */ /* * Copyright (c) 2006 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" struct carpgroup { TAILQ_ENTRY(carpgroup) entry; char *group; int do_demote; int changed_by; }; TAILQ_HEAD(carpgroups, carpgroup) carpgroups = TAILQ_HEAD_INITIALIZER(carpgroups); struct carpgroup *carp_group_find(char *group); int carp_demote_ioctl(char *, int); struct carpgroup * carp_group_find(char *group) { struct carpgroup *c; TAILQ_FOREACH(c, &carpgroups, entry) if (!strcmp(c->group, group)) return (c); return (NULL); } int carp_demote_init(char *group, int force) { struct carpgroup *c; int level; if ((c = carp_group_find(group)) == NULL) { if ((c = calloc(1, sizeof(struct carpgroup))) == NULL) { log_warn("carp_demote_init calloc"); return (-1); } if ((c->group = strdup(group)) == NULL) { log_warn("carp_demote_init strdup"); free(c); return (-1); } /* only demote if this group already is demoted */ if ((level = carp_demote_get(group)) == -1) { free(c->group); free(c); return (-1); } if (level > 0 || force) c->do_demote = 1; TAILQ_INSERT_TAIL(&carpgroups, c, entry); } return (0); } void carp_demote_shutdown(void) { struct carpgroup *c; while ((c = TAILQ_FIRST(&carpgroups)) != NULL) { TAILQ_REMOVE(&carpgroups, c, entry); if (c->do_demote && c->changed_by > 0) carp_demote_ioctl(c->group, -c->changed_by); free(c->group); free(c); } } int carp_demote_get(char *group) { int s; struct ifgroupreq ifgr; if ((s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == -1) { log_warn("carp_demote_get: socket"); return (-1); } memset(&ifgr, 0, sizeof(ifgr)); strlcpy(ifgr.ifgr_name, group, sizeof(ifgr.ifgr_name)); if (ioctl(s, SIOCGIFGATTR, (caddr_t)&ifgr) == -1) { if (errno == ENOENT) log_warnx("group \"%s\" does not exist", group); else log_warn("carp_demote_get: ioctl"); close(s); return (-1); } close(s); return ((int)ifgr.ifgr_attrib.ifg_carp_demoted); } int carp_demote_set(char *group, int demote) { struct carpgroup *c; if ((c = carp_group_find(group)) == NULL) { log_warnx("carp_group_find for %s returned NULL?!", group); return (-1); } if (c->changed_by + demote < 0) { log_warnx("carp_demote_set: changed_by + demote < 0"); return (-1); } if (c->do_demote && carp_demote_ioctl(group, demote) == -1) return (-1); c->changed_by += demote; /* enable demotion when we return to 0, i. e. all sessions up */ if (demote < 0 && c->changed_by == 0) c->do_demote = 1; return (0); } int carp_demote_ioctl(char *group, int demote) { int s, res; struct ifgroupreq ifgr; if ((s = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)) == -1) { log_warn("%s: socket", __func__); return (-1); } memset(&ifgr, 0, sizeof(ifgr)); strlcpy(ifgr.ifgr_name, group, sizeof(ifgr.ifgr_name)); ifgr.ifgr_attrib.ifg_carp_demoted = demote; if ((res = ioctl(s, SIOCSIFGATTR, (caddr_t)&ifgr)) == -1) log_warn("unable to %s the demote state " "of group '%s'", (demote > 0) ? "increment" : "decrement", group); else log_info("%s the demote state of group '%s'", (demote > 0) ? "incremented" : "decremented", group); close(s); return (res); } openbgpd-8.8/src/bgpd/carp-disabled.c100644 001750 001750 00000002251 13441160747 0013241/* $OpenBSD$ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "bgpd.h" #include "session.h" #include "log.h" int carp_demote_init(char *group, int force) { log_warnx("carp demote disabled"); return (-1); } void carp_demote_shutdown(void) { } int carp_demote_get(char *group) { log_warnx("carp demote disabled"); return (-1); } int carp_demote_set(char *group, int demote) { log_warnx("carp demote disabled"); return (-1); } openbgpd-8.8/src/bgpd/timer.c100644 001750 001750 00000005747 14040036063 0011671/* $OpenBSD: timer.c,v 1.19 2020/12/11 12:00:01 claudio Exp $ */ /* * Copyright (c) 2003-2007 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include "bgpd.h" #include "session.h" #include "log.h" #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b)) time_t getmonotime(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) fatal("clock_gettime"); return (ts.tv_sec); } struct timer * timer_get(struct timer_head *th, enum Timer timer) { struct timer *t; TAILQ_FOREACH(t, th, entry) if (t->type == timer) break; return (t); } struct timer * timer_nextisdue(struct timer_head *th, time_t now) { struct timer *t; t = TAILQ_FIRST(th); if (t != NULL && t->val > 0 && t->val <= now) return (t); return (NULL); } time_t timer_nextduein(struct timer_head *th, time_t now) { struct timer *t; if ((t = TAILQ_FIRST(th)) != NULL && t->val > 0) return (MAXIMUM(t->val - now, 0)); return (-1); } int timer_running(struct timer_head *th, enum Timer timer, time_t *left) { struct timer *t = timer_get(th, timer); if (t != NULL && t->val > 0) { if (left != NULL) *left = t->val - getmonotime(); return (1); } return (0); } void timer_set(struct timer_head *th, enum Timer timer, u_int offset) { struct timer *t = timer_get(th, timer); struct timer *next; if (t == NULL) { /* have to create */ if ((t = malloc(sizeof(*t))) == NULL) fatal("timer_set"); t->type = timer; } else { if (t->val == getmonotime() + (time_t)offset) return; TAILQ_REMOVE(th, t, entry); } t->val = getmonotime() + offset; TAILQ_FOREACH(next, th, entry) if (next->val == 0 || next->val > t->val) break; if (next != NULL) TAILQ_INSERT_BEFORE(next, t, entry); else TAILQ_INSERT_TAIL(th, t, entry); } void timer_stop(struct timer_head *th, enum Timer timer) { struct timer *t = timer_get(th, timer); if (t != NULL) { t->val = 0; TAILQ_REMOVE(th, t, entry); TAILQ_INSERT_TAIL(th, t, entry); } } void timer_remove(struct timer_head *th, enum Timer timer) { struct timer *t = timer_get(th, timer); if (t != NULL) { TAILQ_REMOVE(th, t, entry); free(t); } } void timer_remove_all(struct timer_head *th) { struct timer *t; while ((t = TAILQ_FIRST(th)) != NULL) { TAILQ_REMOVE(th, t, entry); free(t); } } openbgpd-8.8/src/bgpd/rde_peer.c100644 001750 001750 00000041203 14751151130 0012323/* $OpenBSD: rde_peer.c,v 1.46 2025/01/27 15:22:11 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgpd.h" #include "rde.h" struct peer_tree peertable = RB_INITIALIZER(&peertable); struct peer_tree zombietable = RB_INITIALIZER(&zombietable); struct rde_peer *peerself; static long imsg_pending; CTASSERT(sizeof(peerself->recv_eor) * 8 >= AID_MAX); CTASSERT(sizeof(peerself->sent_eor) * 8 >= AID_MAX); struct iq { SIMPLEQ_ENTRY(iq) entry; struct imsg imsg; }; int peer_has_as4byte(struct rde_peer *peer) { return peer->capa.as4byte; } /* * Check if ADD_PATH is enabled for aid and mode (rx / tx). If aid is * AID_UNSPEC then the function returns true if any aid has mode enabled. */ int peer_has_add_path(struct rde_peer *peer, uint8_t aid, int mode) { if (aid >= AID_MAX) return 0; return peer->capa.add_path[aid] & mode; } int peer_has_ext_msg(struct rde_peer *peer) { return peer->capa.ext_msg; } int peer_has_ext_nexthop(struct rde_peer *peer, uint8_t aid) { if (aid >= AID_MAX) return 0; return peer->capa.ext_nh[aid]; } int peer_permit_as_set(struct rde_peer *peer) { return peer->flags & PEERFLAG_PERMIT_AS_SET; } void peer_init(struct filter_head *rules) { struct peer_config pc; memset(&pc, 0, sizeof(pc)); snprintf(pc.descr, sizeof(pc.descr), "LOCAL"); pc.id = PEER_ID_SELF; peerself = peer_add(PEER_ID_SELF, &pc, rules); peerself->state = PEER_UP; } void peer_shutdown(void) { struct rde_peer *peer, *np; RB_FOREACH_SAFE(peer, peer_tree, &peertable, np) peer_delete(peer); while (!RB_EMPTY(&zombietable)) peer_reaper(NULL); if (!RB_EMPTY(&peertable)) log_warnx("%s: free non-free table", __func__); } /* * Traverse all peers calling callback for each peer. */ void peer_foreach(void (*callback)(struct rde_peer *, void *), void *arg) { struct rde_peer *peer, *np; RB_FOREACH_SAFE(peer, peer_tree, &peertable, np) callback(peer, arg); } /* * Lookup a peer by peer_id, return NULL if not found. */ struct rde_peer * peer_get(uint32_t id) { struct rde_peer needle; needle.conf.id = id; return RB_FIND(peer_tree, &peertable, &needle); } /* * Find next peer that matches neighbor options in *n. * If peerid was set then pickup the lookup after that peer. * Returns NULL if no more peers match. */ struct rde_peer * peer_match(struct ctl_neighbor *n, uint32_t peerid) { struct rde_peer *peer; if (peerid != 0) { peer = peer_get(peerid); if (peer) peer = RB_NEXT(peer_tree, &peertable, peer); } else peer = RB_MIN(peer_tree, &peertable); for (; peer != NULL; peer = RB_NEXT(peer_tree, &peertable, peer)) { if (rde_match_peer(peer, n)) return peer; } return NULL; } struct rde_peer * peer_add(uint32_t id, struct peer_config *p_conf, struct filter_head *rules) { struct rde_peer *peer; int conflict; if ((peer = peer_get(id))) { memcpy(&peer->conf, p_conf, sizeof(struct peer_config)); return peer; } peer = calloc(1, sizeof(struct rde_peer)); if (peer == NULL) fatal("peer_add"); memcpy(&peer->conf, p_conf, sizeof(struct peer_config)); peer->remote_bgpid = 0; peer->loc_rib_id = rib_find(peer->conf.rib); if (peer->loc_rib_id == RIB_NOTFOUND) fatalx("King Bula's new peer met an unknown RIB"); peer->state = PEER_NONE; peer->eval = peer->conf.eval; peer->role = peer->conf.role; peer->export_type = peer->conf.export_type; peer->flags = peer->conf.flags; SIMPLEQ_INIT(&peer->imsg_queue); peer_apply_out_filter(peer, rules); /* * Assign an even random unique transmit path id. * Odd path_id_tx numbers are for peers using add-path recv. */ do { struct rde_peer *p; conflict = 0; peer->path_id_tx = arc4random() << 1; RB_FOREACH(p, peer_tree, &peertable) { if (p->path_id_tx == peer->path_id_tx) { conflict = 1; break; } } } while (conflict); if (RB_INSERT(peer_tree, &peertable, peer) != NULL) fatalx("rde peer table corrupted"); return peer; } struct filter_head * peer_apply_out_filter(struct rde_peer *peer, struct filter_head *rules) { struct filter_head *old; struct filter_rule *fr, *new; old = peer->out_rules; if ((peer->out_rules = malloc(sizeof(*peer->out_rules))) == NULL) fatal(NULL); TAILQ_INIT(peer->out_rules); TAILQ_FOREACH(fr, rules, entry) { if (rde_filter_skip_rule(peer, fr)) continue; if ((new = malloc(sizeof(*new))) == NULL) fatal(NULL); memcpy(new, fr, sizeof(*new)); filterset_copy(&fr->set, &new->set); TAILQ_INSERT_TAIL(peer->out_rules, new, entry); } return old; } static inline int peer_cmp(struct rde_peer *a, struct rde_peer *b) { if (a->conf.id > b->conf.id) return 1; if (a->conf.id < b->conf.id) return -1; return 0; } RB_GENERATE(peer_tree, rde_peer, entry, peer_cmp); static void peer_generate_update(struct rde_peer *peer, struct rib_entry *re, struct prefix *newpath, struct prefix *oldpath, enum eval_mode mode) { uint8_t aid; aid = re->prefix->aid; /* skip ourself */ if (peer == peerself) return; /* skip peers that never had a session open */ if (peer->state == PEER_NONE) return; /* skip peers using a different rib */ if (peer->loc_rib_id != re->rib_id) return; /* check if peer actually supports the address family */ if (peer->capa.mp[aid] == 0) return; /* skip peers with special export types */ if (peer->export_type == EXPORT_NONE || peer->export_type == EXPORT_DEFAULT_ROUTE) return; /* if reconf skip peers which don't need to reconfigure */ if (mode == EVAL_RECONF && peer->reconf_out == 0) return; /* handle peers with add-path */ if (peer_has_add_path(peer, aid, CAPA_AP_SEND)) { if (peer->eval.mode == ADDPATH_EVAL_ALL) up_generate_addpath_all(peer, re, newpath, oldpath); else up_generate_addpath(peer, re); return; } /* skip regular peers if the best path didn't change */ if (mode == EVAL_ALL && (peer->flags & PEERFLAG_EVALUATE_ALL) == 0) return; up_generate_updates(peer, re); } void rde_generate_updates(struct rib_entry *re, struct prefix *newpath, struct prefix *oldpath, enum eval_mode mode) { struct rde_peer *peer; RB_FOREACH(peer, peer_tree, &peertable) peer_generate_update(peer, re, newpath, oldpath, mode); } /* * Various RIB walker callbacks. */ struct peer_flush { struct rde_peer *peer; time_t staletime; }; static void peer_flush_upcall(struct rib_entry *re, void *arg) { struct rde_peer *peer = ((struct peer_flush *)arg)->peer; struct rde_aspath *asp; struct bgpd_addr addr; struct prefix *p, *np, *rp; time_t staletime = ((struct peer_flush *)arg)->staletime; uint32_t i; uint8_t prefixlen; pt_getaddr(re->prefix, &addr); prefixlen = re->prefix->prefixlen; TAILQ_FOREACH_SAFE(p, &re->prefix_h, entry.list.rib, np) { if (peer != prefix_peer(p)) continue; if (staletime && p->lastchange > staletime) continue; for (i = RIB_LOC_START; i < rib_size; i++) { struct rib *rib = rib_byid(i); if (rib == NULL) continue; rp = prefix_get(rib, peer, p->path_id, &addr, prefixlen); if (rp) { asp = prefix_aspath(rp); if (asp && asp->pftableid) rde_pftable_del(asp->pftableid, rp); prefix_destroy(rp); rde_update_log("flush", i, peer, NULL, &addr, prefixlen); } } prefix_destroy(p); peer->stats.prefix_cnt--; } } /* * Session got established, bring peer up, load RIBs do initial table dump. */ void peer_up(struct rde_peer *peer, struct session_up *sup) { uint8_t i; int force_sync = 1; if (peer->state == PEER_ERR) { /* * There is a race condition when doing PEER_ERR -> PEER_DOWN. * So just do a full reset of the peer here. */ rib_dump_terminate(peer); peer_imsg_flush(peer); peer_flush(peer, AID_UNSPEC, 0); peer->stats.prefix_cnt = 0; peer->state = PEER_DOWN; } /* * Check if no value changed during flap to decide if the RIB * is in sync. The capa check is maybe too strict but it should * not matter for normal operation. */ if (memcmp(&peer->remote_addr, &sup->remote_addr, sizeof(sup->remote_addr)) == 0 && memcmp(&peer->local_v4_addr, &sup->local_v4_addr, sizeof(sup->local_v4_addr)) == 0 && memcmp(&peer->local_v6_addr, &sup->local_v6_addr, sizeof(sup->local_v6_addr)) == 0 && memcmp(&peer->capa, &sup->capa, sizeof(sup->capa)) == 0) force_sync = 0; peer->remote_addr = sup->remote_addr; peer->local_v4_addr = sup->local_v4_addr; peer->local_v6_addr = sup->local_v6_addr; memcpy(&peer->capa, &sup->capa, sizeof(sup->capa)); /* the Adj-RIB-Out does not depend on those */ peer->remote_bgpid = sup->remote_bgpid; peer->local_if_scope = sup->if_scope; peer->short_as = sup->short_as; /* clear eor markers depending on GR flags */ if (peer->capa.grestart.restart) { peer->sent_eor = 0; peer->recv_eor = 0; } else { /* no EOR expected */ peer->sent_eor = ~0; peer->recv_eor = ~0; } peer->state = PEER_UP; if (!force_sync) { for (i = AID_MIN; i < AID_MAX; i++) { if (peer->capa.mp[i]) peer_blast(peer, i); } } else { for (i = AID_MIN; i < AID_MAX; i++) { if (peer->capa.mp[i]) peer_dump(peer, i); } } } /* * Session dropped and no graceful restart is done. Stop everything for * this peer and clean up. */ void peer_down(struct rde_peer *peer) { peer->remote_bgpid = 0; peer->state = PEER_DOWN; /* * stop all pending dumps which may depend on this peer * and flush all pending imsg from the SE. */ rib_dump_terminate(peer); prefix_adjout_flush_pending(peer); peer_imsg_flush(peer); /* flush Adj-RIB-In */ peer_flush(peer, AID_UNSPEC, 0); peer->stats.prefix_cnt = 0; } void peer_delete(struct rde_peer *peer) { if (peer->state != PEER_DOWN) peer_down(peer); /* free filters */ filterlist_free(peer->out_rules); RB_REMOVE(peer_tree, &peertable, peer); while (RB_INSERT(peer_tree, &zombietable, peer) != NULL) { log_warnx("zombie peer conflict"); peer->conf.id = arc4random(); } /* start reaping the zombie */ peer_reaper(peer); } /* * Flush all routes older then staletime. If staletime is 0 all routes will * be flushed. */ void peer_flush(struct rde_peer *peer, uint8_t aid, time_t staletime) { struct peer_flush pf = { peer, staletime }; /* this dump must run synchronous, too much depends on that right now */ if (rib_dump_new(RIB_ADJ_IN, aid, 0, &pf, peer_flush_upcall, NULL, NULL) == -1) fatal("%s: rib_dump_new", __func__); /* every route is gone so reset staletime */ if (aid == AID_UNSPEC) { uint8_t i; for (i = AID_MIN; i < AID_MAX; i++) peer->staletime[i] = 0; } else { peer->staletime[aid] = 0; } } /* * During graceful restart mark a peer as stale if the session goes down. * For the specified AID the Adj-RIB-Out is marked stale and the staletime * is set to the current timestamp for identifying stale routes in Adj-RIB-In. */ void peer_stale(struct rde_peer *peer, uint8_t aid, int flushall) { time_t now; /* flush the now even staler routes out */ if (peer->staletime[aid]) peer_flush(peer, aid, peer->staletime[aid]); peer->staletime[aid] = now = getmonotime(); peer->state = PEER_DOWN; /* * stop all pending dumps which may depend on this peer * and flush all pending imsg from the SE. */ rib_dump_terminate(peer); prefix_adjout_flush_pending(peer); peer_imsg_flush(peer); if (flushall) peer_flush(peer, aid, 0); /* make sure new prefixes start on a higher timestamp */ while (now >= getmonotime()) sleep(1); } /* * RIB walker callback for peer_blast. * Enqueue a prefix onto the update queue so it can be sent out. */ static void peer_blast_upcall(struct prefix *p, void *ptr) { if (p->flags & PREFIX_FLAG_DEAD) { /* ignore dead prefixes, they will go away soon */ } else if ((p->flags & PREFIX_FLAG_MASK) == 0) { /* put entries on the update queue if not already on a queue */ p->flags |= PREFIX_FLAG_UPDATE; if (RB_INSERT(prefix_tree, &prefix_peer(p)->updates[p->pt->aid], p) != NULL) fatalx("%s: RB tree invariant violated", __func__); } } /* * Called after all prefixes are put onto the update queue and we are * ready to blast out updates to the peer. */ static void peer_blast_done(void *ptr, uint8_t aid) { struct rde_peer *peer = ptr; /* Adj-RIB-Out ready, unthrottle peer and inject EOR */ peer->throttled = 0; if (peer->capa.grestart.restart) prefix_add_eor(peer, aid); } /* * Send out the full Adj-RIB-Out by putting all prefixes onto the update * queue. */ void peer_blast(struct rde_peer *peer, uint8_t aid) { if (peer->capa.enhanced_rr && (peer->sent_eor & (1 << aid))) rde_peer_send_rrefresh(peer, aid, ROUTE_REFRESH_BEGIN_RR); /* force out all updates from the Adj-RIB-Out */ if (prefix_dump_new(peer, aid, 0, peer, peer_blast_upcall, peer_blast_done, NULL) == -1) fatal("%s: prefix_dump_new", __func__); } /* RIB walker callbacks for peer_dump. */ static void peer_dump_upcall(struct rib_entry *re, void *ptr) { struct rde_peer *peer = ptr; struct prefix *p; if ((p = prefix_best(re)) == NULL) /* no eligible prefix, not even for 'evaluate all' */ return; peer_generate_update(peer, re, NULL, NULL, 0); } static void peer_dump_done(void *ptr, uint8_t aid) { struct rde_peer *peer = ptr; /* Adj-RIB-Out is ready, blast it out */ peer_blast(peer, aid); } /* * Load the Adj-RIB-Out of a peer normally called when a session comes up * for the first time. Once the Adj-RIB-Out is ready it will blast the * updates out. */ void peer_dump(struct rde_peer *peer, uint8_t aid) { /* throttle peer until dump is done */ peer->throttled = 1; if (peer->export_type == EXPORT_NONE) { peer_blast(peer, aid); } else if (peer->export_type == EXPORT_DEFAULT_ROUTE) { up_generate_default(peer, aid); peer_blast(peer, aid); } else if (aid == AID_FLOWSPECv4 || aid == AID_FLOWSPECv6) { prefix_flowspec_dump(aid, peer, peer_dump_upcall, peer_dump_done); } else { if (rib_dump_new(peer->loc_rib_id, aid, RDE_RUNNER_ROUNDS, peer, peer_dump_upcall, peer_dump_done, NULL) == -1) fatal("%s: rib_dump_new", __func__); } } /* * Start of an enhanced route refresh. Mark all routes as stale. * Once the route refresh ends a End of Route Refresh message is sent * which calls peer_flush() to remove all stale routes. */ void peer_begin_rrefresh(struct rde_peer *peer, uint8_t aid) { time_t now; /* flush the now even staler routes out */ if (peer->staletime[aid]) peer_flush(peer, aid, peer->staletime[aid]); peer->staletime[aid] = now = getmonotime(); /* make sure new prefixes start on a higher timestamp */ while (now >= getmonotime()) sleep(1); } void peer_reaper(struct rde_peer *peer) { if (peer == NULL) peer = RB_ROOT(&zombietable); if (peer == NULL) return; if (!prefix_adjout_reaper(peer)) return; RB_REMOVE(peer_tree, &zombietable, peer); free(peer); } /* * Check if any imsg are pending or any zombie peers are around. * Return 0 if no work is pending. */ int peer_work_pending(void) { if (!RB_EMPTY(&zombietable)) return 1; return imsg_pending != 0; } /* * move an imsg from src to dst, disconnecting any dynamic memory from src. */ static void imsg_move(struct imsg *dst, struct imsg *src) { *dst = *src; memset(src, 0, sizeof(*src)); } /* * push an imsg onto the peer imsg queue. */ void peer_imsg_push(struct rde_peer *peer, struct imsg *imsg) { struct iq *iq; if ((iq = calloc(1, sizeof(*iq))) == NULL) fatal(NULL); imsg_move(&iq->imsg, imsg); SIMPLEQ_INSERT_TAIL(&peer->imsg_queue, iq, entry); imsg_pending++; } /* * pop first imsg from peer imsg queue and move it into imsg argument. * Returns 1 if an element is returned else 0. */ int peer_imsg_pop(struct rde_peer *peer, struct imsg *imsg) { struct iq *iq; iq = SIMPLEQ_FIRST(&peer->imsg_queue); if (iq == NULL) return 0; imsg_move(imsg, &iq->imsg); SIMPLEQ_REMOVE_HEAD(&peer->imsg_queue, entry); free(iq); imsg_pending--; return 1; } /* * flush all imsg queued for a peer. */ void peer_imsg_flush(struct rde_peer *peer) { struct iq *iq; while ((iq = SIMPLEQ_FIRST(&peer->imsg_queue)) != NULL) { SIMPLEQ_REMOVE_HEAD(&peer->imsg_queue, entry); free(iq); imsg_pending--; } } openbgpd-8.8/src/bgpd/rtr.c100644 001750 001750 00000032376 14730105010 0011351/* $OpenBSD: rtr.c,v 1.29 2024/12/02 15:13:57 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" static void rtr_dispatch_imsg_parent(struct imsgbuf *); static void rtr_dispatch_imsg_rde(struct imsgbuf *); volatile sig_atomic_t rtr_quit; static struct imsgbuf *ibuf_main; static struct imsgbuf *ibuf_rde; static struct bgpd_config *conf, *nconf; static struct timer_head expire_timer; static int rtr_recalc_semaphore; static void rtr_sighdlr(int sig) { switch (sig) { case SIGINT: case SIGTERM: rtr_quit = 1; break; } } #define PFD_PIPE_MAIN 0 #define PFD_PIPE_RDE 1 #define PFD_PIPE_COUNT 2 #define EXPIRE_TIMEOUT 300 void rtr_sem_acquire(int cnt) { rtr_recalc_semaphore += cnt; } void rtr_sem_release(int cnt) { rtr_recalc_semaphore -= cnt; if (rtr_recalc_semaphore < 0) fatalx("rtr recalc semaphore underflow"); } /* * Every EXPIRE_TIMEOUT seconds traverse the static roa-set table and expire * all elements where the expires timestamp is smaller or equal to now. * If any change is done recalculate the RTR table. */ static unsigned int rtr_expire_roas(time_t now) { struct roa *roa, *nr; unsigned int recalc = 0; RB_FOREACH_SAFE(roa, roa_tree, &conf->roa, nr) { if (roa->expires != 0 && roa->expires <= now) { recalc++; RB_REMOVE(roa_tree, &conf->roa, roa); free(roa); } } if (recalc != 0) log_info("%u roa-set entries expired", recalc); return recalc; } static unsigned int rtr_expire_aspa(time_t now) { struct aspa_set *aspa, *na; unsigned int recalc = 0; RB_FOREACH_SAFE(aspa, aspa_tree, &conf->aspa, na) { if (aspa->expires != 0 && aspa->expires <= now) { recalc++; RB_REMOVE(aspa_tree, &conf->aspa, aspa); free_aspa(aspa); } } if (recalc != 0) log_info("%u aspa-set entries expired", recalc); return recalc; } void rtr_roa_insert(struct roa_tree *rt, struct roa *in) { struct roa *roa; if ((roa = malloc(sizeof(*roa))) == NULL) fatal("roa alloc"); memcpy(roa, in, sizeof(*roa)); if (RB_INSERT(roa_tree, rt, roa) != NULL) /* just ignore duplicates */ free(roa); } /* * Add an asnum to the aspa_set. The aspa_set is sorted by asnum. */ static void aspa_set_entry(struct aspa_set *aspa, uint32_t asnum) { uint32_t i, num, *newtas; for (i = 0; i < aspa->num; i++) { if (asnum < aspa->tas[i]) break; if (asnum == aspa->tas[i]) return; } num = aspa->num + 1; newtas = reallocarray(aspa->tas, num, sizeof(uint32_t)); if (newtas == NULL) fatal("aspa_set merge"); if (i < aspa->num) { memmove(newtas + i + 1, newtas + i, (aspa->num - i) * sizeof(uint32_t)); } newtas[i] = asnum; aspa->num = num; aspa->tas = newtas; } /* * Insert and merge an aspa_set into the aspa_tree at. */ void rtr_aspa_insert(struct aspa_tree *at, struct aspa_set *mergeset) { struct aspa_set *aspa, needle = { .as = mergeset->as }; uint32_t i; aspa = RB_FIND(aspa_tree, at, &needle); if (aspa == NULL) { if ((aspa = calloc(1, sizeof(*aspa))) == NULL) fatal("aspa insert"); aspa->as = mergeset->as; RB_INSERT(aspa_tree, at, aspa); } for (i = 0; i < mergeset->num; i++) aspa_set_entry(aspa, mergeset->tas[i]); } void rtr_main(int debug, int verbose) { struct passwd *pw; struct pollfd *pfd = NULL; void *newp; size_t pfd_elms = 0, i; time_t timeout; log_init(debug, LOG_DAEMON); log_setverbose(verbose); log_procinit(log_procnames[PROC_RTR]); if ((pw = getpwnam(BGPD_USER)) == NULL) fatal("getpwnam"); if (chroot(pw->pw_dir) == -1) fatal("chroot"); if (chdir("/") == -1) fatal("chdir(\"/\")"); setproctitle("rtr engine"); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) fatal("can't drop privileges"); if (pledge("stdio recvfd", NULL) == -1) fatal("pledge"); signal(SIGTERM, rtr_sighdlr); signal(SIGINT, rtr_sighdlr); signal(SIGPIPE, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGALRM, SIG_IGN); signal(SIGUSR1, SIG_IGN); if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL) fatal(NULL); if (imsgbuf_init(ibuf_main, 3) == -1 || imsgbuf_set_maxsize(ibuf_main, MAX_BGPD_IMSGSIZE) == -1) fatal(NULL); imsgbuf_allow_fdpass(ibuf_main); conf = new_config(); log_info("rtr engine ready"); TAILQ_INIT(&expire_timer); timer_set(&expire_timer, Timer_Rtr_Expire, EXPIRE_TIMEOUT); while (rtr_quit == 0) { i = rtr_count(); if (pfd_elms < PFD_PIPE_COUNT + i) { if ((newp = reallocarray(pfd, PFD_PIPE_COUNT + i, sizeof(struct pollfd))) == NULL) fatal("realloc pollfd"); pfd = newp; pfd_elms = PFD_PIPE_COUNT + i; } /* run the expire timeout every EXPIRE_TIMEOUT seconds */ timeout = timer_nextduein(&expire_timer, getmonotime()); if (timeout == -1) fatalx("roa-set expire timer no longer running"); memset(pfd, 0, sizeof(struct pollfd) * pfd_elms); set_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main); set_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde); i = PFD_PIPE_COUNT; i += rtr_poll_events(pfd + i, pfd_elms - i, &timeout); if (poll(pfd, i, timeout * 1000) == -1) { if (errno == EINTR) continue; fatal("poll error"); } if (handle_pollfd(&pfd[PFD_PIPE_MAIN], ibuf_main) == -1) fatalx("Lost connection to parent"); else rtr_dispatch_imsg_parent(ibuf_main); if (handle_pollfd(&pfd[PFD_PIPE_RDE], ibuf_rde) == -1) { log_warnx("RTR: Lost connection to RDE"); imsgbuf_clear(ibuf_rde); free(ibuf_rde); ibuf_rde = NULL; } else rtr_dispatch_imsg_rde(ibuf_rde); i = PFD_PIPE_COUNT; rtr_check_events(pfd + i, pfd_elms - i); if (timer_nextisdue(&expire_timer, getmonotime()) != NULL) { timer_set(&expire_timer, Timer_Rtr_Expire, EXPIRE_TIMEOUT); if (rtr_expire_roas(time(NULL)) != 0) rtr_recalc(); if (rtr_expire_aspa(time(NULL)) != 0) rtr_recalc(); } } rtr_shutdown(); free_config(conf); free(pfd); /* close pipes */ if (ibuf_rde) { imsgbuf_clear(ibuf_rde); close(ibuf_rde->fd); free(ibuf_rde); } imsgbuf_clear(ibuf_main); close(ibuf_main->fd); free(ibuf_main); log_info("rtr engine exiting"); exit(0); } static void rtr_dispatch_imsg_parent(struct imsgbuf *imsgbuf) { static struct aspa_set *aspa; struct imsg imsg; struct bgpd_config tconf; struct roa roa; struct rtr_config_msg rtrconf; struct rtr_session *rs; uint32_t rtrid; int n, fd; while (imsgbuf) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("%s: imsg_get error", __func__); if (n == 0) break; rtrid = imsg_get_id(&imsg); switch (imsg_get_type(&imsg)) { case IMSG_SOCKET_CONN_RTR: if ((fd = imsg_get_fd(&imsg)) == -1) { log_warnx("expected to receive imsg fd " "but didn't receive any"); break; } if (ibuf_rde) { log_warnx("Unexpected imsg ctl " "connection to RDE received"); imsgbuf_clear(ibuf_rde); free(ibuf_rde); } if ((ibuf_rde = malloc(sizeof(struct imsgbuf))) == NULL) fatal(NULL); if (imsgbuf_init(ibuf_rde, fd) == -1 || imsgbuf_set_maxsize(ibuf_rde, MAX_BGPD_IMSGSIZE) == -1) fatal(NULL); break; case IMSG_SOCKET_SETUP: if ((fd = imsg_get_fd(&imsg)) == -1) { log_warnx("expected to receive imsg fd " "but didn't receive any"); break; } if ((rs = rtr_get(rtrid)) == NULL) { log_warnx("IMSG_SOCKET_SETUP: " "unknown rtr id %d", rtrid); close(fd); break; } rtr_open(rs, fd); break; case IMSG_RECONF_CONF: if (imsg_get_data(&imsg, &tconf, sizeof(tconf)) == -1) fatal("imsg_get_data"); nconf = new_config(); copy_config(nconf, &tconf); rtr_config_prep(); break; case IMSG_RECONF_ROA_ITEM: if (imsg_get_data(&imsg, &roa, sizeof(roa)) == -1) fatal("imsg_get_data"); rtr_roa_insert(&nconf->roa, &roa); break; case IMSG_RECONF_ASPA: if (aspa != NULL) fatalx("unexpected IMSG_RECONF_ASPA"); if ((aspa = calloc(1, sizeof(*aspa))) == NULL) fatal("aspa alloc"); if (imsg_get_data(&imsg, aspa, offsetof(struct aspa_set, tas)) == -1) fatal("imsg_get_data"); break; case IMSG_RECONF_ASPA_TAS: if (aspa == NULL) fatalx("unexpected IMSG_RECONF_ASPA_TAS"); aspa->tas = reallocarray(NULL, aspa->num, sizeof(*aspa->tas)); if (aspa->tas == NULL) fatal("aspa tas alloc"); if (imsg_get_data(&imsg, aspa->tas, aspa->num * sizeof(*aspa->tas)) == -1) fatal("imsg_get_data"); break; case IMSG_RECONF_ASPA_DONE: if (aspa == NULL) fatalx("unexpected IMSG_RECONF_ASPA_DONE"); if (RB_INSERT(aspa_tree, &nconf->aspa, aspa) != NULL) { log_warnx("duplicate ASPA set received"); free_aspa(aspa); } aspa = NULL; break; case IMSG_RECONF_RTR_CONFIG: if (imsg_get_data(&imsg, &rtrconf, sizeof(rtrconf)) == -1) fatal("imsg_get_data"); rs = rtr_get(rtrid); if (rs == NULL) rtr_new(rtrid, &rtrconf); else rtr_config_keep(rs, &rtrconf); break; case IMSG_RECONF_DRAIN: imsg_compose(ibuf_main, IMSG_RECONF_DRAIN, 0, 0, -1, NULL, 0); break; case IMSG_RECONF_DONE: if (nconf == NULL) fatalx("got IMSG_RECONF_DONE but no config"); copy_config(conf, nconf); /* switch the roa, first remove the old one */ free_roatree(&conf->roa); /* then move the RB tree root */ RB_ROOT(&conf->roa) = RB_ROOT(&nconf->roa); RB_ROOT(&nconf->roa) = NULL; /* switch the aspa tree, first remove the old one */ free_aspatree(&conf->aspa); /* then move the RB tree root */ RB_ROOT(&conf->aspa) = RB_ROOT(&nconf->aspa); RB_ROOT(&nconf->aspa) = NULL; /* finally merge the rtr session */ rtr_config_merge(); rtr_expire_roas(time(NULL)); rtr_expire_aspa(time(NULL)); rtr_recalc(); log_info("RTR engine reconfigured"); imsg_compose(ibuf_main, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0); free_config(nconf); nconf = NULL; break; case IMSG_CTL_SHOW_RTR: if ((rs = rtr_get(rtrid)) == NULL) { log_warnx("IMSG_CTL_SHOW_RTR: " "unknown rtr id %d", rtrid); break; } rtr_show(rs, imsg_get_pid(&imsg)); break; case IMSG_CTL_END: imsg_compose(ibuf_main, IMSG_CTL_END, 0, imsg_get_pid(&imsg), -1, NULL, 0); break; } imsg_free(&imsg); } } static void rtr_dispatch_imsg_rde(struct imsgbuf *imsgbuf) { struct imsg imsg; int n; while (imsgbuf) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) fatal("%s: imsg_get error", __func__); if (n == 0) break; /* NOTHING */ imsg_free(&imsg); } } void rtr_imsg_compose(int type, uint32_t id, pid_t pid, void *data, size_t datalen) { imsg_compose(ibuf_main, type, id, pid, -1, data, datalen); } /* * Compress aspa_set tas_aid into the bitfield used by the RDE. * Returns the size of tas and tas_aid bitfield required for this aspa_set. * At the same time tas_aid is overwritten with the bitmasks or cleared * if no extra aid masks are needed. */ static size_t rtr_aspa_set_size(struct aspa_set *aspa) { return aspa->num * sizeof(uint32_t); } /* * Merge all RPKI ROA trees into one as one big union. * Simply try to add all roa entries into a new RB tree. * This could be made a fair bit faster but for now this is good enough. */ void rtr_recalc(void) { struct roa_tree rt; struct aspa_tree at; struct roa *roa, *nr; struct aspa_set *aspa; struct aspa_prep ap = { 0 }; if (rtr_recalc_semaphore > 0) return; RB_INIT(&rt); RB_INIT(&at); RB_FOREACH(roa, roa_tree, &conf->roa) rtr_roa_insert(&rt, roa); rtr_roa_merge(&rt); imsg_compose(ibuf_rde, IMSG_RECONF_ROA_SET, 0, 0, -1, NULL, 0); RB_FOREACH_SAFE(roa, roa_tree, &rt, nr) { imsg_compose(ibuf_rde, IMSG_RECONF_ROA_ITEM, 0, 0, -1, roa, sizeof(*roa)); } free_roatree(&rt); RB_FOREACH(aspa, aspa_tree, &conf->aspa) rtr_aspa_insert(&at, aspa); rtr_aspa_merge(&at); RB_FOREACH(aspa, aspa_tree, &at) { ap.datasize += rtr_aspa_set_size(aspa); ap.entries++; } imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_PREP, 0, 0, -1, &ap, sizeof(ap)); /* walk tree in reverse because aspa_add_set requires that */ RB_FOREACH_REVERSE(aspa, aspa_tree, &at) { struct aspa_set as = { .as = aspa->as, .num = aspa->num }; imsg_compose(ibuf_rde, IMSG_RECONF_ASPA, 0, 0, -1, &as, offsetof(struct aspa_set, tas)); imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_TAS, 0, 0, -1, aspa->tas, aspa->num * sizeof(*aspa->tas)); imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_DONE, 0, 0, -1, NULL, 0); } free_aspatree(&at); imsg_compose(ibuf_rde, IMSG_RECONF_DONE, 0, 0, -1, NULL, 0); } openbgpd-8.8/src/bgpd/rtr_proto.c100644 001750 001750 00000106455 14751151130 0012603/* $OpenBSD: rtr_proto.c,v 1.49 2025/01/25 07:23:30 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "log.h" struct rtr_header { uint8_t version; uint8_t type; union { uint16_t session_id; uint16_t errcode; struct { uint8_t flags; uint8_t zero; }; }; uint32_t length; } __packed; #define RTR_MAX_PDU_SIZE 65535 #define RTR_MAX_PDU_ERROR_SIZE 256 #define RTR_DEFAULT_REFRESH 3600 #define RTR_DEFAULT_RETRY 600 #define RTR_DEFAULT_EXPIRE 7200 #define RTR_DEFAULT_ACTIVE 60 enum rtr_pdu_type { SERIAL_NOTIFY = 0, SERIAL_QUERY, RESET_QUERY, CACHE_RESPONSE, IPV4_PREFIX, IPV6_PREFIX = 6, END_OF_DATA = 7, CACHE_RESET = 8, ROUTER_KEY = 9, ERROR_REPORT = 10, ASPA = 11, }; struct rtr_notify { struct rtr_header hdr; uint32_t serial; } __packed; struct rtr_query { struct rtr_header hdr; uint32_t serial; } __packed; struct rtr_reset { struct rtr_header hdr; } __packed; struct rtr_response { struct rtr_header hdr; } __packed; #define FLAG_ANNOUNCE 0x1 #define FLAG_MASK FLAG_ANNOUNCE struct rtr_ipv4 { struct rtr_header hdr; uint8_t flags; uint8_t prefixlen; uint8_t maxlen; uint8_t zero; uint32_t prefix; uint32_t asnum; } __packed; struct rtr_ipv6 { struct rtr_header hdr; uint8_t flags; uint8_t prefixlen; uint8_t maxlen; uint8_t zero; uint32_t prefix[4]; uint32_t asnum; } __packed; struct rtr_routerkey { struct rtr_header hdr; uint8_t ski[20]; uint32_t asnum; /* followed by Subject Public Key Info */ } __packed; struct rtr_aspa { struct rtr_header hdr; uint32_t cas; /* array of spas filling the rest of the packet */ } __packed; struct rtr_endofdata { struct rtr_header hdr; uint32_t serial; uint32_t refresh; uint32_t retry; uint32_t expire; } __packed; struct rtr_endofdata_v0 { struct rtr_header hdr; uint32_t serial; } __packed; enum rtr_event { RTR_EVNT_START, RTR_EVNT_CON_OPEN, RTR_EVNT_CON_CLOSE, RTR_EVNT_TIMER_REFRESH, RTR_EVNT_TIMER_RETRY, RTR_EVNT_TIMER_EXPIRE, RTR_EVNT_TIMER_ACTIVE, RTR_EVNT_SEND_ERROR, RTR_EVNT_SERIAL_NOTIFY, RTR_EVNT_CACHE_RESPONSE, RTR_EVNT_END_OF_DATA, RTR_EVNT_CACHE_RESET, RTR_EVNT_NO_DATA, RTR_EVNT_RESET_AND_CLOSE, RTR_EVNT_UNSUPP_PROTO_VERSION, RTR_EVNT_NEGOTIATION_DONE, }; static const char *rtr_eventnames[] = { "start", "connection open", "connection closed", "refresh timer expired", "retry timer expired", "expire timer expired", "activity timer expired", "sent error", "serial notify received", "cache response received", "end of data received", "cache reset received", "no data", "connection closed with reset", "unsupported protocol version", "negotiation done", }; enum rtr_state { RTR_STATE_CLOSED, RTR_STATE_ERROR, /* sessions with a state below this line will poll for incoming data */ RTR_STATE_ESTABLISHED, RTR_STATE_EXCHANGE, RTR_STATE_NEGOTIATION, }; static const char *rtr_statenames[] = { "closed", "error", "established", "exchange", "negotiation", }; struct rtr_session { TAILQ_ENTRY(rtr_session) entry; char descr[PEER_DESCR_LEN]; struct roa_tree roa_set; struct aspa_tree aspa; struct timer_head timers; struct msgbuf *w; uint32_t id; /* rtr_config id */ uint32_t serial; uint32_t refresh; uint32_t retry; uint32_t expire; uint32_t active; int session_id; int fd; int active_lock; enum rtr_state state; enum reconf_action reconf_action; enum rtr_error last_sent_error; enum rtr_error last_recv_error; char last_sent_msg[REASON_LEN]; char last_recv_msg[REASON_LEN]; uint8_t version; uint8_t prev_version; uint8_t min_version; uint8_t errored; }; TAILQ_HEAD(, rtr_session) rtrs = TAILQ_HEAD_INITIALIZER(rtrs); static void rtr_fsm(struct rtr_session *, enum rtr_event); static const char * log_rtr(struct rtr_session *rs) { return rs->descr; } static const char * log_rtr_type(enum rtr_pdu_type type) { static char buf[20]; switch (type) { case SERIAL_NOTIFY: return "serial notify"; case SERIAL_QUERY: return "serial query"; case RESET_QUERY: return "reset query"; case CACHE_RESPONSE: return "cache response"; case IPV4_PREFIX: return "IPv4 prefix"; case IPV6_PREFIX: return "IPv6 prefix"; case END_OF_DATA: return "end of data"; case CACHE_RESET: return "cache reset"; case ROUTER_KEY: return "router key"; case ERROR_REPORT: return "error report"; case ASPA: return "aspa"; default: snprintf(buf, sizeof(buf), "unknown %u", type); return buf; } }; static uint8_t rtr_max_session_version(struct rtr_session *rs) { if (rs->min_version > RTR_DEFAULT_VERSION) return rs->min_version; return RTR_DEFAULT_VERSION; } static void rtr_reset_cache(struct rtr_session *rs) { /* reset session */ rs->session_id = -1; timer_stop(&rs->timers, Timer_Rtr_Expire); free_roatree(&rs->roa_set); free_aspatree(&rs->aspa); } static struct ibuf * rtr_newmsg(struct rtr_session *rs, enum rtr_pdu_type type, uint32_t len, uint16_t session_id) { struct ibuf *buf; int saved_errno; if (len > RTR_MAX_PDU_SIZE) { errno = ERANGE; return NULL; } len += sizeof(struct rtr_header); if ((buf = ibuf_open(len)) == NULL) goto fail; if (ibuf_add_n8(buf, rs->version) == -1) goto fail; if (ibuf_add_n8(buf, type) == -1) goto fail; if (ibuf_add_n16(buf, session_id) == -1) goto fail; if (ibuf_add_n32(buf, len) == -1) goto fail; return buf; fail: saved_errno = errno; ibuf_free(buf); errno = saved_errno; return NULL; } static void rtr_send_error(struct rtr_session *, struct ibuf *, enum rtr_error, const char *, ...) __attribute__((__format__ (printf, 4, 5))); /* * Try to send an error PDU to cache, put connection into error * state. */ static void rtr_send_error(struct rtr_session *rs, struct ibuf *pdu, enum rtr_error err, const char *fmt, ...) { struct ibuf *buf; va_list ap; size_t len = 0, mlen = 0; rs->last_sent_error = err; memset(rs->last_sent_msg, 0, sizeof(rs->last_sent_msg)); if (fmt != NULL) { va_start(ap, fmt); vsnprintf(rs->last_sent_msg, sizeof(rs->last_sent_msg), fmt, ap); mlen = strlen(rs->last_sent_msg); va_end(ap); } log_warnx("rtr %s: sending error: %s%s%s", log_rtr(rs), log_rtr_error(err), mlen > 0 ? ": " : "", rs->last_sent_msg); if (pdu != NULL) { ibuf_rewind(pdu); len = ibuf_size(pdu); if (len > RTR_MAX_PDU_ERROR_SIZE) { len = RTR_MAX_PDU_ERROR_SIZE; /* truncate down can not fail */ ibuf_truncate(pdu, RTR_MAX_PDU_ERROR_SIZE); } } buf = rtr_newmsg(rs, ERROR_REPORT, 2 * sizeof(uint32_t) + len + mlen, err); if (buf == NULL) goto fail; if (ibuf_add_n32(buf, len) == -1) goto fail; if (pdu != NULL) { if (ibuf_add_ibuf(buf, pdu) == -1) goto fail; } if (ibuf_add_n32(buf, mlen) == -1) goto fail; if (ibuf_add(buf, rs->last_sent_msg, mlen) == -1) goto fail; ibuf_close(rs->w, buf); rtr_fsm(rs, RTR_EVNT_SEND_ERROR); return; fail: log_warn("rtr %s: send error report", log_rtr(rs)); ibuf_free(buf); } static void rtr_send_reset_query(struct rtr_session *rs) { struct ibuf *buf; buf = rtr_newmsg(rs, RESET_QUERY, 0, 0); if (buf == NULL) goto fail; ibuf_close(rs->w, buf); return; fail: rtr_send_error(rs, NULL, INTERNAL_ERROR, "send %s: %s", log_rtr_type(RESET_QUERY), strerror(errno)); ibuf_free(buf); } static void rtr_send_serial_query(struct rtr_session *rs) { struct ibuf *buf; buf = rtr_newmsg(rs, SERIAL_QUERY, sizeof(uint32_t), rs->session_id); if (buf == NULL) goto fail; if (ibuf_add_n32(buf, rs->serial) == -1) goto fail; ibuf_close(rs->w, buf); return; fail: rtr_send_error(rs, NULL, INTERNAL_ERROR, "send %s: %s", log_rtr_type(SERIAL_QUERY), strerror(errno)); ibuf_free(buf); } /* * Check the session_id of the rtr_header to match the expected value. * Returns -1 on failure and 0 on success. */ static int rtr_check_session_id(struct rtr_session *rs, uint16_t session_id, struct rtr_header *rh, struct ibuf *pdu) { if (session_id != ntohs(rh->session_id)) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad session_id %d (expected %d)", log_rtr_type(rh->type), ntohs(rh->session_id), session_id); return -1; } return 0; } /* * Callback for ibuf_read to get the size of a PDU. */ static struct ibuf * rtr_reader_callback(struct ibuf *hdr, void *arg, int *fd) { struct rtr_session *rs = arg; struct rtr_header rh; struct ibuf *b; ssize_t len; if (ibuf_get(hdr, &rh, sizeof(rh)) == -1) return NULL; len = ntohl(rh.length); if (len > RTR_MAX_PDU_SIZE) { rtr_send_error(rs, hdr, CORRUPT_DATA, "%s: too big: %zu bytes", log_rtr_type(rh.type), len); errno = ERANGE; return NULL; } if ((b = ibuf_open(len)) == NULL) return NULL; return b; } /* * Parse the common rtr header (first 8 bytes) including the * included length field. * Returns -1 on failure. On success msgtype and msglen are set * and the function return 0. */ static int rtr_parse_header(struct rtr_session *rs, struct ibuf *msg, enum rtr_pdu_type *msgtype) { struct rtr_header rh; struct ibuf hdr; size_t len; uint16_t errcode; len = ibuf_size(msg); ibuf_from_ibuf(&hdr, msg); if (ibuf_get(&hdr, &rh, sizeof(rh)) == -1) fatal("%s: ibuf_get", __func__); if (rs->state == RTR_STATE_NEGOTIATION) { switch (rh.type) { case CACHE_RESPONSE: case CACHE_RESET: /* implicit downgrade */ if (rh.version < rs->version) { rs->prev_version = rs->version; rs->version = rh.version; } rtr_fsm(rs, RTR_EVNT_NEGOTIATION_DONE); break; case ERROR_REPORT: errcode = ntohs(rh.session_id); if (errcode == UNSUPP_PROTOCOL_VERS || errcode == NO_DATA_AVAILABLE) { if (rh.version < rs->version) { rs->prev_version = rs->version; rs->version = rh.version; } } break; case SERIAL_NOTIFY: /* ignore SERIAL_NOTIFY */ break; default: rtr_send_error(rs, msg, CORRUPT_DATA, "%s: out of context", log_rtr_type(rh.type)); return -1; } } else if (rh.version != rs->version && rh.type != ERROR_REPORT) { goto badversion; } switch (rh.type) { case SERIAL_NOTIFY: if (len != sizeof(struct rtr_notify)) goto badlen; break; case CACHE_RESPONSE: if (len != sizeof(struct rtr_response)) goto badlen; break; case IPV4_PREFIX: if (len != sizeof(struct rtr_ipv4)) goto badlen; break; case IPV6_PREFIX: if (len != sizeof(struct rtr_ipv6)) goto badlen; break; case END_OF_DATA: if (rs->version == 0) { if (len != sizeof(struct rtr_endofdata_v0)) goto badlen; } else { if (len != sizeof(struct rtr_endofdata)) goto badlen; } break; case CACHE_RESET: if (len != sizeof(struct rtr_reset)) goto badlen; break; case ROUTER_KEY: if (rs->version < 1) goto badversion; if (len < sizeof(struct rtr_routerkey)) goto badlen; break; case ERROR_REPORT: if (len < 16) goto badlen; break; case ASPA: if (rs->version < 2) goto badversion; if (len < sizeof(struct rtr_aspa) || (len % 4) != 0) goto badlen; break; default: rtr_send_error(rs, msg, UNSUPP_PDU_TYPE, "type %s", log_rtr_type(rh.type)); return -1; } *msgtype = rh.type; return 0; badlen: rtr_send_error(rs, msg, CORRUPT_DATA, "%s: bad length: %zu bytes", log_rtr_type(rh.type), len); return -1; badversion: rtr_send_error(rs, msg, UNEXP_PROTOCOL_VERS, "%s: version %d", log_rtr_type(rh.type), rh.version); return -1; } static int rtr_parse_notify(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_notify notify; /* ignore SERIAL_NOTIFY during startup */ if (rs->state == RTR_STATE_NEGOTIATION) return 0; if (ibuf_get(pdu, ¬ify, sizeof(notify)) == -1) goto badlen; /* set session_id if not yet happened */ if (rs->session_id == -1) rs->session_id = ntohs(notify.hdr.session_id); if (rtr_check_session_id(rs, rs->session_id, ¬ify.hdr, pdu) == -1) return -1; if (rs->state != RTR_STATE_ESTABLISHED) { log_warnx("rtr %s: received %s: while in state %s (ignored)", log_rtr(rs), log_rtr_type(SERIAL_NOTIFY), rtr_statenames[rs->state]); return 0; } rtr_fsm(rs, RTR_EVNT_SERIAL_NOTIFY); return 0; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(SERIAL_NOTIFY)); return -1; } static int rtr_parse_cache_response(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_response resp; if (ibuf_get(pdu, &resp, sizeof(resp)) == -1) goto badlen; /* set session_id if not yet happened */ if (rs->session_id == -1) rs->session_id = ntohs(resp.hdr.session_id); if (rtr_check_session_id(rs, rs->session_id, &resp.hdr, pdu) == -1) return -1; if (rs->state != RTR_STATE_ESTABLISHED) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: out of context", log_rtr_type(CACHE_RESPONSE)); return -1; } rtr_fsm(rs, RTR_EVNT_CACHE_RESPONSE); return 0; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(CACHE_RESPONSE)); return -1; } static int rtr_parse_ipv4_prefix(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_ipv4 ip4; struct roa *roa; if (ibuf_get(pdu, &ip4, sizeof(ip4)) == -1) goto badlen; if (rtr_check_session_id(rs, 0, &ip4.hdr, pdu) == -1) return -1; if (rs->state != RTR_STATE_EXCHANGE) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: out of context", log_rtr_type(IPV4_PREFIX)); return -1; } if (ip4.prefixlen > 32 || ip4.maxlen > 32 || ip4.prefixlen > ip4.maxlen) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad prefixlen / maxlen", log_rtr_type(IPV4_PREFIX)); return -1; } if ((roa = calloc(1, sizeof(*roa))) == NULL) { rtr_send_error(rs, NULL, INTERNAL_ERROR, "out of memory"); return -1; } roa->aid = AID_INET; roa->prefixlen = ip4.prefixlen; roa->maxlen = ip4.maxlen; roa->asnum = ntohl(ip4.asnum); roa->prefix.inet.s_addr = ip4.prefix; if (ip4.flags & FLAG_ANNOUNCE) { if (RB_INSERT(roa_tree, &rs->roa_set, roa) != NULL) { rtr_send_error(rs, pdu, DUP_REC_RECV, "%s %s", log_rtr_type(IPV4_PREFIX), log_roa(roa)); free(roa); return -1; } } else { struct roa *r; r = RB_FIND(roa_tree, &rs->roa_set, roa); if (r == NULL) { rtr_send_error(rs, pdu, UNK_REC_WDRAWL, "%s %s", log_rtr_type(IPV4_PREFIX), log_roa(roa)); free(roa); return -1; } RB_REMOVE(roa_tree, &rs->roa_set, r); free(r); free(roa); } return 0; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(IPV4_PREFIX)); return -1; } static int rtr_parse_ipv6_prefix(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_ipv6 ip6; struct roa *roa; if (ibuf_get(pdu, &ip6, sizeof(ip6)) == -1) goto badlen; if (rtr_check_session_id(rs, 0, &ip6.hdr, pdu) == -1) return -1; if (rs->state != RTR_STATE_EXCHANGE) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: out of context", log_rtr_type(IPV6_PREFIX)); return -1; } if (ip6.prefixlen > 128 || ip6.maxlen > 128 || ip6.prefixlen > ip6.maxlen) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad prefixlen / maxlen", log_rtr_type(IPV6_PREFIX)); return -1; } if ((roa = calloc(1, sizeof(*roa))) == NULL) { rtr_send_error(rs, NULL, INTERNAL_ERROR, "out of memory"); return -1; } roa->aid = AID_INET6; roa->prefixlen = ip6.prefixlen; roa->maxlen = ip6.maxlen; roa->asnum = ntohl(ip6.asnum); memcpy(&roa->prefix.inet6, ip6.prefix, sizeof(roa->prefix.inet6)); if (ip6.flags & FLAG_ANNOUNCE) { if (RB_INSERT(roa_tree, &rs->roa_set, roa) != NULL) { rtr_send_error(rs, pdu, DUP_REC_RECV, "%s %s", log_rtr_type(IPV6_PREFIX), log_roa(roa)); free(roa); return -1; } } else { struct roa *r; r = RB_FIND(roa_tree, &rs->roa_set, roa); if (r == NULL) { rtr_send_error(rs, pdu, UNK_REC_WDRAWL, "%s %s", log_rtr_type(IPV6_PREFIX), log_roa(roa)); free(roa); return -1; } RB_REMOVE(roa_tree, &rs->roa_set, r); free(r); free(roa); } return 0; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(IPV6_PREFIX)); return -1; } static int rtr_parse_aspa(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_aspa rtr_aspa; struct aspa_set *aspa, *a; uint32_t cnt, i; uint8_t flags; if (ibuf_get(pdu, &rtr_aspa, sizeof(rtr_aspa)) == -1) goto badlen; flags = rtr_aspa.hdr.flags; cnt = ibuf_size(pdu) / sizeof(uint32_t); if ((flags & FLAG_ANNOUNCE) && cnt == 0) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: " "announce with empty SPAS", log_rtr_type(ASPA)); return -1; } if ((flags & FLAG_ANNOUNCE) == 0 && cnt != 0) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: " "withdraw with non-empty SPAS", log_rtr_type(ASPA)); return -1; } if (rs->state != RTR_STATE_EXCHANGE) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: out of context", log_rtr_type(ASPA)); return -1; } /* treat ASPA records with too many SPAS like a withdraw */ if (cnt > MAX_ASPA_SPAS_COUNT) { struct aspa_set needle = { 0 }; needle.as = ntohl(rtr_aspa.cas); log_warnx("rtr %s: oversized ASPA PDU: " "imlicit withdraw of customerAS %s", log_rtr(rs), log_as(needle.as)); a = RB_FIND(aspa_tree, &rs->aspa, &needle); if (a != NULL) { RB_REMOVE(aspa_tree, &rs->aspa, a); free_aspa(a); } return 0; } /* create aspa_set entry from the rtr aspa pdu */ if ((aspa = calloc(1, sizeof(*aspa))) == NULL) { rtr_send_error(rs, NULL, INTERNAL_ERROR, "out of memory"); return -1; } aspa->as = ntohl(rtr_aspa.cas); aspa->num = cnt; if (cnt > 0) { if ((aspa->tas = calloc(cnt, sizeof(uint32_t))) == NULL) { free_aspa(aspa); rtr_send_error(rs, NULL, INTERNAL_ERROR, "out of memory"); return -1; } for (i = 0; i < cnt; i++) { if (ibuf_get_n32(pdu, &aspa->tas[i]) == -1) { free_aspa(aspa); goto badlen; } } } if (flags & FLAG_ANNOUNCE) { a = RB_INSERT(aspa_tree, &rs->aspa, aspa); if (a != NULL) { RB_REMOVE(aspa_tree, &rs->aspa, a); free_aspa(a); if (RB_INSERT(aspa_tree, &rs->aspa, aspa) != NULL) { rtr_send_error(rs, NULL, INTERNAL_ERROR, "corrupt aspa tree"); free_aspa(aspa); return -1; } } } else { a = RB_FIND(aspa_tree, &rs->aspa, aspa); if (a == NULL) { rtr_send_error(rs, pdu, UNK_REC_WDRAWL, "%s %s", log_rtr_type(ASPA), log_aspa(aspa)); free_aspa(aspa); return -1; } RB_REMOVE(aspa_tree, &rs->aspa, a); free_aspa(a); free_aspa(aspa); } return 0; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(ASPA)); return -1; } static int rtr_parse_end_of_data_v0(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_endofdata_v0 eod; if (ibuf_get(pdu, &eod, sizeof(eod)) == -1) goto badlen; if (rtr_check_session_id(rs, rs->session_id, &eod.hdr, pdu) == -1) return -1; if (rs->state != RTR_STATE_EXCHANGE) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: out of context", log_rtr_type(END_OF_DATA)); return -1; } rs->serial = ntohl(eod.serial); rtr_fsm(rs, RTR_EVNT_END_OF_DATA); return 0; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(END_OF_DATA)); return -1; } static int rtr_parse_end_of_data(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_endofdata eod; uint32_t t; /* version 0 does not have the timing values */ if (rs->version == 0) return rtr_parse_end_of_data_v0(rs, pdu); if (ibuf_get(pdu, &eod, sizeof(eod)) == -1) goto badlen; if (rtr_check_session_id(rs, rs->session_id, &eod.hdr, pdu) == -1) return -1; if (rs->state != RTR_STATE_EXCHANGE) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: out of context", log_rtr_type(END_OF_DATA)); return -1; } rs->serial = ntohl(eod.serial); /* validate timer values to be in the right range */ t = ntohl(eod.refresh); if (t < 1 || t > 86400) goto bad; rs->refresh = t; t = ntohl(eod.retry); if (t < 1 || t > 7200) goto bad; rs->retry = t; t = ntohl(eod.expire); if (t < 600 || t > 172800) goto bad; if (t <= rs->retry || t <= rs->refresh) goto bad; rs->expire = t; rtr_fsm(rs, RTR_EVNT_END_OF_DATA); return 0; bad: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad timeout values", log_rtr_type(END_OF_DATA)); return -1; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(END_OF_DATA)); return -1; } static int rtr_parse_cache_reset(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_reset reset; if (ibuf_get(pdu, &reset, sizeof(reset)) == -1) goto badlen; if (rtr_check_session_id(rs, 0, &reset.hdr, pdu) == -1) return -1; if (rs->state != RTR_STATE_ESTABLISHED) { rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: out of context", log_rtr_type(CACHE_RESET)); return -1; } rtr_fsm(rs, RTR_EVNT_CACHE_RESET); return 0; badlen: rtr_send_error(rs, pdu, CORRUPT_DATA, "%s: bad length", log_rtr_type(CACHE_RESET)); return -1; } /* * Parse an Error Response message. This function behaves a bit different * from other parse functions since on error the connection needs to be * dropped without sending an error response back. */ static int rtr_parse_error(struct rtr_session *rs, struct ibuf *pdu) { struct rtr_header rh; struct ibuf err_pdu; uint32_t pdu_len, msg_len; char *str = NULL; uint16_t errcode; int rv = -1; if (ibuf_get(pdu, &rh, sizeof(rh)) == -1) goto fail; errcode = ntohs(rh.errcode); if (ibuf_get_n32(pdu, &pdu_len) == -1) goto fail; /* for now just ignore the embedded pdu */ if (ibuf_get_ibuf(pdu, pdu_len, &err_pdu) == -1) goto fail; if (ibuf_get_n32(pdu, &msg_len) == -1) goto fail; /* optional error msg */ if (msg_len != 0) if ((str = ibuf_get_string(pdu, msg_len)) == NULL) goto fail; log_warnx("rtr %s: received error: %s%s%s", log_rtr(rs), log_rtr_error(errcode), str ? ": " : "", str ? str : ""); if (errcode == NO_DATA_AVAILABLE) { rtr_fsm(rs, RTR_EVNT_NO_DATA); rv = 0; } else if (errcode == UNSUPP_PROTOCOL_VERS) { rtr_fsm(rs, RTR_EVNT_UNSUPP_PROTO_VERSION); rv = 0; } else rtr_fsm(rs, RTR_EVNT_RESET_AND_CLOSE); rs->last_recv_error = errcode; if (str) strlcpy(rs->last_recv_msg, str, sizeof(rs->last_recv_msg)); else memset(rs->last_recv_msg, 0, sizeof(rs->last_recv_msg)); free(str); return rv; fail: log_warnx("rtr %s: received %s: bad encoding", log_rtr(rs), log_rtr_type(ERROR_REPORT)); rtr_fsm(rs, RTR_EVNT_RESET_AND_CLOSE); return -1; } /* * Try to process received rtr message, it is possible that not a full * message is in the buffer. In that case stop, once new data is available * a retry will be done. */ static void rtr_process_msg(struct rtr_session *rs, struct ibuf *msg) { enum rtr_pdu_type msgtype; /* parse and check header */ if (rtr_parse_header(rs, msg, &msgtype) == -1) return; switch (msgtype) { case SERIAL_NOTIFY: if (rtr_parse_notify(rs, msg) == -1) return; break; case CACHE_RESPONSE: if (rtr_parse_cache_response(rs, msg) == -1) return; break; case IPV4_PREFIX: if (rtr_parse_ipv4_prefix(rs, msg) == -1) return; break; case IPV6_PREFIX: if (rtr_parse_ipv6_prefix(rs, msg) == -1) return; break; case END_OF_DATA: if (rtr_parse_end_of_data(rs, msg) == -1) return; break; case CACHE_RESET: if (rtr_parse_cache_reset(rs, msg) == -1) return; break; case ROUTER_KEY: /* silently ignore router key */ break; case ERROR_REPORT: if (rtr_parse_error(rs, msg) == -1) { /* no need to send back an error */ return; } break; case ASPA: if (rtr_parse_aspa(rs, msg) == -1) return; break; default: /* unreachable, checked in rtr_parse_header() */ rtr_send_error(rs, msg, UNSUPP_PDU_TYPE, "type %s", log_rtr_type(msgtype)); return; } } /* * Simple FSM for RTR sessions */ static void rtr_fsm(struct rtr_session *rs, enum rtr_event event) { enum rtr_state prev_state = rs->state; switch (event) { case RTR_EVNT_UNSUPP_PROTO_VERSION: if (rs->prev_version == rs->version || rs->version < rs->min_version) { /* * Can't downgrade anymore, fail connection. * RFC requires sending the error with the * highest supported version number. */ rs->version = rtr_max_session_version(rs); rtr_send_error(rs, NULL, UNSUPP_PROTOCOL_VERS, "negotiation failed"); return; } /* try again with new version */ if (rs->session_id == -1) rtr_send_reset_query(rs); else rtr_send_serial_query(rs); break; case RTR_EVNT_RESET_AND_CLOSE: rtr_reset_cache(rs); rtr_recalc(); /* FALLTHROUGH */ case RTR_EVNT_CON_CLOSE: if (rs->fd != -1) { /* flush buffers */ msgbuf_clear(rs->w); close(rs->fd); rs->fd = -1; rtr_imsg_compose(IMSG_SOCKET_TEARDOWN, rs->id, 0, NULL, 0); } /* try to reopen session */ if (!rs->errored) timer_set(&rs->timers, Timer_Rtr_Retry, arc4random_uniform(10)); else timer_set(&rs->timers, Timer_Rtr_Retry, rs->retry); rs->errored = 1; /* * A close event during version negotiation needs to remain * in the negotiation state else the same error will happen * over and over again. The RFC is utterly underspecified * and some RTR caches close the connection after sending * the error PDU. */ if (rs->state != RTR_STATE_NEGOTIATION) rs->state = RTR_STATE_CLOSED; break; case RTR_EVNT_START: case RTR_EVNT_TIMER_RETRY: switch (rs->state) { case RTR_STATE_ERROR: rtr_fsm(rs, RTR_EVNT_CON_CLOSE); break; case RTR_STATE_CLOSED: case RTR_STATE_NEGOTIATION: timer_set(&rs->timers, Timer_Rtr_Retry, rs->retry); rtr_imsg_compose(IMSG_SOCKET_SETUP, rs->id, 0, NULL, 0); break; case RTR_STATE_ESTABLISHED: if (rs->session_id == -1) rtr_send_reset_query(rs); else rtr_send_serial_query(rs); default: break; } break; case RTR_EVNT_CON_OPEN: timer_stop(&rs->timers, Timer_Rtr_Retry); rs->state = RTR_STATE_NEGOTIATION; if (rs->session_id == -1) rtr_send_reset_query(rs); else rtr_send_serial_query(rs); break; case RTR_EVNT_SERIAL_NOTIFY: /* schedule a refresh after a quick wait */ timer_set(&rs->timers, Timer_Rtr_Refresh, arc4random_uniform(10)); break; case RTR_EVNT_TIMER_REFRESH: rtr_send_serial_query(rs); break; case RTR_EVNT_TIMER_EXPIRE: rtr_reset_cache(rs); rtr_recalc(); break; case RTR_EVNT_TIMER_ACTIVE: log_warnx("rtr %s: activity timer fired", log_rtr(rs)); rtr_sem_release(rs->active_lock); rtr_recalc(); rs->active_lock = 0; break; case RTR_EVNT_CACHE_RESPONSE: rs->state = RTR_STATE_EXCHANGE; timer_stop(&rs->timers, Timer_Rtr_Refresh); timer_stop(&rs->timers, Timer_Rtr_Retry); timer_set(&rs->timers, Timer_Rtr_Active, rs->active); /* prevent rtr_recalc from running while active */ rs->active_lock = 1; rtr_sem_acquire(rs->active_lock); break; case RTR_EVNT_END_OF_DATA: /* start refresh and expire timers */ timer_set(&rs->timers, Timer_Rtr_Refresh, rs->refresh); timer_set(&rs->timers, Timer_Rtr_Expire, rs->expire); timer_stop(&rs->timers, Timer_Rtr_Active); rs->state = RTR_STATE_ESTABLISHED; rtr_sem_release(rs->active_lock); rtr_recalc(); rs->active_lock = 0; rs->errored = 0; /* clear the last errors */ rs->last_sent_error = NO_ERROR; rs->last_recv_error = NO_ERROR; rs->last_sent_msg[0] = '\0'; rs->last_recv_msg[0] = '\0'; break; case RTR_EVNT_CACHE_RESET: rtr_reset_cache(rs); rtr_recalc(); /* retry after a quick wait */ timer_set(&rs->timers, Timer_Rtr_Retry, arc4random_uniform(10)); break; case RTR_EVNT_NO_DATA: /* start retry timer */ timer_set(&rs->timers, Timer_Rtr_Retry, rs->retry); /* stop refresh timer just to be sure */ timer_stop(&rs->timers, Timer_Rtr_Refresh); rs->state = RTR_STATE_ESTABLISHED; break; case RTR_EVNT_SEND_ERROR: rtr_reset_cache(rs); rtr_recalc(); rs->state = RTR_STATE_ERROR; break; case RTR_EVNT_NEGOTIATION_DONE: rs->state = RTR_STATE_ESTABLISHED; break; } log_debug("rtr %s: state change %s -> %s, reason: %s", log_rtr(rs), rtr_statenames[prev_state], rtr_statenames[rs->state], rtr_eventnames[event]); } /* * IO handler for RTR sessions */ static void rtr_dispatch_msg(struct pollfd *pfd, struct rtr_session *rs) { struct ibuf *b; if (pfd->revents & POLLHUP) { log_warnx("rtr %s: Connection closed, hangup", log_rtr(rs)); rtr_fsm(rs, RTR_EVNT_CON_CLOSE); return; } if (pfd->revents & (POLLERR|POLLNVAL)) { log_warnx("rtr %s: Connection closed, error", log_rtr(rs)); rtr_fsm(rs, RTR_EVNT_CON_CLOSE); return; } if (pfd->revents & POLLOUT && msgbuf_queuelen(rs->w) > 0) { if (ibuf_write(rs->fd, rs->w) == -1) { log_warn("rtr %s: write error", log_rtr(rs)); rtr_fsm(rs, RTR_EVNT_CON_CLOSE); return; } if (rs->state == RTR_STATE_ERROR && msgbuf_queuelen(rs->w) == 0) rtr_fsm(rs, RTR_EVNT_CON_CLOSE); } if (pfd->revents & POLLIN) { switch (ibuf_read(rs->fd, rs->w)) { case -1: /* if already in error state, ignore */ if (rs->state == RTR_STATE_ERROR) return; log_warn("rtr %s: read error", log_rtr(rs)); rtr_fsm(rs, RTR_EVNT_CON_CLOSE); return; case 0: rtr_fsm(rs, RTR_EVNT_CON_CLOSE); return; } /* new data arrived, try to process it */ while ((b = msgbuf_get(rs->w)) != NULL) { rtr_process_msg(rs, b); ibuf_free(b); } } } void rtr_check_events(struct pollfd *pfds, size_t npfds) { struct rtr_session *rs; struct timer *t; time_t now; size_t i = 0; for (i = 0; i < npfds; i++) { if (pfds[i].revents == 0) continue; TAILQ_FOREACH(rs, &rtrs, entry) if (rs->fd == pfds[i].fd) { rtr_dispatch_msg(&pfds[i], rs); break; } if (rs == NULL) log_warnx("%s: unknown fd in pollfds", __func__); } /* run all timers */ now = getmonotime(); TAILQ_FOREACH(rs, &rtrs, entry) if ((t = timer_nextisdue(&rs->timers, now)) != NULL) { /* stop timer so it does not trigger again */ timer_stop(&rs->timers, t->type); switch (t->type) { case Timer_Rtr_Refresh: rtr_fsm(rs, RTR_EVNT_TIMER_REFRESH); break; case Timer_Rtr_Retry: rtr_fsm(rs, RTR_EVNT_TIMER_RETRY); break; case Timer_Rtr_Expire: rtr_fsm(rs, RTR_EVNT_TIMER_EXPIRE); break; case Timer_Rtr_Active: rtr_fsm(rs, RTR_EVNT_TIMER_ACTIVE); break; default: fatalx("King Bula lost in time"); } } } size_t rtr_count(void) { struct rtr_session *rs; size_t count = 0; TAILQ_FOREACH(rs, &rtrs, entry) count++; return count; } size_t rtr_poll_events(struct pollfd *pfds, size_t npfds, time_t *timeout) { struct rtr_session *rs; time_t now = getmonotime(); size_t i = 0; TAILQ_FOREACH(rs, &rtrs, entry) { time_t nextaction; struct pollfd *pfd = pfds + i++; if (i > npfds) fatalx("%s: too many sessions for pollfd", __func__); if ((nextaction = timer_nextduein(&rs->timers, now)) != -1 && nextaction < *timeout) *timeout = nextaction; if (rs->state == RTR_STATE_CLOSED) { pfd->fd = -1; continue; } pfd->fd = rs->fd; pfd->events = 0; if (msgbuf_queuelen(rs->w) > 0) pfd->events |= POLLOUT; if (rs->state >= RTR_STATE_ESTABLISHED) pfd->events |= POLLIN; } return i; } struct rtr_session * rtr_new(uint32_t id, struct rtr_config_msg *conf) { struct rtr_session *rs; if ((rs = calloc(1, sizeof(*rs))) == NULL) fatal("RTR session %s", conf->descr); if ((rs->w = msgbuf_new_reader(sizeof(struct rtr_header), rtr_reader_callback, rs)) == NULL) fatal("RTR session %s", conf->descr); RB_INIT(&rs->roa_set); RB_INIT(&rs->aspa); TAILQ_INIT(&rs->timers); strlcpy(rs->descr, conf->descr, sizeof(rs->descr)); rs->id = id; rs->session_id = -1; rs->min_version = conf->min_version; /* must be set before version */ rs->version = rtr_max_session_version(rs); rs->prev_version = rtr_max_session_version(rs); rs->refresh = RTR_DEFAULT_REFRESH; rs->retry = RTR_DEFAULT_RETRY; rs->expire = RTR_DEFAULT_EXPIRE; rs->active = RTR_DEFAULT_ACTIVE; rs->state = RTR_STATE_CLOSED; rs->reconf_action = RECONF_REINIT; rs->last_recv_error = NO_ERROR; rs->last_sent_error = NO_ERROR; /* make sure that some timer is running to abort bad sessions */ timer_set(&rs->timers, Timer_Rtr_Expire, rs->expire); log_debug("rtr %s: new session, start", log_rtr(rs)); TAILQ_INSERT_TAIL(&rtrs, rs, entry); rtr_fsm(rs, RTR_EVNT_START); return rs; } struct rtr_session * rtr_get(uint32_t id) { struct rtr_session *rs; TAILQ_FOREACH(rs, &rtrs, entry) if (rs->id == id) return rs; return NULL; } void rtr_free(struct rtr_session *rs) { if (rs == NULL) return; rtr_reset_cache(rs); rtr_fsm(rs, RTR_EVNT_CON_CLOSE); timer_remove_all(&rs->timers); msgbuf_free(rs->w); free(rs); } void rtr_open(struct rtr_session *rs, int fd) { if (rs->state != RTR_STATE_CLOSED && rs->state != RTR_STATE_NEGOTIATION) { log_warnx("rtr %s: bad session state", log_rtr(rs)); rtr_fsm(rs, RTR_EVNT_CON_CLOSE); } if (rs->state == RTR_STATE_CLOSED) { rs->version = rtr_max_session_version(rs); rs->prev_version = rtr_max_session_version(rs); } rs->fd = fd; rtr_fsm(rs, RTR_EVNT_CON_OPEN); } void rtr_config_prep(void) { struct rtr_session *rs; TAILQ_FOREACH(rs, &rtrs, entry) rs->reconf_action = RECONF_DELETE; } void rtr_config_merge(void) { struct rtr_session *rs, *nrs; TAILQ_FOREACH_SAFE(rs, &rtrs, entry, nrs) if (rs->reconf_action == RECONF_DELETE) { TAILQ_REMOVE(&rtrs, rs, entry); rtr_free(rs); } } void rtr_config_keep(struct rtr_session *rs, struct rtr_config_msg *conf) { strlcpy(rs->descr, conf->descr, sizeof(rs->descr)); rs->min_version = conf->min_version; rs->reconf_action = RECONF_KEEP; } void rtr_roa_merge(struct roa_tree *rt) { struct rtr_session *rs; struct roa *roa; TAILQ_FOREACH(rs, &rtrs, entry) { RB_FOREACH(roa, roa_tree, &rs->roa_set) rtr_roa_insert(rt, roa); } } void rtr_aspa_merge(struct aspa_tree *at) { struct rtr_session *rs; struct aspa_set *aspa; TAILQ_FOREACH(rs, &rtrs, entry) { RB_FOREACH(aspa, aspa_tree, &rs->aspa) rtr_aspa_insert(at, aspa); } } void rtr_shutdown(void) { struct rtr_session *rs, *nrs; TAILQ_FOREACH_SAFE(rs, &rtrs, entry, nrs) rtr_free(rs); } void rtr_show(struct rtr_session *rs, pid_t pid) { struct ctl_show_rtr msg; struct ctl_timer ct; u_int i; time_t d; memset(&msg, 0, sizeof(msg)); /* descr, remote_addr, local_addr and remote_port set by parent */ msg.version = rs->version; msg.min_version = rs->min_version; msg.serial = rs->serial; msg.refresh = rs->refresh; msg.retry = rs->retry; msg.expire = rs->expire; msg.session_id = rs->session_id; msg.last_sent_error = rs->last_sent_error; msg.last_recv_error = rs->last_recv_error; strlcpy(msg.state, rtr_statenames[rs->state], sizeof(msg.state)); strlcpy(msg.last_sent_msg, rs->last_sent_msg, sizeof(msg.last_sent_msg)); strlcpy(msg.last_recv_msg, rs->last_recv_msg, sizeof(msg.last_recv_msg)); /* send back imsg */ rtr_imsg_compose(IMSG_CTL_SHOW_RTR, rs->id, pid, &msg, sizeof(msg)); /* send back timer imsgs */ for (i = 1; i < Timer_Max; i++) { if (!timer_running(&rs->timers, i, &d)) continue; ct.type = i; ct.val = d; rtr_imsg_compose(IMSG_CTL_SHOW_TIMER, rs->id, pid, &ct, sizeof(ct)); } } openbgpd-8.8/src/bgpd/flowspec.c100644 001750 001750 00000033417 14515663632 0012405/* $OpenBSD: flowspec.c,v 1.5 2023/10/23 13:07:44 claudio Exp $ */ /* * Copyright (c) 2023 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include "bgpd.h" #include "rde.h" /* * Extract the next component from a flowspec NLRI buffer. * Returns the length of the component including type field or -1 on failure. * Also checks that the prefix encoding is valid. */ static int flowspec_next_component(const uint8_t *buf, int len, int is_v6, int *type) { int vlen = 0; uint8_t plen, off, op; *type = 0; if (len < 1) return -1; *type = buf[vlen]; vlen++; if (*type < FLOWSPEC_TYPE_MIN || *type >= FLOWSPEC_TYPE_MAX) return -1; switch (*type) { case FLOWSPEC_TYPE_DEST: case FLOWSPEC_TYPE_SOURCE: if (!is_v6) { /* regular RFC 4271 encoding of prefixes */ if (len < vlen + 1) return -1; plen = buf[vlen]; vlen += PREFIX_SIZE(plen); if (plen > 32 || len < vlen) return -1; } else { /* special RFC 8956 encoding with extra offset */ if (len < vlen + 2) return -1; plen = buf[vlen]; off = buf[vlen + 1]; if (plen > 128 || off >= plen) return -1; vlen += PREFIX_SIZE(plen - off) + 1; /* off is extra */ if (len < vlen) return -1; } break; case FLOWSPEC_TYPE_FLOW: if (!is_v6) return -1; /* FALLTHROUGH */ default: do { if (len < vlen + 1) return -1; op = buf[vlen]; /* first component cannot have and flag set */ if (vlen == 1 && op & FLOWSPEC_OP_AND) return -1; vlen += FLOWSPEC_OP_LEN(op) + 1; if (len < vlen) return -1; } while ((op & FLOWSPEC_OP_EOL) == 0); break; } return vlen; } #define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) /* * Compare two IPv4 flowspec prefix components. * Returns -1 if first prefix is preferred, 1 if second, 0 if equal. */ static int flowspec_cmp_prefix4(const uint8_t *abuf, int ablen, const uint8_t *bbuf, int bblen) { uint8_t a[4] = { 0 }, b[4] = { 0 }; int alen, blen, clen, cmp; alen = abuf[1]; blen = bbuf[1]; clen = MINIMUM(alen, blen); /* only extract the common prefix */ extract_prefix(abuf + 2, ablen - 2, &a, clen, sizeof(a)); extract_prefix(bbuf + 2, bblen - 2, &b, clen, sizeof(b)); /* lowest IP value has precedence */ cmp = memcmp(a, b, sizeof(a)); if (cmp < 0) return -1; if (cmp > 0) return 1; /* if common prefix, more specific route has precedence */ if (alen > blen) return -1; if (alen < blen) return 1; return 0; } /* * Compare two IPv6 flowspec prefix components. * Returns 1 if first prefix is preferred, -1 if second, 0 if equal. * As usual the encoding of IPv6 addresses is extra complex. */ static int flowspec_cmp_prefix6(const uint8_t *abuf, int ablen, const uint8_t *bbuf, int bblen) { uint8_t a[16] = { 0 }, b[16] = { 0 }; int alen, blen, clen, cmp; /* lowest offset has precedence */ if (abuf[2] < bbuf[2]) return -1; if (abuf[2] > bbuf[2]) return 1; /* calculate actual pattern size (len - offset) */ alen = abuf[1] - abuf[2]; blen = bbuf[1] - bbuf[2]; clen = MINIMUM(alen, blen); /* only extract the common prefix */ extract_prefix(abuf + 3, ablen - 3, &a, clen, sizeof(a)); extract_prefix(bbuf + 3, bblen - 3, &b, clen, sizeof(b)); /* lowest IP value has precedence */ cmp = memcmp(a, b, sizeof(a)); if (cmp < 0) return -1; if (cmp > 0) return 1; /* if common prefix, more specific route has precedence */ if (alen > blen) return -1; if (alen < blen) return 1; return 0; } /* * Check if the flowspec NLRI is syntactically valid. */ int flowspec_valid(const uint8_t *buf, int len, int is_v6) { int l, type, prev = 0; /* empty NLRI is invalid */ if (len == 0) return -1; while (len > 0) { l = flowspec_next_component(buf, len, is_v6, &type); if (l == -1) return -1; /* ensure that types are ordered */ if (prev >= type) return -1; prev = type; buf += l; len -= l; } if (len < 0) return -1; return 0; } /* * Compare two valid flowspec NLRI objects according to RFC 8955 & 8956. * Returns -1 if the first object has preference, 1 if not, and 0 if the * two objects are equal. */ int flowspec_cmp(const uint8_t *a, int alen, const uint8_t *b, int blen, int is_v6) { int atype, btype; int acomplen, bcomplen; int cmp; while (alen > 0 && blen > 0) { acomplen = flowspec_next_component(a, alen, is_v6, &atype); bcomplen = flowspec_next_component(b, blen, is_v6, &btype); /* should not happen */ if (acomplen == -1) return 1; if (bcomplen == -1) return -1; /* If types differ, lowest type wins. */ if (atype < btype) return -1; if (atype > btype) return 1; switch (atype) { case FLOWSPEC_TYPE_DEST: case FLOWSPEC_TYPE_SOURCE: if (!is_v6) { cmp = flowspec_cmp_prefix4(a, acomplen, b, bcomplen); } else { cmp = flowspec_cmp_prefix6(a, acomplen, b, bcomplen); } if (cmp != 0) return cmp; break; default: cmp = memcmp(a, b, MINIMUM(acomplen, bcomplen)); /* * Lowest common component prefix wins also * if both commponents are same length also lowest * string has precedence. */ if (cmp < 0) return -1; if (cmp > 0) return 1; /* * Longest component wins when common prefix is equal. * This is not really possible because EOL encoding will * always tie break on the memcmp but the RFC mandates * it (and it is cheap). */ if (acomplen > bcomplen) return -1; if (acomplen < bcomplen) return 1; break; } a += acomplen; alen -= acomplen; b += bcomplen; blen -= bcomplen; /* Rule with more components wins */ if (alen > 0 && blen <= 0) return -1; if (alen <= 0 && blen > 0) return 1; } return 0; } static void shift_right(uint8_t *dst, const uint8_t *src, int off, int len) { uint8_t carry = 0; int i; dst += off / 8; /* go to inital start point */ off %= 8; len = (len + 7) / 8; /* how much to copy in bytes */ for (i = 0; i < len; i++) { dst[i] = carry | src[i] >> off; if (off != 0) carry = src[i] << (8 - off); } dst[i] = carry; } /* * Extract a flowspec component and return its buffer and size. * Returns 1 on success, 0 if component is not present and -1 on error. */ int flowspec_get_component(const uint8_t *flow, int flowlen, int type, int is_v6, const uint8_t **buf, int *len) { int complen, t; *buf = NULL; *len = 0; do { complen = flowspec_next_component(flow, flowlen, is_v6, &t); if (complen == -1) return -1; if (type == t) break; if (type < t) return 0; flow += complen; flowlen -= complen; } while (1); *buf = flow + 1; *len = complen - 1; return 1; } /* * Extract source or destination address into provided bgpd_addr. * Returns 1 on success, 0 if no address was present, -1 on error. * Sets plen to the prefix len and olen to the offset for IPv6 case. * If olen is set to NULL when an IPv6 prefix with offset is fetched * the function will return -1. */ int flowspec_get_addr(const uint8_t *flow, int flowlen, int type, int is_v6, struct bgpd_addr *addr, uint8_t *plen, uint8_t *olen) { const uint8_t *comp; int complen, rv; memset(addr, 0, sizeof(*addr)); *plen = 0; if (olen != NULL) *olen = 0; rv = flowspec_get_component(flow, flowlen, type, is_v6, &comp, &complen); if (rv != 1) return rv; /* flowspec_get_component only returns valid encodings */ if (!is_v6) { addr->aid = AID_INET; if (extract_prefix(comp + 1, complen - 1, &addr->v4, comp[0], sizeof(addr->v4)) == -1) return -1; *plen = comp[0]; } else { uint8_t buf[16] = { 0 }; int xlen, xoff = 0; addr->aid = AID_INET6; xlen = comp[0]; if (comp[1] != 0) { if (olen == NULL) return -1; xoff = comp[1]; xlen -= xoff; } if (extract_prefix(comp + 2, complen - 2, buf, xlen, sizeof(buf)) == -1) return -1; shift_right(addr->v6.s6_addr, buf, xoff, xlen); *plen = comp[0]; if (olen != NULL) *olen = comp[1]; } return 1; } const char * flowspec_fmt_label(int type) { switch (type) { case FLOWSPEC_TYPE_DEST: return "to"; case FLOWSPEC_TYPE_SOURCE: return "from"; case FLOWSPEC_TYPE_PROTO: return "proto"; case FLOWSPEC_TYPE_PORT: case FLOWSPEC_TYPE_DST_PORT: case FLOWSPEC_TYPE_SRC_PORT: return "port"; case FLOWSPEC_TYPE_ICMP_TYPE: return "icmp-type"; case FLOWSPEC_TYPE_ICMP_CODE: return "icmp-code"; case FLOWSPEC_TYPE_TCP_FLAGS: return "flags"; case FLOWSPEC_TYPE_PKT_LEN: return "length"; case FLOWSPEC_TYPE_DSCP: return "tos"; case FLOWSPEC_TYPE_FRAG: return "fragment"; case FLOWSPEC_TYPE_FLOW: return "flow"; default: return "???"; } } static uint64_t extract_val(const uint8_t *comp, int len) { uint64_t val = 0; while (len-- > 0) { val <<= 8; val |= *comp++; } return val; } const char * flowspec_fmt_num_op(const uint8_t *comp, int complen, int *off) { static char buf[32]; uint64_t val, val2 = 0; uint8_t op, op2 = 0; int len, len2 = 0; if (*off == -1) return ""; if (complen < *off + 1) return "bad encoding"; op = comp[*off]; len = FLOWSPEC_OP_LEN(op) + 1; if (complen < *off + len) return "bad encoding"; val = extract_val(comp + *off + 1, FLOWSPEC_OP_LEN(op)); if ((op & FLOWSPEC_OP_EOL) == 0) { if (complen < *off + len + 1) return "bad encoding"; op2 = comp[*off + len]; /* * Check if this is a range specification else fall back * to basic rules. */ if (op2 & FLOWSPEC_OP_AND && (op & FLOWSPEC_OP_NUM_MASK) == FLOWSPEC_OP_NUM_GE && (op2 & FLOWSPEC_OP_NUM_MASK) == FLOWSPEC_OP_NUM_LE) { len2 = FLOWSPEC_OP_LEN(op2) + 1; val2 = extract_val(comp + *off + len + 1, FLOWSPEC_OP_LEN(op2)); } else op2 = 0; } if (op2 & FLOWSPEC_OP_AND) { /* binary range operation */ snprintf(buf, sizeof(buf), "%llu - %llu", (unsigned long long)val, (unsigned long long)val2); } else { /* unary operation */ switch (op & FLOWSPEC_OP_NUM_MASK) { case 0: snprintf(buf, sizeof(buf), "%sfalse", op & FLOWSPEC_OP_AND ? "&& " : ""); break; case FLOWSPEC_OP_NUM_EQ: snprintf(buf, sizeof(buf), "%s%llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_GT: snprintf(buf, sizeof(buf), "%s> %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_GE: snprintf(buf, sizeof(buf), "%s>= %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_LT: snprintf(buf, sizeof(buf), "%s< %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_LE: snprintf(buf, sizeof(buf), "%s<= %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_NOT: snprintf(buf, sizeof(buf), "%s!= %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case 0x7: snprintf(buf, sizeof(buf), "%strue", op & FLOWSPEC_OP_AND ? "&& " : ""); break; } } if (op2 & FLOWSPEC_OP_EOL || op & FLOWSPEC_OP_EOL) *off = -1; else *off += len + len2; return buf; } static const char * fmt_flags(uint64_t val, const char *bits, char *buf, size_t blen) { int i, bi; for (i = 0, bi = 0; i < 64 && val != 0; i++) { if (val & 1) { if (bits[i] == '\0' || bits[i] == ' ') goto fail; buf[bi++] = bits[i]; } val >>= 1; } buf[bi++] = '\0'; return buf; fail: snprintf(buf, blen, "%llx", (unsigned long long)val); return buf; } const char * flowspec_fmt_bin_op(const uint8_t *comp, int complen, int *off, const char *bits) { static char buf[36], bit[17], mask[17]; uint64_t val, val2 = 0; uint8_t op, op2 = 0; int len, len2 = 0; if (*off == -1) return ""; if (complen < *off + 1) return "bad encoding"; op = comp[*off]; len = FLOWSPEC_OP_LEN(op) + 1; if (complen < *off + len) return "bad encoding"; val = extract_val(comp + *off + 1, FLOWSPEC_OP_LEN(op)); if ((op & FLOWSPEC_OP_EOL) == 0) { if (complen < *off + len + 1) return "bad encoding"; op2 = comp[*off + len]; /* * Check if this is a mask specification else fall back * to basic rules. */ if (op2 & FLOWSPEC_OP_AND && (op & FLOWSPEC_OP_BIT_MASK) == FLOWSPEC_OP_BIT_MATCH && (op2 & FLOWSPEC_OP_BIT_MASK) == FLOWSPEC_OP_BIT_NOT) { len2 = FLOWSPEC_OP_LEN(op2) + 1; val2 = extract_val(comp + *off + len + 1, FLOWSPEC_OP_LEN(op2)); } else op2 = 0; } if (op2 & FLOWSPEC_OP_AND) { val2 |= val; snprintf(buf, sizeof(buf), "%s / %s", fmt_flags(val, bits, bit, sizeof(bit)), fmt_flags(val2, bits, mask, sizeof(mask))); } else { switch (op & FLOWSPEC_OP_BIT_MASK) { case 0: snprintf(buf, sizeof(buf), "%s", fmt_flags(val, bits, bit, sizeof(bit))); break; case FLOWSPEC_OP_BIT_NOT: snprintf(buf, sizeof(buf), "/ %s", fmt_flags(val, bits, mask, sizeof(mask))); break; case FLOWSPEC_OP_BIT_MATCH: snprintf(buf, sizeof(buf), "%s / %s", fmt_flags(val, bits, bit, sizeof(bit)), fmt_flags(val, bits, mask, sizeof(mask))); break; case FLOWSPEC_OP_BIT_NOT | FLOWSPEC_OP_BIT_MATCH: snprintf(buf, sizeof(buf), "???"); break; } } if (op2 & FLOWSPEC_OP_EOL || op & FLOWSPEC_OP_EOL) *off = -1; else *off += len + len2; return buf; } openbgpd-8.8/src/bgpd/bgpd.8.in100644 001750 001750 00000023120 14751151130 0012002.\" $OpenBSD: bgpd.8,v 1.84 2025/01/17 12:38:14 claudio Exp $ .\" .\" Copyright (c) 2003, 2004 Henning Brauer .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .Dd $Mdocdate: January 17 2025 $ .Dt BGPD 8 .Os .Sh NAME .Nm bgpd .Nd Border Gateway Protocol (BGP) routing daemon .Sh SYNOPSIS .Nm bgpd .Bk -words .Op Fl cdnvV .Op Fl D Ar macro Ns = Ns Ar value .Op Fl f Ar file .Ek .Sh DESCRIPTION .Nm is a Border Gateway Protocol .Pq BGP daemon which manages the network routing tables. Its main purpose is to exchange information concerning .Qq network reachability with other BGP systems. .Nm uses the Border Gateway Protocol, Version 4, as described in RFC 4271. .Pp BGP is an exterior gateway protocol using a multiple step decision process to find the best path. Advanced filtering can be used to influence the route decision for traffic engineering. The session engine of .Nm is responsible for maintaining the TCP session with each neighbor. Updates are passed to the Route Decision Engine (RDE) where the paths are filtered and used to compute a Routing Information Base (RIB). The parent process is responsible for keeping the RIB in sync with the kernel routing table. .Pp The route decision process selects the best path by evaluating all paths to the same destination. The decision process continues to the next step if paths have equal attributes. Paths that are less preferred are taken out of consideration until there is only one path left. .Bl -enum -width 42 -offset bula .It All paths with errors or loops are not eligible. .It Paths with an unreachable nexthop are not eligible. After this step all remaining paths are valid. .It The path with the highest .Em LOCAL_PREF is selected. .It The path with the shortest .Em AS path attribute is selected. .It The .Em ORIGIN attribute is compared. The order is IGP before EGP before incomplete origins. .It The path with the lowest .Em MULTI_EXIT_DISC metric is selected. Normally, this value is only considered when choosing between multiple routes sent by the same neighbouring AS. However, if .Dq Li rde med compare always is set in the configuration, the metric is compared for routes sent by any AS. .It Comparison of the BGP session type. Paths learned over an external (EBGP) session are preferred over those learned via an internal (IBGP) session. .It The path with the highest local .Em weight is selected. .It If .Dq Li rde route-age evaluate is set then the oldest path is selected. .It The path coming from the neighbor with the lowest .Em BGP ID wins. If the .Em ORIGINATOR_ID attribute is present, that value will be used in the comparison instead. .It The path with the shortest .Em CLUSTER_LIST attribute is selected. If it is not present then a length of 0 is used in the comparison. .It The path coming from the peer with the lowest IP address is selected. IPv4 sessions will be preferred over IPv6 ones. .El .Pp Attributes set by filters can be used to tip the decision process to prefer particular paths over others. This can be achieved by changing the .Em localpref , .Em med , or .Em weight attributes. AS path prepending or changing the .Em med or .Em origin attribute can be used to influence the routing behaviour on remote systems. .Pp To have .Nm enabled at boot time, use .Dq rcctl enable bgpd , which sets .Pp .Dl bgpd_flags=\(dq\(dq .Pp in .Xr rc.conf.local 8 . .Pp When .Nm starts up, it reads settings from a configuration file, typically .Xr bgpd.conf 5 . A running .Nm process can be controlled using the .Xr bgpctl 8 utility. .Pp The options are as follows: .Bl -tag -width "-f fileXXX" .It Fl c Force .Nm to do .Xr carp 4 demotion at startup when the .Em demote functionality is used. Normally, .Nm will only do demotion at startup when the demotion counter for the group in question is already greater than 0. .Nm will start handling demotion after all sessions with demotion configured for the given group have been successfully established. At system startup, .Xr rc 8 has the demotion counter for the group .Em carp increased until after .Nm is started, so this option should .Em not be used in .Xr rc.conf 8 . .It Fl D Ar macro Ns = Ns Ar value Define .Ar macro to be set to .Ar value on the command line. Overrides the definition of .Ar macro in the configuration file. .It Fl d Do not daemonize. If this option is specified, .Nm will run in the foreground and log to .Em stderr . .It Fl f Ar file Use .Ar file as the configuration file, instead of the default .Pa @SYSCONFDIR@/bgpd.conf . .It Fl n Configtest mode. Only check the configuration file for validity. .It Fl v Produce more verbose output. .It Fl V Show the version and exit. .El .Sh FILES .Bl -tag -width "@RUNSTATEDIR@/bgpd.sock." -compact .It Pa @SYSCONFDIR@/bgpd.conf Default .Nm configuration file. .It Pa @RUNSTATEDIR@/bgpd.sock. Default .Nm control socket, where .Ar is the routing domain in which .Nm has been started. .El .Sh SEE ALSO .Xr bgpd.conf 5 , .Xr bgpctl 8 , .Xr bgplg 8 , .Xr bgplgsh 8 .Sh STANDARDS .Rs .%D August 1996 .%R RFC 1997 .%T BGP Communities Attribute .Re .Pp .Rs .%D August 1998 .%R RFC 2385 .%T Protection of BGP Sessions via the TCP MD5 Signature Option .Re .Pp .Rs .%D March 1999 .%R RFC 2545 .%T Use of BGP-4 Multiprotocol Extensions for IPv6 Inter-Domain Routing .Re .Pp .Rs .%D September 2000 .%R RFC 2918 .%T Route Refresh Capability for BGP-4 .Re .Pp .Rs .%D April 2004 .%R RFC 3765 .%T NOPEER Community for Border Gateway Protocol (BGP) Route Scope Control .Re .Pp .Rs .%D January 2006 .%R RFC 4271 .%T A Border Gateway Protocol 4 (BGP-4) .Re .Pp .Rs .%D February 2006 .%R RFC 4360 .%T BGP Extended Communities Attribute .Re .Pp .Rs .%D February 2006 .%R RFC 4364 .%T BGP/MPLS IP Virtual Private Networks (VPNs) .Re .Pp .Rs .%D April 2006 .%R RFC 4456 .%T "BGP Route Reflection: An Alternative to Full Mesh Internal BGP (IBGP)" .Re .Pp .Rs .%D April 2006 .%R RFC 4486 .%T Subcodes for BGP Cease Notification Message .Re .Pp .Rs .%D January 2007 .%R RFC 4724 .%T Graceful Restart Mechanism for BGP .Re .Pp .Rs .%D January 2007 .%R RFC 4760 .%T Multiprotocol Extensions for BGP-4 .Re .Pp .Rs .%D October 2007 .%R RFC 5082 .%T The Generalized TTL Security Mechanism (GTSM) .Re .Pp .Rs .%D February 2009 .%R RFC 5492 .%T Capabilities Advertisement with BGP-4 .Re .Pp .Rs .%D October 2009 .%R RFC 5668 .%T 4-Octet AS Specific BGP Extended Community .Re .Pp .Rs .%D June 2011 .%R RFC 6286 .%T Autonomous-System-Wide Unique BGP Identifier for BGP-4 .Re .Pp .Rs .%D May 2012 .%R RFC 6608 .%T Subcodes for BGP Finite State Machine Error .Re .Pp .Rs .%D Dec 2012 .%R RFC 6793 .%T BGP Support for Four-Octet Autonomous System (AS) Number Space .Re .Pp .Rs .%D August 2015 .%R RFC 7606 .%T Revised Error Handling for BGP UPDATE Messages .Re .Pp .Rs .%D October 2011 .%R RFC 6396 .%T Multi-Threaded Routing Toolkit (MRT) Routing Information Export Format .Re .Pp .Rs .%D May 2012 .%R RFC 6608 .%T Subcodes for BGP Finite State Machine Error .Re .Pp .Rs .%D July 2014 .%R RFC 7313 .%T Enhanced Route Refresh Capability for BGP-4 .Re .Pp .Rs .%D August 2015 .%R RFC 7607 .%T Codification of AS 0 Processing .Re .Pp .Rs .%D July 2016 .%R RFC 7911 .%T Advertisement of Multiple Paths in BGP .Re .Pp .Rs .%D September 2016 .%R RFC 7947 .%T Internet Exchange BGP Route Server .Re .Pp .Rs .%D May 2017 .%R RFC 8050 .%T Multi-Threaded Routing Toolkit (MRT) Routing Information Export Format with BGP Additional Path Extensions .Re .Pp .Rs .%D February 2017 .%R RFC 8092 .%T BGP Large Communities Attribute .Re .Pp .Rs .%D March 2017 .%R RFC 8097 .%T BGP Prefix Origin Validation State Extended Community .Re .Pp .Rs .%D July 2017 .%R RFC 8203 .%T BGP Administrative Shutdown Communication .Re .Pp .Rs .%D September 2017 .%R RFC 8210 .%T The Resource Public Key Infrastructure (RPKI) to Router Protocol, Version 1 .Re .Pp .Rs .%D July 2017 .%R RFC 8212 .%T Default External BGP (EBGP) Route Propagation Behavior without Policies .Re .Pp .Rs .%D March 2018 .%R RFC 8326 .%T Graceful BGP Session Shutdown .Re .Pp .Rs .%D March 2019 .%R RFC 8538 .%T Notification Message Support for BGP Graceful Restart .Re .Pp .Rs .%D October 2019 .%R RFC 8654 .%T Extended Message Support for BGP .Re .Pp .Rs .%D November 2020 .%R RFC 8950 .%T Advertising IPv4 Network Layer Reachability Information (NLRI) with an IPv6 Next Hop .Re .Pp .Rs .%D December 2020 .%R RFC 8955 .%T Dissemination of Flow Specification Rules .Re .Pp .Rs .%D December 2020 .%R RFC 8956 .%T Dissemination of Flow Specification Rules for IPv6 .Re .Pp .Rs .%D July 2021 .%R RFC 9072 .%T Extended Optional Parameters Length for BGP OPEN Message .Re .Pp .Rs .%D May 2022 .%R RFC 9234 .%T Route Leak Prevention and Detection Using Roles in UPDATE and OPEN Messages .Re .Pp .Rs .%D November 2024 .%R RFC 9687 .%T Border Gateway Protocol 4 (BGP-4) Send Hold Timer .Re .Pp .Rs .%D October 2022 .%R draft-ietf-sidrops-aspa-verification .%T BGP AS_PATH Verification Based on Resource Public Key Infrastructure (RPKI) Autonomous System Provider Authorization (ASPA) Objects .Re .Sh HISTORY The .Nm program first appeared in .Ox 3.5 . openbgpd-8.8/src/bgpd/bgpd.conf.5.in100644 001750 001750 00000151440 14751151130 0012732.\" $OpenBSD: bgpd.conf.5,v 1.249 2025/01/27 15:22:11 claudio Exp $ .\" .\" Copyright (c) 2004 Claudio Jeker .\" Copyright (c) 2003, 2004 Henning Brauer .\" Copyright (c) 2002 Daniel Hartmeier .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .Dd $Mdocdate: January 27 2025 $ .Dt BGPD.CONF 5 .Os .Sh NAME .Nm bgpd.conf .Nd BGP routing daemon configuration file .Sh DESCRIPTION The .Xr bgpd 8 daemon implements the Border Gateway Protocol version 4 as described in RFC 4271. .Pp The .Nm config file is divided into the following main sections: .Bl -tag -width xxxx .It Sx MACROS User-defined variables may be defined and used later, simplifying the configuration file. .It Sx GLOBAL CONFIGURATION Global settings for .Xr bgpd 8 . .It Sx SET CONFIGURATION Various lookup tables are defined in this section. .It Sx NETWORK AND FLOWSPEC ANNOUNCEMENTS Networks which should be announced by .Xr bgpd 8 are set in this section. .It Sx MPLS VPN CONFIGURATION The definition and properties for BGP MPLS VPNs are set in this section. .It Sx NEIGHBORS AND GROUPS .Xr bgpd 8 establishes sessions with .Em neighbors . The neighbor definition and properties are set in this section, as well as grouping neighbors for the ease of configuration. .It Sx FILTER Filter rules for incoming and outgoing .Em UPDATES . .El .Pp With the exception of macros, the sections should be grouped and appear in .Nm in the order shown above. .Pp The current line can be extended over multiple lines using a backslash .Pq Sq \e . Comments can be put anywhere in the file using a hash mark .Pq Sq # , and extend to the end of the current line. Care should be taken when commenting out multi-line text: the comment is effective until the end of the entire block. .Pp Argument names not beginning with a letter, digit, or underscore must be quoted. .Pp Additional configuration files can be included with the .Ic include keyword, for example: .Bd -literal -offset indent include "/etc/bgpd/bgpd-10.0.0.1.filter" .Ed .Sh MACROS Macros can be defined that will later be expanded in context. Macro names must start with a letter, digit, or underscore, and may contain any of those characters. Macro names may not be reserved words (for example, .Ic AS , .Ic neighbor , or .Ic group ) . Macros are not expanded inside quotes. .Pp For example: .Bd -literal -offset indent peer1="1.2.3.4" neighbor $peer1 { remote-as 65001 } .Ed .Sh GLOBAL CONFIGURATION These settings affect the operation of the .Xr bgpd 8 daemon as a whole. .Pp .Bl -tag -width Ds -compact .It Ic AS Ar as-number Op Ar as-number Set the local .Em autonomous system number to .Ar as-number . A fallback 2-byte AS number may follow a 4-byte AS number for neighbors that do not support 4-byte AS numbers. The standard and default fallback AS number is 23456. .Pp The AS numbers are assigned by local RIRs, such as: .Pp .Bl -tag -width xxxxxxxx -compact .It AfriNIC for Africa .It APNIC for Asia Pacific .It ARIN for North America and parts of the Caribbean .It LACNIC for Latin America and the Caribbean .It RIPE NCC for Europe, the Middle East, and parts of Asia .El .Pp The AS numbers 64512 \(en 65534 are designated for private use. The AS number 23456 is reserved and should not be used. 4-byte AS numbers may be specified in either the ASPLAIN format: .Bd -literal -offset indent AS 196618 .Ed .Pp or in the older ASDOT format: .Bd -literal -offset indent AS 3.10 .Ed .Pp .It Ic connect-retry Ar seconds Set the number of seconds to wait before attempting to re-open a connection. This timer should be sufficiently large in EBGP configurations. The default is 120 seconds. .Pp .It Xo .Ic dump .Op Ic rib Ar name .Pq Ic table-v2 Ns | Ns Ic table-mp Ns | Ns Ic table .Ar file Op Ar interval .Xc .It Xo .Ic dump .Pq Ic all Ns | Ns Ic updates .Pq Ic in Ns | Ns Ic out .Ar file Op Ar interval .Xc Dump the RIB, a.k.a. the .Em routing information base , or dump ongoing BGP activity, in Multi-threaded Routing Toolkit (MRT) format. The .Ar file is subject to .Xr strftime 3 Ns -expansion. .Pp The .Ic table-v2 and .Ic table-mp RIB formats store multi-protocol RIBs correctly, but the .Ic table format does not. The latter two are provided only to support third-party tools lacking support for the recommended .Ic table-v2 format. Dump an alternative RIB by specifying .Ar name . Specify an .Ar interval in seconds for periodic RIB dumps. .Pp The following will dump the entire RIB table, at startup and every 5 minutes thereafter, to a new file: .Bd -literal -offset indent dump table-v2 "/tmp/rib-dump-%H%M" 300 .Ed .Pp Dumps of ongoing BGP activity include all BGP state transitions, and all BGP messages in the specified direction. Use .Ic updates to dump only BGP .Em UPDATE messages, without state transitions. Specify an .Ar interval in seconds to restart periodically with a new file: .Bd -literal -offset indent dump all in "/tmp/all-in-%H%M" 300 .Ed .Pp .It Ic fib-priority Ar prio Set the routing priority to .Ar prio . The default is 48. .Pp .It Xo .Ic fib-update .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic no , do not update the Forwarding Information Base, a.k.a. the kernel routing table. The default is .Ic yes . .Pp .It Ic holdtime Ar seconds Set the announced holdtime in seconds. This is exchanged with a neighbor upon connection establishment, in the .Em OPEN message, and the shortest holdtime governs the session. .Pp The neighbor session is dropped if the session holdtime passes without receipt of a .Em KEEPALIVE or an .Em UPDATE message from the neighbor. The default is 90 seconds. .Pp .It Ic holdtime min Ar seconds The minimum acceptable holdtime in seconds. This value must be at least 3. .Pp .It Ic listen on Ar address Op Ic port Ar port Specify the local IP address and optional port for .Xr bgpd 8 to listen on. The default is to listen on all local addresses on the current default routing domain. .Pp .It Ic log updates Log sent and received BGP update messages. .Pp .It Xo .Ic nexthop .Ic qualify .Ic via .Pq Ic bgp Ns | Ns Ic default .Xc If set to .Ic bgp , .Xr bgpd 8 may verify nexthops using BGP routes. If set to .Ic default , .Xr bgpd 8 may verify nexthops using the default route. By default .Xr bgpd 8 uses only static routes or routes added by other routing daemons, such as .Xr ospfd 8 . .Pp .It Xo .Ic rde Ic evaluate .Pq Ic default Ns | Ns Ic all .Xc If set to .Ar all , keep evaluating alternative paths in case the selected path is filtered out. By default if a path is filtered by the output filters then no alternative path is sent to this peer. .Pp .It Xo .Ic rde Ic med Ic compare .Pq Ic always Ns | Ns Ic strict .Xc If set to .Ic always , the .Em MULTI_EXIT_DISC attributes will always be compared. The default is .Ic strict , where the metric is only compared between peers belonging to the same AS. .Pp .It Xo .Ic rde .Ic rib Ar name .Op Ic no evaluate .Xc .It Xo .Ic rde .Ic rib Ar name .Op Ic rtable Ar number .Xc Create an additional RIB named .Ar name . The degree to which its routes may be utilized is configurable. They may be excluded from the decision process that selects usable routes with the .Ic no evaluate flag, and this precludes their export to any kernel routing table. By default its routes will be evaluated, but not exported to the kernel. They may be both evaluated and exported if associated with a given .Ic rtable .Ar number , which must belong to the routing domain that .Xr bgpd 8 was started in. This table will not be consulted during nexthop verification unless it is the one that .Xr bgpd 8 was started in. It is unnecessary to create .Ic Adj-RIB-In and .Ic Loc-RIB , which are created automatically and used by default. .Pp .It Ic rde rib Loc-RIB include filtered Include filtered prefixes in the .Ic Loc-RIB . Filtered prefixes are not eligible by the decision process but can be displayed by .Xr bgpctl 8 . .Pp .It Xo .Ic rde .Ic route-age .Pq Ic ignore Ns | Ns Ic evaluate .Xc If set to .Ic evaluate , the route decision process will also consider the age of the route in addition to its path attributes, giving preference to the older, typically more stable, route. This renders the decision process nondeterministic. The default is .Ic ignore . .Pp .It Xo .Ic reject Ic as-set .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic yes , .Em AS paths attributes containing .Em AS_SET path segments will be rejected and all prefixes will be treated as withdraws. The default is .Ic yes . .Pp .It Ic router-id Ar dotted-quad Set the BGP router ID, which must be non-zero and should be unique within the AS. By default, the router ID is the highest IPv4 address assigned to the local machine. .Bd -literal -offset indent router-id 10.0.0.1 .Ed .Pp .It Ic rtable Ar number Work with the given kernel routing table instead of the default table, which is the one .Xr bgpd 8 was started in. For nexthop verification, .Xr bgpd 8 will always consult the default table. This is the same as using the following syntax: .Bd -literal -offset indent rde rib Loc-RIB rtable number .Ed .Pp .It Ic socket Qo Ar path Qc Op Ic restricted Create a control socket at .Ar path . If .Ic restricted is specified, a restricted control socket will be created. By default .Pa @RUNSTATEDIR@/bgpd.sock. is used where .Ar is the routing domain in which .Xr bgpd 8 has been started. By default, no restricted socket is created. .Pp .It Ic staletime Ar seconds Set the upper bound in seconds stale routes are kept during graceful restart. The default is 180 seconds. .Pp .It Xo .Ic transparent-as .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic yes , attribute transparency is enabled. .Em AS paths to EBGP neighbors are not prepended with the local AS. Additionally, the MULTI_EXIT_DISC attribute is passed transparently and automatic filtering based on the well-known communities .Ic NO_EXPORT , .Ic NO_ADVERTISE , and .Ic NO_EXPORT_SUBCONFED is disabled. The default is .Ic no . .El .Sh SET CONFIGURATION .Xr bgpd 8 supports the efficient lookup of data within named .Em sets . An .Ic as-set , a .Ic prefix-set , and an .Ic origin-set store AS numbers, prefixes, and prefixes/source-as pairs, respectively. Such sets may be referenced by filter rules; see the .Sx FILTER section for details. It is more efficient to evaluate a set than a long series of rules for filtering each of its members. .Pp One single .Ic roa-set may be defined, against which .Xr bgpd 8 will validate the origin of each prefix. The .Ic roa-set and the .Ic aspa-set are merged with the corresponding tables received via .Ic rtr sessions. .Pp A set definition can span multiple lines, and an optional comma is allowed between elements. The same set can be defined more than once, in this case the definitions are merged into one common set. .Pp .Bl -tag -width Ds -compact .It Xo .Ic as-set Ar name .Ic { Ar as-number ... Ic } .Xc An .Ic as-set stores AS numbers, and can be used with the AS specific parameter in .Sx FILTER rules. .Pp .It Xo .Ic aspa-set .Ic { Ic customer-as Ar as-number .Op Ic expires Ar seconds .Ic provider-as Ic { Ar as-number .Ic ... Ic } ... Ic } .Xc The .Ic aspa-set holds a collection of .Em Validated ASPA Payloads Pq VAPs . Each as AS_PATH received from an eBGP peer is checked against the .Ic aspa-set , and the ASPA Validation State (AVS) is set. .Ic expires can be set to the seconds since Epoch until when this VAP is valid. .Bd -literal -offset indent aspa-set { customer-as 64511 provider-as { 64496 65496 } customer-as 64496 provider-as { 65496 64544 } } .Ed .Pp .It Xo .Ic origin-set Ar name .Ic { Ar address Ns Li / Ns Ar len .Op Ic maxlen Ar mlen .Ic source-as Ar asn ... Ic } .Xc An .Ic origin-set stores prefix/source-as pairs, and can be used to filter on the combination by using the .Ic origin-set parameter in .Sx FILTER rules. .Bd -literal -offset indent origin-set private { 10.0.0.0/8 maxlen 24 source-as 64511 203.0.113.0/24 source-as 64496 } .Ed .Pp .It Xo .Ic prefix-set Ar name .Ic { Ar address Ns Li / Ns Ar len ... Ic } .Xc A .Ic prefix-set stores network prefixes and can be used in place of the .Ic prefix parameter in .Sx FILTER rules, and in .Ic network statements. A prefix can be followed by the prefixlen operators listed for the .Ic prefix parameter in the .Sx PARAMETERS section. .Pp The first example below creates a set of prefixes called .Dq private , to hold a number of RFC 1918 private network blocks. The second example shows the use of prefixlen operators. .Bd -literal -offset indent prefix-set private { 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7 } prefix-set as64496set { 192.0.2.0/24 prefixlen >= 26, 2001:db8::/32 or-longer } .Ed .Pp .It Xo .Ic roa-set .Ic { Ar address Ns Li / Ns Ar len .Op Ic maxlen Ar mlen .Ic source-as Ar asn .Oo Ic expires Ar seconds Oc ... Ic } .Xc The .Ic roa-set holds a collection of .Em Validated ROA Payloads Pq VRPs . Each received prefix is checked against the .Ic roa-set , and the Origin Validation State (OVS) is set. .Ic expires can be set to the seconds since Epoch until when this VRP is valid. .Bd -literal -offset indent roa-set { 192.0.2.0/23 maxlen 24 source-as 64511 203.0.113.0/24 source-as 64496 } .Ed .Pp .It Xo .Ic rtr Ar address .Ic { Ar ... Ic } .Xc The .Ic rtr block specifies a .Em RPKI to Router Pq RTR session. .Em RTR sessions provide another means to load .Em VRP sets into .Xr bgpd 8 . Changes propagated via the RTR protocol do not need a config reload and are immediately applied. The union of all .Em VRP sets received via .Ic rtr sessions and the entries in the .Ic roa-set is used to validate the origin of routes. The rtr session properties are as follows: .Pp .Bl -tag -width Ds -compact .It Ic descr Ar description Add a description. The description is used in logging and status reports, but has no further meaning for .Xr bgpd 8 . .Pp .It Ic local-address Ar address Bind to the specific IP address before opening the TCP connection to the .Em rtr server. .Pp .Ic min-version Ar number Require a minimal RTR version of .Ar number . To ensure that ASPA records are synchronised over RTR a minimal version of 2 is required. .Pp .It Ic port Ar number Specify the TCP destination port for the .Em rtr session. If not specified, the default .Ic port is .Em 323 . .El .El .Sh NETWORK AND FLOWSPEC ANNOUNCEMENTS .Ic network statements specify the networks that .Xr bgpd 8 will announce as its own. An announcement must also be permitted by the .Sx FILTER rules. By default .Xr bgpd 8 announces no networks. .Pp .Bl -tag -width Ds -compact .It Xo .Ic network .Ar address Ns Li / Ns Ar prefix .Op Ic set ... .Xc Announce the specified prefix as belonging to our AS. .Pp .It Xo .Ic network .Pq Ic inet Ns | Ns Ic inet6 .Ic connected Op Ic set ... .Xc Announce routes to directly attached networks. .Pp .It Xo .Ic network prefix-set .Ar name .Op Ic set ... .Xc Announce all networks in the prefix-set .Ar name . .Pp .It Xo .Ic network .Pq Ic inet Ns | Ns Ic inet6 .Ic priority Ar number Op Ic set ... .Xc Announce routes having the specified .Ar priority . .Pp .It Xo .Ic network .Pq Ic inet Ns | Ns Ic inet6 .Ic rtlabel Ar label Op Ic set ... .Xc Announce routes having the specified .Ar label . .Pp .It Xo .Ic network .Pq Ic inet Ns | Ns Ic inet6 .Ic static Op Ic set ... .Xc Announce all static routes. .El .Pp Each .Ic network statement may set default .Em AS path attributes : .Bd -literal -offset indent network 192.168.7.0/24 set localpref 220 .Ed .Pp See also the .Sx ATTRIBUTE SET section. .Pp .Ic flowspec statements specify the flowspec rules that .Xr bgpd 8 will announce as its own. .\"An announcement must also be permitted by the .\".Sx FILTER .\"rules. By default .Xr bgpd 8 announces no flowspec rules. .Pp .Bl -tag -width Ds -compact .It Xo .Ic flowspec .Pq Ic inet Ns | Ns Ic inet6 .Ar rule Op Ic set ... .Xc Announce an IPv4 or IPv6 specific flowspec .Ar rule including the .Em AS path attributes specified by .Ar set . .El .Pp The following rule parameters can be set. Most number arguments in the below rules can be specified as a list of ranges enclosed in curly brackets using these operators: .Bd -literal -offset indent = (equal, default) != (unequal) < (less than) <= (less than or equal) > (greater than) >= (greater than or equal) - (range including boundaries) >< (except range) .Ed .Pp .Sq >< , and .Sq - are binary operators (they take two arguments). .Pp .Bl -tag -width Ds -compact .It Ic from Ar source Op Ic port Ar list .It Ic to Ar dest Op Ic port Ar list This rule applies only to packets with the specified source or destination addresses and ports. Addresses can be specified in CIDR notation (matching netblocks) or using .Cm any to match any address. In most cases a .Ic to address must be specified and be part of the announced networks. .Pp Ports can be specified either by number or by name. For example, port 80 can be specified as .Cm www . For a list of all port name to number mappings see the file .Pa /etc/services . .It Ic flags Ar a Ns / Ns Ar b This rule only applies to TCP packets that have the flags .Ar a set out of set .Ar b . Flags not specified in .Ar b are ignored. The flags are: (F)IN, (S)YN, (R)ST, (P)USH, (A)CK, (U)RG, (E)CE, and C(W)R. .It Ic fragment Ar a Ns / Ns Ar b This rule only applies to fragmented packets which match the specified flags. The flags are: (D)on't fragment, (I)s fragment, (F)irst fragment, and (L)ast fragment. .It Ic icmp-type Ar type Op Ic code Ar code .It Ic icmp6-type Ar type Op Ic code Ar code This rule only applies to ICMP or ICMP6 packets with the specified type and code. Text names for ICMP types and codes are listed in .Xr icmp 4 and .Xr icmp6 4 . .It Ic length Ar pktlen This rule applies only to packets matching the specified .Ar pktlen . .It Ic proto Ar protocol This rule applies only to packets of this protocol. Common protocols are ICMP, ICMP6, TCP, and UDP. For a list of all the protocol name to number mappings see the file .Pa /etc/protocols . .It Ic tos Ar string Ns | Ns Ar number This rule applies to packets with the specified TOS bits set. .Ar string may be one of .Cm critical , .Cm inetcontrol , .Cm lowdelay , .Cm netcontrol , .Cm throughput , .Cm reliability , or one of the DiffServ Code Points: .Cm ef , .Cm af11 No ... Cm af43 , .Cm cs0 No ... Cm cs7 ; .Ar number may be either a hex or decimal number. .El .Pp The action taken when a flowspec rules matches depends on extended communities. For example to block all traffic either .Ic ext-community Ic flow-rate Ar as-number : Ns 0 or .Ic ext-community Ic flow-pps Ar as-number : Ns 0 need to be set. .Sh MPLS VPN CONFIGURATION A .Ic vpn section configures a router to participate in an MPLS Virtual Private Network. It specifies an .Xr mpe 4 interface to use, a description, and various properties of the VPN: .Bd -literal -offset indent vpn "description" on mpe1 { rd 65002:1 import-target rt 65002:42 export-target rt 65002:42 network 192.168.1/24 } .Ed .Pp .Xr bgpd 8 will not exchange VPN routes with a neighbor by default, see the .Sx NEIGHBORS AND GROUPS section. The description is used when logging but has no further meaning to .Xr bgpd 8 . .Pp The .Xr mpe 4 interface will be used as the outgoing interface for routes to the VPN, and local networks will be announced with the MPLS label specified on the interface. The interface can provide VPN connectivity for another rdomain by being configured in that rdomain. The required rdomain must be configured on the interface before .Xr bgpd 8 uses it. Multiple VPNs may be connected to a single rdomain, including the rdomain that .Xr bgpd 8 is running in. .Pp An example .Xr hostname.if 5 configuration for an .Xr mpe 4 interface providing connectivity to rdomain 1: .Bd -literal -offset indent rdomain 1 mplslabel 2000 inet 192.198.0.1 255.255.255.255 up .Ed .Pp The VPN properties are as follows: .Pp .Bl -tag -width Ds -compact .It Ic export-target Ar subtype as-number : Ns Ar local .It Ic export-target Ar subtype IP : Ns Ar local Classify announced networks by tagging them with an .Em extended community of the given arguments. The community .Ar subtype should be a .Em route target , .Ic rt , to ensure interoperability. The arguments are further detailed in the .Sx ATTRIBUTE SET section. More than one .Ic export-target can be specified. .Pp .It Xo .Ic fib-update .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic no , do not update the Forwarding Information Base, a.k.a. the kernel routing table. The default is .Ic yes . .Pp .It Ic import-target Ar subtype as-number : Ns Ar local .It Ic import-target Ar subtype IP : Ns Ar local The rdomain imports only those prefixes tagged with an .Em extended community matching an .Ic import-target . The community .Ar subtype should be a .Em route target , .Ic rt , to ensure interoperability. The arguments are further detailed in the .Sx ATTRIBUTE SET section. More than one .Ic import-target can be specified. .Pp .It Ic network Ar argument ... Announce the given networks within this VPN; see the .Sx NETWORK ANNOUNCEMENTS section. .Pp .It Ic rd Ar as-number : Ns Ar local .It Ic rd Ar IP : Ns Ar local The Route Distinguisher .Ic rd supplies BGP with namespaces to disambiguate VPN prefixes, as these needn't be globally unique. Unlike route targets, the .Ic rd neither identifies the origin of the prefix nor controls into which VPNs the prefix is distributed. The .Ar as-number or .Ar IP of a .Ic rd should be set to a number or IP that was assigned by an appropriate authority, whereas .Ar local can be chosen by the local operator. .El .Sh NEIGHBORS AND GROUPS .Xr bgpd 8 establishes TCP connections to other BGP speakers called .Em neighbors . A neighbor and its properties are specified by a .Tg .Ic neighbor section: .Bd -literal -offset indent neighbor 10.0.0.2 { remote-as 65002 descr "a neighbor" } .Ed .Pp Neighbors placed within a .Tg .Ic group section inherit the properties common to that group: .Bd -literal -offset indent group "peering AS65002" { remote-as 65002 neighbor 10.0.0.2 { descr "AS65002-p1" } neighbor 10.0.0.3 { descr "AS65002-p2" } } .Ed .Pp An entire network of neighbors may be accommodated by specifying an address/netmask pair: .Bd -literal -offset indent neighbor 10.0.0.0/8 .Ed .Pp This is a .Em template that recognises as a neighbor any connection from within the given network. Such neighbors inherit their template's properties, except for their IP address. A template may omit .Ic remote-as ; .Xr bgpd 8 then accepts any AS presented by the neighbor in the .Em OPEN message. .Pp The neighbor properties are as follows: .Pp .Bl -tag -width Ds -compact .It Xo .Ic announce .Pq Ic IPv4 Ns | Ns Ic IPv6 .Pq Ic none Ns | Ns Ic unicast Ns | Ns Ic vpn Ns | Ns Ic flowspec .Op Ic enforce .Xc For the given address family, control which .Em subsequent address families are announced during the capabilities negotiation. Only routes for that address family and subsequent address families will be announced and processed. .Pp At the moment, only .Ic none , which disables the announcement of that address family, .Ic unicast , .Ic vpn , which allows the distribution of BGP MPLS VPNs, and .Ic flowspec , which allows the distribution of Flow Specification Rules, are supported. .Pp The default is .Ic unicast for the same address family of the session. .Pp .It Xo .Ic announce add-path recv .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic yes , the receive add-path capability is announced, which allows reception of multiple paths per prefix. The default is .Ic no . .Pp .It Xo .Ic announce add-path send .Pq Ic no Ns | Ns Ic all .Op Ic enforce .Xc .It Xo .Ic announce add-path send .Pq Ic best Ns | Ns Ic ecmp Ns | Ns Ic as-wide-best .Op Ic plus Ar num .Op Ic max Ar num .Op Ic enforce .Xc If set to .Ic all , .Ic best , .Ic ecmp , or .Ic as-wide-best , the send add-path capability is announced, which allows sending multiple paths per prefix. The paths sent depend on which mode is selected: .Pp .Bl -tag -width as-wide-best -compact .It Ic no do not advertise add-path send capability .It Ic all send all valid paths .It Ic best send the best path .It Ic ecmp send paths with equal nexthop cost .It Ic as-wide-best send paths where the first 8 checks of the decision process match .El .Pp .Ic plus allows the inclusion of additional backup paths and works for .Ic best , .Ic ecmp , and .Ic as-wide-best . .Ic max can be used to limit the total amount of paths sent for .Ic ecmp and .Ic as-wide-best . Right now .Ic ecmp and .Ic as-wide-best are equivalent. The default is .Ic no . If .Ic add-path Ic send is active then the setting of .Ic rde Ic evaluate is ignored. .Pp .It Xo .Ic announce as-4byte .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic no , the 4-byte AS capability is not announced and so native 4-byte AS support is disabled. If .Ic enforce is set, the session will only be established if the neighbor also announces the capability. The default is .Ic yes . .Pp .It Xo .Ic announce enhanced refresh .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic yes , the enhanced route refresh capability is announced. If .Ic enforce is set, the session will only be established if the neighbor also announces the capability. The default is .Ic no . .Pp .It Xo .Ic announce extended message .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic yes , the extended message capability is announced. If negotiated, the default maximum message size is increased from 4096 to 65535 bytes. If .Ic enforce is set, the session will only be established if the neighbor also announces the capability. The default is .Ic no . .Pp .It Xo .Ic announce extended nexthop .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic yes , the extended nexthop encoding capability is announced. If negotiated, .Ic IPv4 unicast and .Ic vpn sessions can send paths with a IPv6 nexthop. If .Ic enforce is set, the session will only be established if the neighbor also announces the capability. The default is .Ic no . .Pp .It Xo .Ic announce graceful notification .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic yes , the graceful notification extension to graceful restart is announced. The default is .Ic no . .Ic announce refresh must be enabled to enable graceful notifications. .Pp .It Xo .Ic announce policy .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic yes , add the open policy role capability. If the role of the neighbor does not correspond to the expected role then the session will be closed. If .Ic enforce is set, the session will only be established if the neighbor also announces the capability. The default is .Ic no . .Pp .It Xo .Ic announce refresh .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic no , the route refresh capability is not announced. If .Ic enforce is set, the session will only be established if the neighbor also announces the capability. The default is .Ic yes . .Pp .It Xo .Ic announce restart .Pq Ic yes Ns | Ns Ic no Ns | Ns Ic enforce .Xc If set to .Ic no , the graceful restart capability is not announced. Currently only the End-of-RIB marker is supported and announced by the .Ic restart capability. If .Ic enforce is set, the session will only be established if the neighbor also announces the capability. The default is .Ic yes . .Pp .It Xo .Ic as-override .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic yes , all occurrences of the neighbor AS in the .Em AS path will be replaced with the local AS before running the filters. The Adj-RIB-In still holds the unmodified AS path. The default value is .Ic no . .Pp .It Ic demote Ar group Increase the .Xr carp 4 demotion counter on the given interface group, usually .Ar carp , when the session is not in state .Em ESTABLISHED . The demotion counter will be increased as soon as .Xr bgpd 8 starts and decreased 60 seconds after the session went to state .Em ESTABLISHED . For neighbors added at runtime, the demotion counter is only increased after the session has been .Em ESTABLISHED at least once before dropping. .Pp For more information on interface groups, see the .Ic group keyword in .Xr ifconfig 8 . .Pp .It Ic depend on Ar interface The neighbor session will be kept in state .Em IDLE as long as .Ar interface reports no link. For .Xr carp 4 interfaces, no link means that the interface is currently .Em backup . This is primarily intended to be used with .Xr carp 4 to reduce failover times. .Pp The state of the network interfaces on the system can be viewed using the .Cm show interfaces command to .Xr bgpctl 8 . .Pp .It Ic descr Ar description Add a description. The description is used when logging neighbor events, in status reports, for specifying neighbors, etc., but has no further meaning to .Xr bgpd 8 . .Pp .It Ic down Op Ar reason Do not start the session when .Xr bgpd 8 comes up but stay in .Em IDLE . If the session is cleared at runtime, after a .Ic down .Ar reason was configured at runtime, the .Ar reason is sent as Administrative Shutdown Communication. The .Ar reason cannot exceed 255 octets. .Pp .It Xo .Ic dump .Pq Ic all Ns | Ns Ic updates .Pq Ic in Ns | Ns Ic out .Ar file Op Ar interval .Xc Dump ongoing BGP activity for a particular neighbor. See also the .Ic dump setting in .Sx GLOBAL CONFIGURATION . .Pp .It Xo .Ic enforce local-as .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic no , .Em AS paths will not be checked for AS loop detection. This feature is similar to allowas-in in some other BGP implementations. Since there is no AS path loop check, this feature is dangerous, and requires you to add filters to prevent receiving your own prefixes. The default value is .Ic yes . .Pp .It Xo .Ic enforce neighbor-as .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic yes , .Em AS paths whose .Em leftmost AS is not equal to the .Em remote AS of the neighbor are rejected and a .Em NOTIFICATION is sent back. The default value for IBGP peers is .Ic no otherwise the default is .Ic yes . .Pp .It Xo .Ic export .Sm off .Pq Ic none | default-route .Sm on .Xc If set to .Ic none , no .Em UPDATE messages will be sent to the neighbor. If set to .Ic default-route , only the default route will be announced to the neighbor. .Pp .It Ic holdtime Ar seconds Set the holdtime in seconds. Inherited from the global configuration if not given. .Pp .It Ic holdtime min Ar seconds Set the minimal acceptable holdtime. Inherited from the global configuration if not given. .Pp .It Xo .Ic ipsec .Pq Ic ah Ns | Ns Ic esp .Pq Ic in Ns | Ns Ic out .Ic spi Ar spi-number authspec Op Ar encspec .Xc Enable IPsec with static keying. There must be at least two .Ic ipsec statements per peer with manual keying, one per direction. .Ar authspec specifies the authentication algorithm and key. It can be .Bd -literal -offset indent sha1 md5 .Ed .Pp .Ar encspec specifies the encryption algorithm and key. .Ic ah does not support encryption. With .Ic esp , encryption is optional. .Ar encspec can be .Bd -literal -offset indent 3des 3des-cbc aes aes-128-cbc .Ed .Pp Keys must be given in hexadecimal format. After changing settings, a session needs to be reset to use the new keys. The .Ic ipsec flows only work with session using the default port 179. .Pp .It Xo .Ic ipsec .Pq Ic ah Ns | Ns Ic esp .Ic ike .Xc Enable IPsec with dynamic keying. In this mode, .Xr bgpd 8 sets up the flows, and a key management daemon such as .Xr isakmpd 8 is responsible for managing the session keys. With .Xr isakmpd 8 , it is sufficient to copy the peer's public key, found in .Pa /etc/isakmpd/local.pub , to the local machine. It must be stored in a file named after the peer's IP address and must be stored in .Pa /etc/isakmpd/pubkeys/ipv4/ . The local public key must be copied to the peer in the same way. As .Xr bgpd 8 manages the flows on its own, it is sufficient to restrict .Xr isakmpd 8 to only take care of keying by specifying the flags .Fl Ka . This can be done in .Xr rc.conf.local 8 . After starting the .Xr isakmpd 8 and .Xr bgpd 8 daemons on both sides, the session should be established. After changing settings, a session needs to be reset to use the new keys. The .Ic ipsec flows only work with session using the default port 179. .Pp .It Ic local-address Ar address .It Ic no local-address When .Xr bgpd 8 initiates the TCP connection to the neighbor system, it normally does not bind to a specific IP address. If a .Ic local-address is given, .Xr bgpd 8 binds to this address first. .Ic no local-address reverts back to the default. .Pp .It Ic local-as Ar as-number Op Ar as-number Set the AS number sent to the remote system. Used as described above under .Sx GLOBAL CONFIGURATION option .Ic AS . .Pp Since there is no AS path loop check, this option is dangerous, and requires you to add filters to prevent receiving your ASNs. Intended to be used temporarily, for migrations to another AS. .Pp .It Ic log no Disable neighbor specific logging. .Pp .It Ic log updates Log received and sent updates for this neighbor. .Pp .It Xo .Ic max-prefix Ar number .Op Ic restart Ar number .Xc Terminate the session when the maximum .Ar number of prefixes received is exceeded (no such limit is imposed by default). If .Ic restart is specified, the session will be restarted after .Ar number minutes. .Pp .It Xo .Ic max-prefix Ar number Ic out .Op Ic restart Ar number .Xc Terminate the session when the maximum .Ar number of prefixes sent is exceeded (no such limit is imposed by default). If .Ic restart is specified, the session will be restarted after .Ar number minutes. .Pp .It Ic multihop Ar hops Neighbors not in the same AS as the local .Xr bgpd 8 normally have to be directly connected to the local machine. If this is not the case, the .Ic multihop statement defines the maximum hops the neighbor may be away. .Pp .It Ic passive Do not attempt to actively open a TCP connection to the neighbor system. .Pp .It Ic port Ar port Connect to the peer using .Ar port instead of the default BGP port 179. .Pp .It Xo .Ic reject Ic as-set .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic yes , .Em AS paths attributes containing .Em AS_SET path segments will be rejected and all prefixes will be treated as withdraws. The default is inherited from the global .Ic reject Ic as-set setting. .Pp .It Ic remote-as Ar as-number Set the AS number of the remote system. .Pp .It Xo .Ic rde Ic evaluate .Pq Ic default Ns | Ns Ic all .Xc If set to .Ar all , keep evaluating alternative paths in case the selected path is filtered out. By default if a path is filtered by the output filters then no alternative path is sent to this peer. The default is inherited from the global .Ic rde Ic evaluate setting. .Pp .It Ic rib Ar name Bind the neighbor to the specified RIB. .Pp .It Ic role Ar role Set the local role for this eBGP session. Setting a role is required for ASPA verification, the open policy role capability and Only-To-Customer (OTC) attribute of RFC 9234. The role can be one of .Ar none , .Ar provider , .Ar customer , .Ar rs , .Ar rs-client , or .Ar peer . If the role is set to .Ar none the .Ic announce Ic policy will also be disabled. On iBGP session the role setting is ignored and forced to .Ar none . .Pp .It Ic route-reflector Op Ar address Act as an RFC 4456 .Em route-reflector for this neighbor. An optional cluster ID can be specified; otherwise the BGP ID will be used. .Pp .It Ic set Ar attribute ... Set the .Em AS path attributes to some default per .Ic neighbor or .Ic group block: .Bd -literal -offset indent set localpref 300 .Ed .Pp See also the .Sx ATTRIBUTE SET section. Set parameters are applied to the received prefixes; the only exceptions are .Ic prepend-self , .Ic nexthop no-modify and .Ic nexthop self . These sets are rewritten into filter rules and can be viewed with .Dq bgpd -nv . .Pp .It Ic staletime Ar seconds Set the upper bound stale time in seconds for graceful restart. Inherited from the global configuration if not given. .Pp .It Ic tcp md5sig password Ar secret .It Ic tcp md5sig key Ar secret Enable TCP MD5 signatures per RFC 2385. The shared secret can either be given as a password or hexadecimal key. .Bd -literal -offset indent tcp md5sig password mekmitasdigoat tcp md5sig key deadbeef .Ed After changing keys, a session needs to be reset to use the new keys. .Pp .It Xo .Ic transparent-as .Pq Ic yes Ns | Ns Ic no .Xc If set to .Ic yes , attribute transparency is enabled. See also the .Ic transparent-as setting in .Sx GLOBAL CONFIGURATION . The default is inherited from the global .Ic transparent-as setting. .Pp .It Xo .Ic ttl-security .Pq Ic yes Ns | Ns Ic no .Xc Enable or disable ttl-security. When enabled, outgoing packets are sent using a TTL of 255 and a check is made against an incoming packet's TTL. For directly connected peers, incoming packets are required to have a TTL of 255, ensuring they have not been routed. For multihop peers, incoming packets are required to have a TTL of 256 minus multihop distance, ensuring they have not passed through more than the expected number of hops. The default is .Ic no . .El .Sh FILTER .Xr bgpd 8 filters all BGP .Em UPDATE messages, including its own announcements, and blocks them by default. Filter rules may match on neighbor, direction, .Em prefix or .Em AS path attributes . Filter rules may also modify .Em AS path attributes . .Pp For each .Em UPDATE processed by the filter, the filter rules are evaluated in sequential order, from first to last. The last matching .Ic allow or .Ic deny rule decides what action is taken. The default action is to deny. .Pp The following actions can be used in the filter: .Bl -tag -width xxxxxxxx .It Ic allow The .Em UPDATE is passed. .It Ic deny The .Em UPDATE is blocked. .It Ic match Apply the filter attribute set without influencing the filter decision. .El .Sh PARAMETERS The rule parameters specify the .Em UPDATES to which a rule applies. An .Em UPDATE always comes from, or goes to, one neighbor. Most parameters are optional, but each can appear at most once per rule. If a parameter is specified, the rule only applies to packets with matching attributes. .Pp .Bl -tag -width Ds -compact .It Xo .Ar as-type Op Ar operator .Ar as-number .Xc .It Ar as-type Ic as-set Ar name This rule applies only to .Em UPDATES where the .Em AS path matches. The part of the .Em AS path specified by the .Ar as-type is matched against the .Ar as-number or the .Ic as-set Ar name : .Pp .Bl -tag -width transmit-as -compact .It Ic AS (any part) .It Ic peer-as (leftmost AS number) .It Ic source-as (rightmost AS number) .It Ic transit-as (all but the rightmost AS number) .El .Pp .Ar as-number is an AS number as explained above under .Sx GLOBAL CONFIGURATION . It may be set to .Ic neighbor-as , which is expanded to the current neighbor remote AS number, or .Ic local-as , which is expanded to the locally assigned AS number. .Pp When specifying an .Ic as-set Ar name , the AS path will instead be matched against all the AS numbers in the set. .Pp The .Ar operator can be unspecified (this case is identical to the equality operator), or one of the numerical operators .Bd -literal -offset indent = (equal) != (unequal) - (range including boundaries) >< (except range) .Ed .Pp >< and - are binary operators (they take two arguments); with these, .Ar as-number cannot be set to .Ic neighbor-as . .Pp Multiple .Ar as-number entries for a given type or .Ar as-type as-number entries may also be specified, separated by commas or whitespace, if enclosed in curly brackets: .Bd -literal -offset indent deny from any AS { 1, 2, 3 } deny from any { AS 1, source-as 2, transit-as 3 } deny from any { AS { 1, 2, 3 }, source-as 4, transit-as 5 } .Ed .Pp .It Xo .Ic avs .Pq Ic valid | unknown | invalid .Xc This rule applies only to .Em UPDATES where the ASPA Validation State (AVS) matches. .Pp .It Xo .Ic community .Ar as-number Ns Li \&: Ns Ar local .Xc .It Ic community Ar name This rule applies only to .Em UPDATES where the .Ic community path attribute is present and matches. Communities are specified as .Ar as-number : Ns Ar local , where .Ar as-number is an AS number and .Ar local is a locally significant number between zero and .Li 65535 . Both .Ar as-number and .Ar local may be set to .Sq * to do wildcard matching. Alternatively, well-known communities may be given by name instead and include .Ic BLACKHOLE , .Ic GRACEFUL_SHUTDOWN , .Ic NO_EXPORT , .Ic NO_ADVERTISE , .Ic NO_EXPORT_SUBCONFED , and .Ic NO_PEER . Both .Ar as-number and .Ar local may be set to .Ic neighbor-as , which is expanded to the current neighbor remote AS number, or .Ic local-as , which is expanded to the locally assigned AS number. .Pp .It Xo .Ic large-community .Ar as-number : Ns Ar local : Ns Ar local .Xc This rule applies only to .Em UPDATES where the .Ic Large community path attribute is present and matches. Communities are specified as .Ar as-number : Ns Ar local : Ns Ar local , where .Ar as-number is an AS number and .Ar local is a locally significant number between zero and .Li 4294967295 . Both .Ar as-number and .Ar local may be set to .Sq * to do wildcard matching, .Ic neighbor-as , which is expanded to the current neighbor remote AS number, or .Ic local-as , which is expanded to the locally assigned AS number. .Pp .It Xo .Ic ext-community .Ar subtype as-number : Ns Ar local .Xc .It Xo .Ic ext-community .Ar subtype IP : Ns Ar local .Xc .It Xo .Ic ext-community .Ar subtype numvalue .Xc .It Xo .Ic ext-community .Ic ovs .Pq Ic valid | not-found | invalid .Xc This rule applies only to .Em UPDATES where the .Em extended community path attribute is present and matches. Extended Communities are specified by a .Ar subtype and normally two values, a globally unique part (e.g. the AS number) and a local part. Both .Ar as-number and .Ar local may be set to .Ic neighbor-as , which is expanded to the current neighbor remote AS number, or .Ic local-as , which is expanded to the locally assigned AS number. Wildcard matching is supported for .Ar local , .Ar numvalue and .Ar subtype . If wildcard matching is used on the .Ar subtype then .Ar numvalue also needs to be set to .Sq * . See also the .Sx ATTRIBUTE SET section for further information about the encoding. .Pp .It Xo .Pq Ic from Ns | Ns Ic to .Ar peer .Xc This rule applies only to .Em UPDATES coming from, or going to, this particular neighbor. This parameter must be specified. .Ar peer is one of the following: .Pp .Bl -tag -width "group descr" -compact .It Ic any Any neighbor will be matched. .It Ic ibgp All .Em IBGP neighbors will be matched. .It Ic ebgp All .Em EBGP neighbors will be matched. .It Ar address Neighbors with this address will be matched. .It Ic group Ar descr Neighbors in this group will be matched. .It Ic AS Ar as-number Neighbors with this AS will be matched. .El .Pp Multiple .Ar peer entries may also be specified, separated by commas or whitespace, if enclosed in curly brackets: .Bd -literal -offset indent deny from { 128.251.16.1, 251.128.16.2, group hojo } .Ed .Pp .It Pq Ic inet Ns | Ns Ic inet6 Match only routes in the IPv4 or IPv6 address families, respectively. .Ic inet is an alias for .Qq prefix 0.0.0.0/0 prefixlen >= 0 ; .Ic inet6 is an alias for .Qq prefix ::/0 prefixlen >= 0 . .Pp .It Ic max-as-len Ar len This rule applies only to .Em UPDATES where the .Em AS path has more than .Ar len elements. .Pp .It Ic max-as-seq Ar len This rule applies only to .Em UPDATES where a single .Em AS number is repeated more than .Ar len times. .Pp .It Ic max-communities Ns | Ns Ic max-large-communities Ns | \ Ns Ic max-ext-communities Ar num This rule applies only to .Em UPDATES where the .Em Basic , .Em Large , or .Em Extended Community attribute has more than .Ar num elements. .Pp .It Ic nexthop Ar address This rule applies only to .Em UPDATES where the nexthop is equal to .Ar address . The .Ar address can be set to .Em neighbor in which case the nexthop is compared against the address of the neighbor. Nexthop filtering is not supported on locally announced networks and one must take into consideration previous rules overwriting nexthops. .Pp .It Ic origin-set Ar name This rule applies only to .Em UPDATES that match the given origin-set .Ar name . .Pp .It Xo .Ic ovs .Pq Ic valid | not-found | invalid .Xc This rule applies only to .Em UPDATES where the Origin Validation State (OVS) matches. .Pp .It Ic prefix Ar address Ns Li / Ns Ar len .It Ic prefix Ar address Ns Li / Ns Ar len Ic prefixlen Ar range .It Ic prefix Ar address Ns Li / Ns Ar len Ic or-longer .It Ic prefix Ar address Ns Li / Ns Ar len Ic maxlen Ar mlen This rule applies only to .Em UPDATES for the specified prefix. .Pp Multiple entries may be specified, separated by commas or whitespace, if enclosed in curly brackets: .Bd -literal -offset indent deny from any prefix { 192.168.0.0/16, 10.0.0.0/8 or-longer } .Ed .Pp Multiple lists can also be specified, which is useful for macro expansion: .Bd -literal -offset indent good="{ 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8 }" bad="{ 224.0.0.0/4 prefixlen >= 4, 240.0.0.0/4 prefixlen >= 4 }" ugly="{ 127.0.0.1/8, 169.254.0.0/16 }" deny from any prefix { $good $bad $ugly } .Ed .Pp Prefix length ranges are specified by using these operators: .Bd -literal -offset indent = (equal) != (unequal) < (less than) <= (less than or equal) > (greater than) >= (greater than or equal) - (range including boundaries) >< (except range) .Ed .Pp >< and - are binary operators (they take two arguments). For instance, to match all prefix lengths >= 8 and <= 12, and hence the CIDR netmasks 8, 9, 10, 11 and 12: .Bd -literal -offset indent prefixlen 8-12 .Ed .Pp Or, to match all prefix lengths < 8 or > 12, and hence the CIDR netmasks 0\(en7 and 13\(en32: .Bd -literal -offset indent prefixlen 8><12 .Ed .Pp This will match all prefixes in the 10.0.0.0/8 netblock with netmasks longer than 16: .Bd -literal -offset indent prefix 10.0.0.0/8 prefixlen > 16 .Ed .Pp .Ic or-longer is a shorthand for: .Bd -literal -offset indent .Ic prefix Ar address Ns Li / Ns Ar len Ic prefixlen >= Ar len .Ed .Pp .Ic maxlen Ar mlen is a shorthand for: .Bd -literal -offset indent .Ic prefix Ar address Ns Li / Ns Ar len Ic prefixlen <= Ar mlen .Ed .Pp .It Ic prefix-set Ar name Op Ic or-longer This rule applies only to .Em UPDATES that match the given prefix-set .Ar name . With .Ic or-longer , the .Em UPDATES will match any prefix in the prefix-set where .Bd -literal -offset indent .Ic address Ns Li / Ns Ar len Ic prefixlen >= Ar len .Ed .Pp .It Ic quick If an .Em UPDATE matches a rule which has the .Ic quick option set, this rule is considered the last matching rule, and evaluation of subsequent rules is skipped. .Pp .It Ic rib Ar name Apply rule only to the specified RIB. This only applies for received updates, so not for rules using the .Ar to peer parameter. .Pp .It Ic set Ar attribute ... All matching rules can set the .Em AS path attributes to some default. The set of every matching rule is applied, not only the last matching one. See also the following section. .El .Sh ATTRIBUTE SET .Em AS path attributes can be modified with .Ic set . .Pp .Ic set can be used on .Ic network statements, in .Ic neighbor or .Ic group blocks, and on filter rules. Attribute sets can be expressed as lists. .Pp The following attributes can be modified: .Pp .Bl -tag -width Ds -compact .It Xo .Ic community Op Ar delete .Ar as-number : Ns Ar local .Xc .It Xo .Ic community Op Ar delete .Ar name .Xc Set or delete the .Em COMMUNITIES AS path attribute. Communities are specified as .Ar as-number : Ns Ar local , where .Ar as-number is an AS number and .Ar local is a locally significant number between zero and .Li 65535 . Alternately, well-known communities may be specified by name: .Ic GRACEFUL_SHUTDOWN , .Ic NO_EXPORT , .Ic NO_ADVERTISE , .Ic NO_EXPORT_SUBCONFED , or .Ic NO_PEER . For .Cm delete , both .Ar as-number and .Ar local may be set to .Sq * to do wildcard matching. .Pp .It Xo .Ic large-community Op Ar delete .Ar as-number : Ns Ar local : Ns Ar local .Xc .It Xo .Ic large-community Op Ar delete .Ar name .Xc Set or delete the .Em Large Communities path attribute. Communities are specified as .Ar as-number : Ns Ar local : Ns Ar local , where .Ar as-number is an AS number and .Ar local is a locally significant number between zero and .Li 4294967295 . For .Cm delete , both .Ar as-number and .Ar local may be set to .Sq * to do wildcard matching. .Pp .It Xo .Ic ext-community Op Ar delete .Ar subtype as-number : Ns Ar local .Xc .It Xo .Ic ext-community Op Ar delete .Ar subtype IP : Ns Ar local .Xc .It Xo .Ic ext-community Op Ar delete .Ar subtype numvalue .Xc .It Xo .Ic ext-community Op Ar delete .Ic ovs .Pq Ic valid | not-found | invalid .Xc Set or delete the .Em Extended Community AS path attribute. Extended Communities are specified by a .Ar subtype and normally two values, a globally unique part (e.g. the AS number) and a local part. The type is selected depending on the encoding of the global part. Two-octet AS Specific Extended Communities and Four-octet AS Specific Extended Communities are encoded as .Ar as-number : Ns Ar local . Four-octet encoding is used if the .Ar as-number is bigger than 65535 or if the AS_DOT encoding is used. IPv4 Address Specific Extended Communities are encoded as .Ar IP : Ns Ar local . Opaque Extended Communities are encoded with a single numeric value. The .Ar ovs subtype can only be set to .Ar valid , .Ar not-found , or .Ar invalid . Currently the following subtypes are supported: .Bd -literal -offset indent bdc BGP Data Collection defgw Default Gateway esi-lab ESI Label esi-rt ES-Import Route Target l2vid L2VPN Identifier mac-mob MAC Mobility odi OSPF Domain Identifier ort OSPF Route Type ori OSPF Router ID ovs BGP Origin Validation State rt Route Target soo Route Origin / Source of Origin srcas Source AS vrfri VRF Route Import .Ed .Pp Not all type and subtype value pairs are allowed by IANA and the parser will ensure that no invalid combination is created. .Pp For .Cm delete , .Ar subtype , .Ar numvalue , or .Ar local , may be set to .Sq * to do wildcard matching. If wildcard matching is used on the .Ar subtype then .Ar numvalue also needs to be set to .Sq * . .Pp .It Ic localpref Ar number Set the .Em LOCAL_PREF AS path attribute. If .Ar number starts with a plus or minus sign, .Em LOCAL_PREF will be adjusted by adding or subtracting .Ar number ; otherwise it will be set to .Ar number . The default is 100. .Pp .It Ic med Ar number .It Ic metric Ar number Set the .Em MULTI_EXIT_DISC AS path attribute. If .Ar number starts with a plus or minus sign, .Em MULTI_EXIT_DISC will be adjusted by adding or subtracting .Ar number ; otherwise it will be set to .Ar number . .Pp .It Xo .Ic origin .Sm off .Pq Ic igp | egp | incomplete .Sm on .Xc Set the .Em ORIGIN AS path attribute to mark the source of this route as being injected from an igp protocol, an egp protocol or being an aggregated route. .Pp .It Xo .Ic nexthop .Sm off .Pq Ar address | Ic blackhole | reject | self | no-modify .Sm on .Xc Set the .Em NEXTHOP AS path attribute to a different nexthop address or use blackhole or reject routes. .Em blackhole and .Em reject only affect the FIB and will not alter the nexthop address. .Em self forces the nexthop to be set to the local interface address. If set to .Em no-modify , the nexthop attribute is not modified for EBGP multihop sessions. By default EBGP multihop sessions use the local interface address. On other IBGP and directly connected EBGP sessions .Em no-modify is ignored. The set .Ar address is used on IBGP session and on directly connected EBGP session if the .Ar address is part of the connected network. On EBGP multihop session .Em no-modify has to be set to force the nexthop to .Ar address . .Bd -literal -offset indent set nexthop 192.168.0.1 set nexthop blackhole set nexthop reject set nexthop no-modify set nexthop self .Ed .Pp .It Ic pftable Ar table Add the prefix in the update to the specified .Xr pf 4 table, regardless of whether or not the path was selected for routing. This option may be useful in building realtime blacklists. .Pp .It Ic prepend-neighbor Ar number Prepend the neighbor's AS .Ar number times to the .Em AS path . .Pp .It Ic prepend-self Ar number Prepend the local AS .Ar number times to the .Em AS path . .Pp .It Ic rtlabel Ar label Add the prefix to the kernel routing table with the specified .Ar label . .Pp .It Ic weight Ar number The .Em weight is used to tip prefixes with equally long AS paths in one or the other direction. A prefix is weighed at a very late stage in the decision process. If .Ar number starts with a plus or minus sign, the .Em weight will be adjusted by adding or subtracting .Ar number ; otherwise it will be set to .Ar number . .Em Weight is a local non-transitive attribute, and is a .Xr bgpd 8 Ns -specific extension. For prefixes with equally long paths, the prefix with the larger weight is selected. .El .Sh FILES .Bl -tag -width "@SYSCONFDIR@/bgpd.conf" -compact .It Pa @SYSCONFDIR@/bgpd.conf .Xr bgpd 8 configuration file. .El .Sh SEE ALSO .Xr strftime 3 , .Xr ipsec 4 , .Xr pf 4 , .Xr rdomain 4 , .Xr tcp 4 , .Xr bgpctl 8 , .Xr bgpd 8 , .Xr ipsecctl 8 , .Xr isakmpd 8 , .Xr rc.conf.local 8 .Sh HISTORY The .Nm file format first appeared in .Ox 3.5 . openbgpd-8.8/src/bgpctl/Makefile.am100644 001750 001750 00000003615 14576036603 0013006# # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS += -I$(top_srcdir)/src/bgpd AM_CPPFLAGS += -I$(top_srcdir)/src/bgpctl ACLOCAL_AMFLAGS = -Im4 sbin_PROGRAMS = bgpctl man_MANS = bgpctl.8 EXTRA_DIST = bgpctl.8.in CLEANFILES = $(man_MANS) bgpctl_CFLAGS = $(AM_CFLAGS) bgpctl_CFLAGS += -DSYSCONFDIR=\"$(sysconfdir)\" bgpctl_CFLAGS += -DRUNSTATEDIR=\"$(runstatedir)\" bgpctl_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) -lutil -lm bgpctl_LDADD += $(top_builddir)/compat/libcompat.la bgpctl_LDADD += $(top_builddir)/compat/libcompatnoopt.la bgpctl_SOURCES = bgpctl.c bgpctl_SOURCES += ometric.c bgpctl_SOURCES += output.c bgpctl_SOURCES += output_json.c bgpctl_SOURCES += output_ometric.c bgpctl_SOURCES += parser.c bgpctl_SOURCES += mrtparser.c bgpctl_SOURCES += util.c bgpctl_SOURCES += json.c bgpctl_SOURCES += flowspec.c bgpctl_DEPENDENCIES = $(man_MANS) noinst_HEADERS = bgpctl.h noinst_HEADERS += json.h noinst_HEADERS += mrtparser.h noinst_HEADERS += ometric.h noinst_HEADERS += parser.h bgpctl.8: bgpctl.8.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ '$(srcdir)/bgpctl.8.in' >$@ openbgpd-8.8/src/bgpctl/bgpctl.h100644 001750 001750 00000004605 14571326703 0012374/* $OpenBSD: bgpctl.h,v 1.24 2024/01/31 11:23:20 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ struct parse_result; struct output { void (*head)(struct parse_result *); void (*neighbor)(struct peer *, struct parse_result *); void (*timer)(struct ctl_timer *); void (*fib)(struct kroute_full *); void (*fib_table)(struct ktable *); void (*flowspec)(struct flowspec *); void (*nexthop)(struct ctl_show_nexthop *); void (*interface)(struct ctl_show_interface *); void (*attr)(struct ibuf *, int, int); void (*communities)(struct ibuf *, struct parse_result *); void (*rib)(struct ctl_show_rib *, struct ibuf *, struct parse_result *); void (*rib_mem)(struct rde_memstats *); void (*set)(struct ctl_show_set *); void (*rtr)(struct ctl_show_rtr *); void (*result)(u_int); void (*tail)(void); }; extern const struct output show_output, json_output, ometric_output; #define EOL0(flag) ((flag & F_CTL_SSV) ? ';' : '\n') time_t get_monotime(time_t); char *fmt_peer(const char *, const struct bgpd_addr *, int); const char *fmt_timeframe(time_t); const char *fmt_monotime(time_t); const char *fmt_fib_flags(uint16_t); const char *fmt_origin(uint8_t, int); const char *fmt_flags(uint32_t, int); const char *fmt_ovs(uint8_t, int); const char *fmt_avs(uint8_t, int); const char *fmt_auth_method(enum auth_method); const char *fmt_mem(long long); const char *fmt_errstr(uint8_t, uint8_t); const char *fmt_attr(uint8_t, int); const char *fmt_community(uint16_t, uint16_t); const char *fmt_large_community(uint32_t, uint32_t, uint32_t); const char *fmt_ext_community(uint64_t); const char *fmt_set_type(struct ctl_show_set *); #define MPLS_LABEL_OFFSET 12 openbgpd-8.8/src/bgpctl/json.h100644 001750 001750 00000002627 14453465437 0012103/* $OpenBSD: json.h,v 1.8 2023/06/05 16:24:05 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include void json_do_start(FILE *); int json_do_finish(void); void json_do_array(const char *); void json_do_object(const char *, int); void json_do_end(void); void json_do_printf(const char *, const char *, ...) __attribute__((__format__ (printf, 2, 3))); void json_do_string(const char *, const char *); void json_do_hexdump(const char *, void *, size_t); void json_do_bool(const char *, int); void json_do_uint(const char *, unsigned long long); void json_do_int(const char *, long long); void json_do_double(const char *, double); openbgpd-8.8/src/bgpctl/mrtparser.h100644 001750 001750 00000004756 14571326703 0013147/* $OpenBSD: mrtparser.h,v 1.7 2024/02/01 11:37:10 claudio Exp $ */ /* * Copyright (c) 2011 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "bgpd.h" /* data structures for the MSG_TABLE_DUMP_V2 format */ struct mrt_peer_entry { struct bgpd_addr addr; uint32_t bgp_id; uint32_t asnum; }; struct mrt_peer { char *view; struct mrt_peer_entry *peers; uint32_t bgp_id; uint16_t npeers; }; struct mrt_attr { void *attr; size_t attr_len; }; struct mrt_rib_entry { void *aspath; struct mrt_attr *attrs; struct bgpd_addr nexthop; time_t originated; uint32_t local_pref; uint32_t med; uint32_t path_id; uint16_t peer_idx; uint16_t aspath_len; uint16_t nattrs; uint8_t origin; }; struct mrt_rib { struct mrt_rib_entry *entries; struct bgpd_addr prefix; uint32_t seqnum; uint16_t nentries; uint8_t prefixlen; uint8_t add_path; }; /* data structures for the BGP4MP MESSAGE and STATE types */ struct mrt_bgp_state { struct timespec time; struct bgpd_addr src; struct bgpd_addr dst; uint32_t src_as; uint32_t dst_as; uint16_t old_state; uint16_t new_state; }; struct mrt_bgp_msg { struct timespec time; struct bgpd_addr src; struct bgpd_addr dst; uint32_t src_as; uint32_t dst_as; uint8_t add_path; struct ibuf msg; }; #define MRT_ATTR_ORIGIN 1 #define MRT_ATTR_ASPATH 2 #define MRT_ATTR_NEXTHOP 3 #define MRT_ATTR_MED 4 #define MRT_ATTR_LOCALPREF 5 #define MRT_ATTR_MP_REACH_NLRI 14 #define MRT_ATTR_AS4PATH 17 #define MRT_ATTR_EXTLEN 0x10 #define MRT_PREFIX_LEN(x) ((((u_int)x) + 7) / 8) struct mrt_parser { void (*dump)(struct mrt_rib *, struct mrt_peer *, void *); void (*state)(struct mrt_bgp_state *, void *); void (*message)(struct mrt_bgp_msg *, void *); void *arg; }; void mrt_parse(int, struct mrt_parser *, int); openbgpd-8.8/src/bgpctl/ometric.h100644 001750 001750 00000004067 14403051271 0012552/* $OpenBSD: ometric.h,v 1.6 2023/01/06 13:26:57 tb Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ enum ometric_type { OMT_UNKNOWN, OMT_GAUGE, OMT_COUNTER, OMT_STATESET, OMT_HISTOGRAM, OMT_SUMMARY, OMT_INFO, }; struct ometric; struct olabels; struct ometric *ometric_new(enum ometric_type, const char *, const char *); struct ometric *ometric_new_state(const char * const *, size_t, const char *, const char *); void ometric_free_all(void); struct olabels *olabels_new(const char * const *, const char **); void olabels_free(struct olabels *); int ometric_output_all(FILE *); /* functions to set gauge and counter metrics */ void ometric_set_int(struct ometric *, uint64_t, struct olabels *); void ometric_set_float(struct ometric *, double, struct olabels *); void ometric_set_timespec(struct ometric *, const struct timespec *, struct olabels *); void ometric_set_info(struct ometric *, const char **, const char **, struct olabels *); void ometric_set_state(struct ometric *, const char *, struct olabels *); void ometric_set_int_with_labels(struct ometric *, uint64_t, const char **, const char **, struct olabels *); void ometric_set_timespec_with_labels(struct ometric *, struct timespec *, const char **, const char **, struct olabels *); #define OKV(...) (const char *[]){ __VA_ARGS__, NULL } openbgpd-8.8/src/bgpctl/parser.h100644 001750 001750 00000004500 14422264225 0012402/* $OpenBSD: parser.h,v 1.46 2023/04/21 09:12:41 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include "bgpd.h" enum actions { NONE, SHOW, SHOW_SUMMARY, SHOW_SUMMARY_TERSE, SHOW_NEIGHBOR, SHOW_NEIGHBOR_TIMERS, SHOW_NEIGHBOR_TERSE, SHOW_FIB, SHOW_FIB_TABLES, SHOW_RIB, SHOW_MRT, SHOW_SET, SHOW_RTR, SHOW_RIB_MEM, SHOW_NEXTHOP, SHOW_INTERFACE, SHOW_METRICS, RELOAD, FIB, FIB_COUPLE, FIB_DECOUPLE, LOG_VERBOSE, LOG_BRIEF, NEIGHBOR, NEIGHBOR_UP, NEIGHBOR_DOWN, NEIGHBOR_CLEAR, NEIGHBOR_RREFRESH, NEIGHBOR_DESTROY, NETWORK_ADD, NETWORK_REMOVE, NETWORK_FLUSH, NETWORK_SHOW, NETWORK_MRT, NETWORK_BULK_ADD, NETWORK_BULK_REMOVE, FLOWSPEC_ADD, FLOWSPEC_REMOVE, FLOWSPEC_FLUSH, FLOWSPEC_SHOW, }; struct parse_result { struct bgpd_addr addr; struct bgpd_addr peeraddr; struct filter_as as; struct filter_set_head set; struct community community; char peerdesc[PEER_DESCR_LEN]; char rib[PEER_DESCR_LEN]; char reason[REASON_LEN]; const char *ext_comm_subtype; uint64_t rd; int flags; int is_group; int mrtfd; u_int rtableid; uint32_t pathid; enum actions action; uint8_t validation_state; uint8_t prefixlen; uint8_t aid; struct flowstate { struct bgpd_addr src; struct bgpd_addr dst; uint8_t *components[FLOWSPEC_TYPE_MAX]; uint16_t complen[FLOWSPEC_TYPE_MAX]; uint8_t srclen; uint8_t dstlen; } flow; }; __dead void usage(void); struct parse_result *parse(int, char *[]); int parse_prefix(const char *, size_t, struct bgpd_addr *, uint8_t *); openbgpd-8.8/src/bgpctl/Makefile.in100644 001750 001750 00000126744 14751151140 0013015# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ sbin_PROGRAMS = bgpctl$(EXEEXT) subdir = src/bgpctl ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" PROGRAMS = $(sbin_PROGRAMS) am_bgpctl_OBJECTS = bgpctl-bgpctl.$(OBJEXT) bgpctl-ometric.$(OBJEXT) \ bgpctl-output.$(OBJEXT) bgpctl-output_json.$(OBJEXT) \ bgpctl-output_ometric.$(OBJEXT) bgpctl-parser.$(OBJEXT) \ bgpctl-mrtparser.$(OBJEXT) bgpctl-util.$(OBJEXT) \ bgpctl-json.$(OBJEXT) bgpctl-flowspec.$(OBJEXT) bgpctl_OBJECTS = $(am_bgpctl_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = bgpctl_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(bgpctl_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/bgpctl-bgpctl.Po \ ./$(DEPDIR)/bgpctl-flowspec.Po ./$(DEPDIR)/bgpctl-json.Po \ ./$(DEPDIR)/bgpctl-mrtparser.Po ./$(DEPDIR)/bgpctl-ometric.Po \ ./$(DEPDIR)/bgpctl-output.Po ./$(DEPDIR)/bgpctl-output_json.Po \ ./$(DEPDIR)/bgpctl-output_ometric.Po \ ./$(DEPDIR)/bgpctl-parser.Po ./$(DEPDIR)/bgpctl-util.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(bgpctl_SOURCES) DIST_SOURCES = $(bgpctl_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } man8dir = $(mandir)/man8 NROFF = nroff MANS = $(man_MANS) HEADERS = $(noinst_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LDFLAGS = @AM_LDFLAGS@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BGPD_USER = @BGPD_USER@ BGPLGD_USER = @BGPLGD_USER@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ WWW_USER = @WWW_USER@ YACC = @YACC@ YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwrunstatedir = @wwwrunstatedir@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/bgpd \ -I$(top_srcdir)/src/bgpctl ACLOCAL_AMFLAGS = -Im4 man_MANS = bgpctl.8 EXTRA_DIST = bgpctl.8.in CLEANFILES = $(man_MANS) bgpctl_CFLAGS = $(AM_CFLAGS) -DSYSCONFDIR=\"$(sysconfdir)\" \ -DRUNSTATEDIR=\"$(runstatedir)\" bgpctl_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) -lutil -lm \ $(top_builddir)/compat/libcompat.la \ $(top_builddir)/compat/libcompatnoopt.la bgpctl_SOURCES = bgpctl.c ometric.c output.c output_json.c \ output_ometric.c parser.c mrtparser.c util.c json.c flowspec.c bgpctl_DEPENDENCIES = $(man_MANS) noinst_HEADERS = bgpctl.h json.h mrtparser.h ometric.h parser.h all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/bgpctl/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign src/bgpctl/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): install-sbinPROGRAMS: $(sbin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ || test -f $$p1 \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \ } \ ; done uninstall-sbinPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(sbindir)" && rm -f $$files clean-sbinPROGRAMS: @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list bgpctl$(EXEEXT): $(bgpctl_OBJECTS) $(bgpctl_DEPENDENCIES) $(EXTRA_bgpctl_DEPENDENCIES) @rm -f bgpctl$(EXEEXT) $(AM_V_CCLD)$(bgpctl_LINK) $(bgpctl_OBJECTS) $(bgpctl_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-bgpctl.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-flowspec.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-json.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-mrtparser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-ometric.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-output.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-output_json.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-output_ometric.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-parser.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgpctl-util.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @echo '# dummy' >$@-t && $(am__mv) $@-t $@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< bgpctl-bgpctl.o: bgpctl.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-bgpctl.o -MD -MP -MF $(DEPDIR)/bgpctl-bgpctl.Tpo -c -o bgpctl-bgpctl.o `test -f 'bgpctl.c' || echo '$(srcdir)/'`bgpctl.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-bgpctl.Tpo $(DEPDIR)/bgpctl-bgpctl.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bgpctl.c' object='bgpctl-bgpctl.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-bgpctl.o `test -f 'bgpctl.c' || echo '$(srcdir)/'`bgpctl.c bgpctl-bgpctl.obj: bgpctl.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-bgpctl.obj -MD -MP -MF $(DEPDIR)/bgpctl-bgpctl.Tpo -c -o bgpctl-bgpctl.obj `if test -f 'bgpctl.c'; then $(CYGPATH_W) 'bgpctl.c'; else $(CYGPATH_W) '$(srcdir)/bgpctl.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-bgpctl.Tpo $(DEPDIR)/bgpctl-bgpctl.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bgpctl.c' object='bgpctl-bgpctl.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-bgpctl.obj `if test -f 'bgpctl.c'; then $(CYGPATH_W) 'bgpctl.c'; else $(CYGPATH_W) '$(srcdir)/bgpctl.c'; fi` bgpctl-ometric.o: ometric.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-ometric.o -MD -MP -MF $(DEPDIR)/bgpctl-ometric.Tpo -c -o bgpctl-ometric.o `test -f 'ometric.c' || echo '$(srcdir)/'`ometric.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-ometric.Tpo $(DEPDIR)/bgpctl-ometric.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ometric.c' object='bgpctl-ometric.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-ometric.o `test -f 'ometric.c' || echo '$(srcdir)/'`ometric.c bgpctl-ometric.obj: ometric.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-ometric.obj -MD -MP -MF $(DEPDIR)/bgpctl-ometric.Tpo -c -o bgpctl-ometric.obj `if test -f 'ometric.c'; then $(CYGPATH_W) 'ometric.c'; else $(CYGPATH_W) '$(srcdir)/ometric.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-ometric.Tpo $(DEPDIR)/bgpctl-ometric.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='ometric.c' object='bgpctl-ometric.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-ometric.obj `if test -f 'ometric.c'; then $(CYGPATH_W) 'ometric.c'; else $(CYGPATH_W) '$(srcdir)/ometric.c'; fi` bgpctl-output.o: output.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-output.o -MD -MP -MF $(DEPDIR)/bgpctl-output.Tpo -c -o bgpctl-output.o `test -f 'output.c' || echo '$(srcdir)/'`output.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-output.Tpo $(DEPDIR)/bgpctl-output.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='output.c' object='bgpctl-output.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-output.o `test -f 'output.c' || echo '$(srcdir)/'`output.c bgpctl-output.obj: output.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-output.obj -MD -MP -MF $(DEPDIR)/bgpctl-output.Tpo -c -o bgpctl-output.obj `if test -f 'output.c'; then $(CYGPATH_W) 'output.c'; else $(CYGPATH_W) '$(srcdir)/output.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-output.Tpo $(DEPDIR)/bgpctl-output.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='output.c' object='bgpctl-output.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-output.obj `if test -f 'output.c'; then $(CYGPATH_W) 'output.c'; else $(CYGPATH_W) '$(srcdir)/output.c'; fi` bgpctl-output_json.o: output_json.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-output_json.o -MD -MP -MF $(DEPDIR)/bgpctl-output_json.Tpo -c -o bgpctl-output_json.o `test -f 'output_json.c' || echo '$(srcdir)/'`output_json.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-output_json.Tpo $(DEPDIR)/bgpctl-output_json.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='output_json.c' object='bgpctl-output_json.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-output_json.o `test -f 'output_json.c' || echo '$(srcdir)/'`output_json.c bgpctl-output_json.obj: output_json.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-output_json.obj -MD -MP -MF $(DEPDIR)/bgpctl-output_json.Tpo -c -o bgpctl-output_json.obj `if test -f 'output_json.c'; then $(CYGPATH_W) 'output_json.c'; else $(CYGPATH_W) '$(srcdir)/output_json.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-output_json.Tpo $(DEPDIR)/bgpctl-output_json.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='output_json.c' object='bgpctl-output_json.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-output_json.obj `if test -f 'output_json.c'; then $(CYGPATH_W) 'output_json.c'; else $(CYGPATH_W) '$(srcdir)/output_json.c'; fi` bgpctl-output_ometric.o: output_ometric.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-output_ometric.o -MD -MP -MF $(DEPDIR)/bgpctl-output_ometric.Tpo -c -o bgpctl-output_ometric.o `test -f 'output_ometric.c' || echo '$(srcdir)/'`output_ometric.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-output_ometric.Tpo $(DEPDIR)/bgpctl-output_ometric.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='output_ometric.c' object='bgpctl-output_ometric.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-output_ometric.o `test -f 'output_ometric.c' || echo '$(srcdir)/'`output_ometric.c bgpctl-output_ometric.obj: output_ometric.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-output_ometric.obj -MD -MP -MF $(DEPDIR)/bgpctl-output_ometric.Tpo -c -o bgpctl-output_ometric.obj `if test -f 'output_ometric.c'; then $(CYGPATH_W) 'output_ometric.c'; else $(CYGPATH_W) '$(srcdir)/output_ometric.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-output_ometric.Tpo $(DEPDIR)/bgpctl-output_ometric.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='output_ometric.c' object='bgpctl-output_ometric.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-output_ometric.obj `if test -f 'output_ometric.c'; then $(CYGPATH_W) 'output_ometric.c'; else $(CYGPATH_W) '$(srcdir)/output_ometric.c'; fi` bgpctl-parser.o: parser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-parser.o -MD -MP -MF $(DEPDIR)/bgpctl-parser.Tpo -c -o bgpctl-parser.o `test -f 'parser.c' || echo '$(srcdir)/'`parser.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-parser.Tpo $(DEPDIR)/bgpctl-parser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='parser.c' object='bgpctl-parser.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-parser.o `test -f 'parser.c' || echo '$(srcdir)/'`parser.c bgpctl-parser.obj: parser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-parser.obj -MD -MP -MF $(DEPDIR)/bgpctl-parser.Tpo -c -o bgpctl-parser.obj `if test -f 'parser.c'; then $(CYGPATH_W) 'parser.c'; else $(CYGPATH_W) '$(srcdir)/parser.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-parser.Tpo $(DEPDIR)/bgpctl-parser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='parser.c' object='bgpctl-parser.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-parser.obj `if test -f 'parser.c'; then $(CYGPATH_W) 'parser.c'; else $(CYGPATH_W) '$(srcdir)/parser.c'; fi` bgpctl-mrtparser.o: mrtparser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-mrtparser.o -MD -MP -MF $(DEPDIR)/bgpctl-mrtparser.Tpo -c -o bgpctl-mrtparser.o `test -f 'mrtparser.c' || echo '$(srcdir)/'`mrtparser.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-mrtparser.Tpo $(DEPDIR)/bgpctl-mrtparser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mrtparser.c' object='bgpctl-mrtparser.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-mrtparser.o `test -f 'mrtparser.c' || echo '$(srcdir)/'`mrtparser.c bgpctl-mrtparser.obj: mrtparser.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-mrtparser.obj -MD -MP -MF $(DEPDIR)/bgpctl-mrtparser.Tpo -c -o bgpctl-mrtparser.obj `if test -f 'mrtparser.c'; then $(CYGPATH_W) 'mrtparser.c'; else $(CYGPATH_W) '$(srcdir)/mrtparser.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-mrtparser.Tpo $(DEPDIR)/bgpctl-mrtparser.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mrtparser.c' object='bgpctl-mrtparser.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-mrtparser.obj `if test -f 'mrtparser.c'; then $(CYGPATH_W) 'mrtparser.c'; else $(CYGPATH_W) '$(srcdir)/mrtparser.c'; fi` bgpctl-util.o: util.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-util.o -MD -MP -MF $(DEPDIR)/bgpctl-util.Tpo -c -o bgpctl-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-util.Tpo $(DEPDIR)/bgpctl-util.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='util.c' object='bgpctl-util.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c bgpctl-util.obj: util.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-util.obj -MD -MP -MF $(DEPDIR)/bgpctl-util.Tpo -c -o bgpctl-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-util.Tpo $(DEPDIR)/bgpctl-util.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='util.c' object='bgpctl-util.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi` bgpctl-json.o: json.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-json.o -MD -MP -MF $(DEPDIR)/bgpctl-json.Tpo -c -o bgpctl-json.o `test -f 'json.c' || echo '$(srcdir)/'`json.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-json.Tpo $(DEPDIR)/bgpctl-json.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='json.c' object='bgpctl-json.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-json.o `test -f 'json.c' || echo '$(srcdir)/'`json.c bgpctl-json.obj: json.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-json.obj -MD -MP -MF $(DEPDIR)/bgpctl-json.Tpo -c -o bgpctl-json.obj `if test -f 'json.c'; then $(CYGPATH_W) 'json.c'; else $(CYGPATH_W) '$(srcdir)/json.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-json.Tpo $(DEPDIR)/bgpctl-json.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='json.c' object='bgpctl-json.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-json.obj `if test -f 'json.c'; then $(CYGPATH_W) 'json.c'; else $(CYGPATH_W) '$(srcdir)/json.c'; fi` bgpctl-flowspec.o: flowspec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-flowspec.o -MD -MP -MF $(DEPDIR)/bgpctl-flowspec.Tpo -c -o bgpctl-flowspec.o `test -f 'flowspec.c' || echo '$(srcdir)/'`flowspec.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-flowspec.Tpo $(DEPDIR)/bgpctl-flowspec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='flowspec.c' object='bgpctl-flowspec.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-flowspec.o `test -f 'flowspec.c' || echo '$(srcdir)/'`flowspec.c bgpctl-flowspec.obj: flowspec.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -MT bgpctl-flowspec.obj -MD -MP -MF $(DEPDIR)/bgpctl-flowspec.Tpo -c -o bgpctl-flowspec.obj `if test -f 'flowspec.c'; then $(CYGPATH_W) 'flowspec.c'; else $(CYGPATH_W) '$(srcdir)/flowspec.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgpctl-flowspec.Tpo $(DEPDIR)/bgpctl-flowspec.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='flowspec.c' object='bgpctl-flowspec.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgpctl_CFLAGS) $(CFLAGS) -c -o bgpctl-flowspec.obj `if test -f 'flowspec.c'; then $(CYGPATH_W) 'flowspec.c'; else $(CYGPATH_W) '$(srcdir)/flowspec.c'; fi` mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-man8: $(man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(man_MANS)'; \ test -n "$(man8dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.8[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \ done; } uninstall-man8: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man8dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.8[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(PROGRAMS) $(MANS) $(HEADERS) installdirs: for dir in "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-generic clean-libtool clean-sbinPROGRAMS \ mostlyclean-am distclean: distclean-am -rm -f ./$(DEPDIR)/bgpctl-bgpctl.Po -rm -f ./$(DEPDIR)/bgpctl-flowspec.Po -rm -f ./$(DEPDIR)/bgpctl-json.Po -rm -f ./$(DEPDIR)/bgpctl-mrtparser.Po -rm -f ./$(DEPDIR)/bgpctl-ometric.Po -rm -f ./$(DEPDIR)/bgpctl-output.Po -rm -f ./$(DEPDIR)/bgpctl-output_json.Po -rm -f ./$(DEPDIR)/bgpctl-output_ometric.Po -rm -f ./$(DEPDIR)/bgpctl-parser.Po -rm -f ./$(DEPDIR)/bgpctl-util.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-man install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-sbinPROGRAMS install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-man8 install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/bgpctl-bgpctl.Po -rm -f ./$(DEPDIR)/bgpctl-flowspec.Po -rm -f ./$(DEPDIR)/bgpctl-json.Po -rm -f ./$(DEPDIR)/bgpctl-mrtparser.Po -rm -f ./$(DEPDIR)/bgpctl-ometric.Po -rm -f ./$(DEPDIR)/bgpctl-output.Po -rm -f ./$(DEPDIR)/bgpctl-output_json.Po -rm -f ./$(DEPDIR)/bgpctl-output_ometric.Po -rm -f ./$(DEPDIR)/bgpctl-parser.Po -rm -f ./$(DEPDIR)/bgpctl-util.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-man uninstall-sbinPROGRAMS uninstall-man: uninstall-man8 .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-generic clean-libtool clean-sbinPROGRAMS cscopelist-am \ ctags ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-dvi install-dvi-am install-exec \ install-exec-am install-html install-html-am install-info \ install-info-am install-man install-man8 install-pdf \ install-pdf-am install-ps install-ps-am install-sbinPROGRAMS \ install-strip installcheck installcheck-am installdirs \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \ uninstall-man uninstall-man8 uninstall-sbinPROGRAMS .PRECIOUS: Makefile bgpctl.8: bgpctl.8.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ '$(srcdir)/bgpctl.8.in' >$@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: openbgpd-8.8/src/bgpctl/bgpctl.c100644 001750 001750 00000135705 14751151130 0012363/* $OpenBSD: bgpctl.c,v 1.315 2025/01/31 20:07:53 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer * Copyright (c) 2004-2019 Claudio Jeker * Copyright (c) 2016 Job Snijders * Copyright (c) 2016 Peter Hessler * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "version.h" #include "bgpctl.h" #include "parser.h" #include "mrtparser.h" int main(int, char *[]); int show(struct imsg *, struct parse_result *); void send_filterset(struct imsgbuf *, struct filter_set_head *); void show_mrt_dump_neighbors(struct mrt_rib *, struct mrt_peer *, void *); void show_mrt_dump(struct mrt_rib *, struct mrt_peer *, void *); void network_mrt_dump(struct mrt_rib *, struct mrt_peer *, void *); void show_mrt_state(struct mrt_bgp_state *, void *); void show_mrt_msg(struct mrt_bgp_msg *, void *); const char *msg_type(uint8_t); void network_bulk(struct parse_result *); int match_aspath(void *, uint16_t, struct filter_as *); struct flowspec *res_to_flowspec(struct parse_result *); struct imsgbuf *imsgbuf; struct mrt_parser show_mrt = { show_mrt_dump, show_mrt_state, show_mrt_msg }; struct mrt_parser net_mrt = { network_mrt_dump, NULL, NULL }; const struct output *output = &show_output; int tableid; int nodescr; __dead void usage(void) { extern char *__progname; fprintf(stderr, "usage: %s [-jnV] [-s socket] command [argument ...]\n", __progname); exit(1); } int main(int argc, char *argv[]) { struct sockaddr_un sa_un; int fd, n, done, numdone, ch, verbose = 0; struct imsg imsg; struct network_config net; struct parse_result *res; struct ctl_neighbor neighbor; struct ctl_show_rib_request ribreq; struct flowspec *f; char *sockname; enum imsg_type type; if (pledge("stdio rpath wpath cpath unix inet dns", NULL) == -1) err(1, "pledge"); tableid = getrtable(); if (asprintf(&sockname, "%s.%d", SOCKET_NAME, tableid) == -1) err(1, "asprintf"); while ((ch = getopt(argc, argv, "jns:V")) != -1) { switch (ch) { case 'n': if (++nodescr > 1) usage(); break; case 'j': output = &json_output; break; case 's': sockname = optarg; break; case 'V': fprintf(stderr, "OpenBGPD %s\n", BGPD_VERSION); return 0; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; if ((res = parse(argc, argv)) == NULL) exit(1); memcpy(&neighbor.addr, &res->peeraddr, sizeof(neighbor.addr)); strlcpy(neighbor.descr, res->peerdesc, sizeof(neighbor.descr)); neighbor.is_group = res->is_group; strlcpy(neighbor.reason, res->reason, sizeof(neighbor.reason)); switch (res->action) { case SHOW_MRT: if (pledge("stdio", NULL) == -1) err(1, "pledge"); memset(&ribreq, 0, sizeof(ribreq)); if (res->as.type != AS_UNDEF) ribreq.as = res->as; if (res->addr.aid) { ribreq.prefix = res->addr; ribreq.prefixlen = res->prefixlen; } /* XXX currently no communities support */ ribreq.neighbor = neighbor; ribreq.aid = res->aid; ribreq.flags = res->flags; ribreq.validation_state = res->validation_state; show_mrt.arg = &ribreq; if (res->flags & F_CTL_NEIGHBORS) show_mrt.dump = show_mrt_dump_neighbors; else output->head(res); mrt_parse(res->mrtfd, &show_mrt, 1); exit(0); default: break; } if (pledge("stdio unix", NULL) == -1) err(1, "pledge"); if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) err(1, "control_init: socket"); memset(&sa_un, 0, sizeof(sa_un)); sa_un.sun_family = AF_UNIX; if (strlcpy(sa_un.sun_path, sockname, sizeof(sa_un.sun_path)) >= sizeof(sa_un.sun_path)) errx(1, "socket name too long"); if (connect(fd, (struct sockaddr *)&sa_un, sizeof(sa_un)) == -1) err(1, "connect: %s", sockname); if (pledge("stdio", NULL) == -1) err(1, "pledge"); if ((imsgbuf = malloc(sizeof(struct imsgbuf))) == NULL) err(1, NULL); if (imsgbuf_init(imsgbuf, fd) == -1 || imsgbuf_set_maxsize(imsgbuf, MAX_BGPD_IMSGSIZE) == -1) err(1, NULL); done = 0; switch (res->action) { case NONE: case SHOW_MRT: usage(); /* NOTREACHED */ case SHOW: case SHOW_SUMMARY: imsg_compose(imsgbuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0); break; case SHOW_SUMMARY_TERSE: imsg_compose(imsgbuf, IMSG_CTL_SHOW_TERSE, 0, 0, -1, NULL, 0); break; case SHOW_FIB: if (!res->addr.aid) { struct ctl_kroute_req req = { 0 }; req.af = aid2af(res->aid); req.flags = res->flags; imsg_compose(imsgbuf, IMSG_CTL_KROUTE, res->rtableid, 0, -1, &req, sizeof(req)); } else imsg_compose(imsgbuf, IMSG_CTL_KROUTE_ADDR, res->rtableid, 0, -1, &res->addr, sizeof(res->addr)); break; case SHOW_FIB_TABLES: imsg_compose(imsgbuf, IMSG_CTL_SHOW_FIB_TABLES, 0, 0, -1, NULL, 0); break; case SHOW_NEXTHOP: imsg_compose(imsgbuf, IMSG_CTL_SHOW_NEXTHOP, res->rtableid, 0, -1, NULL, 0); break; case SHOW_INTERFACE: imsg_compose(imsgbuf, IMSG_CTL_SHOW_INTERFACE, 0, 0, -1, NULL, 0); break; case SHOW_SET: imsg_compose(imsgbuf, IMSG_CTL_SHOW_SET, 0, 0, -1, NULL, 0); break; case SHOW_RTR: imsg_compose(imsgbuf, IMSG_CTL_SHOW_RTR, 0, 0, -1, NULL, 0); break; case SHOW_NEIGHBOR: case SHOW_NEIGHBOR_TIMERS: case SHOW_NEIGHBOR_TERSE: neighbor.show_timers = (res->action == SHOW_NEIGHBOR_TIMERS); if (res->peeraddr.aid || res->peerdesc[0]) imsg_compose(imsgbuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, &neighbor, sizeof(neighbor)); else imsg_compose(imsgbuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0); break; case SHOW_RIB: memset(&ribreq, 0, sizeof(ribreq)); type = IMSG_CTL_SHOW_RIB; if (res->addr.aid) { ribreq.prefix = res->addr; ribreq.prefixlen = res->prefixlen; type = IMSG_CTL_SHOW_RIB_PREFIX; } if (res->as.type != AS_UNDEF) ribreq.as = res->as; if (res->community.flags != 0) ribreq.community = res->community; ribreq.neighbor = neighbor; strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib)); ribreq.aid = res->aid; ribreq.path_id = res->pathid; ribreq.flags = res->flags; imsg_compose(imsgbuf, type, 0, 0, -1, &ribreq, sizeof(ribreq)); break; case SHOW_RIB_MEM: imsg_compose(imsgbuf, IMSG_CTL_SHOW_RIB_MEM, 0, 0, -1, NULL, 0); break; case SHOW_METRICS: output = &ometric_output; numdone = 2; imsg_compose(imsgbuf, IMSG_CTL_SHOW_NEIGHBOR, 0, 0, -1, NULL, 0); imsg_compose(imsgbuf, IMSG_CTL_SHOW_RIB_MEM, 0, 0, -1, NULL, 0); break; case RELOAD: imsg_compose(imsgbuf, IMSG_CTL_RELOAD, 0, 0, -1, res->reason, sizeof(res->reason)); if (res->reason[0]) printf("reload request sent: %s\n", res->reason); else printf("reload request sent.\n"); break; case FIB: errx(1, "action==FIB"); break; case FIB_COUPLE: imsg_compose(imsgbuf, IMSG_CTL_FIB_COUPLE, res->rtableid, 0, -1, NULL, 0); printf("couple request sent.\n"); done = 1; break; case FIB_DECOUPLE: imsg_compose(imsgbuf, IMSG_CTL_FIB_DECOUPLE, res->rtableid, 0, -1, NULL, 0); printf("decouple request sent.\n"); done = 1; break; case NEIGHBOR: errx(1, "action==NEIGHBOR"); break; case NEIGHBOR_UP: imsg_compose(imsgbuf, IMSG_CTL_NEIGHBOR_UP, 0, 0, -1, &neighbor, sizeof(neighbor)); break; case NEIGHBOR_DOWN: imsg_compose(imsgbuf, IMSG_CTL_NEIGHBOR_DOWN, 0, 0, -1, &neighbor, sizeof(neighbor)); break; case NEIGHBOR_CLEAR: imsg_compose(imsgbuf, IMSG_CTL_NEIGHBOR_CLEAR, 0, 0, -1, &neighbor, sizeof(neighbor)); break; case NEIGHBOR_RREFRESH: imsg_compose(imsgbuf, IMSG_CTL_NEIGHBOR_RREFRESH, 0, 0, -1, &neighbor, sizeof(neighbor)); break; case NEIGHBOR_DESTROY: imsg_compose(imsgbuf, IMSG_CTL_NEIGHBOR_DESTROY, 0, 0, -1, &neighbor, sizeof(neighbor)); break; case NETWORK_BULK_ADD: case NETWORK_BULK_REMOVE: network_bulk(res); printf("requests sent.\n"); done = 1; break; case NETWORK_ADD: case NETWORK_REMOVE: memset(&net, 0, sizeof(net)); net.prefix = res->addr; net.prefixlen = res->prefixlen; net.rd = res->rd; /* attribute sets are not supported */ if (res->action == NETWORK_ADD) { imsg_compose(imsgbuf, IMSG_NETWORK_ADD, 0, 0, -1, &net, sizeof(net)); send_filterset(imsgbuf, &res->set); imsg_compose(imsgbuf, IMSG_NETWORK_DONE, 0, 0, -1, NULL, 0); } else imsg_compose(imsgbuf, IMSG_NETWORK_REMOVE, 0, 0, -1, &net, sizeof(net)); printf("request sent.\n"); done = 1; break; case NETWORK_FLUSH: imsg_compose(imsgbuf, IMSG_NETWORK_FLUSH, 0, 0, -1, NULL, 0); printf("request sent.\n"); done = 1; break; case NETWORK_SHOW: memset(&ribreq, 0, sizeof(ribreq)); ribreq.aid = res->aid; strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib)); imsg_compose(imsgbuf, IMSG_CTL_SHOW_NETWORK, 0, 0, -1, &ribreq, sizeof(ribreq)); break; case NETWORK_MRT: memset(&ribreq, 0, sizeof(ribreq)); if (res->as.type != AS_UNDEF) ribreq.as = res->as; if (res->addr.aid) { ribreq.prefix = res->addr; ribreq.prefixlen = res->prefixlen; } /* XXX currently no community support */ ribreq.neighbor = neighbor; ribreq.aid = res->aid; ribreq.flags = res->flags; net_mrt.arg = &ribreq; mrt_parse(res->mrtfd, &net_mrt, 1); done = 1; break; case FLOWSPEC_ADD: case FLOWSPEC_REMOVE: f = res_to_flowspec(res); /* attribute sets are not supported */ if (res->action == FLOWSPEC_ADD) { imsg_compose(imsgbuf, IMSG_FLOWSPEC_ADD, 0, 0, -1, f, FLOWSPEC_SIZE + f->len); send_filterset(imsgbuf, &res->set); imsg_compose(imsgbuf, IMSG_FLOWSPEC_DONE, 0, 0, -1, NULL, 0); } else imsg_compose(imsgbuf, IMSG_FLOWSPEC_REMOVE, 0, 0, -1, f, FLOWSPEC_SIZE + f->len); printf("request sent.\n"); done = 1; break; case FLOWSPEC_FLUSH: imsg_compose(imsgbuf, IMSG_FLOWSPEC_FLUSH, 0, 0, -1, NULL, 0); printf("request sent.\n"); done = 1; break; case FLOWSPEC_SHOW: memset(&ribreq, 0, sizeof(ribreq)); switch (res->aid) { case AID_INET: ribreq.aid = AID_FLOWSPECv4; break; case AID_INET6: ribreq.aid = AID_FLOWSPECv6; break; case AID_UNSPEC: ribreq.aid = res->aid; break; default: errx(1, "flowspec family %s currently not supported", aid2str(res->aid)); } strlcpy(ribreq.rib, res->rib, sizeof(ribreq.rib)); imsg_compose(imsgbuf, IMSG_CTL_SHOW_FLOWSPEC, 0, 0, -1, &ribreq, sizeof(ribreq)); break; case LOG_VERBOSE: verbose = 1; /* FALLTHROUGH */ case LOG_BRIEF: imsg_compose(imsgbuf, IMSG_CTL_LOG_VERBOSE, 0, 0, -1, &verbose, sizeof(verbose)); printf("logging request sent.\n"); done = 1; break; } output->head(res); again: if (imsgbuf_flush(imsgbuf) == -1) err(1, "write error"); while (!done) { while (!done) { if ((n = imsg_get(imsgbuf, &imsg)) == -1) err(1, "imsg_get error"); if (n == 0) break; done = show(&imsg, res); imsg_free(&imsg); } if (done) break; if ((n = imsgbuf_read(imsgbuf)) == -1) err(1, "read error"); if (n == 0) errx(1, "pipe closed"); } if (res->action == SHOW_METRICS && --numdone > 0) { done = 0; goto again; } output->tail(); close(fd); free(imsgbuf); exit(0); } int show(struct imsg *imsg, struct parse_result *res) { struct peer p; struct ctl_timer t; struct ctl_show_interface iface; struct ctl_show_nexthop nh; struct ctl_show_set set; struct ctl_show_rtr rtr; struct kroute_full kf; struct ktable kt; struct flowspec f; struct ctl_show_rib rib; struct rde_memstats stats; struct ibuf ibuf; u_int rescode; switch (imsg->hdr.type) { case IMSG_CTL_SHOW_NEIGHBOR: if (output->neighbor == NULL) break; if (imsg_get_data(imsg, &p, sizeof(p)) == -1) err(1, "imsg_get_data"); output->neighbor(&p, res); break; case IMSG_CTL_SHOW_TIMER: if (output->timer == NULL) break; if (imsg_get_data(imsg, &t, sizeof(t)) == -1) err(1, "imsg_get_data"); if (t.type > 0 && t.type < Timer_Max) output->timer(&t); break; case IMSG_CTL_SHOW_INTERFACE: if (output->interface == NULL) break; if (imsg_get_data(imsg, &iface, sizeof(iface)) == -1) err(1, "imsg_get_data"); output->interface(&iface); break; case IMSG_CTL_SHOW_NEXTHOP: if (output->nexthop == NULL) break; if (imsg_get_data(imsg, &nh, sizeof(nh)) == -1) err(1, "imsg_get_data"); output->nexthop(&nh); break; case IMSG_CTL_KROUTE: case IMSG_CTL_SHOW_NETWORK: if (output->fib == NULL) break; if (imsg_get_data(imsg, &kf, sizeof(kf)) == -1) err(1, "imsg_get_data"); output->fib(&kf); break; case IMSG_CTL_SHOW_FLOWSPEC: if (output->flowspec == NULL) break; if (imsg_get_data(imsg, &f, sizeof(f)) == -1) err(1, "imsg_get_data"); output->flowspec(&f); break; case IMSG_CTL_SHOW_FIB_TABLES: if (output->fib_table == NULL) break; if (imsg_get_data(imsg, &kt, sizeof(kt)) == -1) err(1, "imsg_get_data"); output->fib_table(&kt); break; case IMSG_CTL_SHOW_RIB: if (output->rib == NULL) break; if (imsg_get_ibuf(imsg, &ibuf) == -1) err(1, "imsg_get_ibuf"); if (ibuf_get(&ibuf, &rib, sizeof(rib)) == -1) err(1, "imsg_get_ibuf"); output->rib(&rib, &ibuf, res); break; case IMSG_CTL_SHOW_RIB_COMMUNITIES: if (output->communities == NULL) break; if (imsg_get_ibuf(imsg, &ibuf) == -1) err(1, "imsg_get_ibuf"); output->communities(&ibuf, res); break; case IMSG_CTL_SHOW_RIB_ATTR: if (output->attr == NULL) break; if (imsg_get_ibuf(imsg, &ibuf) == -1) err(1, "imsg_get_ibuf"); output->attr(&ibuf, res->flags, 0); break; case IMSG_CTL_SHOW_RIB_MEM: if (output->rib_mem == NULL) break; if (imsg_get_data(imsg, &stats, sizeof(stats)) == -1) err(1, "imsg_get_data"); output->rib_mem(&stats); return (1); case IMSG_CTL_SHOW_SET: if (output->set == NULL) break; if (imsg_get_data(imsg, &set, sizeof(set)) == -1) err(1, "imsg_get_data"); output->set(&set); break; case IMSG_CTL_SHOW_RTR: if (output->rtr == NULL) break; if (imsg_get_data(imsg, &rtr, sizeof(rtr)) == -1) err(1, "imsg_get_data"); output->rtr(&rtr); break; case IMSG_CTL_RESULT: if (output->result == NULL) break; if (imsg_get_data(imsg, &rescode, sizeof(rescode)) == -1) err(1, "imsg_get_data"); output->result(rescode); return (1); case IMSG_CTL_END: return (1); default: warnx("unknown imsg %d received", imsg->hdr.type); break; } return (0); } time_t get_monotime(time_t t) { struct timespec ts; if (t == 0) return -1; if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) err(1, "clock_gettime"); if (t > ts.tv_sec) /* time in the future is not possible */ t = ts.tv_sec; return (ts.tv_sec - t); } char * fmt_peer(const char *descr, const struct bgpd_addr *remote_addr, int masklen) { const char *ip; char *p; if (descr && descr[0] && !nodescr) { if ((p = strdup(descr)) == NULL) err(1, NULL); return (p); } ip = log_addr(remote_addr); if (masklen != -1 && ((remote_addr->aid == AID_INET && masklen != 32) || (remote_addr->aid == AID_INET6 && masklen != 128))) { if (asprintf(&p, "%s/%u", ip, masklen) == -1) err(1, NULL); } else { if ((p = strdup(ip)) == NULL) err(1, NULL); } return (p); } const char * fmt_auth_method(enum auth_method method) { switch (method) { case AUTH_MD5SIG: return ", using md5sig"; case AUTH_IPSEC_MANUAL_ESP: return ", using ipsec manual esp"; case AUTH_IPSEC_MANUAL_AH: return ", using ipsec manual ah"; case AUTH_IPSEC_IKE_ESP: return ", using ipsec ike esp"; case AUTH_IPSEC_IKE_AH: return ", using ipsec ike ah"; case AUTH_NONE: /* FALLTHROUGH */ default: return ""; } } #define TF_LEN 16 const char * fmt_timeframe(time_t t) { static char buf[TF_LEN]; unsigned int sec, min, hrs, day; unsigned long long week; if (t < 0) t = 0; week = t; sec = week % 60; week /= 60; min = week % 60; week /= 60; hrs = week % 24; week /= 24; day = week % 7; week /= 7; if (week >= 1000) snprintf(buf, TF_LEN, "%02lluw", week); else if (week > 0) snprintf(buf, TF_LEN, "%02lluw%01ud%02uh", week, day, hrs); else if (day > 0) snprintf(buf, TF_LEN, "%01ud%02uh%02um", day, hrs, min); else snprintf(buf, TF_LEN, "%02u:%02u:%02u", hrs, min, sec); return (buf); } const char * fmt_monotime(time_t t) { t = get_monotime(t); if (t == -1) return ("Never"); return (fmt_timeframe(t)); } const char * fmt_fib_flags(uint16_t flags) { static char buf[8]; if (flags & F_BGPD) strlcpy(buf, "B", sizeof(buf)); else if (flags & F_CONNECTED) strlcpy(buf, "C", sizeof(buf)); else if (flags & F_STATIC) strlcpy(buf, "S", sizeof(buf)); else strlcpy(buf, " ", sizeof(buf)); if (flags & F_NEXTHOP) strlcat(buf, "N", sizeof(buf)); else strlcat(buf, " ", sizeof(buf)); if (flags & F_REJECT && flags & F_BLACKHOLE) strlcat(buf, "f", sizeof(buf)); else if (flags & F_REJECT) strlcat(buf, "r", sizeof(buf)); else if (flags & F_BLACKHOLE) strlcat(buf, "b", sizeof(buf)); else strlcat(buf, " ", sizeof(buf)); return buf; } const char * fmt_origin(uint8_t origin, int sum) { switch (origin) { case ORIGIN_IGP: return (sum ? "i" : "IGP"); case ORIGIN_EGP: return (sum ? "e" : "EGP"); case ORIGIN_INCOMPLETE: return (sum ? "?" : "incomplete"); default: return (sum ? "X" : "bad origin"); } } const char * fmt_flags(uint32_t flags, int sum) { static char buf[80]; char flagstr[5]; char *p = flagstr; if (sum) { if (flags & F_PREF_FILTERED) *p++ = 'F'; if (flags & F_PREF_INVALID) *p++ = 'E'; if (flags & F_PREF_OTC_LEAK) *p++ = 'L'; if (flags & F_PREF_ANNOUNCE) *p++ = 'A'; if (flags & F_PREF_INTERNAL) *p++ = 'I'; if (flags & F_PREF_STALE) *p++ = 'S'; if (flags & F_PREF_ELIGIBLE) *p++ = '*'; if (flags & F_PREF_BEST) *p++ = '>'; if (flags & F_PREF_ECMP) *p++ = 'm'; if (flags & F_PREF_AS_WIDE) *p++ = 'w'; *p = '\0'; snprintf(buf, sizeof(buf), "%-5s", flagstr); } else { if (flags & F_PREF_INTERNAL) strlcpy(buf, "internal", sizeof(buf)); else strlcpy(buf, "external", sizeof(buf)); if (flags & F_PREF_FILTERED) strlcat(buf, ", filtered", sizeof(buf)); if (flags & F_PREF_INVALID) strlcat(buf, ", invalid", sizeof(buf)); if (flags & F_PREF_OTC_LEAK) strlcat(buf, ", otc leak", sizeof(buf)); if (flags & F_PREF_STALE) strlcat(buf, ", stale", sizeof(buf)); if (flags & F_PREF_ELIGIBLE) strlcat(buf, ", valid", sizeof(buf)); if (flags & F_PREF_BEST) strlcat(buf, ", best", sizeof(buf)); if (flags & F_PREF_ECMP) strlcat(buf, ", ecmp", sizeof(buf)); if (flags & F_PREF_AS_WIDE) strlcat(buf, ", as-wide", sizeof(buf)); if (flags & F_PREF_ANNOUNCE) strlcat(buf, ", announced", sizeof(buf)); if (strlen(buf) >= sizeof(buf) - 1) errx(1, "%s buffer too small", __func__); } return buf; } const char * fmt_ovs(uint8_t validation_state, int sum) { switch (validation_state) { case ROA_INVALID: return (sum ? "!" : "invalid"); case ROA_VALID: return (sum ? "V" : "valid"); default: return (sum ? "N" : "not-found"); } } const char * fmt_avs(uint8_t validation_state, int sum) { switch (validation_state) { case ASPA_INVALID: return (sum ? "!" : "invalid"); case ASPA_VALID: return (sum ? "V" : "valid"); default: return (sum ? "?" : "unknown"); } } const char * fmt_mem(long long num) { static char buf[16]; if (fmt_scaled(num, buf) == -1) snprintf(buf, sizeof(buf), "%lldB", num); return (buf); } const char * fmt_errstr(uint8_t errcode, uint8_t subcode) { static char errbuf[256]; const char *errstr = NULL; const char *suberr = NULL; int uk = 0; if (errcode == 0) /* no error */ return NULL; if (errcode < sizeof(errnames)/sizeof(char *)) errstr = errnames[errcode]; switch (errcode) { case ERR_HEADER: if (subcode < sizeof(suberr_header_names)/sizeof(char *)) suberr = suberr_header_names[subcode]; else uk = 1; break; case ERR_OPEN: if (subcode < sizeof(suberr_open_names)/sizeof(char *)) suberr = suberr_open_names[subcode]; else uk = 1; break; case ERR_UPDATE: if (subcode < sizeof(suberr_update_names)/sizeof(char *)) suberr = suberr_update_names[subcode]; else uk = 1; break; case ERR_HOLDTIMEREXPIRED: if (subcode != 0) uk = 1; break; case ERR_FSM: if (subcode < sizeof(suberr_fsm_names)/sizeof(char *)) suberr = suberr_fsm_names[subcode]; else uk = 1; break; case ERR_CEASE: if (subcode < sizeof(suberr_cease_names)/sizeof(char *)) suberr = suberr_cease_names[subcode]; else uk = 1; break; default: snprintf(errbuf, sizeof(errbuf), "unknown error code %u subcode %u", errcode, subcode); return (errbuf); } if (uk) snprintf(errbuf, sizeof(errbuf), "%s, unknown subcode %u", errstr, subcode); else if (suberr == NULL) return (errstr); else snprintf(errbuf, sizeof(errbuf), "%s, %s", errstr, suberr); return (errbuf); } const char * fmt_attr(uint8_t type, int flags) { #define CHECK_FLAGS(s, t, m) \ if (((s) & ~(ATTR_DEFMASK | (m))) != (t)) pflags = 1 static char cstr[48]; int pflags = 0; switch (type) { case ATTR_ORIGIN: CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0); strlcpy(cstr, "Origin", sizeof(cstr)); break; case ATTR_ASPATH: CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0); strlcpy(cstr, "AS-Path", sizeof(cstr)); break; case ATTR_AS4_PATH: CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0); strlcpy(cstr, "AS4-Path", sizeof(cstr)); break; case ATTR_NEXTHOP: CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0); strlcpy(cstr, "Nexthop", sizeof(cstr)); break; case ATTR_MED: CHECK_FLAGS(flags, ATTR_OPTIONAL, 0); strlcpy(cstr, "Med", sizeof(cstr)); break; case ATTR_LOCALPREF: CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0); strlcpy(cstr, "Localpref", sizeof(cstr)); break; case ATTR_ATOMIC_AGGREGATE: CHECK_FLAGS(flags, ATTR_WELL_KNOWN, 0); strlcpy(cstr, "Atomic Aggregate", sizeof(cstr)); break; case ATTR_AGGREGATOR: CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL); strlcpy(cstr, "Aggregator", sizeof(cstr)); break; case ATTR_AS4_AGGREGATOR: CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL); strlcpy(cstr, "AS4-Aggregator", sizeof(cstr)); break; case ATTR_COMMUNITIES: CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL); strlcpy(cstr, "Communities", sizeof(cstr)); break; case ATTR_ORIGINATOR_ID: CHECK_FLAGS(flags, ATTR_OPTIONAL, 0); strlcpy(cstr, "Originator Id", sizeof(cstr)); break; case ATTR_CLUSTER_LIST: CHECK_FLAGS(flags, ATTR_OPTIONAL, 0); strlcpy(cstr, "Cluster Id List", sizeof(cstr)); break; case ATTR_MP_REACH_NLRI: CHECK_FLAGS(flags, ATTR_OPTIONAL, 0); strlcpy(cstr, "MP Reach NLRI", sizeof(cstr)); break; case ATTR_MP_UNREACH_NLRI: CHECK_FLAGS(flags, ATTR_OPTIONAL, 0); strlcpy(cstr, "MP Unreach NLRI", sizeof(cstr)); break; case ATTR_EXT_COMMUNITIES: CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL); strlcpy(cstr, "Ext. Communities", sizeof(cstr)); break; case ATTR_LARGE_COMMUNITIES: CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL); strlcpy(cstr, "Large Communities", sizeof(cstr)); break; case ATTR_OTC: CHECK_FLAGS(flags, ATTR_OPTIONAL|ATTR_TRANSITIVE, ATTR_PARTIAL); strlcpy(cstr, "OTC", sizeof(cstr)); break; default: /* ignore unknown attributes */ snprintf(cstr, sizeof(cstr), "Unknown Attribute #%u", type); pflags = 1; break; } if (flags != -1 && pflags) { strlcat(cstr, " flags [", sizeof(cstr)); if (flags & ATTR_OPTIONAL) strlcat(cstr, "O", sizeof(cstr)); if (flags & ATTR_TRANSITIVE) strlcat(cstr, "T", sizeof(cstr)); if (flags & ATTR_PARTIAL) strlcat(cstr, "P", sizeof(cstr)); strlcat(cstr, "]", sizeof(cstr)); } return (cstr); #undef CHECK_FLAGS } const char * fmt_community(uint16_t a, uint16_t v) { static char buf[12]; if (a == COMMUNITY_WELLKNOWN) switch (v) { case COMMUNITY_GRACEFUL_SHUTDOWN: return "GRACEFUL_SHUTDOWN"; case COMMUNITY_NO_EXPORT: return "NO_EXPORT"; case COMMUNITY_NO_ADVERTISE: return "NO_ADVERTISE"; case COMMUNITY_NO_EXPSUBCONFED: return "NO_EXPORT_SUBCONFED"; case COMMUNITY_NO_PEER: return "NO_PEER"; case COMMUNITY_BLACKHOLE: return "BLACKHOLE"; default: break; } snprintf(buf, sizeof(buf), "%hu:%hu", a, v); return buf; } const char * fmt_large_community(uint32_t d1, uint32_t d2, uint32_t d3) { static char buf[33]; snprintf(buf, sizeof(buf), "%u:%u:%u", d1, d2, d3); return buf; } const char * fmt_ext_community(uint64_t ext) { static char buf[32]; struct in_addr ip; uint32_t as4, u32; uint16_t as2, u16; uint8_t type, subtype; type = ext >> 56; subtype = ext >> 48; switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_GEN_TWO_AS: as2 = ext >> 32; u32 = ext; snprintf(buf, sizeof(buf), "%s %s:%u", log_ext_subtype(type, subtype), log_as(as2), u32); return buf; case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_GEN_IPV4: ip.s_addr = htonl(ext >> 16); u16 = ext; snprintf(buf, sizeof(buf), "%s %s:%hu", log_ext_subtype(type, subtype), inet_ntoa(ip), u16); return buf; case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_GEN_FOUR_AS: as4 = ext >> 16; u16 = ext; snprintf(buf, sizeof(buf), "%s %s:%hu", log_ext_subtype(type, subtype), log_as(as4), u16); return buf; case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: ext &= 0xffffffffffffULL; snprintf(buf, sizeof(buf), "%s 0x%llx", log_ext_subtype(type, subtype), (unsigned long long)ext); return buf; case EXT_COMMUNITY_NON_TRANS_OPAQUE: ext &= 0xffffffffffffULL; if (subtype == EXT_COMMUNITY_SUBTYPE_OVS) { switch (ext) { case EXT_COMMUNITY_OVS_VALID: snprintf(buf, sizeof(buf), "%s valid", log_ext_subtype(type, subtype)); return buf; case EXT_COMMUNITY_OVS_NOTFOUND: snprintf(buf, sizeof(buf), "%s not-found", log_ext_subtype(type, subtype)); return buf; case EXT_COMMUNITY_OVS_INVALID: snprintf(buf, sizeof(buf), "%s invalid", log_ext_subtype(type, subtype)); return buf; default: snprintf(buf, sizeof(buf), "%s 0x%llx", log_ext_subtype(type, subtype), (unsigned long long)ext); return buf; } } else { snprintf(buf, sizeof(buf), "%s 0x%llx", log_ext_subtype(type, subtype), (unsigned long long)ext); return buf; } break; default: snprintf(buf, sizeof(buf), "0x%llx", (unsigned long long)ext); return buf; } } const char * fmt_set_type(struct ctl_show_set *set) { switch (set->type) { case ASPA_SET: return "ASPA"; case ROA_SET: return "ROA"; case PREFIX_SET: return "PREFIX"; case ORIGIN_SET: return "ORIGIN"; case ASNUM_SET: return "ASNUM"; default: return "BULA"; } } void send_filterset(struct imsgbuf *i, struct filter_set_head *set) { struct filter_set *s; while ((s = TAILQ_FIRST(set)) != NULL) { imsg_compose(i, IMSG_FILTER_SET, 0, 0, -1, s, sizeof(struct filter_set)); TAILQ_REMOVE(set, s, entry); free(s); } } void network_bulk(struct parse_result *res) { struct network_config net; struct filter_set *s = NULL; struct bgpd_addr h; char *line = NULL; size_t linesize = 0; ssize_t linelen; uint8_t len; FILE *f; if ((f = fdopen(STDIN_FILENO, "r")) == NULL) err(1, "Failed to open stdin\n"); while ((linelen = getline(&line, &linesize, f)) != -1) { char *b, *buf = line; while ((b = strsep(&buf, " \t\n")) != NULL) { if (*b == '\0') /* skip empty tokens */ continue; /* Stop processing after a comment */ if (*b == '#') break; memset(&net, 0, sizeof(net)); if (parse_prefix(b, strlen(b), &h, &len) != 1) errx(1, "bad prefix: %s", b); net.prefix = h; net.prefixlen = len; net.rd = res->rd; if (res->action == NETWORK_BULK_ADD) { imsg_compose(imsgbuf, IMSG_NETWORK_ADD, 0, 0, -1, &net, sizeof(net)); /* * can't use send_filterset since that * would free the set. */ TAILQ_FOREACH(s, &res->set, entry) { imsg_compose(imsgbuf, IMSG_FILTER_SET, 0, 0, -1, s, sizeof(*s)); } imsg_compose(imsgbuf, IMSG_NETWORK_DONE, 0, 0, -1, NULL, 0); } else imsg_compose(imsgbuf, IMSG_NETWORK_REMOVE, 0, 0, -1, &net, sizeof(net)); } } free(line); if (ferror(f)) err(1, "getline"); fclose(f); } void show_mrt_dump_neighbors(struct mrt_rib *mr, struct mrt_peer *mp, void *arg) { struct mrt_peer_entry *p; struct in_addr ina; uint16_t i; ina.s_addr = htonl(mp->bgp_id); printf("view: %s BGP ID: %s Number of peers: %u\n\n", mp->view, inet_ntoa(ina), mp->npeers); printf("%-30s %8s %15s\n", "Neighbor", "AS", "BGP ID"); for (i = 0; i < mp->npeers; i++) { p = &mp->peers[i]; ina.s_addr = htonl(p->bgp_id); printf("%-30s %8u %15s\n", log_addr(&p->addr), p->asnum, inet_ntoa(ina)); } /* we only print the first message */ exit(0); } void show_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg) { struct ctl_show_rib ctl; struct parse_result res; struct ctl_show_rib_request *req = arg; struct mrt_rib_entry *mre; struct ibuf ibuf; time_t now; uint16_t i, j; memset(&res, 0, sizeof(res)); res.flags = req->flags; now = time(NULL); for (i = 0; i < mr->nentries; i++) { mre = &mr->entries[i]; memset(&ctl, 0, sizeof(ctl)); ctl.prefix = mr->prefix; ctl.prefixlen = mr->prefixlen; if (mre->originated <= now) ctl.age = now - mre->originated; ctl.true_nexthop = mre->nexthop; ctl.exit_nexthop = mre->nexthop; ctl.origin = mre->origin; ctl.local_pref = mre->local_pref; ctl.med = mre->med; /* weight is not part of the mrt dump so it can't be set */ if (mr->add_path) { ctl.flags |= F_PREF_PATH_ID; ctl.path_id = mre->path_id; } if (mre->peer_idx < mp->npeers) { ctl.remote_addr = mp->peers[mre->peer_idx].addr; ctl.remote_id = mp->peers[mre->peer_idx].bgp_id; } /* filter by neighbor */ if (req->neighbor.addr.aid != AID_UNSPEC && memcmp(&req->neighbor.addr, &ctl.remote_addr, sizeof(ctl.remote_addr)) != 0) continue; /* filter by AF */ if (req->aid && req->aid != ctl.prefix.aid) return; /* filter by prefix */ if (req->prefix.aid != AID_UNSPEC) { if (req->flags & F_LONGER) { if (req->prefixlen > ctl.prefixlen) return; if (prefix_compare(&req->prefix, &ctl.prefix, req->prefixlen)) return; } else if (req->flags & F_SHORTER) { if (req->prefixlen < ctl.prefixlen) return; if (prefix_compare(&req->prefix, &ctl.prefix, ctl.prefixlen)) return; } else { if (req->prefixlen != ctl.prefixlen) return; if (prefix_compare(&req->prefix, &ctl.prefix, req->prefixlen)) return; } } /* filter by AS */ if (req->as.type != AS_UNDEF && !match_aspath(mre->aspath, mre->aspath_len, &req->as)) continue; ibuf_from_buffer(&ibuf, mre->aspath, mre->aspath_len); output->rib(&ctl, &ibuf, &res); if (req->flags & F_CTL_DETAIL) { for (j = 0; j < mre->nattrs; j++) { ibuf_from_buffer(&ibuf, mre->attrs[j].attr, mre->attrs[j].attr_len); output->attr(&ibuf, req->flags, 0); } } } } void network_mrt_dump(struct mrt_rib *mr, struct mrt_peer *mp, void *arg) { struct ctl_show_rib ctl; struct network_config net; struct ctl_show_rib_request *req = arg; struct mrt_rib_entry *mre; struct ibuf *msg; time_t now; uint16_t i, j; /* can't announce more than one path so ignore add-path */ if (mr->add_path) return; now = time(NULL); for (i = 0; i < mr->nentries; i++) { mre = &mr->entries[i]; memset(&ctl, 0, sizeof(ctl)); ctl.prefix = mr->prefix; ctl.prefixlen = mr->prefixlen; if (mre->originated <= now) ctl.age = now - mre->originated; ctl.true_nexthop = mre->nexthop; ctl.exit_nexthop = mre->nexthop; ctl.origin = mre->origin; ctl.local_pref = mre->local_pref; ctl.med = mre->med; if (mre->peer_idx < mp->npeers) { ctl.remote_addr = mp->peers[mre->peer_idx].addr; ctl.remote_id = mp->peers[mre->peer_idx].bgp_id; } /* filter by neighbor */ if (req->neighbor.addr.aid != AID_UNSPEC && memcmp(&req->neighbor.addr, &ctl.remote_addr, sizeof(ctl.remote_addr)) != 0) continue; /* filter by AF */ if (req->aid && req->aid != ctl.prefix.aid) return; /* filter by prefix */ if (req->prefix.aid != AID_UNSPEC) { if (!prefix_compare(&req->prefix, &ctl.prefix, req->prefixlen)) { if (req->flags & F_LONGER) { if (req->prefixlen > ctl.prefixlen) return; } else if (req->prefixlen != ctl.prefixlen) return; } else return; } /* filter by AS */ if (req->as.type != AS_UNDEF && !match_aspath(mre->aspath, mre->aspath_len, &req->as)) continue; memset(&net, 0, sizeof(net)); net.prefix = ctl.prefix; net.prefixlen = ctl.prefixlen; net.type = NETWORK_MRTCLONE; /* XXX rd can't be set and will be 0 */ imsg_compose(imsgbuf, IMSG_NETWORK_ADD, 0, 0, -1, &net, sizeof(net)); if ((msg = imsg_create(imsgbuf, IMSG_NETWORK_ASPATH, 0, 0, sizeof(ctl) + mre->aspath_len)) == NULL) errx(1, "imsg_create failure"); if (imsg_add(msg, &ctl, sizeof(ctl)) == -1 || imsg_add(msg, mre->aspath, mre->aspath_len) == -1) errx(1, "imsg_add failure"); imsg_close(imsgbuf, msg); for (j = 0; j < mre->nattrs; j++) imsg_compose(imsgbuf, IMSG_NETWORK_ATTR, 0, 0, -1, mre->attrs[j].attr, mre->attrs[j].attr_len); imsg_compose(imsgbuf, IMSG_NETWORK_DONE, 0, 0, -1, NULL, 0); if (imsgbuf_flush(imsgbuf) == -1) err(1, "write error"); } } static const char * fmt_time(struct timespec *t) { static char timebuf[32]; static struct timespec prevtime; struct timespec temp; timespecsub(t, &prevtime, &temp); snprintf(timebuf, sizeof(timebuf), "%lld.%06ld", (long long)temp.tv_sec, temp.tv_nsec / 1000); prevtime = *t; return (timebuf); } void show_mrt_state(struct mrt_bgp_state *ms, void *arg) { printf("%s %s[%u] -> ", fmt_time(&ms->time), log_addr(&ms->src), ms->src_as); printf("%s[%u]: %s -> %s\n", log_addr(&ms->dst), ms->dst_as, statenames[ms->old_state], statenames[ms->new_state]); } static void print_afi(struct ibuf *b) { uint16_t afi; uint8_t safi, aid; if (ibuf_get_n16(b, &afi) == -1 || /* afi, 2 byte */ ibuf_skip(b, 1) == -1 || /* reserved, 1 byte */ ibuf_get_n8(b, &safi) == -1 || /* safi, 1 byte */ ibuf_size(b) != 0) { printf("bad length"); return; } if (afi2aid(afi, safi, &aid) == -1) printf("unknown afi %u safi %u", afi, safi); else printf("%s", aid2str(aid)); } static void print_capability(uint8_t capa_code, struct ibuf *b) { uint32_t as; switch (capa_code) { case CAPA_MP: printf("multiprotocol capability: "); print_afi(b); break; case CAPA_REFRESH: printf("route refresh capability"); break; case CAPA_RESTART: printf("graceful restart capability"); /* XXX there is more needed here */ break; case CAPA_AS4BYTE: printf("4-byte AS num capability: "); if (ibuf_get_n32(b, &as) == -1 || ibuf_size(b) != 0) printf("bad length"); else printf("AS %u", as); break; case CAPA_ADD_PATH: printf("add-path capability"); /* XXX there is more needed here */ break; case CAPA_ENHANCED_RR: printf("enhanced route refresh capability"); break; case CAPA_EXT_MSG: printf("extended message capability"); break; default: printf("unknown capability %u length %zu", capa_code, ibuf_size(b)); break; } } static void print_notification(uint8_t errcode, uint8_t subcode) { const char *suberrname = NULL; int uk = 0; switch (errcode) { case ERR_HEADER: if (subcode >= sizeof(suberr_header_names)/sizeof(char *)) uk = 1; else suberrname = suberr_header_names[subcode]; break; case ERR_OPEN: if (subcode >= sizeof(suberr_open_names)/sizeof(char *)) uk = 1; else suberrname = suberr_open_names[subcode]; break; case ERR_UPDATE: if (subcode >= sizeof(suberr_update_names)/sizeof(char *)) uk = 1; else suberrname = suberr_update_names[subcode]; break; case ERR_CEASE: if (subcode >= sizeof(suberr_cease_names)/sizeof(char *)) uk = 1; else suberrname = suberr_cease_names[subcode]; break; case ERR_HOLDTIMEREXPIRED: if (subcode != 0) uk = 1; break; case ERR_FSM: if (subcode >= sizeof(suberr_fsm_names)/sizeof(char *)) uk = 1; else suberrname = suberr_fsm_names[subcode]; break; default: printf("unknown errcode %u, subcode %u", errcode, subcode); return; } if (uk) printf("%s, unknown subcode %u", errnames[errcode], subcode); else { if (suberrname == NULL) printf("%s", errnames[errcode]); else printf("%s, %s", errnames[errcode], suberrname); } } static int show_mrt_capabilities(struct ibuf *b) { uint8_t capa_code, capa_len; struct ibuf cbuf; while (ibuf_size(b) > 0) { if (ibuf_get_n8(b, &capa_code) == -1 || ibuf_get_n8(b, &capa_len) == -1 || ibuf_get_ibuf(b, capa_len, &cbuf) == -1) { printf("truncated capabilities"); return (-1); } printf("\n "); print_capability(capa_code, &cbuf); } return (0); } static void show_mrt_open(struct ibuf *b) { struct in_addr ina; uint32_t bgpid; uint16_t short_as, holdtime; uint8_t version, optparamlen; /* length check up to optparamlen already happened */ if (ibuf_get_n8(b, &version) == -1 || ibuf_get_n16(b, &short_as) == -1 || ibuf_get_n16(b, &holdtime) == -1 || ibuf_get_n32(b, &bgpid) == -1 || ibuf_get_n8(b, &optparamlen) == -1) { trunc: printf("truncated message"); return; } printf("\n "); ina.s_addr = htonl(bgpid); printf("Version: %d AS: %u Holdtime: %u BGP Id: %s Paramlen: %u", version, short_as, holdtime, inet_ntoa(ina), optparamlen); if (optparamlen != ibuf_size(b)) { /* XXX missing support for RFC9072 */ printf("optional parameter length mismatch"); return; } while (ibuf_size(b) > 0) { uint8_t op_type, op_len; if (ibuf_get_n8(b, &op_type) == -1 || ibuf_get_n8(b, &op_len) == -1) goto trunc; printf("\n "); switch (op_type) { case OPT_PARAM_CAPABILITIES: printf("Capabilities: %u bytes", op_len); if (show_mrt_capabilities(b) == -1) return; break; case OPT_PARAM_AUTH: default: printf("unsupported optional parameter: type %u", op_type); return; } } } static void show_mrt_notification(struct ibuf *b) { char reason[REASON_LEN]; uint8_t errcode, subcode, reason_len, c; size_t i, len; if (ibuf_get_n8(b, &errcode) == -1 || ibuf_get_n8(b, &subcode) == -1) { trunc: printf("truncated message"); return; } printf("\n "); print_notification(errcode, subcode); if (errcode == ERR_CEASE && (subcode == ERR_CEASE_ADMIN_DOWN || subcode == ERR_CEASE_ADMIN_RESET)) { if (ibuf_size(b) > 1) { if (ibuf_get_n8(b, &reason_len) == -1) goto trunc; if (ibuf_get(b, reason, reason_len) == -1) goto trunc; reason[reason_len] = '\0'; printf("shutdown reason: \"%s\"", log_reason(reason)); } } if (errcode == ERR_OPEN && subcode == ERR_OPEN_CAPA) { if (show_mrt_capabilities(b) == -1) return; } if (ibuf_size(b) > 0) { len = ibuf_size(b); printf("\n additional data, %zu bytes", len); for (i = 0; i < len; i++) { if (i % 16 == 0) printf("\n "); if (i % 8 == 0) printf(" "); if (ibuf_get_n8(b, &c) == -1) goto trunc; printf(" %02X", c); } } } /* XXX this function does not handle JSON output */ static void show_mrt_update(struct ibuf *b, int reqflags, int addpath) { struct bgpd_addr prefix; struct ibuf wbuf, abuf; uint32_t pathid; uint16_t wlen, alen; uint8_t prefixlen; if (ibuf_get_n16(b, &wlen) == -1 || ibuf_get_ibuf(b, wlen, &wbuf) == -1) goto trunc; if (wlen > 0) { printf("\n Withdrawn prefixes:"); while (ibuf_size(&wbuf) > 0) { if (addpath) if (ibuf_get_n32(&wbuf, &pathid) == -1) goto trunc; if (nlri_get_prefix(&wbuf, &prefix, &prefixlen) == -1) goto trunc; printf(" %s/%u", log_addr(&prefix), prefixlen); if (addpath) printf(" path-id %u", pathid); } } if (ibuf_get_n16(b, &alen) == -1 || ibuf_get_ibuf(b, alen, &abuf) == -1) goto trunc; printf("\n"); /* alen attributes here */ while (ibuf_size(&abuf) > 0) { struct ibuf attrbuf; uint16_t attrlen; uint8_t flags; ibuf_from_ibuf(&abuf, &attrbuf); if (ibuf_get_n8(&attrbuf, &flags) == -1 || ibuf_skip(&attrbuf, 1) == -1) goto trunc; /* get the attribute length */ if (flags & ATTR_EXTLEN) { if (ibuf_get_n16(&attrbuf, &attrlen) == -1) goto trunc; } else { uint8_t tmp; if (ibuf_get_n8(&attrbuf, &tmp) == -1) goto trunc; attrlen = tmp; } if (ibuf_truncate(&attrbuf, attrlen) == -1) goto trunc; ibuf_rewind(&attrbuf); if (ibuf_skip(&abuf, ibuf_size(&attrbuf)) == -1) goto trunc; output->attr(&attrbuf, reqflags, addpath); } if (ibuf_size(b) > 0) { printf(" NLRI prefixes:"); while (ibuf_size(b) > 0) { if (addpath) if (ibuf_get_n32(b, &pathid) == -1) goto trunc; if (nlri_get_prefix(b, &prefix, &prefixlen) == -1) goto trunc; printf(" %s/%u", log_addr(&prefix), prefixlen); if (addpath) printf(" path-id %u", pathid); } } return; trunc: printf("truncated message"); } void show_mrt_msg(struct mrt_bgp_msg *mm, void *arg) { static const uint8_t marker[MSGSIZE_HEADER_MARKER] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; uint8_t m[MSGSIZE_HEADER_MARKER]; struct ibuf *b; uint16_t len; uint8_t type; struct ctl_show_rib_request *req = arg; printf("%s %s[%u] -> ", fmt_time(&mm->time), log_addr(&mm->src), mm->src_as); printf("%s[%u]: size %zu%s ", log_addr(&mm->dst), mm->dst_as, ibuf_size(&mm->msg), mm->add_path ? " addpath" : ""); b = &mm->msg; if (ibuf_get(b, m, sizeof(m)) == -1) { printf("bad message: short header\n"); return; } /* parse BGP message header */ if (memcmp(m, marker, sizeof(marker))) { printf("incorrect marker in BGP message\n"); return; } if (ibuf_get_n16(b, &len) == -1 || ibuf_get_n8(b, &type) == -1) { printf("bad message: short header\n"); return; } if (len < MSGSIZE_HEADER || len > MAX_PKTSIZE) { printf("illegal header length: %u byte\n", len); return; } switch (type) { case BGP_OPEN: printf("%s ", msgtypenames[type]); if (len < MSGSIZE_OPEN_MIN) { printf("bad length: %u bytes\n", len); return; } show_mrt_open(b); break; case BGP_NOTIFICATION: printf("%s ", msgtypenames[type]); if (len < MSGSIZE_NOTIFICATION_MIN) { printf("bad length: %u bytes\n", len); return; } show_mrt_notification(b); break; case BGP_UPDATE: printf("%s ", msgtypenames[type]); if (len < MSGSIZE_UPDATE_MIN) { printf("bad length: %u bytes\n", len); return; } show_mrt_update(b, req->flags, mm->add_path); break; case BGP_KEEPALIVE: printf("%s ", msgtypenames[type]); if (len != MSGSIZE_KEEPALIVE) { printf("bad length: %u bytes\n", len); return; } /* nothing */ break; case BGP_RREFRESH: printf("%s ", msgtypenames[type]); if (len != MSGSIZE_RREFRESH) { printf("bad length: %u bytes\n", len); return; } print_afi(b); break; default: printf("unknown type %u\n", type); return; } printf("\n"); } const char * msg_type(uint8_t type) { if (type >= sizeof(msgtypenames)/sizeof(msgtypenames[0])) return "BAD"; return (msgtypenames[type]); } int match_aspath(void *data, uint16_t len, struct filter_as *f) { uint8_t *seg; int final; uint16_t seg_size; uint8_t i, seg_len; uint32_t as = 0; if (f->type == AS_EMPTY) { if (len == 0) return (1); else return (0); } seg = data; /* just check the leftmost AS */ if (f->type == AS_PEER && len >= 6) { as = aspath_extract(seg, 0); if (f->as_min == as) return (1); else return (0); } for (; len >= 6; len -= seg_size, seg += seg_size) { seg_len = seg[1]; seg_size = 2 + sizeof(uint32_t) * seg_len; final = (len == seg_size); if (f->type == AS_SOURCE) { /* * Just extract the rightmost AS * but if that segment is an AS_SET then the rightmost * AS of a previous AS_SEQUENCE segment should be used. * Because of that just look at AS_SEQUENCE segments. */ if (seg[0] == AS_SEQUENCE) as = aspath_extract(seg, seg_len - 1); /* not yet in the final segment */ if (!final) continue; if (f->as_min == as) return (1); else return (0); } /* AS_TRANSIT or AS_ALL */ for (i = 0; i < seg_len; i++) { /* * the source (rightmost) AS is excluded from * AS_TRANSIT matches. */ if (final && i == seg_len - 1 && f->type == AS_TRANSIT) return (0); as = aspath_extract(seg, i); if (f->as_min == as) return (1); } } return (0); } static void component_finish(int type, uint8_t *data, int len) { uint8_t *last; int i; switch (type) { case FLOWSPEC_TYPE_DEST: case FLOWSPEC_TYPE_SOURCE: /* nothing todo */ return; default: break; } i = 0; do { last = data + i; i += FLOWSPEC_OP_LEN(*last) + 1; } while (i < len); *last |= FLOWSPEC_OP_EOL; } static void push_prefix(struct parse_result *r, int type, struct bgpd_addr *addr, uint8_t len) { void *data; uint8_t *comp; int complen, l; switch (addr->aid) { case AID_UNSPEC: return; case AID_INET: complen = PREFIX_SIZE(len); data = &addr->v4; break; case AID_INET6: /* IPv6 includes an offset byte */ complen = PREFIX_SIZE(len) + 1; data = &addr->v6; break; default: errx(1, "unsupported address family for flowspec address"); } comp = malloc(complen); if (comp == NULL) err(1, NULL); l = 0; comp[l++] = len; if (addr->aid == AID_INET6) comp[l++] = 0; memcpy(comp + l, data, complen - l); r->flow.complen[type] = complen; r->flow.components[type] = comp; } struct flowspec * res_to_flowspec(struct parse_result *r) { struct flowspec *f; int i, len = 0; uint8_t aid; switch (r->aid) { case AID_INET: aid = AID_FLOWSPECv4; break; case AID_INET6: aid = AID_FLOWSPECv6; break; default: errx(1, "unsupported AFI %s for flowspec rule", aid2str(r->aid)); } push_prefix(r, FLOWSPEC_TYPE_DEST, &r->flow.dst, r->flow.dstlen); push_prefix(r, FLOWSPEC_TYPE_SOURCE, &r->flow.src, r->flow.srclen); for (i = FLOWSPEC_TYPE_MIN; i < FLOWSPEC_TYPE_MAX; i++) if (r->flow.components[i] != NULL) len += r->flow.complen[i] + 1; if (len == 0) errx(1, "no flowspec rule defined"); f = malloc(FLOWSPEC_SIZE + len); if (f == NULL) err(1, NULL); memset(f, 0, FLOWSPEC_SIZE); f->aid = aid; f->len = len; len = 0; for (i = FLOWSPEC_TYPE_MIN; i < FLOWSPEC_TYPE_MAX; i++) if (r->flow.components[i] != NULL) { f->data[len++] = i; component_finish(i, r->flow.components[i], r->flow.complen[i]); memcpy(f->data + len, r->flow.components[i], r->flow.complen[i]); len += r->flow.complen[i]; } return f; } openbgpd-8.8/src/bgpctl/ometric.c100644 001750 001750 00000025232 14403051271 0012542/* $OpenBSD: ometric.c,v 1.10 2023/01/06 13:26:57 tb Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include "ometric.h" struct olabel { STAILQ_ENTRY(olabel) entry; const char *key; char *value; }; struct olabels { STAILQ_HEAD(, olabel) labels; struct olabels *next; int refcnt; }; enum ovalue_type { OVT_INTEGER, OVT_DOUBLE, OVT_TIMESPEC, }; struct ovalue { STAILQ_ENTRY(ovalue) entry; struct olabels *labels; union { unsigned long long i; double f; struct timespec ts; } value; enum ovalue_type valtype; }; STAILQ_HEAD(ovalues, ovalue); struct ometric { STAILQ_ENTRY(ometric) entry; struct ovalues vals; const char *name; const char *help; const char *const *stateset; size_t setsize; enum ometric_type type; }; STAILQ_HEAD(, ometric) ometrics = STAILQ_HEAD_INITIALIZER(ometrics); static const char *suffixes[] = { "_total", "_created", "_count", "_sum", "_bucket", "_gcount", "_gsum", "_info", }; /* * Return true if name has one of the above suffixes. */ static int strsuffix(const char *name) { const char *suffix; size_t i; suffix = strrchr(name, '_'); if (suffix == NULL) return 0; for (i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); i++) { if (strcmp(suffix, suffixes[i]) == 0) return 1; } return 0; } static void ometric_check(const char *name) { struct ometric *om; if (strsuffix(name)) errx(1, "reserved name suffix used: %s", name); STAILQ_FOREACH(om, &ometrics, entry) if (strcmp(name, om->name) == 0) errx(1, "duplicate name: %s", name); } /* * Allocate and return new ometric. The name and help string need to remain * valid until the ometric is freed. Normally constant strings should be used. */ struct ometric * ometric_new(enum ometric_type type, const char *name, const char *help) { struct ometric *om; ometric_check(name); if ((om = calloc(1, sizeof(*om))) == NULL) err(1, NULL); om->name = name; om->help = help; om->type = type; STAILQ_INIT(&om->vals); STAILQ_INSERT_TAIL(&ometrics, om, entry); return om; } /* * Same as above but for a stateset. The states is an array of constant strings * with statecnt elements. The states, name and help pointers need to remain * valid until the ometric is freed. */ struct ometric * ometric_new_state(const char * const *states, size_t statecnt, const char *name, const char *help) { struct ometric *om; ometric_check(name); if ((om = calloc(1, sizeof(*om))) == NULL) err(1, NULL); om->name = name; om->help = help; om->type = OMT_STATESET; om->stateset = states; om->setsize = statecnt; STAILQ_INIT(&om->vals); STAILQ_INSERT_TAIL(&ometrics, om, entry); return om; } void ometric_free_all(void) { struct ometric *om; struct ovalue *ov; while ((om = STAILQ_FIRST(&ometrics)) != NULL) { STAILQ_REMOVE_HEAD(&ometrics, entry); while ((ov = STAILQ_FIRST(&om->vals)) != NULL) { STAILQ_REMOVE_HEAD(&om->vals, entry); olabels_free(ov->labels); free(ov); } free(om); } } static struct olabels * olabels_ref(struct olabels *ol) { struct olabels *x = ol; while (x != NULL) { x->refcnt++; x = x->next; } return ol; } /* * Create a new set of labels based on keys and values arrays. * keys must end in a NULL element. values needs to hold as many elements * but the elements can be NULL. values are copied for the olabel but * keys needs to point to constant memory. */ struct olabels * olabels_new(const char * const *keys, const char **values) { struct olabels *ol; struct olabel *l; if ((ol = malloc(sizeof(*ol))) == NULL) err(1, NULL); STAILQ_INIT(&ol->labels); ol->refcnt = 1; ol->next = NULL; while (*keys != NULL) { if (*values && **values != '\0') { if ((l = malloc(sizeof(*l))) == NULL) err(1, NULL); l->key = *keys; if ((l->value = strdup(*values)) == NULL) err(1, NULL); STAILQ_INSERT_TAIL(&ol->labels, l, entry); } keys++; values++; } return ol; } /* * Free olables once nothing uses them anymore. */ void olabels_free(struct olabels *ol) { struct olabels *next; struct olabel *l; for ( ; ol != NULL; ol = next) { next = ol->next; if (--ol->refcnt == 0) { while ((l = STAILQ_FIRST(&ol->labels)) != NULL) { STAILQ_REMOVE_HEAD(&ol->labels, entry); free(l->value); free(l); } free(ol); } } } /* * Add one extra label onto the label stack. Once no longer used the * value needs to be freed with olabels_free(). */ static struct olabels * olabels_add_extras(struct olabels *ol, const char **keys, const char **values) { struct olabels *new; new = olabels_new(keys, values); new->next = olabels_ref(ol); return new; } /* * Output function called last. */ static const char * ometric_type(enum ometric_type type) { switch (type) { case OMT_GAUGE: return "gauge"; case OMT_COUNTER: return "counter"; case OMT_STATESET: return "stateset"; case OMT_HISTOGRAM: return "histogram"; case OMT_SUMMARY: return "summary"; case OMT_INFO: return "info"; default: return "unknown"; } } static int ometric_output_labels(FILE *out, const struct olabels *ol) { struct olabel *l; const char *comma = ""; if (ol == NULL) return fprintf(out, " "); if (fprintf(out, "{") < 0) return -1; while (ol != NULL) { STAILQ_FOREACH(l, &ol->labels, entry) { if (fprintf(out, "%s%s=\"%s\"", comma, l->key, l->value) < 0) return -1; comma = ","; } ol = ol->next; } return fprintf(out, "} "); } static int ometric_output_value(FILE *out, const struct ovalue *ov) { switch (ov->valtype) { case OVT_INTEGER: return fprintf(out, "%llu", ov->value.i); case OVT_DOUBLE: return fprintf(out, "%g", ov->value.f); case OVT_TIMESPEC: return fprintf(out, "%lld.%09ld", (long long)ov->value.ts.tv_sec, ov->value.ts.tv_nsec); } return -1; } static int ometric_output_name(FILE *out, const struct ometric *om) { const char *suffix; switch (om->type) { case OMT_COUNTER: suffix = "_total"; break; case OMT_INFO: suffix = "_info"; break; default: suffix = ""; break; } return fprintf(out, "%s%s", om->name, suffix); } /* * Output all metric values with TYPE and optional HELP strings. */ int ometric_output_all(FILE *out) { struct ometric *om; struct ovalue *ov; STAILQ_FOREACH(om, &ometrics, entry) { if (om->help) if (fprintf(out, "# HELP %s %s\n", om->name, om->help) < 0) return -1; if (fprintf(out, "# TYPE %s %s\n", om->name, ometric_type(om->type)) < 0) return -1; STAILQ_FOREACH(ov, &om->vals, entry) { if (ometric_output_name(out, om) < 0) return -1; if (ometric_output_labels(out, ov->labels) < 0) return -1; if (ometric_output_value(out, ov) < 0) return -1; if (fprintf(out, "\n") < 0) return -1; } } if (fprintf(out, "# EOF\n") < 0) return -1; return 0; } /* * Value setters */ static void ometric_set_int_value(struct ometric *om, uint64_t val, struct olabels *ol) { struct ovalue *ov; if ((ov = malloc(sizeof(*ov))) == NULL) err(1, NULL); ov->value.i = val; ov->valtype = OVT_INTEGER; ov->labels = olabels_ref(ol); STAILQ_INSERT_TAIL(&om->vals, ov, entry); } /* * Set an integer value with label ol. ol can be NULL. */ void ometric_set_int(struct ometric *om, uint64_t val, struct olabels *ol) { if (om->type != OMT_COUNTER && om->type != OMT_GAUGE) errx(1, "%s incorrect ometric type", __func__); ometric_set_int_value(om, val, ol); } /* * Set a floating point value with label ol. ol can be NULL. */ void ometric_set_float(struct ometric *om, double val, struct olabels *ol) { struct ovalue *ov; if (om->type != OMT_COUNTER && om->type != OMT_GAUGE) errx(1, "%s incorrect ometric type", __func__); if ((ov = malloc(sizeof(*ov))) == NULL) err(1, NULL); ov->value.f = val; ov->valtype = OVT_DOUBLE; ov->labels = olabels_ref(ol); STAILQ_INSERT_TAIL(&om->vals, ov, entry); } /* * Set an timespec value with label ol. ol can be NULL. */ void ometric_set_timespec(struct ometric *om, const struct timespec *ts, struct olabels *ol) { struct ovalue *ov; if (om->type != OMT_GAUGE) errx(1, "%s incorrect ometric type", __func__); if ((ov = malloc(sizeof(*ov))) == NULL) err(1, NULL); ov->value.ts = *ts; ov->valtype = OVT_TIMESPEC; ov->labels = olabels_ref(ol); STAILQ_INSERT_TAIL(&om->vals, ov, entry); } /* * Add an info value (which is the value 1 but with extra key-value pairs). */ void ometric_set_info(struct ometric *om, const char **keys, const char **values, struct olabels *ol) { struct olabels *extra = NULL; if (om->type != OMT_INFO) errx(1, "%s incorrect ometric type", __func__); if (keys != NULL) extra = olabels_add_extras(ol, keys, values); ometric_set_int_value(om, 1, extra != NULL ? extra : ol); olabels_free(extra); } /* * Set a stateset to one of its states. */ void ometric_set_state(struct ometric *om, const char *state, struct olabels *ol) { struct olabels *extra; size_t i; int val; if (om->type != OMT_STATESET) errx(1, "%s incorrect ometric type", __func__); for (i = 0; i < om->setsize; i++) { if (strcasecmp(state, om->stateset[i]) == 0) val = 1; else val = 0; extra = olabels_add_extras(ol, OKV(om->name), OKV(om->stateset[i])); ometric_set_int_value(om, val, extra); olabels_free(extra); } } /* * Set a value with an extra label, the key should be a constant string while * the value is copied into the extra label. */ void ometric_set_int_with_labels(struct ometric *om, uint64_t val, const char **keys, const char **values, struct olabels *ol) { struct olabels *extra; extra = olabels_add_extras(ol, keys, values); ometric_set_int(om, val, extra); olabels_free(extra); } void ometric_set_timespec_with_labels(struct ometric *om, struct timespec *ts, const char **keys, const char **values, struct olabels *ol) { struct olabels *extra; extra = olabels_add_extras(ol, keys, values); ometric_set_timespec(om, ts, extra); olabels_free(extra); } openbgpd-8.8/src/bgpctl/output.c100644 001750 001750 00000076637 14751151130 0012460/* $OpenBSD: output.c,v 1.59 2025/01/29 13:14:41 claudio Exp $ */ /* * Copyright (c) 2003 Henning Brauer * Copyright (c) 2004-2019 Claudio Jeker * Copyright (c) 2016 Job Snijders * Copyright (c) 2016 Peter Hessler * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "bgpctl.h" #include "parser.h" static void show_head(struct parse_result *res) { switch (res->action) { case SHOW: case SHOW_SUMMARY: printf("%-20s %8s %10s %10s %5s %-8s %s\n", "Neighbor", "AS", "MsgRcvd", "MsgSent", "OutQ", "Up/Down", "State/PrfRcvd"); break; case SHOW_FIB: printf("flags: B = BGP, C = Connected, S = Static\n"); printf(" N = BGP Nexthop reachable via this route\n"); printf(" r = reject route, b = blackhole route\n\n"); printf("%-5s %-4s %-32s %-32s\n", "flags", "prio", "destination", "gateway"); break; case SHOW_FIB_TABLES: printf("%-5s %-20s %-8s\n", "Table", "Description", "State"); break; case SHOW_NEXTHOP: printf("Flags: * = nexthop valid\n"); printf("\n %-15s %-19s%-4s %-15s %-20s\n", "Nexthop", "Route", "Prio", "Gateway", "Iface"); break; case SHOW_INTERFACE: printf("%-15s%-9s%-9s%-7s%s\n", "Interface", "rdomain", "Nexthop", "Flags", "Link state"); break; case SHOW_RIB: if (res->flags & F_CTL_DETAIL) break; printf("flags: " "* = Valid, > = Selected, I = via IBGP, A = Announced,\n" " S = Stale, E = Error, F = Filtered, L = Leaked\n"); printf("origin validation state: " "N = not-found, V = valid, ! = invalid\n"); printf("aspa validation state: " "? = unknown, V = valid, ! = invalid\n"); printf("origin: i = IGP, e = EGP, ? = Incomplete\n\n"); printf("%-5s %3s %-20s %-15s %5s %5s %s\n", "flags", "vs", "destination", "gateway", "lpref", "med", "aspath origin"); break; case SHOW_SET: printf("%-6s %-34s %7s %7s %6s %11s\n", "Type", "Name", "#IPv4", "#IPv6", "#ASnum", "Last Change"); break; case NETWORK_SHOW: printf("flags: S = Static\n"); printf("%-5s %-4s %-32s %-32s\n", "flags", "prio", "destination", "gateway"); break; case FLOWSPEC_SHOW: printf("flags: S = Static\n"); default: break; } } static void show_summary(struct peer *p) { char *s; const char *a; size_t alen; s = fmt_peer(p->conf.descr, &p->conf.remote_addr, p->conf.remote_masklen); a = log_as(p->conf.remote_as); alen = strlen(a); /* max displayed length of the peers name is 28 */ if (alen < 28) { if (strlen(s) > 28 - alen) s[28 - alen] = '\0'; } else alen = 0; printf("%-*s %s %10llu %10llu %5u %-8s ", (28 - (int)alen), s, a, p->stats.msg_rcvd_open + p->stats.msg_rcvd_notification + p->stats.msg_rcvd_update + p->stats.msg_rcvd_keepalive + p->stats.msg_rcvd_rrefresh, p->stats.msg_sent_open + p->stats.msg_sent_notification + p->stats.msg_sent_update + p->stats.msg_sent_keepalive + p->stats.msg_sent_rrefresh, p->stats.msg_queue_len, fmt_monotime(p->stats.last_updown)); if (p->state == STATE_ESTABLISHED) { printf("%6u", p->stats.prefix_cnt); if (p->conf.max_prefix != 0) printf("/%u", p->conf.max_prefix); } else if (p->conf.template) printf("Template"); else printf("%s", statenames[p->state]); printf("\n"); free(s); } static void show_neighbor_capa_mp(struct capabilities *capa) { int comma; uint8_t i; printf(" Multiprotocol extensions: "); for (i = AID_MIN, comma = 0; i < AID_MAX; i++) if (capa->mp[i]) { printf("%s%s", comma ? ", " : "", aid2str(i)); comma = 1; } printf("\n"); } static void show_neighbor_capa_add_path(struct capabilities *capa) { const char *mode; int comma; uint8_t i; printf(" Add-path: "); for (i = AID_MIN, comma = 0; i < AID_MAX; i++) { switch (capa->add_path[i]) { case 0: default: continue; case CAPA_AP_RECV: mode = "recv"; break; case CAPA_AP_SEND: mode = "send"; break; case CAPA_AP_BIDIR: mode = "bidir"; } printf("%s%s %s", comma ? ", " : "", aid2str(i), mode); comma = 1; } printf("\n"); } static void show_neighbor_capa_restart(struct capabilities *capa) { int comma; uint8_t i; printf(" Graceful Restart: "); if (capa->grestart.timeout) printf("timeout: %d, ", capa->grestart.timeout); if (capa->grestart.grnotification) printf("graceful notification, "); for (i = AID_MIN, comma = 0; i < AID_MAX; i++) if (capa->grestart.flags[i] & CAPA_GR_PRESENT) { if (!comma && capa->grestart.flags[i] & CAPA_GR_RESTART) printf("restarted, "); if (comma) printf(", "); printf("%s", aid2str(i)); if (capa->grestart.flags[i] & CAPA_GR_FORWARD) printf(" (preserved)"); comma = 1; } printf("\n"); } static void show_neighbor_msgstats(struct peer *p) { printf(" Message statistics:\n"); printf(" %-15s %-10s %-10s\n", "", "Sent", "Received"); printf(" %-15s %10llu %10llu\n", "Opens", p->stats.msg_sent_open, p->stats.msg_rcvd_open); printf(" %-15s %10llu %10llu\n", "Notifications", p->stats.msg_sent_notification, p->stats.msg_rcvd_notification); printf(" %-15s %10llu %10llu\n", "Updates", p->stats.msg_sent_update, p->stats.msg_rcvd_update); printf(" %-15s %10llu %10llu\n", "Keepalives", p->stats.msg_sent_keepalive, p->stats.msg_rcvd_keepalive); printf(" %-15s %10llu %10llu\n", "Route Refresh", p->stats.msg_sent_rrefresh, p->stats.msg_rcvd_rrefresh); printf(" %-15s %10llu %10llu\n\n", "Total", p->stats.msg_sent_open + p->stats.msg_sent_notification + p->stats.msg_sent_update + p->stats.msg_sent_keepalive + p->stats.msg_sent_rrefresh, p->stats.msg_rcvd_open + p->stats.msg_rcvd_notification + p->stats.msg_rcvd_update + p->stats.msg_rcvd_keepalive + p->stats.msg_rcvd_rrefresh); printf(" Update statistics:\n"); printf(" %-15s %-10s %-10s %-10s\n", "", "Sent", "Received", "Pending"); printf(" %-15s %10u %10u\n", "Prefixes", p->stats.prefix_out_cnt, p->stats.prefix_cnt); printf(" %-15s %10llu %10llu %10u\n", "Updates", p->stats.prefix_sent_update, p->stats.prefix_rcvd_update, p->stats.pending_update); printf(" %-15s %10llu %10llu %10u\n", "Withdraws", p->stats.prefix_sent_withdraw, p->stats.prefix_rcvd_withdraw, p->stats.pending_withdraw); printf(" %-15s %10llu %10llu\n", "End-of-Rib", p->stats.prefix_sent_eor, p->stats.prefix_rcvd_eor); printf(" Route Refresh statistics:\n"); printf(" %-15s %10llu %10llu\n", "Request", p->stats.refresh_sent_req, p->stats.refresh_rcvd_req); printf(" %-15s %10llu %10llu\n", "Begin-of-RR", p->stats.refresh_sent_borr, p->stats.refresh_rcvd_borr); printf(" %-15s %10llu %10llu\n", "End-of-RR", p->stats.refresh_sent_eorr, p->stats.refresh_rcvd_eorr); } static void show_neighbor_full(struct peer *p, struct parse_result *res) { const char *errstr; struct in_addr ina; char *s; int hascapamp, hascapaap; uint8_t i; if ((p->conf.remote_addr.aid == AID_INET && p->conf.remote_masklen != 32) || (p->conf.remote_addr.aid == AID_INET6 && p->conf.remote_masklen != 128)) { if (asprintf(&s, "%s/%u", log_addr(&p->conf.remote_addr), p->conf.remote_masklen) == -1) err(1, NULL); } else if ((s = strdup(log_addr(&p->conf.remote_addr))) == NULL) err(1, "strdup"); printf("BGP neighbor is %s, ", s); free(s); if (p->conf.remote_as == 0 && p->conf.template) printf("remote AS: accept any"); else printf("remote AS %s", log_as(p->conf.remote_as)); if (p->conf.template) printf(", Template"); if (p->template) printf(", Cloned"); if (p->conf.passive) printf(", Passive"); if (p->conf.ebgp && p->conf.distance > 1) printf(", Multihop (%u)", (int)p->conf.distance); printf("\n"); if (p->conf.descr[0]) printf(" Description: %s\n", p->conf.descr); if (p->conf.ebgp && p->conf.role != ROLE_NONE) printf(" Role: %s\n", log_policy(p->conf.role)); if (p->conf.max_prefix) { printf(" Max-prefix: %u", p->conf.max_prefix); if (p->conf.max_prefix_restart) printf(" (restart %u)", p->conf.max_prefix_restart); } if (p->conf.max_out_prefix) { printf(" Max-prefix out: %u", p->conf.max_out_prefix); if (p->conf.max_out_prefix_restart) printf(" (restart %u)", p->conf.max_out_prefix_restart); } if (p->conf.max_prefix || p->conf.max_out_prefix) printf("\n"); if (p->state == STATE_ESTABLISHED) { ina.s_addr = htonl(p->remote_bgpid); printf(" BGP version 4, remote router-id %s", inet_ntoa(ina)); printf("%s\n", fmt_auth_method(p->auth_conf.method)); } printf(" BGP state = %s", statenames[p->state]); if (p->conf.down) { printf(", marked down"); } if (p->conf.reason[0]) { printf(" with shutdown reason \"%s\"", log_reason(p->conf.reason)); } if (p->stats.last_updown != 0) printf(", %s for %s", p->state == STATE_ESTABLISHED ? "up" : "down", fmt_monotime(p->stats.last_updown)); printf("\n"); printf(" Last read %s, holdtime %us, keepalive interval %us\n", fmt_monotime(p->stats.last_read), p->holdtime, p->holdtime/3); printf(" Last write %s\n", fmt_monotime(p->stats.last_write)); hascapamp = 0; hascapaap = 0; for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.peer.mp[i]) hascapamp = 1; if (p->capa.peer.add_path[i]) hascapaap = 1; } if (hascapamp || hascapaap || p->capa.peer.grestart.restart || p->capa.peer.refresh || p->capa.peer.enhanced_rr || p->capa.peer.as4byte || p->capa.peer.policy) { printf(" Neighbor capabilities:\n"); if (hascapamp) show_neighbor_capa_mp(&p->capa.peer); if (p->capa.peer.as4byte) printf(" 4-byte AS numbers\n"); if (p->capa.peer.refresh) printf(" Route Refresh\n"); if (p->capa.peer.enhanced_rr) printf(" Enhanced Route Refresh\n"); if (p->capa.peer.ext_msg) printf(" Extended message\n"); if (p->capa.peer.grestart.restart) show_neighbor_capa_restart(&p->capa.peer); if (hascapaap) show_neighbor_capa_add_path(&p->capa.peer); if (p->capa.peer.policy) printf(" Open Policy role %s (local %s)\n", log_policy(p->remote_role), log_policy(p->conf.role)); } hascapamp = 0; hascapaap = 0; for (i = AID_MIN; i < AID_MAX; i++) { if (p->capa.neg.mp[i]) hascapamp = 1; if (p->capa.neg.add_path[i]) hascapaap = 1; } if (hascapamp || hascapaap || p->capa.neg.grestart.restart || p->capa.neg.refresh || p->capa.neg.enhanced_rr || p->capa.neg.as4byte || p->capa.neg.policy) { printf(" Negotiated capabilities:\n"); if (hascapamp) show_neighbor_capa_mp(&p->capa.neg); if (p->capa.neg.as4byte) printf(" 4-byte AS numbers\n"); if (p->capa.neg.refresh) printf(" Route Refresh\n"); if (p->capa.neg.enhanced_rr) printf(" Enhanced Route Refresh\n"); if (p->capa.neg.ext_msg) printf(" Extended message\n"); if (p->capa.neg.grestart.restart) show_neighbor_capa_restart(&p->capa.neg); if (hascapaap) show_neighbor_capa_add_path(&p->capa.neg); if (p->capa.neg.policy) printf(" Open Policy role %s (local %s)\n", log_policy(p->remote_role), log_policy(p->conf.role)); } printf("\n"); if (res->action == SHOW_NEIGHBOR_TIMERS) return; show_neighbor_msgstats(p); printf("\n"); errstr = fmt_errstr(p->stats.last_sent_errcode, p->stats.last_sent_suberr); if (errstr) printf(" Last error sent: %s\n", errstr); errstr = fmt_errstr(p->stats.last_rcvd_errcode, p->stats.last_rcvd_suberr); if (errstr) printf(" Last error received: %s\n", errstr); if (p->stats.last_reason[0]) { printf(" Last received shutdown reason: \"%s\"\n", log_reason(p->stats.last_reason)); } if (p->state >= STATE_OPENSENT) { printf(" Local host: %20s, Local port: %5u\n", log_addr(&p->local), p->local_port); printf(" Remote host: %20s, Remote port: %5u\n", log_addr(&p->remote), p->remote_port); printf("\n"); } } static void show_neighbor(struct peer *p, struct parse_result *res) { char *s; switch (res->action) { case SHOW: case SHOW_SUMMARY: show_summary(p); break; case SHOW_SUMMARY_TERSE: s = fmt_peer(p->conf.descr, &p->conf.remote_addr, p->conf.remote_masklen); printf("%s %s %s\n", s, log_as(p->conf.remote_as), p->conf.template ? "Template" : statenames[p->state]); free(s); break; case SHOW_NEIGHBOR: case SHOW_NEIGHBOR_TIMERS: show_neighbor_full(p, res); break; case SHOW_NEIGHBOR_TERSE: s = fmt_peer(NULL, &p->conf.remote_addr, p->conf.remote_masklen); printf("%llu %llu %llu %llu %llu %llu %llu %llu %llu " "%llu %u %u %llu %llu %llu %llu %s %s \"%s\"\n", p->stats.msg_sent_open, p->stats.msg_rcvd_open, p->stats.msg_sent_notification, p->stats.msg_rcvd_notification, p->stats.msg_sent_update, p->stats.msg_rcvd_update, p->stats.msg_sent_keepalive, p->stats.msg_rcvd_keepalive, p->stats.msg_sent_rrefresh, p->stats.msg_rcvd_rrefresh, p->stats.prefix_cnt, p->conf.max_prefix, p->stats.prefix_sent_update, p->stats.prefix_rcvd_update, p->stats.prefix_sent_withdraw, p->stats.prefix_rcvd_withdraw, s, log_as(p->conf.remote_as), p->conf.descr); free(s); break; default: break; } } static void show_timer(struct ctl_timer *t) { printf(" %-20s ", timernames[t->type]); if (t->val <= 0) printf("%-20s\n", "due"); else printf("due in %-13s\n", fmt_timeframe(t->val)); } static void show_fib(struct kroute_full *kf) { char *p; if (asprintf(&p, "%s/%u", log_addr(&kf->prefix), kf->prefixlen) == -1) err(1, NULL); printf("%-5s %4i %-32s ", fmt_fib_flags(kf->flags), kf->priority, p); free(p); if (kf->flags & F_CONNECTED) printf("link#%u", kf->ifindex); else printf("%s", log_addr(&kf->nexthop)); if (kf->flags & F_MPLS) printf(" mpls %d", ntohl(kf->mplslabel) >> MPLS_LABEL_OFFSET); printf("\n"); } static void show_fib_table(struct ktable *kt) { printf("%5i %-20s %-8s%s\n", kt->rtableid, kt->descr, kt->fib_sync ? "coupled" : "decoupled", kt->fib_sync != kt->fib_conf ? "*" : ""); } static void print_flowspec_list(struct flowspec *f, int type, int is_v6) { const uint8_t *comp; const char *fmt; int complen, off = 0; if (flowspec_get_component(f->data, f->len, type, is_v6, &comp, &complen) != 1) return; printf("%s ", flowspec_fmt_label(type)); fmt = flowspec_fmt_num_op(comp, complen, &off); if (off == -1) { printf("%s ", fmt); } else { printf("{ %s ", fmt); do { fmt = flowspec_fmt_num_op(comp, complen, &off); printf("%s ", fmt); } while (off != -1); printf("} "); } } static void print_flowspec_flags(struct flowspec *f, int type, int is_v6) { const uint8_t *comp; const char *fmt, *flags; int complen, off = 0; switch (type) { case FLOWSPEC_TYPE_TCP_FLAGS: flags = FLOWSPEC_TCP_FLAG_STRING; break; case FLOWSPEC_TYPE_FRAG: if (!is_v6) flags = FLOWSPEC_FRAG_STRING4; else flags = FLOWSPEC_FRAG_STRING6; break; default: printf("??? "); return; } if (flowspec_get_component(f->data, f->len, type, is_v6, &comp, &complen) != 1) return; printf("%s ", flowspec_fmt_label(type)); fmt = flowspec_fmt_bin_op(comp, complen, &off, flags); if (off == -1) { printf("%s ", fmt); } else { printf("{ %s ", fmt); do { fmt = flowspec_fmt_bin_op(comp, complen, &off, flags); printf("%s ", fmt); } while (off != -1); printf("} "); } } static void print_flowspec_addr(struct flowspec *f, int type, int is_v6) { struct bgpd_addr addr; uint8_t plen; flowspec_get_addr(f->data, f->len, type, is_v6, &addr, &plen, NULL); if (plen == 0) printf("%s any ", flowspec_fmt_label(type)); else printf("%s %s/%u ", flowspec_fmt_label(type), log_addr(&addr), plen); } static void show_flowspec(struct flowspec *f) { int is_v6 = (f->aid == AID_FLOWSPECv6); printf("%-5s ", fmt_fib_flags(f->flags)); print_flowspec_list(f, FLOWSPEC_TYPE_PROTO, is_v6); print_flowspec_addr(f, FLOWSPEC_TYPE_SOURCE, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_SRC_PORT, is_v6); print_flowspec_addr(f, FLOWSPEC_TYPE_DEST, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_DST_PORT, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_DSCP, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_PKT_LEN, is_v6); print_flowspec_flags(f, FLOWSPEC_TYPE_TCP_FLAGS, is_v6); print_flowspec_flags(f, FLOWSPEC_TYPE_FRAG, is_v6); /* TODO: fixup the code handling to be like in the parser */ print_flowspec_list(f, FLOWSPEC_TYPE_ICMP_TYPE, is_v6); print_flowspec_list(f, FLOWSPEC_TYPE_ICMP_CODE, is_v6); printf("\n"); } static void show_nexthop(struct ctl_show_nexthop *nh) { char *s; printf("%s %-15s ", nh->valid ? "*" : " ", log_addr(&nh->addr)); if (!nh->krvalid) { printf("\n"); return; } if (asprintf(&s, "%s/%u", log_addr(&nh->kr.prefix), nh->kr.prefixlen) == -1) err(1, NULL); printf("%-20s", s); free(s); printf("%3i %-15s ", nh->kr.priority, nh->kr.flags & F_CONNECTED ? "connected" : log_addr(&nh->kr.nexthop)); if (nh->iface.ifname[0]) { printf("%s (%s, %s)", nh->iface.ifname, nh->iface.is_up ? "UP" : "DOWN", nh->iface.baudrate ? get_baudrate(nh->iface.baudrate, "bps") : nh->iface.linkstate); } printf("\n"); } static void show_interface(struct ctl_show_interface *iface) { printf("%-15s", iface->ifname); printf("%-9u", iface->rdomain); printf("%-9s", iface->nh_reachable ? "ok" : "invalid"); printf("%-7s", iface->is_up ? "UP" : ""); if (iface->media[0]) printf("%s, ", iface->media); printf("%s", iface->linkstate); if (iface->baudrate > 0) printf(", %s", get_baudrate(iface->baudrate, "Bit/s")); printf("\n"); } static void show_communities(struct ibuf *data, struct parse_result *res) { struct community c; uint64_t ext; uint8_t type = 0; while (ibuf_size(data) != 0) { if (ibuf_get(data, &c, sizeof(c)) == -1) { warn("communities"); break; } if (type != c.flags) { if (type != 0) printf("%c", EOL0(res->flags)); printf(" %s:", fmt_attr(c.flags, ATTR_OPTIONAL | ATTR_TRANSITIVE)); type = c.flags; } switch (c.flags) { case COMMUNITY_TYPE_BASIC: printf(" %s", fmt_community(c.data1, c.data2)); break; case COMMUNITY_TYPE_LARGE: printf(" %s", fmt_large_community(c.data1, c.data2, c.data3)); break; case COMMUNITY_TYPE_EXT: ext = (uint64_t)c.data3 << 48; switch ((c.data3 >> 8) & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: ext |= ((uint64_t)c.data1 & 0xffff) << 32; ext |= (uint64_t)c.data2; break; case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: ext |= (uint64_t)c.data1 << 16; ext |= (uint64_t)c.data2 & 0xffff; break; } printf(" %s", fmt_ext_community(ext)); break; } } printf("%c", EOL0(res->flags)); } static void show_community(struct ibuf *buf) { uint16_t a, v; while (ibuf_size(buf) > 0) { if (ibuf_get_n16(buf, &a) == -1 || ibuf_get_n16(buf, &v) == -1) { printf("bad length"); return; } printf("%s", fmt_community(a, v)); if (ibuf_size(buf) > 0) printf(" "); } } static void show_large_community(struct ibuf *buf) { uint32_t a, l1, l2; while (ibuf_size(buf) > 0) { if (ibuf_get_n32(buf, &a) == -1 || ibuf_get_n32(buf, &l1) == -1 || ibuf_get_n32(buf, &l2) == -1) { printf("bad length"); return; } printf("%s", fmt_large_community(a, l1, l2)); if (ibuf_size(buf) > 0) printf(" "); } } static void show_ext_community(struct ibuf *buf) { uint64_t ext; while (ibuf_size(buf) > 0) { if (ibuf_get_n64(buf, &ext) == -1) { printf("bad length"); return; } printf("%s", fmt_ext_community(ext)); if (ibuf_size(buf) > 0) printf(" "); } } static void show_attr(struct ibuf *buf, int reqflags, int addpath) { struct in_addr id; struct bgpd_addr prefix; struct ibuf asbuf, *path = NULL; char *aspath; size_t i, alen; uint32_t as, pathid, val; uint16_t short_as, afi; uint8_t flags, type, safi, aid, prefixlen, origin, b; int e2, e4; if (ibuf_get_n8(buf, &flags) == -1 || ibuf_get_n8(buf, &type) == -1) goto bad_len; /* get the attribute length */ if (flags & ATTR_EXTLEN) { uint16_t attr_len; if (ibuf_get_n16(buf, &attr_len) == -1) goto bad_len; alen = attr_len; } else { uint8_t attr_len; if (ibuf_get_n8(buf, &attr_len) == -1) goto bad_len; alen = attr_len; } /* bad imsg len how can that happen!? */ if (alen > ibuf_size(buf)) goto bad_len; printf(" %s: ", fmt_attr(type, flags)); switch (type) { case ATTR_ORIGIN: if (alen != 1 || ibuf_get_n8(buf, &origin) == -1) goto bad_len; printf("%s", fmt_origin(origin, 0)); break; case ATTR_ASPATH: case ATTR_AS4_PATH: /* prefer 4-byte AS here */ e4 = aspath_verify(buf, 1, 0); e2 = aspath_verify(buf, 0, 0); if (e4 == 0 || e4 == AS_ERR_SOFT) { ibuf_from_ibuf(&asbuf, buf); } else if (e2 == 0 || e2 == AS_ERR_SOFT) { if ((path = aspath_inflate(buf)) == NULL) { printf("aspath_inflate failed"); break; } ibuf_from_ibuf(&asbuf, path); } else { printf("bad AS-Path"); break; } if (aspath_asprint(&aspath, &asbuf) == -1) err(1, NULL); printf("%s", aspath); free(aspath); ibuf_free(path); break; case ATTR_NEXTHOP: case ATTR_ORIGINATOR_ID: if (alen != 4 || ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; printf("%s", inet_ntoa(id)); break; case ATTR_MED: case ATTR_LOCALPREF: if (alen != 4 || ibuf_get_n32(buf, &val) == -1) goto bad_len; printf("%u", val); break; case ATTR_AGGREGATOR: case ATTR_AS4_AGGREGATOR: if (alen == 8) { if (ibuf_get_n32(buf, &as) == -1 || ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; } else if (alen == 6) { if (ibuf_get_n16(buf, &short_as) == -1 || ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; as = short_as; } else { goto bad_len; } printf("%s [%s]", log_as(as), inet_ntoa(id)); break; case ATTR_COMMUNITIES: show_community(buf); break; case ATTR_CLUSTER_LIST: while (ibuf_size(buf) > 0) { if (ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; printf(" %s", inet_ntoa(id)); } break; case ATTR_MP_REACH_NLRI: case ATTR_MP_UNREACH_NLRI: if (ibuf_get_n16(buf, &afi) == -1 || ibuf_get_n8(buf, &safi) == -1) goto bad_len; if (afi2aid(afi, safi, &aid) == -1) { printf("bad AFI/SAFI pair"); break; } printf(" %s", aid2str(aid)); if (type == ATTR_MP_REACH_NLRI) { struct bgpd_addr nexthop; uint8_t nhlen; if (ibuf_get_n8(buf, &nhlen) == -1) goto bad_len; memset(&nexthop, 0, sizeof(nexthop)); switch (aid) { case AID_INET6: nexthop.aid = aid; if (nhlen != 16 && nhlen != 32) goto bad_len; if (ibuf_get(buf, &nexthop.v6, sizeof(nexthop.v6)) == -1) goto bad_len; break; case AID_VPN_IPv4: if (nhlen != 12) goto bad_len; nexthop.aid = AID_INET; if (ibuf_skip(buf, sizeof(uint64_t)) == -1 || ibuf_get(buf, &nexthop.v4, sizeof(nexthop.v4)) == -1) goto bad_len; break; case AID_VPN_IPv6: if (nhlen != 24) goto bad_len; nexthop.aid = AID_INET6; if (ibuf_skip(buf, sizeof(uint64_t)) == -1 || ibuf_get(buf, &nexthop.v6, sizeof(nexthop.v6)) == -1) goto bad_len; break; default: printf("unhandled AID #%u", aid); goto done; } /* ignore reserved (old SNPA) field as per RFC4760 */ if (ibuf_skip(buf, 1) == -1) goto bad_len; printf(" nexthop: %s", log_addr(&nexthop)); } while (ibuf_size(buf) > 0) { if (addpath) if (ibuf_get_n32(buf, &pathid) == -1) goto bad_len; switch (aid) { case AID_INET6: if (nlri_get_prefix6(buf, &prefix, &prefixlen) == -1) goto bad_len; break; case AID_VPN_IPv4: if (nlri_get_vpn4(buf, &prefix, &prefixlen, 1) == -1) goto bad_len; break; case AID_VPN_IPv6: if (nlri_get_vpn6(buf, &prefix, &prefixlen, 1) == -1) goto bad_len; break; default: printf("unhandled AID #%u", aid); goto done; } printf(" %s/%u", log_addr(&prefix), prefixlen); if (addpath) printf(" path-id %u", pathid); } break; case ATTR_EXT_COMMUNITIES: show_ext_community(buf); break; case ATTR_LARGE_COMMUNITIES: show_large_community(buf); break; case ATTR_OTC: if (alen != 4 || ibuf_get_n32(buf, &as) == -1) goto bad_len; printf("%s", log_as(as)); break; case ATTR_ATOMIC_AGGREGATE: default: printf(" len %zu", alen); if (alen) { printf(":"); for (i = 0; i < alen; i++) { if (ibuf_get_n8(buf, &b) == -1) goto bad_len; printf(" %02x", b); } } break; } done: printf("%c", EOL0(reqflags)); return; bad_len: printf("bad length%c", EOL0(reqflags)); } static void show_rib_brief(struct ctl_show_rib *r, struct ibuf *asbuf) { char *p, *aspath; if (asprintf(&p, "%s/%u", log_addr(&r->prefix), r->prefixlen) == -1) err(1, NULL); printf("%s %s-%s %-20s %-15s %5u %5u ", fmt_flags(r->flags, 1), fmt_ovs(r->roa_validation_state, 1), fmt_avs(r->aspa_validation_state, 1), p, log_addr(&r->exit_nexthop), r->local_pref, r->med); free(p); if (aspath_asprint(&aspath, asbuf) == -1) err(1, NULL); if (strlen(aspath) > 0) printf("%s ", aspath); free(aspath); printf("%s\n", fmt_origin(r->origin, 1)); } static void show_rib_detail(struct ctl_show_rib *r, struct ibuf *asbuf, int flag0) { struct in_addr id; char *aspath, *s; printf("\nBGP routing table entry for %s/%u%c", log_addr(&r->prefix), r->prefixlen, EOL0(flag0)); if (aspath_asprint(&aspath, asbuf) == -1) err(1, NULL); if (strlen(aspath) > 0) printf(" %s%c", aspath, EOL0(flag0)); free(aspath); s = fmt_peer(r->descr, &r->remote_addr, -1); id.s_addr = htonl(r->remote_id); printf(" Nexthop %s ", log_addr(&r->exit_nexthop)); printf("(via %s) Neighbor %s (%s)", log_addr(&r->true_nexthop), s, inet_ntoa(id)); if (r->flags & F_PREF_PATH_ID) printf(" Path-Id: %u", r->path_id); printf("%c", EOL0(flag0)); free(s); printf(" Origin %s, metric %u, localpref %u, weight %u, ovs %s, ", fmt_origin(r->origin, 0), r->med, r->local_pref, r->weight, fmt_ovs(r->roa_validation_state, 0)); printf("avs %s, %s", fmt_avs(r->aspa_validation_state, 0), fmt_flags(r->flags, 0)); printf("%c Last update: %s ago%c", EOL0(flag0), fmt_timeframe(r->age), EOL0(flag0)); } static void show_rib(struct ctl_show_rib *r, struct ibuf *aspath, struct parse_result *res) { if (res->flags & F_CTL_DETAIL) show_rib_detail(r, aspath, res->flags); else show_rib_brief(r, aspath); } static void show_rib_mem(struct rde_memstats *stats) { size_t pts = 0; int i; printf("RDE memory statistics\n"); for (i = 0; i < AID_MAX; i++) { if (stats->pt_cnt[i] == 0) continue; pts += stats->pt_size[i]; printf("%10lld %s network entries using %s of memory\n", stats->pt_cnt[i], aid_vals[i].name, fmt_mem(stats->pt_size[i])); } printf("%10lld rib entries using %s of memory\n", stats->rib_cnt, fmt_mem(stats->rib_cnt * sizeof(struct rib_entry))); printf("%10lld prefix entries using %s of memory\n", stats->prefix_cnt, fmt_mem(stats->prefix_cnt * sizeof(struct prefix))); printf("%10lld BGP path attribute entries using %s of memory\n", stats->path_cnt, fmt_mem(stats->path_cnt * sizeof(struct rde_aspath))); printf("\t and holding %lld references\n", stats->path_refs); printf("%10lld BGP AS-PATH attribute entries using " "%s of memory\n", stats->aspath_cnt, fmt_mem(stats->aspath_size)); printf("%10lld entries for %lld BGP communities " "using %s of memory\n", stats->comm_cnt, stats->comm_nmemb, fmt_mem(stats->comm_cnt * sizeof(struct rde_community) + stats->comm_size * sizeof(struct community))); printf("\t and holding %lld references\n", stats->comm_refs); printf("%10lld BGP attributes entries using %s of memory\n", stats->attr_cnt, fmt_mem(stats->attr_cnt * sizeof(struct attr))); printf("\t and holding %lld references\n", stats->attr_refs); printf("%10lld BGP attributes using %s of memory\n", stats->attr_dcnt, fmt_mem(stats->attr_data)); printf("%10lld as-set elements in %lld tables using " "%s of memory\n", stats->aset_nmemb, stats->aset_cnt, fmt_mem(stats->aset_size)); printf("%10lld prefix-set elements using %s of memory\n", stats->pset_cnt, fmt_mem(stats->pset_size)); printf("RIB using %s of memory\n", fmt_mem(pts + stats->prefix_cnt * sizeof(struct prefix) + stats->rib_cnt * sizeof(struct rib_entry) + stats->path_cnt * sizeof(struct rde_aspath) + stats->aspath_size + stats->attr_cnt * sizeof(struct attr) + stats->attr_data)); printf("Sets using %s of memory\n", fmt_mem(stats->aset_size + stats->pset_size)); } static void show_rib_set(struct ctl_show_set *set) { char buf[64]; if (set->type == ASNUM_SET || set->type == ASPA_SET) snprintf(buf, sizeof(buf), "%7s %7s %6zu", "-", "-", set->as_cnt); else snprintf(buf, sizeof(buf), "%7zu %7zu %6s", set->v4_cnt, set->v6_cnt, "-"); printf("%-6s %-34s %s %11s\n", fmt_set_type(set), set->name, buf, fmt_monotime(set->lastchange)); } static void show_rtr(struct ctl_show_rtr *rtr) { static int not_first; if (not_first) printf("\n"); not_first = 1; printf("RTR neighbor is %s, port %u\n", log_addr(&rtr->remote_addr), rtr->remote_port); printf(" State: %s\n", rtr->state); if (rtr->descr[0]) printf(" Description: %s\n", rtr->descr); if (rtr->local_addr.aid != AID_UNSPEC) printf(" Local Address: %s\n", log_addr(&rtr->local_addr)); if (rtr->session_id != -1) printf(" Version: %u min %u Session ID: %d Serial #: %u\n", rtr->version, rtr->min_version, rtr->session_id, rtr->serial); printf(" Refresh: %u, Retry: %u, Expire: %u\n", rtr->refresh, rtr->retry, rtr->expire); if (rtr->last_sent_error != NO_ERROR) { printf(" Last sent error: %s\n", log_rtr_error(rtr->last_sent_error)); if (rtr->last_sent_msg[0]) printf(" with reason \"%s\"\n", log_reason(rtr->last_sent_msg)); } if (rtr->last_recv_error != NO_ERROR) { printf(" Last received error: %s\n", log_rtr_error(rtr->last_recv_error)); if (rtr->last_recv_msg[0]) printf(" with reason \"%s\"\n", log_reason(rtr->last_recv_msg)); } printf("\n"); } static void show_result(u_int rescode) { if (rescode == 0) printf("request processed\n"); else if (rescode >= sizeof(ctl_res_strerror)/sizeof(ctl_res_strerror[0])) printf("unknown result error code %u\n", rescode); else printf("%s\n", ctl_res_strerror[rescode]); } static void show_tail(void) { /* nothing */ } const struct output show_output = { .head = show_head, .neighbor = show_neighbor, .timer = show_timer, .fib = show_fib, .fib_table = show_fib_table, .flowspec = show_flowspec, .nexthop = show_nexthop, .interface = show_interface, .communities = show_communities, .attr = show_attr, .rib = show_rib, .rib_mem = show_rib_mem, .set = show_rib_set, .rtr = show_rtr, .result = show_result, .tail = show_tail, }; openbgpd-8.8/src/bgpctl/output_json.c100644 001750 001750 00000065161 14730105010 0013470/* $OpenBSD: output_json.c,v 1.50 2024/12/13 19:22:01 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "bgpctl.h" #include "parser.h" #include "json.h" static void json_head(struct parse_result *res) { json_do_start(stdout); } static void json_neighbor_capabilities(struct capabilities *capa) { int hascapamp = 0, hascapaap = 0; uint8_t i; for (i = AID_MIN; i < AID_MAX; i++) { if (capa->mp[i]) hascapamp = 1; if (capa->add_path[i]) hascapaap = 1; } if (!hascapamp && !hascapaap && !capa->grestart.restart && !capa->refresh && !capa->enhanced_rr && !capa->as4byte) return; json_do_object("capabilities", 0); json_do_bool("as4byte", capa->as4byte); json_do_bool("refresh", capa->refresh); json_do_bool("enhanced_refresh", capa->enhanced_rr); json_do_bool("extended_message", capa->ext_msg); if (hascapamp) { json_do_array("multiprotocol"); for (i = AID_MIN; i < AID_MAX; i++) if (capa->mp[i]) json_do_string("mp", aid2str(i)); json_do_end(); } if (capa->grestart.restart) { int restarted = 0, present = 0; for (i = AID_MIN; i < AID_MAX; i++) if (capa->grestart.flags[i] & CAPA_GR_PRESENT) { present = 1; if (capa->grestart.flags[i] & CAPA_GR_RESTART) restarted = 1; break; } json_do_object("graceful_restart", 0); json_do_bool("eor", 1); json_do_bool("restart", restarted); if (capa->grestart.timeout) json_do_uint("timeout", capa->grestart.timeout); if (capa->grestart.grnotification) json_do_bool("graceful_notification", 1); if (present) { json_do_array("protocols"); for (i = AID_MIN; i < AID_MAX; i++) if (capa->grestart.flags[i] & CAPA_GR_PRESENT) { json_do_object("family", 1); json_do_string("family", aid2str(i)); json_do_bool("preserved", capa->grestart.flags[i] & CAPA_GR_FORWARD); json_do_end(); } json_do_end(); } json_do_end(); } if (hascapaap) { json_do_array("add-path"); for (i = AID_MIN; i < AID_MAX; i++) if (capa->add_path[i]) { json_do_object("add-path-elm", 1); json_do_string("family", aid2str(i)); switch (capa->add_path[i]) { case CAPA_AP_RECV: json_do_string("mode", "recv"); break; case CAPA_AP_SEND: json_do_string("mode", "send"); break; case CAPA_AP_BIDIR: json_do_string("mode", "bidir"); break; default: json_do_printf("mode", "unknown %d", capa->add_path[i]); break; } json_do_end(); } json_do_end(); } if (capa->policy) { json_do_string("open_policy", capa->policy == 2 ? "enforce" : "present"); } json_do_end(); } static void json_neighbor_stats(struct peer *p) { json_do_object("stats", 0); json_do_string("last_read", fmt_monotime(p->stats.last_read)); json_do_int("last_read_sec", get_monotime(p->stats.last_read)); json_do_string("last_write", fmt_monotime(p->stats.last_write)); json_do_int("last_write_sec", get_monotime(p->stats.last_write)); json_do_object("prefixes", 1); json_do_uint("sent", p->stats.prefix_out_cnt); json_do_uint("received", p->stats.prefix_cnt); json_do_end(); json_do_object("message", 0); json_do_object("sent", 0); json_do_uint("open", p->stats.msg_sent_open); json_do_uint("notifications", p->stats.msg_sent_notification); json_do_uint("updates", p->stats.msg_sent_update); json_do_uint("keepalives", p->stats.msg_sent_keepalive); json_do_uint("route_refresh", p->stats.msg_sent_rrefresh); json_do_uint("total", p->stats.msg_sent_open + p->stats.msg_sent_notification + p->stats.msg_sent_update + p->stats.msg_sent_keepalive + p->stats.msg_sent_rrefresh); json_do_end(); json_do_object("received", 0); json_do_uint("open", p->stats.msg_rcvd_open); json_do_uint("notifications", p->stats.msg_rcvd_notification); json_do_uint("updates", p->stats.msg_rcvd_update); json_do_uint("keepalives", p->stats.msg_rcvd_keepalive); json_do_uint("route_refresh", p->stats.msg_rcvd_rrefresh); json_do_uint("total", p->stats.msg_rcvd_open + p->stats.msg_rcvd_notification + p->stats.msg_rcvd_update + p->stats.msg_rcvd_keepalive + p->stats.msg_rcvd_rrefresh); json_do_end(); json_do_end(); json_do_object("update", 0); json_do_object("sent", 1); json_do_uint("updates", p->stats.prefix_sent_update); json_do_uint("withdraws", p->stats.prefix_sent_withdraw); json_do_uint("eor", p->stats.prefix_sent_eor); json_do_end(); json_do_object("received", 1); json_do_uint("updates", p->stats.prefix_rcvd_update); json_do_uint("withdraws", p->stats.prefix_rcvd_withdraw); json_do_uint("eor", p->stats.prefix_rcvd_eor); json_do_end(); json_do_object("pending", 1); json_do_uint("updates", p->stats.pending_update); json_do_uint("withdraws", p->stats.pending_withdraw); json_do_end(); json_do_end(); json_do_object("route-refresh", 0); json_do_object("sent", 1); json_do_uint("request", p->stats.refresh_sent_req); json_do_uint("borr", p->stats.refresh_sent_borr); json_do_uint("eorr", p->stats.refresh_sent_eorr); json_do_end(); json_do_object("received", 1); json_do_uint("request", p->stats.refresh_rcvd_req); json_do_uint("borr", p->stats.refresh_rcvd_borr); json_do_uint("eorr", p->stats.refresh_rcvd_eorr); json_do_end(); json_do_end(); json_do_end(); } static void json_neighbor_full(struct peer *p) { const char *errstr; /* config */ json_do_object("config", 0); json_do_bool("template", p->conf.template); json_do_bool("cloned", p->template != NULL); json_do_bool("passive", p->conf.passive); json_do_bool("down", p->conf.down); json_do_bool("multihop", p->conf.ebgp && p->conf.distance > 1); if (p->conf.ebgp && p->conf.distance > 1) json_do_uint("multihop_distance", p->conf.distance); if (p->conf.max_prefix) { json_do_uint("max_prefix", p->conf.max_prefix); if (p->conf.max_prefix_restart) json_do_uint("max_prefix_restart", p->conf.max_prefix_restart); } if (p->conf.max_out_prefix) { json_do_uint("max_out_prefix", p->conf.max_out_prefix); if (p->conf.max_out_prefix_restart) json_do_uint("max_out_prefix_restart", p->conf.max_out_prefix_restart); } if (p->auth_conf.method != AUTH_NONE) json_do_string("authentication", fmt_auth_method(p->auth_conf.method)); json_do_bool("ttl_security", p->conf.ttlsec); json_do_uint("holdtime", p->conf.holdtime); json_do_uint("min_holdtime", p->conf.min_holdtime); if (p->conf.ebgp && p->conf.role != ROLE_NONE) json_do_string("role", log_policy(p->conf.role)); /* capabilities */ json_neighbor_capabilities(&p->conf.capabilities); json_do_end(); /* stats */ json_neighbor_stats(p); /* errors */ if (p->conf.reason[0]) json_do_string("my_shutdown_reason", log_reason(p->conf.reason)); if (p->stats.last_reason[0]) json_do_string("last_shutdown_reason", log_reason(p->stats.last_reason)); errstr = fmt_errstr(p->stats.last_sent_errcode, p->stats.last_sent_suberr); if (errstr) json_do_string("last_error_sent", errstr); errstr = fmt_errstr(p->stats.last_rcvd_errcode, p->stats.last_rcvd_suberr); if (errstr) json_do_string("last_error_received", errstr); /* connection info */ if (p->state >= STATE_OPENSENT) { json_do_object("session", 0); json_do_uint("holdtime", p->holdtime); json_do_uint("keepalive", p->holdtime / 3); json_do_object("local", 0); json_do_string("address", log_addr(&p->local)); json_do_uint("port", p->local_port); json_neighbor_capabilities(&p->capa.ann); json_do_end(); json_do_object("remote", 0); json_do_string("address", log_addr(&p->remote)); json_do_uint("port", p->remote_port); json_neighbor_capabilities(&p->capa.peer); json_do_end(); /* capabilities */ json_neighbor_capabilities(&p->capa.neg); if (p->conf.ebgp && p->conf.role != ROLE_NONE) { json_do_string("remote_role", log_policy(p->remote_role)); json_do_string("local_role", log_policy(p->conf.role)); } json_do_end(); } } static void json_neighbor(struct peer *p, struct parse_result *res) { json_do_array("neighbors"); json_do_object("neighbor", 0); json_do_string("remote_as", log_as(p->conf.remote_as)); if (p->conf.descr[0]) json_do_string("description", p->conf.descr); if (p->conf.group[0]) json_do_string("group", p->conf.group); if (!p->conf.template) json_do_string("remote_addr", log_addr(&p->conf.remote_addr)); else json_do_printf("remote_addr", "%s/%u", log_addr(&p->conf.remote_addr), p->conf.remote_masklen); if (p->state == STATE_ESTABLISHED) { struct in_addr ina; ina.s_addr = htonl(p->remote_bgpid); json_do_string("bgpid", inet_ntoa(ina)); } json_do_string("state", statenames[p->state]); json_do_string("last_updown", fmt_monotime(p->stats.last_updown)); json_do_int("last_updown_sec", get_monotime(p->stats.last_updown)); switch (res->action) { case SHOW: case SHOW_SUMMARY: case SHOW_SUMMARY_TERSE: /* only show basic data */ break; case SHOW_NEIGHBOR: case SHOW_NEIGHBOR_TIMERS: case SHOW_NEIGHBOR_TERSE: json_neighbor_full(p); break; default: break; } /* keep the object open in case there are timers */ } static void json_timer(struct ctl_timer *t) { json_do_array("timers"); json_do_object("timer", 1); json_do_string("name", timernames[t->type]); json_do_int("due", t->val); json_do_end(); } static void json_fib(struct kroute_full *kf) { const char *origin; json_do_array("fib"); json_do_object("fib_entry", 0); json_do_printf("prefix", "%s/%u", log_addr(&kf->prefix), kf->prefixlen); json_do_uint("priority", kf->priority); if (kf->flags & F_BGPD) origin = "bgp"; else if (kf->flags & F_CONNECTED) origin = "connected"; else if (kf->flags & F_STATIC) origin = "static"; else origin = "unknown"; json_do_string("origin", origin); json_do_bool("used_by_nexthop", kf->flags & F_NEXTHOP); json_do_bool("blackhole", kf->flags & F_BLACKHOLE); json_do_bool("reject", kf->flags & F_REJECT); if (kf->flags & F_CONNECTED) json_do_printf("nexthop", "link#%u", kf->ifindex); else json_do_string("nexthop", log_addr(&kf->nexthop)); if (kf->flags & F_MPLS) { json_do_array("mplslabel"); json_do_uint("mplslabel", ntohl(kf->mplslabel) >> MPLS_LABEL_OFFSET); json_do_end(); } json_do_end(); } static void json_fib_table(struct ktable *kt) { json_do_array("fibtables"); json_do_object("fibtable", 0); json_do_uint("rtableid", kt->rtableid); json_do_string("description", kt->descr); json_do_bool("coupled", kt->fib_sync); json_do_bool("admin_change", kt->fib_sync != kt->fib_conf); json_do_end(); } static void json_do_interface(struct ctl_show_interface *iface) { json_do_object("interface", 0); json_do_string("name", iface->ifname); json_do_uint("rdomain", iface->rdomain); json_do_bool("is_up", iface->is_up); json_do_bool("nh_reachable", iface->nh_reachable); if (iface->media[0]) json_do_string("media", iface->media); json_do_string("linkstate", iface->linkstate); if (iface->baudrate > 0) json_do_uint("baudrate", iface->baudrate); json_do_end(); } static void json_nexthop(struct ctl_show_nexthop *nh) { json_do_array("nexthops"); json_do_object("nexthop", 0); json_do_string("address", log_addr(&nh->addr)); json_do_bool("valid", nh->valid); if (!nh->krvalid) goto done; json_do_printf("prefix", "%s/%u", log_addr(&nh->kr.prefix), nh->kr.prefixlen); json_do_uint("priority", nh->kr.priority); json_do_bool("connected", nh->kr.flags & F_CONNECTED); json_do_string("nexthop", log_addr(&nh->kr.nexthop)); if (nh->iface.ifname[0]) json_do_interface(&nh->iface); done: json_do_end(); /* keep array open */ } static void json_interface(struct ctl_show_interface *iface) { json_do_array("interfaces"); json_do_interface(iface); } static void json_communities(struct ibuf *data, struct parse_result *res) { struct community c; uint64_t ext; while (ibuf_size(data) != 0) { if (ibuf_get(data, &c, sizeof(c)) == -1) { warn("communities"); return; } switch (c.flags) { case COMMUNITY_TYPE_BASIC: json_do_array("communities"); json_do_string("community", fmt_community(c.data1, c.data2)); break; case COMMUNITY_TYPE_LARGE: json_do_array("large_communities"); json_do_string("community", fmt_large_community(c.data1, c.data2, c.data3)); break; case COMMUNITY_TYPE_EXT: ext = (uint64_t)c.data3 << 48; switch ((c.data3 >> 8) & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: ext |= ((uint64_t)c.data1 & 0xffff) << 32; ext |= (uint64_t)c.data2; break; case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: ext |= (uint64_t)c.data1 << 16; ext |= (uint64_t)c.data2 & 0xffff; break; } json_do_array("extended_communities"); json_do_string("community", fmt_ext_community(ext)); break; } } } static void json_do_community(struct ibuf *buf) { uint16_t a, v; json_do_array("communities"); while (ibuf_size(buf) > 0) { if (ibuf_get_n16(buf, &a) == -1 || ibuf_get_n16(buf, &v) == -1) { json_do_string("error", "bad length"); return; } json_do_string("community", fmt_community(a, v)); } json_do_end(); } static void json_do_large_community(struct ibuf *buf) { uint32_t a, l1, l2; json_do_array("large_communities"); while (ibuf_size(buf) > 0) { if (ibuf_get_n32(buf, &a) == -1 || ibuf_get_n32(buf, &l1) == -1 || ibuf_get_n32(buf, &l2) == -1) { json_do_string("error", "bad length"); return; } json_do_string("community", fmt_large_community(a, l1, l2)); } json_do_end(); } static void json_do_ext_community(struct ibuf *buf) { uint64_t ext; json_do_array("extended_communities"); while (ibuf_size(buf) > 0) { if (ibuf_get_n64(buf, &ext) == -1) { json_do_string("error", "bad length"); return; } json_do_string("community", fmt_ext_community(ext)); } json_do_end(); } static void json_attr(struct ibuf *buf, int reqflags, int addpath) { struct bgpd_addr prefix; struct in_addr id; struct ibuf asbuf, *path = NULL; char *aspath; uint32_t as, pathid, val; uint16_t alen, afi, short_as; uint8_t flags, type, safi, aid, prefixlen, origin; int e4, e2; json_do_array("attributes"); json_do_object("attribute", 0); if (ibuf_get_n8(buf, &flags) == -1 || ibuf_get_n8(buf, &type) == -1) goto bad_len; json_do_string("type", fmt_attr(type, -1)); json_do_object("flags", 1); json_do_bool("partial", flags & ATTR_PARTIAL); json_do_bool("transitive", flags & ATTR_TRANSITIVE); json_do_bool("optional", flags & ATTR_OPTIONAL); json_do_end(); if (flags & ATTR_EXTLEN) { uint16_t attr_len; if (ibuf_get_n16(buf, &attr_len) == -1) goto bad_len; alen = attr_len; } else { uint8_t attr_len; if (ibuf_get_n8(buf, &attr_len) == -1) goto bad_len; alen = attr_len; } json_do_uint("length", alen); /* bad imsg len how can that happen!? */ if (alen > ibuf_size(buf)) goto bad_len; switch (type) { case ATTR_ORIGIN: if (alen != 1 || ibuf_get_n8(buf, &origin) == -1) goto bad_len; json_do_string("origin", fmt_origin(origin, 0)); break; case ATTR_ASPATH: case ATTR_AS4_PATH: /* prefer 4-byte AS here */ e4 = aspath_verify(buf, 1, 0); e2 = aspath_verify(buf, 0, 0); if (e4 == 0 || e4 == AS_ERR_SOFT) { ibuf_from_ibuf(&asbuf, buf); } else if (e2 == 0 || e2 == AS_ERR_SOFT) { if ((path = aspath_inflate(buf)) == NULL) { json_do_string("error", "aspath_inflate failed"); break; } ibuf_from_ibuf(&asbuf, path); } else { json_do_string("error", "bad AS-Path"); break; } if (aspath_asprint(&aspath, &asbuf) == -1) err(1, NULL); json_do_string("aspath", aspath); free(aspath); ibuf_free(path); break; case ATTR_NEXTHOP: if (alen != 4 || ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; json_do_string("nexthop", inet_ntoa(id)); break; case ATTR_MED: case ATTR_LOCALPREF: if (alen != 4 || ibuf_get_n32(buf, &val) == -1) goto bad_len; json_do_uint("metric", val); break; case ATTR_AGGREGATOR: case ATTR_AS4_AGGREGATOR: if (alen == 8) { if (ibuf_get_n32(buf, &as) == -1 || ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; } else if (alen == 6) { if (ibuf_get_n16(buf, &short_as) == -1 || ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; as = short_as; } else { goto bad_len; } json_do_uint("AS", as); json_do_string("router_id", inet_ntoa(id)); break; case ATTR_COMMUNITIES: json_do_community(buf); break; case ATTR_ORIGINATOR_ID: if (alen != 4 || ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; json_do_string("originator", inet_ntoa(id)); break; case ATTR_CLUSTER_LIST: json_do_array("cluster_list"); while (ibuf_size(buf) > 0) { if (ibuf_get(buf, &id, sizeof(id)) == -1) goto bad_len; json_do_string("cluster_id", inet_ntoa(id)); } json_do_end(); break; case ATTR_MP_REACH_NLRI: case ATTR_MP_UNREACH_NLRI: if (ibuf_get_n16(buf, &afi) == -1 || ibuf_get_n8(buf, &safi) == -1) goto bad_len; if (afi2aid(afi, safi, &aid) == -1) { json_do_printf("error", "bad AFI/SAFI pair: %d/%d", afi, safi); break; } json_do_string("family", aid2str(aid)); if (type == ATTR_MP_REACH_NLRI) { struct bgpd_addr nexthop; uint8_t nhlen; if (ibuf_get_n8(buf, &nhlen) == -1) goto bad_len; memset(&nexthop, 0, sizeof(nexthop)); switch (aid) { case AID_INET6: nexthop.aid = aid; if (nhlen != 16 && nhlen != 32) goto bad_len; if (ibuf_get(buf, &nexthop.v6, sizeof(nexthop.v6)) == -1) goto bad_len; break; case AID_VPN_IPv4: if (nhlen != 12) goto bad_len; nexthop.aid = AID_INET; if (ibuf_skip(buf, sizeof(uint64_t)) == -1 || ibuf_get(buf, &nexthop.v4, sizeof(nexthop.v4)) == -1) goto bad_len; break; case AID_VPN_IPv6: if (nhlen != 24) goto bad_len; nexthop.aid = AID_INET6; if (ibuf_skip(buf, sizeof(uint64_t)) == -1 || ibuf_get(buf, &nexthop.v6, sizeof(nexthop.v6)) == -1) goto bad_len; break; default: json_do_printf("error", "unhandled AID: %d", aid); return; } /* ignore reserved (old SNPA) field as per RFC4760 */ if (ibuf_skip(buf, 1) == -1) goto bad_len; json_do_string("nexthop", log_addr(&nexthop)); } json_do_array("NLRI"); while (ibuf_size(buf) > 0) { json_do_object("prefix", 1); if (addpath) if (ibuf_get_n32(buf, &pathid) == -1) goto bad_len; switch (aid) { case AID_INET6: if (nlri_get_prefix6(buf, &prefix, &prefixlen) == -1) goto bad_len; break; case AID_VPN_IPv4: if (nlri_get_vpn4(buf, &prefix, &prefixlen, 1) == -1) goto bad_len; break; case AID_VPN_IPv6: if (nlri_get_vpn6(buf, &prefix, &prefixlen, 1) == -1) goto bad_len; break; default: json_do_printf("error", "unhandled AID: %d", aid); return; } json_do_printf("prefix", "%s/%u", log_addr(&prefix), prefixlen); if (addpath) json_do_uint("path_id", pathid); json_do_end(); } json_do_end(); break; case ATTR_EXT_COMMUNITIES: json_do_ext_community(buf); break; case ATTR_LARGE_COMMUNITIES: json_do_large_community(buf); break; case ATTR_OTC: if (alen != 4 || ibuf_get_n32(buf, &as) == -1) goto bad_len; json_do_uint("as", as); break; case ATTR_ATOMIC_AGGREGATE: default: if (alen) json_do_hexdump("data", ibuf_data(buf), ibuf_size(buf)); break; } return; bad_len: json_do_string("error", "bad length"); } static void json_rib(struct ctl_show_rib *r, struct ibuf *asbuf, struct parse_result *res) { struct in_addr id; char *aspath; json_do_array("rib"); json_do_object("rib_entry", 0); json_do_printf("prefix", "%s/%u", log_addr(&r->prefix), r->prefixlen); if (aspath_asprint(&aspath, asbuf) == -1) err(1, NULL); json_do_string("aspath", aspath); free(aspath); json_do_string("exit_nexthop", log_addr(&r->exit_nexthop)); json_do_string("true_nexthop", log_addr(&r->true_nexthop)); json_do_object("neighbor", 1); if (r->descr[0]) json_do_string("description", r->descr); json_do_string("remote_addr", log_addr(&r->remote_addr)); id.s_addr = htonl(r->remote_id); json_do_string("bgp_id", inet_ntoa(id)); json_do_end(); if (r->flags & F_PREF_PATH_ID) json_do_uint("path_id", r->path_id); /* flags */ json_do_bool("valid", r->flags & F_PREF_ELIGIBLE); if (r->flags & F_PREF_FILTERED) json_do_bool("filtered", 1); if (r->flags & F_PREF_BEST) json_do_bool("best", 1); if (r->flags & F_PREF_ECMP) json_do_bool("ecmp", 1); if (r->flags & F_PREF_AS_WIDE) json_do_bool("as-wide", 1); if (r->flags & F_PREF_INTERNAL) json_do_string("source", "internal"); else json_do_string("source", "external"); if (r->flags & F_PREF_STALE) json_do_bool("stale", 1); if (r->flags & F_PREF_ANNOUNCE) json_do_bool("announced", 1); /* various attribibutes */ json_do_string("ovs", fmt_ovs(r->roa_validation_state, 0)); json_do_string("avs", fmt_avs(r->aspa_validation_state, 0)); json_do_string("origin", fmt_origin(r->origin, 0)); json_do_uint("metric", r->med); json_do_uint("localpref", r->local_pref); json_do_uint("weight", r->weight); json_do_int("dmetric", r->dmetric); json_do_string("last_update", fmt_timeframe(r->age)); json_do_int("last_update_sec", r->age); /* keep the object open for communities and attributes */ } static void json_rib_mem_element(const char *name, uint64_t count, uint64_t size, uint64_t refs) { json_do_object(name, 1); if (count != UINT64_MAX) json_do_uint("count", count); if (size != UINT64_MAX) json_do_uint("size", size); if (refs != UINT64_MAX) json_do_uint("references", refs); json_do_end(); } static void json_rib_mem(struct rde_memstats *stats) { size_t pts = 0; int i; json_do_object("memory", 0); for (i = 0; i < AID_MAX; i++) { if (stats->pt_cnt[i] == 0) continue; pts += stats->pt_size[i]; json_rib_mem_element(aid_vals[i].name, stats->pt_cnt[i], stats->pt_size[i], UINT64_MAX); } json_rib_mem_element("rib", stats->rib_cnt, stats->rib_cnt * sizeof(struct rib_entry), UINT64_MAX); json_rib_mem_element("prefix", stats->prefix_cnt, stats->prefix_cnt * sizeof(struct prefix), UINT64_MAX); json_rib_mem_element("rde_aspath", stats->path_cnt, stats->path_cnt * sizeof(struct rde_aspath), stats->path_refs); json_rib_mem_element("aspath", stats->aspath_cnt, stats->aspath_size, UINT64_MAX); json_rib_mem_element("community_entries", stats->comm_cnt, stats->comm_cnt * sizeof(struct rde_community), UINT64_MAX); json_rib_mem_element("community", stats->comm_nmemb, stats->comm_size * sizeof(struct community), stats->comm_refs); json_rib_mem_element("attributes_entries", stats->attr_cnt, stats->attr_cnt * sizeof(struct attr), stats->attr_refs); json_rib_mem_element("attributes", stats->attr_dcnt, stats->attr_data, UINT64_MAX); json_rib_mem_element("total", UINT64_MAX, pts + stats->prefix_cnt * sizeof(struct prefix) + stats->rib_cnt * sizeof(struct rib_entry) + stats->path_cnt * sizeof(struct rde_aspath) + stats->aspath_size + stats->attr_cnt * sizeof(struct attr) + stats->attr_data, UINT64_MAX); json_do_end(); json_do_object("sets", 0); json_rib_mem_element("as_set", stats->aset_nmemb, stats->aset_size, UINT64_MAX); json_rib_mem_element("as_set_tables", stats->aset_cnt, UINT64_MAX, UINT64_MAX); json_rib_mem_element("prefix_set", stats->pset_cnt, stats->pset_size, UINT64_MAX); json_rib_mem_element("total", UINT64_MAX, stats->aset_size + stats->pset_size, UINT64_MAX); json_do_end(); } static void json_rib_set(struct ctl_show_set *set) { json_do_array("sets"); json_do_object("set", 0); json_do_string("name", set->name); json_do_string("type", fmt_set_type(set)); json_do_string("last_change", fmt_monotime(set->lastchange)); json_do_int("last_change_sec", get_monotime(set->lastchange)); if (set->type == ASNUM_SET || set->type == ASPA_SET) { json_do_uint("num_ASnum", set->as_cnt); } else { json_do_uint("num_IPv4", set->v4_cnt); json_do_uint("num_IPv6", set->v6_cnt); } json_do_end(); } static void json_rtr(struct ctl_show_rtr *rtr) { json_do_array("rtrs"); json_do_object("rtr", 0); if (rtr->descr[0]) json_do_string("descr", rtr->descr); json_do_string("remote_addr", log_addr(&rtr->remote_addr)); json_do_uint("remote_port", rtr->remote_port); if (rtr->local_addr.aid != AID_UNSPEC) json_do_string("local_addr", log_addr(&rtr->local_addr)); json_do_string("state", rtr->state); if (rtr->session_id != -1) { json_do_uint("version", rtr->version); json_do_uint("minimal_version", rtr->min_version); json_do_uint("session_id", rtr->session_id); json_do_uint("serial", rtr->serial); } json_do_uint("refresh", rtr->refresh); json_do_uint("retry", rtr->retry); json_do_uint("expire", rtr->expire); if (rtr->last_sent_error != NO_ERROR) { json_do_string("last_sent_error", log_rtr_error(rtr->last_sent_error)); if (rtr->last_sent_msg[0]) json_do_string("last_sent_msg", log_reason(rtr->last_sent_msg)); } if (rtr->last_recv_error != NO_ERROR) { json_do_string("last_recv_error", log_rtr_error(rtr->last_recv_error)); if (rtr->last_recv_msg[0]) json_do_string("last_recv_msg", log_reason(rtr->last_recv_msg)); } } static void json_result(u_int rescode) { if (rescode == 0) json_do_string("status", "OK"); else if (rescode >= sizeof(ctl_res_strerror)/sizeof(ctl_res_strerror[0])) { json_do_string("status", "FAILED"); json_do_printf("error", "unknown error %d", rescode); } else { json_do_string("status", "FAILED"); json_do_string("error", ctl_res_strerror[rescode]); } } static void json_tail(void) { json_do_finish(); } const struct output json_output = { .head = json_head, .neighbor = json_neighbor, .timer = json_timer, .fib = json_fib, .fib_table = json_fib_table, .nexthop = json_nexthop, .interface = json_interface, .communities = json_communities, .attr = json_attr, .rib = json_rib, .rib_mem = json_rib_mem, .set = json_rib_set, .rtr = json_rtr, .result = json_result, .tail = json_tail, }; openbgpd-8.8/src/bgpctl/output_ometric.c100644 001750 001750 00000030676 14556177656 0014223/* $OpenBSD: output_ometric.c,v 1.13 2024/01/23 15:55:20 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include "bgpd.h" #include "session.h" #include "rde.h" #include "version.h" #include "bgpctl.h" #include "parser.h" #include "ometric.h" struct ometric *bgpd_info, *bgpd_scrape_time; struct ometric *peer_info, *peer_state, *peer_state_raw, *peer_last_change, *peer_last_read, *peer_last_write; struct ometric *peer_prefixes_transmit, *peer_prefixes_receive; struct ometric *peer_message_transmit, *peer_message_receive; struct ometric *peer_update_transmit, *peer_update_pending, *peer_update_receive; struct ometric *peer_withdraw_transmit, *peer_withdraw_pending, *peer_withdraw_receive; struct ometric *peer_rr_req_transmit, *peer_rr_req_receive; struct ometric *peer_rr_borr_transmit, *peer_rr_borr_receive; struct ometric *peer_rr_eorr_transmit, *peer_rr_eorr_receive; struct ometric *rde_mem_size, *rde_mem_count, *rde_mem_ref_count; struct ometric *rde_set_size, *rde_set_count, *rde_table_count; struct timespec start_time, end_time; static void ometric_head(struct parse_result *arg) { struct olabels *ol = NULL; const char *keys[4] = { "nodename", "domainname", "release", NULL }; const char *values[4]; char hostname[HOST_NAME_MAX + 1]; char *domainname; clock_gettime(CLOCK_MONOTONIC, &start_time); bgpd_info = ometric_new(OMT_INFO, "bgpd", "bgpd information"); bgpd_scrape_time = ometric_new(OMT_GAUGE, "bgpd_scrape_seconds", "bgpd scrape time in seconds"); if (gethostname(hostname, sizeof(hostname))) err(1, "gethostname"); if ((domainname = strchr(hostname, '.'))) *domainname++ = '\0'; values[0] = hostname; values[1] = domainname; values[2] = BGPD_VERSION; values[3] = NULL; ol = olabels_new(keys, values); ometric_set_info(bgpd_info, NULL, NULL, ol); olabels_free(ol); /* * per neighbor stats: attrs will be remote_as, remote_addr, * description and group */ peer_info = ometric_new(OMT_INFO, "bgpd_peer", "peer information"); peer_state = ometric_new_state(statenames, sizeof(statenames) / sizeof(statenames[0]), "bgpd_peer_state", "peer session state"); peer_state_raw = ometric_new(OMT_GAUGE, "bgpd_peer_state_raw", "peer session state raw int value"); peer_last_change = ometric_new(OMT_GAUGE, "bgpd_peer_last_change_seconds", "time in seconds since peer's last up/down state change"); peer_last_read = ometric_new(OMT_GAUGE, "bgpd_peer_last_read_seconds", "peer time since last read in seconds"); peer_last_write = ometric_new(OMT_GAUGE, "bgpd_peer_last_write_seconds", "peer time since last write in seconds"); peer_prefixes_transmit = ometric_new(OMT_GAUGE, "bgpd_peer_prefixes_transmit", "number of prefixes sent to peer"); peer_prefixes_receive = ometric_new(OMT_GAUGE, "bgpd_peer_prefixes_receive", "number of prefixes received from peer"); peer_message_transmit = ometric_new(OMT_COUNTER, "bgpd_peer_message_transmit", "per message type count of transmitted messages"); peer_message_receive = ometric_new(OMT_COUNTER, "bgpd_peer_message_receive", "per message type count of received messages"); peer_update_transmit = ometric_new(OMT_COUNTER, "bgpd_peer_update_transmit", "number of prefixes sent as update"); peer_update_pending = ometric_new(OMT_COUNTER, "bgpd_peer_update_pending", "number of pending update prefixes"); peer_update_receive = ometric_new(OMT_COUNTER, "bgpd_peer_update_receive", "number of prefixes received as update"); peer_withdraw_transmit = ometric_new(OMT_COUNTER, "bgpd_peer_withdraw_transmit", "number of withdrawn prefixes sent to peer"); peer_withdraw_pending = ometric_new(OMT_COUNTER, "bgpd_peer_withdraw_pending", "number of pending withdrawn prefixes"); peer_withdraw_receive = ometric_new(OMT_COUNTER, "bgpd_peer_withdraw_receive", "number of withdrawn prefixes received from peer"); peer_rr_req_transmit = ometric_new(OMT_COUNTER, "bgpd_peer_route_refresh_req_transmit", "number of route-refresh request transmitted to peer"); peer_rr_req_receive = ometric_new(OMT_COUNTER, "bgpd_peer_route_refresh_req_receive", "number of route-refresh request received from peer"); peer_rr_borr_transmit = ometric_new(OMT_COUNTER, "bgpd_peer_route_refresh_borr_transmit", "number of ext. route-refresh BORR messages transmitted to peer"); peer_rr_borr_receive = ometric_new(OMT_COUNTER, "bgpd_peer_route_refresh_borr_receive", "number of ext. route-refresh BORR messages received from peer"); peer_rr_eorr_transmit = ometric_new(OMT_COUNTER, "bgpd_peer_route_refresh_eorr_transmit", "number of ext. route-refresh EORR messages transmitted to peer"); peer_rr_eorr_receive = ometric_new(OMT_COUNTER, "bgpd_peer_route_refresh_eorr_receive", "number of ext. route-refresh EORR messages received from peer"); /* RDE memory statistics */ rde_mem_size = ometric_new(OMT_GAUGE, "bgpd_rde_memory_usage_bytes", "memory usage in bytes"); rde_mem_count = ometric_new(OMT_GAUGE, "bgpd_rde_memory_usage_objects", "number of object in use"); rde_mem_ref_count = ometric_new(OMT_GAUGE, "bgpd_rde_memory_usage_references", "number of references held"); rde_set_size = ometric_new(OMT_GAUGE, "bgpd_rde_set_usage_bytes", "memory usage of set in bytes"); rde_set_count = ometric_new(OMT_GAUGE, "bgpd_rde_set_usage_objects", "number of object in set"); rde_table_count = ometric_new(OMT_GAUGE, "bgpd_rde_set_usage_tables", "number of as_set tables"); } static void ometric_neighbor_stats(struct peer *p, struct parse_result *arg) { struct olabels *ol = NULL; const char *keys[5] = { "remote_addr", "remote_as", "description", "group", NULL }; const char *values[5]; /* skip neighbor templates */ if (p->conf.template) return; values[0] = log_addr(&p->conf.remote_addr); values[1] = log_as(p->conf.remote_as); values[2] = p->conf.descr; values[3] = p->conf.group; values[4] = NULL; ol = olabels_new(keys, values); ometric_set_info(peer_info, NULL, NULL, ol); ometric_set_state(peer_state, statenames[p->state], ol); ometric_set_int(peer_state_raw, p->state, ol); ometric_set_int(peer_last_change, get_monotime(p->stats.last_updown), ol); if (p->state == STATE_ESTABLISHED) { ometric_set_int(peer_last_read, get_monotime(p->stats.last_read), ol); ometric_set_int(peer_last_write, get_monotime(p->stats.last_write), ol); } ometric_set_int(peer_prefixes_transmit, p->stats.prefix_out_cnt, ol); ometric_set_int(peer_prefixes_receive, p->stats.prefix_cnt, ol); ometric_set_int_with_labels(peer_message_transmit, p->stats.msg_sent_open, OKV("messages"), OKV("open"), ol); ometric_set_int_with_labels(peer_message_transmit, p->stats.msg_sent_notification, OKV("messages"), OKV("notification"), ol); ometric_set_int_with_labels(peer_message_transmit, p->stats.msg_sent_update, OKV("messages"), OKV("update"), ol); ometric_set_int_with_labels(peer_message_transmit, p->stats.msg_sent_keepalive, OKV("messages"), OKV("keepalive"), ol); ometric_set_int_with_labels(peer_message_transmit, p->stats.msg_sent_rrefresh, OKV("messages"), OKV("route_refresh"), ol); ometric_set_int_with_labels(peer_message_receive, p->stats.msg_rcvd_open, OKV("messages"), OKV("open"), ol); ometric_set_int_with_labels(peer_message_receive, p->stats.msg_rcvd_notification, OKV("messages"), OKV("notification"), ol); ometric_set_int_with_labels(peer_message_receive, p->stats.msg_rcvd_update, OKV("messages"), OKV("update"), ol); ometric_set_int_with_labels(peer_message_receive, p->stats.msg_rcvd_keepalive, OKV("messages"), OKV("keepalive"), ol); ometric_set_int_with_labels(peer_message_receive, p->stats.msg_rcvd_rrefresh, OKV("messages"), OKV("route_refresh"), ol); ometric_set_int(peer_update_transmit, p->stats.prefix_sent_update, ol); ometric_set_int(peer_update_pending, p->stats.pending_update, ol); ometric_set_int(peer_update_receive, p->stats.prefix_rcvd_update, ol); ometric_set_int(peer_withdraw_transmit, p->stats.prefix_sent_withdraw, ol); ometric_set_int(peer_withdraw_pending, p->stats.pending_withdraw, ol); ometric_set_int(peer_withdraw_receive, p->stats.prefix_rcvd_withdraw, ol); ometric_set_int(peer_rr_req_transmit, p->stats.refresh_sent_req, ol); ometric_set_int(peer_rr_req_receive, p->stats.refresh_rcvd_req, ol); ometric_set_int(peer_rr_borr_transmit, p->stats.refresh_sent_borr, ol); ometric_set_int(peer_rr_borr_receive, p->stats.refresh_rcvd_borr, ol); ometric_set_int(peer_rr_eorr_transmit, p->stats.refresh_sent_eorr, ol); ometric_set_int(peer_rr_eorr_receive, p->stats.refresh_rcvd_eorr, ol); olabels_free(ol); } static void ometric_rib_mem_element(const char *v, uint64_t count, uint64_t size, uint64_t refs) { if (count != UINT64_MAX) ometric_set_int_with_labels(rde_mem_count, count, OKV("type"), OKV(v), NULL); if (size != UINT64_MAX) ometric_set_int_with_labels(rde_mem_size, size, OKV("type"), OKV(v), NULL); if (refs != UINT64_MAX) ometric_set_int_with_labels(rde_mem_ref_count, refs, OKV("type"), OKV(v), NULL); } static void ometric_rib_mem(struct rde_memstats *stats) { size_t pts = 0; int i; for (i = 0; i < AID_MAX; i++) { if (stats->pt_cnt[i] == 0) continue; pts += stats->pt_size[i]; ometric_rib_mem_element(aid_vals[i].name, stats->pt_cnt[i], stats->pt_size[i], UINT64_MAX); } ometric_rib_mem_element("rib", stats->rib_cnt, stats->rib_cnt * sizeof(struct rib_entry), UINT64_MAX); ometric_rib_mem_element("prefix", stats->prefix_cnt, stats->prefix_cnt * sizeof(struct prefix), UINT64_MAX); ometric_rib_mem_element("rde_aspath", stats->path_cnt, stats->path_cnt * sizeof(struct rde_aspath), stats->path_refs); ometric_rib_mem_element("aspath", stats->aspath_cnt, stats->aspath_size, UINT64_MAX); ometric_rib_mem_element("community_entries", stats->comm_cnt, stats->comm_cnt * sizeof(struct rde_community), UINT64_MAX); ometric_rib_mem_element("community", stats->comm_nmemb, stats->comm_size * sizeof(struct community), stats->comm_refs); ometric_rib_mem_element("attributes_entries", stats->attr_cnt, stats->attr_cnt * sizeof(struct attr), stats->attr_refs); ometric_rib_mem_element("attributes", stats->attr_dcnt, stats->attr_data, UINT64_MAX); ometric_rib_mem_element("total", UINT64_MAX, pts + stats->prefix_cnt * sizeof(struct prefix) + stats->rib_cnt * sizeof(struct rib_entry) + stats->path_cnt * sizeof(struct rde_aspath) + stats->aspath_size + stats->attr_cnt * sizeof(struct attr) + stats->attr_data, UINT64_MAX); ometric_set_int(rde_table_count, stats->aset_cnt, NULL); ometric_set_int_with_labels(rde_set_size, stats->aset_size, OKV("type"), OKV("as_set"), NULL); ometric_set_int_with_labels(rde_set_count, stats->aset_nmemb, OKV("type"), OKV("as_set"), NULL); ometric_set_int_with_labels(rde_set_size, stats->pset_size, OKV("type"), OKV("prefix_set"), NULL); ometric_set_int_with_labels(rde_set_count, stats->pset_cnt, OKV("type"), OKV("prefix_set"), NULL); ometric_rib_mem_element("set_total", UINT64_MAX, stats->aset_size + stats->pset_size, UINT64_MAX); } static void ometric_tail(void) { struct timespec elapsed_time; clock_gettime(CLOCK_MONOTONIC, &end_time); timespecsub(&end_time, &start_time, &elapsed_time); ometric_set_timespec(bgpd_scrape_time, &elapsed_time, NULL); ometric_output_all(stdout); ometric_free_all(); } const struct output ometric_output = { .head = ometric_head, .neighbor = ometric_neighbor_stats, .rib_mem = ometric_rib_mem, .tail = ometric_tail, }; openbgpd-8.8/src/bgpctl/parser.c100644 001750 001750 00000117157 14673014240 0012410/* $OpenBSD: parser.c,v 1.137 2024/08/22 08:17:54 florian Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer * Copyright (c) 2016 Job Snijders * Copyright (c) 2016 Peter Hessler * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include "parser.h" enum token_type { ENDTOKEN, NOTOKEN, ANYTOKEN, KEYWORD, ADDRESS, PEERADDRESS, FLAG, ASNUM, ASTYPE, PREFIX, PEERDESC, GROUPDESC, RIBNAME, COMMUNICATION, COMMUNITY, EXTCOMMUNITY, LRGCOMMUNITY, LOCALPREF, MED, NEXTHOP, PFTABLE, PREPNBR, PREPSELF, WEIGHT, RD, FAMILY, RTABLE, FILENAME, PATHID, FLOW_PROTO, FLOW_SRC, FLOW_DST, FLOW_SRCPORT, FLOW_DSTPORT, FLOW_ICMPTYPE, FLOW_ICMPCODE, FLOW_LENGTH, FLOW_DSCP, FLOW_FLAGS, FLOW_FRAGS, }; struct token { enum token_type type; const char *keyword; int value; const struct token *next; }; static const struct token *prevtable; static const struct token t_main[]; static const struct token t_show[]; static const struct token t_show_summary[]; static const struct token t_show_fib[]; static const struct token t_show_rib[]; static const struct token t_show_avs[]; static const struct token t_show_ovs[]; static const struct token t_show_mrt[]; static const struct token t_show_mrt_file[]; static const struct token t_show_rib_neigh[]; static const struct token t_show_mrt_neigh[]; static const struct token t_show_rib_rib[]; static const struct token t_show_neighbor[]; static const struct token t_show_neighbor_modifiers[]; static const struct token t_fib[]; static const struct token t_neighbor[]; static const struct token t_neighbor_modifiers[]; static const struct token t_show_rib_as[]; static const struct token t_show_mrt_as[]; static const struct token t_show_prefix[]; static const struct token t_show_ip[]; static const struct token t_network[]; static const struct token t_flowspec[]; static const struct token t_flowfamily[]; static const struct token t_flowrule[]; static const struct token t_flowsrc[]; static const struct token t_flowdst[]; static const struct token t_flowsrcport[]; static const struct token t_flowdstport[]; static const struct token t_flowicmp[]; static const struct token t_bulk[]; static const struct token t_network_show[]; static const struct token t_prefix[]; static const struct token t_set[]; static const struct token t_nexthop[]; static const struct token t_pftable[]; static const struct token t_log[]; static const struct token t_communication[]; static const struct token t_main[] = { { KEYWORD, "fib", FIB, t_fib}, { KEYWORD, "flowspec", NONE, t_flowspec}, { KEYWORD, "log", NONE, t_log}, { KEYWORD, "neighbor", NEIGHBOR, t_neighbor}, { KEYWORD, "network", NONE, t_network}, { KEYWORD, "reload", RELOAD, t_communication}, { KEYWORD, "show", SHOW, t_show}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show[] = { { NOTOKEN, "", NONE, NULL}, { KEYWORD, "fib", SHOW_FIB, t_show_fib}, { KEYWORD, "flowspec", FLOWSPEC_SHOW, t_network_show}, { KEYWORD, "interfaces", SHOW_INTERFACE, NULL}, { KEYWORD, "ip", NONE, t_show_ip}, { KEYWORD, "metrics", SHOW_METRICS, NULL}, { KEYWORD, "mrt", SHOW_MRT, t_show_mrt}, { KEYWORD, "neighbor", SHOW_NEIGHBOR, t_show_neighbor}, { KEYWORD, "network", NETWORK_SHOW, t_network_show}, { KEYWORD, "nexthop", SHOW_NEXTHOP, NULL}, { KEYWORD, "rib", SHOW_RIB, t_show_rib}, { KEYWORD, "rtr", SHOW_RTR, NULL}, { KEYWORD, "sets", SHOW_SET, NULL}, { KEYWORD, "summary", SHOW_SUMMARY, t_show_summary}, { KEYWORD, "tables", SHOW_FIB_TABLES, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_summary[] = { { NOTOKEN, "", NONE, NULL}, { KEYWORD, "terse", SHOW_SUMMARY_TERSE, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_fib[] = { { NOTOKEN, "", NONE, NULL}, { FLAG, "bgp", F_BGPD, t_show_fib}, { FLAG, "connected", F_CONNECTED, t_show_fib}, { FLAG, "nexthop", F_NEXTHOP, t_show_fib}, { FLAG, "static", F_STATIC, t_show_fib}, { RTABLE, "table", NONE, t_show_fib}, { FAMILY, "", NONE, t_show_fib}, { ADDRESS, "", NONE, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_rib[] = { { NOTOKEN, "", NONE, NULL}, { ASTYPE, "as", AS_ALL, t_show_rib_as}, { KEYWORD, "avs", NONE, t_show_avs}, { FLAG, "best", F_CTL_BEST, t_show_rib}, { COMMUNITY, "community", NONE, t_show_rib}, { FLAG, "detail", F_CTL_DETAIL, t_show_rib}, { FLAG, "disqualified", F_CTL_INELIGIBLE, t_show_rib}, { ASTYPE, "empty-as", AS_EMPTY, t_show_rib}, { FLAG, "error", F_CTL_INVALID, t_show_rib}, { EXTCOMMUNITY, "ext-community", NONE, t_show_rib}, { FLAG, "filtered", F_CTL_FILTERED, t_show_rib}, { FLAG, "in", F_CTL_ADJ_IN, t_show_rib}, { LRGCOMMUNITY, "large-community", NONE, t_show_rib}, { FLAG, "leaked", F_CTL_LEAKED, t_show_rib}, { KEYWORD, "memory", SHOW_RIB_MEM, NULL}, { KEYWORD, "neighbor", NONE, t_show_rib_neigh}, { FLAG, "out", F_CTL_ADJ_OUT, t_show_rib}, { KEYWORD, "ovs", NONE, t_show_ovs}, { PATHID, "path-id", NONE, t_show_rib}, { ASTYPE, "peer-as", AS_PEER, t_show_rib_as}, { FLAG, "selected", F_CTL_BEST, t_show_rib}, { ASTYPE, "source-as", AS_SOURCE, t_show_rib_as}, { FLAG, "ssv", F_CTL_SSV, t_show_rib}, { KEYWORD, "summary", SHOW_SUMMARY, t_show_summary}, { KEYWORD, "table", NONE, t_show_rib_rib}, { ASTYPE, "transit-as", AS_TRANSIT, t_show_rib_as}, { FAMILY, "", NONE, t_show_rib}, { PREFIX, "", NONE, t_show_prefix}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_avs[] = { { FLAG, "invalid", F_CTL_AVS_INVALID, t_show_rib}, { FLAG, "unknown", F_CTL_AVS_UNKNOWN, t_show_rib}, { FLAG, "valid" , F_CTL_AVS_VALID, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_ovs[] = { { FLAG, "invalid", F_CTL_OVS_INVALID, t_show_rib}, { FLAG, "not-found", F_CTL_OVS_NOTFOUND, t_show_rib}, { FLAG, "valid" , F_CTL_OVS_VALID, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_mrt[] = { { NOTOKEN, "", NONE, NULL}, { ASTYPE, "as", AS_ALL, t_show_mrt_as}, { FLAG, "detail", F_CTL_DETAIL, t_show_mrt}, { ASTYPE, "empty-as", AS_EMPTY, t_show_mrt}, { KEYWORD, "file", NONE, t_show_mrt_file}, { KEYWORD, "neighbor", NONE, t_show_mrt_neigh}, { ASTYPE, "peer-as", AS_PEER, t_show_mrt_as}, { FLAG, "peers", F_CTL_NEIGHBORS,t_show_mrt}, { ASTYPE, "source-as", AS_SOURCE, t_show_mrt_as}, { FLAG, "ssv", F_CTL_SSV, t_show_mrt}, { ASTYPE, "transit-as", AS_TRANSIT, t_show_mrt_as}, { FAMILY, "", NONE, t_show_mrt}, { PREFIX, "", NONE, t_show_prefix}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_mrt_file[] = { { FILENAME, "", NONE, t_show_mrt}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_rib_neigh_group[] = { { GROUPDESC, "", NONE, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_rib_neigh[] = { { KEYWORD, "group", NONE, t_show_rib_neigh_group}, { PEERADDRESS, "", NONE, t_show_rib}, { PEERDESC, "", NONE, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_mrt_neigh[] = { { PEERADDRESS, "", NONE, t_show_mrt}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_rib_rib[] = { { RIBNAME, "", NONE, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_neighbor_modifiers[] = { { NOTOKEN, "", NONE, NULL}, { KEYWORD, "messages", SHOW_NEIGHBOR, NULL}, { KEYWORD, "terse", SHOW_NEIGHBOR_TERSE, NULL}, { KEYWORD, "timers", SHOW_NEIGHBOR_TIMERS, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_neighbor_group[] = { { GROUPDESC, "", NONE, t_show_neighbor_modifiers}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_neighbor[] = { { NOTOKEN, "", NONE, NULL}, { KEYWORD, "group", NONE, t_show_neighbor_group}, { PEERADDRESS, "", NONE, t_show_neighbor_modifiers}, { PEERDESC, "", NONE, t_show_neighbor_modifiers}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_fib[] = { { KEYWORD, "couple", FIB_COUPLE, NULL}, { KEYWORD, "decouple", FIB_DECOUPLE, NULL}, { RTABLE, "table", NONE, t_fib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_neighbor_group[] = { { GROUPDESC, "", NONE, t_neighbor_modifiers}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_neighbor[] = { { KEYWORD, "group", NONE, t_neighbor_group}, { PEERADDRESS, "", NONE, t_neighbor_modifiers}, { PEERDESC, "", NONE, t_neighbor_modifiers}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_communication[] = { { NOTOKEN, "", NONE, NULL}, { COMMUNICATION, "", NONE, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_neighbor_modifiers[] = { { KEYWORD, "clear", NEIGHBOR_CLEAR, t_communication}, { KEYWORD, "destroy", NEIGHBOR_DESTROY, NULL}, { KEYWORD, "down", NEIGHBOR_DOWN, t_communication}, { KEYWORD, "refresh", NEIGHBOR_RREFRESH, NULL}, { KEYWORD, "up", NEIGHBOR_UP, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_rib_as[] = { { ASNUM, "", NONE, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_mrt_as[] = { { ASNUM, "", NONE, t_show_mrt}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_prefix[] = { { FLAG, "all", F_LONGER, t_show_rib}, { FLAG, "longer-prefixes", F_LONGER, t_show_rib}, { FLAG, "or-longer", F_LONGER, t_show_rib}, { FLAG, "or-shorter", F_SHORTER, t_show_rib}, { ANYTOKEN, "", NONE, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_show_ip[] = { { KEYWORD, "bgp", SHOW_RIB, t_show_rib}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_network[] = { { KEYWORD, "add", NETWORK_ADD, t_prefix}, { KEYWORD, "bulk", NONE, t_bulk}, { KEYWORD, "delete", NETWORK_REMOVE, t_prefix}, { KEYWORD, "flush", NETWORK_FLUSH, NULL}, { KEYWORD, "mrt", NETWORK_MRT, t_show_mrt}, { KEYWORD, "show", NETWORK_SHOW, t_network_show}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowspec[] = { { KEYWORD, "add", FLOWSPEC_ADD, t_flowfamily}, { KEYWORD, "delete", FLOWSPEC_REMOVE,t_flowfamily}, { KEYWORD, "flush", FLOWSPEC_FLUSH, NULL}, { KEYWORD, "show", FLOWSPEC_SHOW, t_network_show}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowfamily[] = { { FAMILY, "", NONE, t_flowrule}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowrule[] = { { NOTOKEN, "", NONE, NULL}, { FLOW_FLAGS, "flags", NONE, t_flowrule}, { FLOW_FRAGS, "fragment", NONE, t_flowrule}, { KEYWORD, "from", NONE, t_flowsrc}, { FLOW_ICMPTYPE,"icmp-type", NONE, t_flowicmp}, { FLOW_LENGTH, "length", NONE, t_flowrule}, { FLOW_PROTO, "proto", NONE, t_flowrule}, { KEYWORD, "set", NONE, t_set}, { KEYWORD, "to", NONE, t_flowdst}, { FLOW_DSCP, "dscp", NONE, t_flowrule}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowsrc[] = { { KEYWORD, "any", NONE, t_flowsrcport}, { FLOW_SRC, "", NONE, t_flowsrcport}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowdst[] = { { KEYWORD, "any", NONE, t_flowdstport}, { FLOW_DST, "", NONE, t_flowdstport}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowsrcport[] = { { FLOW_SRCPORT, "port", NONE, t_flowrule}, { ANYTOKEN, "", NONE, t_flowrule}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowdstport[] = { { FLOW_DSTPORT, "port", NONE, t_flowrule}, { ANYTOKEN, "", NONE, t_flowrule}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_flowicmp[] = { { FLOW_ICMPCODE,"code", NONE, t_flowrule}, { ANYTOKEN, "", NONE, t_flowrule}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_bulk[] = { { KEYWORD, "add", NETWORK_BULK_ADD, t_set}, { KEYWORD, "delete", NETWORK_BULK_REMOVE, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_prefix[] = { { PREFIX, "", NONE, t_set}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_network_show[] = { { NOTOKEN, "", NONE, NULL}, { FAMILY, "", NONE, NULL}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_rd[] = { { RD, "", NONE, t_set}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_set[] = { { NOTOKEN, "", NONE, NULL}, { COMMUNITY, "community", NONE, t_set}, { EXTCOMMUNITY, "ext-community", NONE, t_set}, { LRGCOMMUNITY, "large-community", NONE, t_set}, { LOCALPREF, "localpref", NONE, t_set}, { MED, "med", NONE, t_set}, { MED, "metric", NONE, t_set}, { KEYWORD, "nexthop", NONE, t_nexthop}, { KEYWORD, "pftable", NONE, t_pftable}, { PREPNBR, "prepend-neighbor", NONE, t_set}, { PREPSELF, "prepend-self", NONE, t_set}, { KEYWORD, "rd", NONE, t_rd}, { WEIGHT, "weight", NONE, t_set}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_nexthop[] = { { NEXTHOP, "", NONE, t_set}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_pftable[] = { { PFTABLE, "", NONE, t_set}, { ENDTOKEN, "", NONE, NULL} }; static const struct token t_log[] = { { KEYWORD, "brief", LOG_BRIEF, NULL}, { KEYWORD, "verbose", LOG_VERBOSE, NULL}, { ENDTOKEN, "", NONE, NULL} }; static struct parse_result res; const struct token *match_token(int, char *[], const struct token [], int *); void show_valid_args(const struct token []); int parse_addr(const char *, struct bgpd_addr *); int parse_asnum(const char *, size_t, uint32_t *); int parse_number(const char *, struct parse_result *, enum token_type); void parsecommunity(struct community *c, char *s); void parselargecommunity(struct community *c, char *s); void parseextcommunity(struct community *c, const char *t, char *s); int parse_nexthop(const char *, struct parse_result *); int parse_flow_numop(int, char *[], struct parse_result *, enum token_type); struct parse_result * parse(int argc, char *argv[]) { const struct token *table = t_main; const struct token *match; int used; memset(&res, 0, sizeof(res)); res.rtableid = getrtable(); TAILQ_INIT(&res.set); while (argc >= 0) { if ((match = match_token(argc, argv, table, &used)) == NULL) { fprintf(stderr, "valid commands/args:\n"); show_valid_args(table); return (NULL); } if (match->type == ANYTOKEN) { if (prevtable == NULL) prevtable = table; table = match->next; continue; } argc -= used; argv += used; if (match->type == NOTOKEN || match->next == NULL) break; table = match->next; } if (argc > 0) { fprintf(stderr, "superfluous argument: %s\n", argv[0]); return (NULL); } return (&res); } const struct token * match_token(int argc, char *argv[], const struct token table[], int *argsused) { u_int i, match; const struct token *t = NULL; struct filter_set *fs; const char *word = argv[0]; size_t wordlen = 0; *argsused = 1; match = 0; if (word != NULL) wordlen = strlen(word); for (i = 0; table[i].type != ENDTOKEN; i++) { switch (table[i].type) { case NOTOKEN: if (word == NULL || wordlen == 0) { match++; t = &table[i]; } break; case ANYTOKEN: /* match anything if nothing else matched before */ if (match == 0) { match++; t = &table[i]; } break; case KEYWORD: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0) { match++; t = &table[i]; if (t->value) res.action = t->value; } break; case FLAG: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0) { match++; t = &table[i]; res.flags |= t->value; } break; case FAMILY: if (word == NULL) break; if (!strcmp(word, "inet") || !strcasecmp(word, "IPv4")) { match++; t = &table[i]; res.aid = AID_INET; } if (!strcmp(word, "inet6") || !strcasecmp(word, "IPv6")) { match++; t = &table[i]; res.aid = AID_INET6; } if (!strcasecmp(word, "VPNv4")) { match++; t = &table[i]; res.aid = AID_VPN_IPv4; } if (!strcasecmp(word, "VPNv6")) { match++; t = &table[i]; res.aid = AID_VPN_IPv6; } break; case ADDRESS: if (parse_addr(word, &res.addr)) { match++; t = &table[i]; } break; case PEERADDRESS: if (parse_addr(word, &res.peeraddr)) { match++; t = &table[i]; } break; case FLOW_SRC: if (parse_prefix(word, wordlen, &res.flow.src, &res.flow.srclen)) { match++; t = &table[i]; if (res.aid != res.flow.src.aid) errx(1, "wrong address family in " "flowspec rule"); } break; case FLOW_DST: if (parse_prefix(word, wordlen, &res.flow.dst, &res.flow.dstlen)) { match++; t = &table[i]; if (res.aid != res.flow.dst.aid) errx(1, "wrong address family in " "flowspec rule"); } break; case PREFIX: if (parse_prefix(word, wordlen, &res.addr, &res.prefixlen)) { match++; t = &table[i]; } break; case ASTYPE: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0) { match++; t = &table[i]; res.as.type = t->value; } break; case ASNUM: if (parse_asnum(word, wordlen, &res.as.as_min)) { res.as.as_max = res.as.as_min; match++; t = &table[i]; } break; case GROUPDESC: res.is_group = 1; /* FALLTHROUGH */ case PEERDESC: if (!match && word != NULL && wordlen > 0) { if (strlcpy(res.peerdesc, word, sizeof(res.peerdesc)) >= sizeof(res.peerdesc)) errx(1, "neighbor description too " "long"); match++; t = &table[i]; } break; case RIBNAME: if (!match && word != NULL && wordlen > 0) { if (strlcpy(res.rib, word, sizeof(res.rib)) >= sizeof(res.rib)) errx(1, "rib name too long"); match++; t = &table[i]; } break; case COMMUNICATION: if (!match && word != NULL && wordlen > 0) { if (strlcpy(res.reason, word, sizeof(res.reason)) >= sizeof(res.reason)) errx(1, "shutdown reason too long"); match++; t = &table[i]; } break; case COMMUNITY: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0 && argc > 1) { parsecommunity(&res.community, argv[1]); *argsused += 1; if ((fs = calloc(1, sizeof(*fs))) == NULL) err(1, NULL); fs->type = ACTION_SET_COMMUNITY; fs->action.community = res.community; TAILQ_INSERT_TAIL(&res.set, fs, entry); match++; t = &table[i]; } break; case LRGCOMMUNITY: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0 && argc > 1) { parselargecommunity(&res.community, argv[1]); *argsused += 1; if ((fs = calloc(1, sizeof(*fs))) == NULL) err(1, NULL); fs->type = ACTION_SET_COMMUNITY; fs->action.community = res.community; TAILQ_INSERT_TAIL(&res.set, fs, entry); match++; t = &table[i]; } break; case EXTCOMMUNITY: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0 && argc > 2) { parseextcommunity(&res.community, argv[1], argv[2]); *argsused += 2; if ((fs = calloc(1, sizeof(*fs))) == NULL) err(1, NULL); fs->type = ACTION_SET_COMMUNITY; fs->action.community = res.community; TAILQ_INSERT_TAIL(&res.set, fs, entry); match++; t = &table[i]; } break; case RD: if (word != NULL && wordlen > 0) { char *p = strdup(word); struct community ext = { 0 }; uint64_t rd; if (p == NULL) err(1, NULL); parseextcommunity(&ext, "rt", p); free(p); switch (ext.data3 >> 8) { case EXT_COMMUNITY_TRANS_TWO_AS: rd = (0ULL << 48); rd |= ((uint64_t)ext.data1 & 0xffff) << 32; rd |= (uint64_t)ext.data2; break; case EXT_COMMUNITY_TRANS_IPV4: rd = (1ULL << 48); rd |= (uint64_t)ext.data1 << 16; rd |= (uint64_t)ext.data2 & 0xffff; break; case EXT_COMMUNITY_TRANS_FOUR_AS: rd = (2ULL << 48); rd |= (uint64_t)ext.data1 << 16; rd |= (uint64_t)ext.data2 & 0xffff; break; default: errx(1, "bad encoding of rd"); } res.rd = htobe64(rd); match++; t = &table[i]; } break; case LOCALPREF: case MED: case PREPNBR: case PREPSELF: case WEIGHT: case RTABLE: case PATHID: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0 && argc > 1 && parse_number(argv[1], &res, table[i].type)) { *argsused += 1; match++; t = &table[i]; } break; case NEXTHOP: if (word != NULL && wordlen > 0 && parse_nexthop(word, &res)) { match++; t = &table[i]; } break; case PFTABLE: if (word != NULL && wordlen > 0) { if ((fs = calloc(1, sizeof(struct filter_set))) == NULL) err(1, NULL); if (strlcpy(fs->action.pftable, word, sizeof(fs->action.pftable)) >= sizeof(fs->action.pftable)) errx(1, "pftable name too long"); TAILQ_INSERT_TAIL(&res.set, fs, entry); match++; t = &table[i]; } break; case FILENAME: if (word != NULL && wordlen > 0) { if ((res.mrtfd = open(word, O_RDONLY)) == -1) { /* * ignore error if path has no / and * does not exist. In hope to print * usage. */ if (errno == ENOENT && !strchr(word, '/')) break; err(1, "mrt open(%s)", word); } match++; t = &table[i]; } break; case FLOW_SRCPORT: case FLOW_DSTPORT: case FLOW_PROTO: case FLOW_ICMPTYPE: case FLOW_ICMPCODE: case FLOW_LENGTH: case FLOW_DSCP: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0 && argc > 1) { *argsused += parse_flow_numop(argc, argv, &res, table[i].type); match++; t = &table[i]; } break; case FLOW_FLAGS: case FLOW_FRAGS: if (word != NULL && strncmp(word, table[i].keyword, wordlen) == 0) { errx(1, "%s not yet implemented", word); } break; case ENDTOKEN: break; } } if (match != 1) { if (word == NULL) fprintf(stderr, "missing argument:\n"); else if (match > 1) fprintf(stderr, "ambiguous argument: %s\n", word); else if (match < 1) fprintf(stderr, "unknown argument: %s\n", word); return (NULL); } return (t); } void show_valid_args(const struct token table[]) { int i; if (prevtable != NULL) { const struct token *t = prevtable; prevtable = NULL; show_valid_args(t); fprintf(stderr, "or any of\n"); } for (i = 0; table[i].type != ENDTOKEN; i++) { switch (table[i].type) { case NOTOKEN: fprintf(stderr, " \n"); break; case ANYTOKEN: break; case KEYWORD: case FLAG: case ASTYPE: fprintf(stderr, " %s\n", table[i].keyword); break; case ADDRESS: case PEERADDRESS: fprintf(stderr, "
\n"); break; case PREFIX: case FLOW_SRC: case FLOW_DST: fprintf(stderr, "
[/]\n"); break; case ASNUM: fprintf(stderr, " \n"); break; case GROUPDESC: case PEERDESC: fprintf(stderr, " \n"); break; case RIBNAME: fprintf(stderr, " \n"); break; case COMMUNICATION: fprintf(stderr, " \n"); break; case COMMUNITY: fprintf(stderr, " %s \n", table[i].keyword); break; case LRGCOMMUNITY: fprintf(stderr, " %s \n", table[i].keyword); break; case EXTCOMMUNITY: fprintf(stderr, " %s \n", table[i].keyword); break; case RD: fprintf(stderr, " \n"); break; case LOCALPREF: case MED: case PREPNBR: case PREPSELF: case WEIGHT: case RTABLE: case PATHID: fprintf(stderr, " %s \n", table[i].keyword); break; case NEXTHOP: fprintf(stderr, "
\n"); break; case PFTABLE: fprintf(stderr, " \n"); break; case FAMILY: fprintf(stderr, " [ inet | inet6 | IPv4 | IPv6 | " "VPNv4 | VPNv6 ]\n"); break; case FILENAME: fprintf(stderr, " \n"); break; case FLOW_SRCPORT: case FLOW_DSTPORT: case FLOW_PROTO: case FLOW_ICMPTYPE: case FLOW_ICMPCODE: case FLOW_LENGTH: case FLOW_DSCP: fprintf(stderr, " %s \n", table[i].keyword); break; case FLOW_FLAGS: case FLOW_FRAGS: fprintf(stderr, " %s \n", table[i].keyword); break; case ENDTOKEN: break; } } } int parse_addr(const char *word, struct bgpd_addr *addr) { struct in_addr ina; struct addrinfo hints, *r; if (word == NULL) return (0); memset(&ina, 0, sizeof(ina)); if (inet_net_pton(AF_INET, word, &ina, sizeof(ina)) != -1) { memset(addr, 0, sizeof(*addr)); addr->aid = AID_INET; addr->v4 = ina; return (1); } memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_DGRAM; /*dummy*/ hints.ai_flags = AI_NUMERICHOST; if (getaddrinfo(word, "0", &hints, &r) == 0) { sa2addr(r->ai_addr, addr, NULL); freeaddrinfo(r); return (1); } return (0); } int parse_prefix(const char *word, size_t wordlen, struct bgpd_addr *addr, uint8_t *prefixlen) { struct bgpd_addr tmp; char *p, *ps; const char *errstr; int mask = -1; if (word == NULL) return (0); memset(&tmp, 0, sizeof(tmp)); if ((p = strrchr(word, '/')) != NULL) { size_t plen = strlen(p); mask = strtonum(p + 1, 0, 128, &errstr); if (errstr) errx(1, "netmask %s", errstr); if ((ps = malloc(wordlen - plen + 1)) == NULL) err(1, "parse_prefix: malloc"); strlcpy(ps, word, wordlen - plen + 1); if (parse_addr(ps, &tmp) == 0) { free(ps); return (0); } free(ps); } else if (parse_addr(word, &tmp) == 0) return (0); switch (tmp.aid) { case AID_INET: if (mask == -1) mask = 32; if (mask > 32) errx(1, "invalid netmask: too large"); break; case AID_INET6: if (mask == -1) mask = 128; break; default: return (0); } applymask(addr, &tmp, mask); *prefixlen = mask; return (1); } int parse_asnum(const char *word, size_t wordlen, uint32_t *asnum) { const char *errstr; char *dot, *parseword; uint32_t uval, uvalh = 0; if (word == NULL) return (0); if (wordlen < 1 || word[0] < '0' || word[0] > '9') return (0); parseword = strdup(word); if ((dot = strchr(parseword, '.')) != NULL) { *dot++ = '\0'; uvalh = strtonum(parseword, 0, USHRT_MAX, &errstr); if (errstr) errx(1, "AS number is %s: %s", errstr, word); uval = strtonum(dot, 0, USHRT_MAX, &errstr); if (errstr) errx(1, "AS number is %s: %s", errstr, word); } else { uval = strtonum(parseword, 0, UINT_MAX, &errstr); if (errstr) errx(1, "AS number is %s: %s", errstr, word); } free(parseword); *asnum = uval | (uvalh << 16); return (1); } int parse_number(const char *word, struct parse_result *r, enum token_type type) { struct filter_set *fs; const char *errstr; u_int uval; if (word == NULL) return (0); uval = strtonum(word, 0, UINT_MAX, &errstr); if (errstr) errx(1, "number is %s: %s", errstr, word); /* number was parseable */ switch (type) { case RTABLE: r->rtableid = uval; return (1); case PATHID: r->pathid = uval; r->flags |= F_CTL_HAS_PATHID; return (1); default: break; } if ((fs = calloc(1, sizeof(struct filter_set))) == NULL) err(1, NULL); switch (type) { case LOCALPREF: fs->type = ACTION_SET_LOCALPREF; fs->action.metric = uval; break; case MED: fs->type = ACTION_SET_MED; fs->action.metric = uval; break; case PREPNBR: if (uval > 128) { free(fs); return (0); } fs->type = ACTION_SET_PREPEND_PEER; fs->action.prepend = uval; break; case PREPSELF: if (uval > 128) { free(fs); return (0); } fs->type = ACTION_SET_PREPEND_SELF; fs->action.prepend = uval; break; case WEIGHT: fs->type = ACTION_SET_WEIGHT; fs->action.metric = uval; break; default: errx(1, "king bula sez bad things happen"); } TAILQ_INSERT_TAIL(&r->set, fs, entry); return (1); } static void getcommunity(char *s, int large, uint32_t *val, uint32_t *flag) { long long max = USHRT_MAX; const char *errstr; *flag = 0; *val = 0; if (strcmp(s, "*") == 0) { *flag = COMMUNITY_ANY; return; } else if (strcmp(s, "neighbor-as") == 0) { *flag = COMMUNITY_NEIGHBOR_AS; return; } else if (strcmp(s, "local-as") == 0) { *flag = COMMUNITY_LOCAL_AS; return; } if (large) max = UINT_MAX; *val = strtonum(s, 0, max, &errstr); if (errstr) errx(1, "Community %s is %s (max: %llu)", s, errstr, max); } static void setcommunity(struct community *c, uint32_t as, uint32_t data, uint32_t asflag, uint32_t dataflag) { c->flags = COMMUNITY_TYPE_BASIC; c->flags |= asflag << 8; c->flags |= dataflag << 16; c->data1 = as; c->data2 = data; c->data3 = 0; } void parsecommunity(struct community *c, char *s) { char *p; uint32_t as, data, asflag, dataflag; /* Well-known communities */ if (strcasecmp(s, "GRACEFUL_SHUTDOWN") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_GRACEFUL_SHUTDOWN, 0, 0); return; } else if (strcasecmp(s, "NO_EXPORT") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPORT, 0, 0); return; } else if (strcasecmp(s, "NO_ADVERTISE") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_ADVERTISE, 0, 0); return; } else if (strcasecmp(s, "NO_EXPORT_SUBCONFED") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_EXPSUBCONFED, 0, 0); return; } else if (strcasecmp(s, "NO_PEER") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_NO_PEER, 0, 0); return; } else if (strcasecmp(s, "BLACKHOLE") == 0) { setcommunity(c, COMMUNITY_WELLKNOWN, COMMUNITY_BLACKHOLE, 0, 0); return; } if ((p = strchr(s, ':')) == NULL) errx(1, "Bad community syntax"); *p++ = 0; getcommunity(s, 0, &as, &asflag); getcommunity(p, 0, &data, &dataflag); setcommunity(c, as, data, asflag, dataflag); } void parselargecommunity(struct community *c, char *s) { char *p, *q; uint32_t dflag1, dflag2, dflag3; if ((p = strchr(s, ':')) == NULL) errx(1, "Bad community syntax"); *p++ = 0; if ((q = strchr(p, ':')) == NULL) errx(1, "Bad community syntax"); *q++ = 0; getcommunity(s, 1, &c->data1, &dflag1); getcommunity(p, 1, &c->data2, &dflag2); getcommunity(q, 1, &c->data3, &dflag3); c->flags = COMMUNITY_TYPE_LARGE; c->flags |= dflag1 << 8; c->flags |= dflag2 << 16; c->flags |= dflag3 << 24; } static int parsesubtype(const char *name, int *type, int *subtype) { const struct ext_comm_pairs *cp; int found = 0; for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if (strcmp(name, cp->subname) == 0) { if (found == 0) { *type = cp->type; *subtype = cp->subtype; } found++; } } if (found > 1) *type = -1; return (found); } static int parseextvalue(int type, char *s, uint32_t *v, uint32_t *flag) { const char *errstr; char *p; struct in_addr ip; uint32_t uvalh, uval; if (type != -1) { /* nothing */ } else if (strcmp(s, "neighbor-as") == 0) { *flag = COMMUNITY_NEIGHBOR_AS; *v = 0; return EXT_COMMUNITY_TRANS_TWO_AS; } else if (strcmp(s, "local-as") == 0) { *flag = COMMUNITY_LOCAL_AS; *v = 0; return EXT_COMMUNITY_TRANS_TWO_AS; } else if ((p = strchr(s, '.')) == NULL) { /* AS_PLAIN number (4 or 2 byte) */ strtonum(s, 0, USHRT_MAX, &errstr); if (errstr == NULL) type = EXT_COMMUNITY_TRANS_TWO_AS; else type = EXT_COMMUNITY_TRANS_FOUR_AS; } else if (strchr(p + 1, '.') == NULL) { /* AS_DOT number (4-byte) */ type = EXT_COMMUNITY_TRANS_FOUR_AS; } else { /* more than one dot -> IP address */ type = EXT_COMMUNITY_TRANS_IPV4; } switch (type & EXT_COMMUNITY_VALUE) { case EXT_COMMUNITY_TRANS_TWO_AS: uval = strtonum(s, 0, USHRT_MAX, &errstr); if (errstr) errx(1, "Bad ext-community %s is %s", s, errstr); *v = uval; break; case EXT_COMMUNITY_TRANS_FOUR_AS: if ((p = strchr(s, '.')) == NULL) { uval = strtonum(s, 0, UINT_MAX, &errstr); if (errstr) errx(1, "Bad ext-community %s is %s", s, errstr); *v = uval; break; } *p++ = '\0'; uvalh = strtonum(s, 0, USHRT_MAX, &errstr); if (errstr) errx(1, "Bad ext-community %s is %s", s, errstr); uval = strtonum(p, 0, USHRT_MAX, &errstr); if (errstr) errx(1, "Bad ext-community %s is %s", p, errstr); *v = uval | (uvalh << 16); break; case EXT_COMMUNITY_TRANS_IPV4: if (inet_pton(AF_INET, s, &ip) != 1) errx(1, "Bad ext-community %s not parseable", s); *v = ntohl(ip.s_addr); break; default: errx(1, "%s: unexpected type %d", __func__, type); } return (type); } void parseextcommunity(struct community *c, const char *t, char *s) { const struct ext_comm_pairs *cp; char *p, *ep; uint64_t ullval; uint32_t uval, uval2, dflag1 = 0, dflag2 = 0; int type = 0, subtype = 0; if (strcmp(t, "*") == 0 && strcmp(s, "*") == 0) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= COMMUNITY_ANY << 24; return; } if (parsesubtype(t, &type, &subtype) == 0) errx(1, "Bad ext-community unknown type"); switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_GEN_TWO_AS: case EXT_COMMUNITY_GEN_FOUR_AS: case EXT_COMMUNITY_GEN_IPV4: case -1: if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } if ((p = strchr(s, ':')) == NULL) errx(1, "Bad ext-community %s", s); *p++ = '\0'; type = parseextvalue(type, s, &uval, &dflag1); switch (type) { case EXT_COMMUNITY_TRANS_TWO_AS: case EXT_COMMUNITY_GEN_TWO_AS: getcommunity(p, 1, &uval2, &dflag2); break; case EXT_COMMUNITY_TRANS_IPV4: case EXT_COMMUNITY_TRANS_FOUR_AS: case EXT_COMMUNITY_GEN_IPV4: case EXT_COMMUNITY_GEN_FOUR_AS: getcommunity(p, 0, &uval2, &dflag2); break; default: errx(1, "parseextcommunity: unexpected result"); } c->data1 = uval; c->data2 = uval2; break; case EXT_COMMUNITY_TRANS_OPAQUE: case EXT_COMMUNITY_TRANS_EVPN: if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } errno = 0; ullval = strtoull(s, &ep, 0); if (s[0] == '\0' || *ep != '\0') errx(1, "Bad ext-community bad value"); if (errno == ERANGE && ullval > EXT_COMMUNITY_OPAQUE_MAX) errx(1, "Bad ext-community value too big"); c->data1 = ullval >> 32; c->data2 = ullval; break; case EXT_COMMUNITY_NON_TRANS_OPAQUE: if (subtype == EXT_COMMUNITY_SUBTYPE_OVS) { if (strcmp(s, "valid") == 0) { c->data2 = EXT_COMMUNITY_OVS_VALID; break; } else if (strcmp(s, "invalid") == 0) { c->data2 = EXT_COMMUNITY_OVS_INVALID; break; } else if (strcmp(s, "not-found") == 0) { c->data2 = EXT_COMMUNITY_OVS_NOTFOUND; break; } else if (strcmp(s, "*") == 0) { dflag1 = COMMUNITY_ANY; break; } } errx(1, "Bad ext-community %s", s); } c->data3 = type << 8 | subtype; /* special handling of ext-community rt * since type is not known */ if (dflag1 == COMMUNITY_ANY && type == -1) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= dflag1 << 8; return; } /* verify type/subtype combo */ for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if (cp->type == type && cp->subtype == subtype) { c->flags = COMMUNITY_TYPE_EXT; c->flags |= dflag1 << 8; c->flags |= dflag2 << 16; return; } } errx(1, "Bad ext-community bad format for type"); } int parse_nexthop(const char *word, struct parse_result *r) { struct filter_set *fs; if ((fs = calloc(1, sizeof(struct filter_set))) == NULL) err(1, NULL); if (strcmp(word, "blackhole") == 0) fs->type = ACTION_SET_NEXTHOP_BLACKHOLE; else if (strcmp(word, "reject") == 0) fs->type = ACTION_SET_NEXTHOP_REJECT; else if (strcmp(word, "no-modify") == 0) fs->type = ACTION_SET_NEXTHOP_NOMODIFY; else if (parse_addr(word, &fs->action.nexthop)) { fs->type = ACTION_SET_NEXTHOP; } else { free(fs); return (0); } TAILQ_INSERT_TAIL(&r->set, fs, entry); return (1); } static int unary_op(const char *op) { if (strcmp(op, "=") == 0) return FLOWSPEC_OP_NUM_EQ; if (strcmp(op, "!=") == 0) return FLOWSPEC_OP_NUM_NOT; if (strcmp(op, ">") == 0) return FLOWSPEC_OP_NUM_GT; if (strcmp(op, ">=") == 0) return FLOWSPEC_OP_NUM_GE; if (strcmp(op, "<") == 0) return FLOWSPEC_OP_NUM_LT; if (strcmp(op, "<=") == 0) return FLOWSPEC_OP_NUM_LE; return -1; } static enum comp_ops binary_op(const char *op) { if (strcmp(op, "-") == 0) return OP_RANGE; if (strcmp(op, "><") == 0) return OP_XRANGE; return OP_NONE; } static void push_numop(struct parse_result *r, int type, uint8_t op, int and, long long val) { uint8_t *comp; void *data; uint32_t u32; uint16_t u16; uint8_t u8, flag = 0; int len, complen; flag |= op; if (and) flag |= FLOWSPEC_OP_AND; if (val < 0 || val > 0xffffffff) { errx(1, "unsupported value for flowspec num_op"); } else if (val <= 255) { len = 1; u8 = val; data = &u8; } else if (val <= 0xffff) { len = 2; u16 = htons(val); data = &u16; flag |= 1 << FLOWSPEC_OP_LEN_SHIFT; } else { len = 4; u32 = htonl(val); data = &u32; flag |= 2 << FLOWSPEC_OP_LEN_SHIFT; } complen = r->flow.complen[type]; comp = realloc(r->flow.components[type], complen + len + 1); if (comp == NULL) err(1, NULL); comp[complen++] = flag; memcpy(comp + complen, data, len); complen += len; r->flow.complen[type] = complen; r->flow.components[type] = comp; } int parse_flow_numop(int argc, char *argv[], struct parse_result *r, enum token_type toktype) { const char *errstr; long long val, val2; int numargs, type; int is_list = 0; int op; switch (toktype) { case FLOW_PROTO: type = FLOWSPEC_TYPE_PROTO; break; case FLOW_SRCPORT: type = FLOWSPEC_TYPE_SRC_PORT; break; case FLOW_DSTPORT: type = FLOWSPEC_TYPE_DST_PORT; break; case FLOW_ICMPTYPE: type = FLOWSPEC_TYPE_ICMP_TYPE; break; case FLOW_ICMPCODE: type = FLOWSPEC_TYPE_ICMP_CODE; break; case FLOW_LENGTH: type = FLOWSPEC_TYPE_PKT_LEN; break; case FLOW_DSCP: type = FLOWSPEC_TYPE_DSCP; break; default: errx(1, "parse_flow_numop called with unsupported type"); } /* skip keyword (which is already accounted for) */ argc--; argv++; numargs = argc; while (argc > 0) { if (strcmp(argv[0], "{") == 0) { is_list = 1; argc--; argv++; } else if (is_list && strcmp(argv[0], "}") == 0) { is_list = 0; argc--; argv++; } else if ((op = unary_op(argv[0])) != -1) { if (argc < 2) errx(1, "missing argument in flowspec " "definition"); val = strtonum(argv[1], LLONG_MIN, LLONG_MAX, &errstr); if (errstr) errx(1, "\"%s\" invalid number: %s", argv[0], errstr); push_numop(r, type, op, 0, val); argc -= 2; argv += 2; } else { val = strtonum(argv[0], LLONG_MIN, LLONG_MAX, &errstr); if (errstr) errx(1, "\"%s\" invalid number: %s", argv[0], errstr); if (argc >= 3 && (op = binary_op(argv[1])) != OP_NONE) { val2 = strtonum(argv[2], LLONG_MIN, LLONG_MAX, &errstr); if (errstr) errx(1, "\"%s\" invalid number: %s", argv[2], errstr); switch (op) { case OP_RANGE: push_numop(r, type, FLOWSPEC_OP_NUM_GE, 0, val); push_numop(r, type, FLOWSPEC_OP_NUM_LE, 1, val2); break; case OP_XRANGE: push_numop(r, type, FLOWSPEC_OP_NUM_LT, 0, val); push_numop(r, type, FLOWSPEC_OP_NUM_GT, 0, val2); break; } argc -= 3; argv += 3; } else { push_numop(r, type, FLOWSPEC_OP_NUM_EQ, 0, val); argc--; argv++; } } if (is_list == 0) break; } return numargs - argc; } openbgpd-8.8/src/bgpctl/mrtparser.c100644 001750 001750 00000057647 14571326703 0013151/* $OpenBSD: mrtparser.c,v 1.22 2024/02/01 11:37:10 claudio Exp $ */ /* * Copyright (c) 2011 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include "mrt.h" #include "mrtparser.h" struct mrt_peer *mrt_parse_v2_peer(struct mrt_hdr *, struct ibuf *); struct mrt_rib *mrt_parse_v2_rib(struct mrt_hdr *, struct ibuf *, int); int mrt_parse_dump(struct mrt_hdr *, struct ibuf *, struct mrt_peer **, struct mrt_rib **); int mrt_parse_dump_mp(struct mrt_hdr *, struct ibuf *, struct mrt_peer **, struct mrt_rib **, int); int mrt_extract_attr(struct mrt_rib_entry *, struct ibuf *, uint8_t, int); void mrt_free_peers(struct mrt_peer *); void mrt_free_rib(struct mrt_rib *); u_char *mrt_aspath_inflate(struct ibuf *, uint16_t *); int mrt_extract_addr(struct ibuf *, struct bgpd_addr *, uint8_t); int mrt_extract_prefix(struct ibuf *, uint8_t, struct bgpd_addr *, uint8_t *, int); int mrt_parse_state(struct mrt_bgp_state *, struct mrt_hdr *, struct ibuf *, int); int mrt_parse_msg(struct mrt_bgp_msg *, struct mrt_hdr *, struct ibuf *, int); static size_t mrt_read_buf(int fd, void *buf, size_t len) { char *b = buf; ssize_t n; while (len > 0) { if ((n = read(fd, b, len)) == -1) { if (errno == EINTR) continue; err(1, "read"); } if (n == 0) break; b += n; len -= n; } return (b - (char *)buf); } static struct ibuf * mrt_read_msg(int fd, struct mrt_hdr *hdr) { struct ibuf *buf; size_t len; memset(hdr, 0, sizeof(*hdr)); if (mrt_read_buf(fd, hdr, sizeof(*hdr)) != sizeof(*hdr)) return (NULL); len = ntohl(hdr->length); if ((buf = ibuf_open(len)) == NULL) err(1, "ibuf_open(%zu)", len); if (mrt_read_buf(fd, ibuf_reserve(buf, len), len) != len) { ibuf_free(buf); return (NULL); } return (buf); } void mrt_parse(int fd, struct mrt_parser *p, int verbose) { struct mrt_hdr h; struct mrt_bgp_state s; struct mrt_bgp_msg m; struct mrt_peer *pctx = NULL; struct mrt_rib *r; struct ibuf *msg; while ((msg = mrt_read_msg(fd, &h)) != NULL) { if (ibuf_size(msg) != ntohl(h.length)) errx(1, "corrupt message, %zu vs %u", ibuf_size(msg), ntohl(h.length)); switch (ntohs(h.type)) { case MSG_NULL: case MSG_START: case MSG_DIE: case MSG_I_AM_DEAD: case MSG_PEER_DOWN: case MSG_PROTOCOL_BGP: case MSG_PROTOCOL_IDRP: case MSG_PROTOCOL_BGP4PLUS: case MSG_PROTOCOL_BGP4PLUS1: if (verbose) printf("deprecated MRT type %d\n", ntohs(h.type)); break; case MSG_PROTOCOL_RIP: case MSG_PROTOCOL_RIPNG: case MSG_PROTOCOL_OSPF: case MSG_PROTOCOL_ISIS_ET: case MSG_PROTOCOL_ISIS: case MSG_PROTOCOL_OSPFV3_ET: case MSG_PROTOCOL_OSPFV3: if (verbose) printf("unsupported MRT type %d\n", ntohs(h.type)); break; case MSG_TABLE_DUMP: switch (ntohs(h.subtype)) { case MRT_DUMP_AFI_IP: case MRT_DUMP_AFI_IPv6: if (p->dump == NULL) break; if (mrt_parse_dump(&h, msg, &pctx, &r) == 0) { if (p->dump) p->dump(r, pctx, p->arg); mrt_free_rib(r); } break; default: if (verbose) printf("unknown AFI %d in table dump\n", ntohs(h.subtype)); break; } break; case MSG_TABLE_DUMP_V2: switch (ntohs(h.subtype)) { case MRT_DUMP_V2_PEER_INDEX_TABLE: if (p->dump == NULL) break; if (pctx) mrt_free_peers(pctx); pctx = mrt_parse_v2_peer(&h, msg); break; case MRT_DUMP_V2_RIB_IPV4_UNICAST: case MRT_DUMP_V2_RIB_IPV4_MULTICAST: case MRT_DUMP_V2_RIB_IPV6_UNICAST: case MRT_DUMP_V2_RIB_IPV6_MULTICAST: case MRT_DUMP_V2_RIB_GENERIC: case MRT_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH: case MRT_DUMP_V2_RIB_IPV4_MULTICAST_ADDPATH: case MRT_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH: case MRT_DUMP_V2_RIB_IPV6_MULTICAST_ADDPATH: case MRT_DUMP_V2_RIB_GENERIC_ADDPATH: if (p->dump == NULL) break; r = mrt_parse_v2_rib(&h, msg, verbose); if (r) { if (p->dump) p->dump(r, pctx, p->arg); mrt_free_rib(r); } break; default: if (verbose) printf("unhandled DUMP_V2 subtype %d\n", ntohs(h.subtype)); break; } break; case MSG_PROTOCOL_BGP4MP_ET: case MSG_PROTOCOL_BGP4MP: switch (ntohs(h.subtype)) { case BGP4MP_STATE_CHANGE: case BGP4MP_STATE_CHANGE_AS4: if (mrt_parse_state(&s, &h, msg, verbose) != -1) { if (p->state) p->state(&s, p->arg); } break; case BGP4MP_MESSAGE: case BGP4MP_MESSAGE_AS4: case BGP4MP_MESSAGE_LOCAL: case BGP4MP_MESSAGE_AS4_LOCAL: case BGP4MP_MESSAGE_ADDPATH: case BGP4MP_MESSAGE_AS4_ADDPATH: case BGP4MP_MESSAGE_LOCAL_ADDPATH: case BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH: if (mrt_parse_msg(&m, &h, msg, verbose) != -1) { if (p->message) p->message(&m, p->arg); } break; case BGP4MP_ENTRY: if (p->dump == NULL) break; if (mrt_parse_dump_mp(&h, msg, &pctx, &r, verbose) == 0) { if (p->dump) p->dump(r, pctx, p->arg); mrt_free_rib(r); } break; default: if (verbose) printf("unhandled BGP4MP subtype %d\n", ntohs(h.subtype)); break; } break; default: if (verbose) printf("unknown MRT type %d\n", ntohs(h.type)); break; } ibuf_free(msg); } if (pctx) mrt_free_peers(pctx); } static int mrt_afi2aid(int afi, int safi, int verbose) { switch (afi) { case MRT_DUMP_AFI_IP: if (safi == -1 || safi == 1 || safi == 2) return AID_INET; else if (safi == 128) return AID_VPN_IPv4; break; case MRT_DUMP_AFI_IPv6: if (safi == -1 || safi == 1 || safi == 2) return AID_INET6; else if (safi == 128) return AID_VPN_IPv6; break; default: break; } if (verbose) printf("unhandled AFI/SAFI %d/%d\n", afi, safi); return AID_UNSPEC; } struct mrt_peer * mrt_parse_v2_peer(struct mrt_hdr *hdr, struct ibuf *msg) { struct mrt_peer_entry *peers = NULL; struct mrt_peer *p; uint32_t bid; uint16_t cnt, i; if (ibuf_size(msg) < 8) /* min msg size */ return NULL; p = calloc(1, sizeof(struct mrt_peer)); if (p == NULL) err(1, "calloc"); /* collector bgp id */ if (ibuf_get_n32(msg, &bid) == -1 || ibuf_get_n16(msg, &cnt) == -1) goto fail; /* view name */ if (cnt != 0) { if ((p->view = malloc(cnt + 1)) == NULL) err(1, "malloc"); if (ibuf_get(msg, p->view, cnt) == -1) goto fail; p->view[cnt] = 0; } else if ((p->view = strdup("")) == NULL) err(1, "strdup"); /* peer_count */ if (ibuf_get_n16(msg, &cnt) == -1) goto fail; /* peer entries */ if ((peers = calloc(cnt, sizeof(struct mrt_peer_entry))) == NULL) err(1, "calloc"); for (i = 0; i < cnt; i++) { uint8_t type; if (ibuf_get_n8(msg, &type) == -1 || ibuf_get_n32(msg, &peers[i].bgp_id) == -1) goto fail; if (type & MRT_DUMP_V2_PEER_BIT_I) { if (mrt_extract_addr(msg, &peers[i].addr, AID_INET6) == -1) goto fail; } else { if (mrt_extract_addr(msg, &peers[i].addr, AID_INET) == -1) goto fail; } if (type & MRT_DUMP_V2_PEER_BIT_A) { if (ibuf_get_n32(msg, &peers[i].asnum) == -1) goto fail; } else { uint16_t as2; if (ibuf_get_n16(msg, &as2) == -1) goto fail; peers[i].asnum = as2; } } p->peers = peers; p->npeers = cnt; return (p); fail: mrt_free_peers(p); free(peers); return (NULL); } struct mrt_rib * mrt_parse_v2_rib(struct mrt_hdr *hdr, struct ibuf *msg, int verbose) { struct mrt_rib_entry *entries = NULL; struct mrt_rib *r; uint16_t i, afi; uint8_t safi, aid; r = calloc(1, sizeof(struct mrt_rib)); if (r == NULL) err(1, "calloc"); /* seq_num */ if (ibuf_get_n32(msg, &r->seqnum) == -1) goto fail; switch (ntohs(hdr->subtype)) { case MRT_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH: case MRT_DUMP_V2_RIB_IPV4_MULTICAST_ADDPATH: r->add_path = 1; /* FALLTHROUGH */ case MRT_DUMP_V2_RIB_IPV4_UNICAST: case MRT_DUMP_V2_RIB_IPV4_MULTICAST: /* prefix */ if (mrt_extract_prefix(msg, AID_INET, &r->prefix, &r->prefixlen, verbose) == -1) goto fail; break; case MRT_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH: case MRT_DUMP_V2_RIB_IPV6_MULTICAST_ADDPATH: r->add_path = 1; /* FALLTHROUGH */ case MRT_DUMP_V2_RIB_IPV6_UNICAST: case MRT_DUMP_V2_RIB_IPV6_MULTICAST: /* prefix */ if (mrt_extract_prefix(msg, AID_INET6, &r->prefix, &r->prefixlen, verbose) == -1) goto fail; break; case MRT_DUMP_V2_RIB_GENERIC_ADDPATH: /* * RFC8050 handling for add-path has special handling for * RIB_GENERIC_ADDPATH but nobody implements it that way. * So just use the same way as for the other _ADDPATH types. */ r->add_path = 1; /* FALLTHROUGH */ case MRT_DUMP_V2_RIB_GENERIC: /* fetch AFI/SAFI pair */ if (ibuf_get_n16(msg, &afi) == -1 || ibuf_get_n8(msg, &safi) == -1) goto fail; if ((aid = mrt_afi2aid(afi, safi, verbose)) == AID_UNSPEC) goto fail; /* prefix */ if (mrt_extract_prefix(msg, aid, &r->prefix, &r->prefixlen, verbose) == -1) goto fail; break; default: errx(1, "unknown subtype %hd", ntohs(hdr->subtype)); } /* entries count */ if (ibuf_get_n16(msg, &r->nentries) == -1) goto fail; /* entries */ if ((entries = calloc(r->nentries, sizeof(struct mrt_rib_entry))) == NULL) err(1, "calloc"); for (i = 0; i < r->nentries; i++) { struct ibuf abuf; uint32_t otm; uint16_t alen; /* peer index */ if (ibuf_get_n16(msg, &entries[i].peer_idx) == -1) goto fail; /* originated */ if (ibuf_get_n32(msg, &otm) == -1) goto fail; entries[i].originated = otm; if (r->add_path) { if (ibuf_get_n32(msg, &entries[i].path_id) == -1) goto fail; } /* attr_len */ if (ibuf_get_n16(msg, &alen) == -1 || ibuf_get_ibuf(msg, alen, &abuf) == -1) goto fail; /* attr */ if (mrt_extract_attr(&entries[i], &abuf, r->prefix.aid, 1) == -1) goto fail; } r->entries = entries; return (r); fail: mrt_free_rib(r); free(entries); return (NULL); } int mrt_parse_dump(struct mrt_hdr *hdr, struct ibuf *msg, struct mrt_peer **pp, struct mrt_rib **rp) { struct ibuf abuf; struct mrt_peer *p; struct mrt_rib *r; struct mrt_rib_entry *re; uint32_t tmp32; uint16_t tmp16, alen; if (*pp == NULL) { *pp = calloc(1, sizeof(struct mrt_peer)); if (*pp == NULL) err(1, "calloc"); (*pp)->peers = calloc(1, sizeof(struct mrt_peer_entry)); if ((*pp)->peers == NULL) err(1, "calloc"); (*pp)->npeers = 1; } p = *pp; *rp = r = calloc(1, sizeof(struct mrt_rib)); if (r == NULL) err(1, "calloc"); re = calloc(1, sizeof(struct mrt_rib_entry)); if (re == NULL) err(1, "calloc"); r->nentries = 1; r->entries = re; if (ibuf_skip(msg, sizeof(uint16_t)) == -1 || /* view */ ibuf_get_n16(msg, &tmp16) == -1) /* seqnum */ goto fail; r->seqnum = tmp16; switch (ntohs(hdr->subtype)) { case MRT_DUMP_AFI_IP: if (mrt_extract_addr(msg, &r->prefix, AID_INET) == -1) goto fail; break; case MRT_DUMP_AFI_IPv6: if (mrt_extract_addr(msg, &r->prefix, AID_INET6) == -1) goto fail; break; } if (ibuf_get_n8(msg, &r->prefixlen) == -1 || /* prefixlen */ ibuf_skip(msg, 1) == -1 || /* status */ ibuf_get_n32(msg, &tmp32) == -1) /* originated */ goto fail; re->originated = tmp32; /* peer ip */ switch (ntohs(hdr->subtype)) { case MRT_DUMP_AFI_IP: if (mrt_extract_addr(msg, &p->peers->addr, AID_INET) == -1) goto fail; break; case MRT_DUMP_AFI_IPv6: if (mrt_extract_addr(msg, &p->peers->addr, AID_INET6) == -1) goto fail; break; } if (ibuf_get_n16(msg, &tmp16) == -1) goto fail; p->peers->asnum = tmp16; if (ibuf_get_n16(msg, &alen) == -1 || ibuf_get_ibuf(msg, alen, &abuf) == -1) goto fail; /* attr */ if (mrt_extract_attr(re, &abuf, r->prefix.aid, 0) == -1) goto fail; return (0); fail: mrt_free_rib(r); return (-1); } int mrt_parse_dump_mp(struct mrt_hdr *hdr, struct ibuf *msg, struct mrt_peer **pp, struct mrt_rib **rp, int verbose) { struct ibuf abuf; struct mrt_peer *p; struct mrt_rib *r; struct mrt_rib_entry *re; uint32_t tmp32; uint16_t asnum, alen, afi; uint8_t safi, nhlen, aid; if (*pp == NULL) { *pp = calloc(1, sizeof(struct mrt_peer)); if (*pp == NULL) err(1, "calloc"); (*pp)->peers = calloc(1, sizeof(struct mrt_peer_entry)); if ((*pp)->peers == NULL) err(1, "calloc"); (*pp)->npeers = 1; } p = *pp; *rp = r = calloc(1, sizeof(struct mrt_rib)); if (r == NULL) err(1, "calloc"); re = calloc(1, sizeof(struct mrt_rib_entry)); if (re == NULL) err(1, "calloc"); r->nentries = 1; r->entries = re; /* just ignore the microsec field for _ET header for now */ if (ntohs(hdr->type) == MSG_PROTOCOL_BGP4MP_ET) { if (ibuf_skip(msg, sizeof(uint32_t)) == -1) goto fail; } if (ibuf_skip(msg, sizeof(uint16_t)) == -1 || /* source AS */ ibuf_get_n16(msg, &asnum) == -1 || /* dest AS */ ibuf_skip(msg, sizeof(uint16_t)) == -1 || /* iface index */ ibuf_get_n16(msg, &afi) == -1) goto fail; p->peers->asnum = asnum; /* source + dest ip */ switch (afi) { case MRT_DUMP_AFI_IP: /* source IP */ if (ibuf_skip(msg, sizeof(struct in_addr)) == -1) goto fail; /* dest IP */ if (mrt_extract_addr(msg, &p->peers->addr, AID_INET) == -1) goto fail; break; case MRT_DUMP_AFI_IPv6: /* source IP */ if (ibuf_skip(msg, sizeof(struct in6_addr)) == -1) goto fail; /* dest IP */ if (mrt_extract_addr(msg, &p->peers->addr, AID_INET6) == -1) goto fail; break; } if (ibuf_skip(msg, sizeof(uint16_t)) == -1 || /* view */ ibuf_skip(msg, sizeof(uint16_t)) == -1 || /* status */ ibuf_get_n32(msg, &tmp32) == -1) /* originated */ goto fail; re->originated = tmp32; if (ibuf_get_n16(msg, &afi) == -1 || /* afi */ ibuf_get_n8(msg, &safi) == -1) /* safi */ goto fail; if ((aid = mrt_afi2aid(afi, safi, verbose)) == AID_UNSPEC) goto fail; if (ibuf_get_n8(msg, &nhlen) == -1) /* nhlen */ goto fail; /* nexthop */ if (mrt_extract_addr(msg, &re->nexthop, aid) == -1) goto fail; /* prefix */ if (mrt_extract_prefix(msg, aid, &r->prefix, &r->prefixlen, verbose) == -1) goto fail; if (ibuf_get_n16(msg, &alen) == -1 || ibuf_get_ibuf(msg, alen, &abuf) == -1) goto fail; if (mrt_extract_attr(re, &abuf, r->prefix.aid, 0) == -1) goto fail; return (0); fail: mrt_free_rib(r); return (-1); } int mrt_extract_attr(struct mrt_rib_entry *re, struct ibuf *buf, uint8_t aid, int as4) { struct ibuf abuf; struct mrt_attr *ap; size_t alen, hlen; uint8_t type, flags; do { ibuf_from_ibuf(&abuf, buf); if (ibuf_get_n8(&abuf, &flags) == -1 || ibuf_get_n8(&abuf, &type) == -1) return (-1); if (flags & MRT_ATTR_EXTLEN) { uint16_t tmp16; if (ibuf_get_n16(&abuf, &tmp16) == -1) return (-1); alen = tmp16; hlen = 4; } else { uint8_t tmp8; if (ibuf_get_n8(&abuf, &tmp8) == -1) return (-1); alen = tmp8; hlen = 3; } if (ibuf_truncate(&abuf, alen) == -1) return (-1); /* consume the attribute in buf before moving forward */ if (ibuf_skip(buf, hlen + alen) == -1) return (-1); switch (type) { case MRT_ATTR_ORIGIN: if (alen != 1) return (-1); if (ibuf_get_n8(&abuf, &re->origin) == -1) return (-1); break; case MRT_ATTR_ASPATH: if (as4) { re->aspath_len = alen; if ((re->aspath = malloc(alen)) == NULL) err(1, "malloc"); if (ibuf_get(&abuf, re->aspath, alen) == -1) return (-1); } else { re->aspath = mrt_aspath_inflate(&abuf, &re->aspath_len); if (re->aspath == NULL) return (-1); } break; case MRT_ATTR_NEXTHOP: if (alen != 4) return (-1); if (aid != AID_INET) break; if (ibuf_get(&abuf, &re->nexthop.v4, sizeof(re->nexthop.v4)) == -1) return (-1); re->nexthop.aid = AID_INET; break; case MRT_ATTR_MED: if (alen != 4) return (-1); if (ibuf_get_n32(&abuf, &re->med) == -1) return (-1); break; case MRT_ATTR_LOCALPREF: if (alen != 4) return (-1); if (ibuf_get_n32(&abuf, &re->local_pref) == -1) return (-1); break; case MRT_ATTR_MP_REACH_NLRI: /* * XXX horrible hack: * Once again IETF and the real world differ in the * implementation. In short the abbreviated MP_NLRI * hack in the standard is not used in real life. * Detect the two cases by looking at the first byte * of the payload (either the nexthop addr length (RFC) * or the high byte of the AFI (old form)). If the * first byte matches the expected nexthop length it * is expected to be the RFC 6396 encoding. * * Checking for the hack skips over the nhlen. */ { uint8_t hack; if (ibuf_get_n8(&abuf, &hack) == -1) return (-1); if (hack != alen - 1) { if (ibuf_skip(&abuf, 3) == -1) return (-1); } } switch (aid) { case AID_INET6: if (ibuf_get(&abuf, &re->nexthop.v6, sizeof(re->nexthop.v6)) == -1) return (-1); re->nexthop.aid = aid; break; case AID_VPN_IPv4: if (ibuf_skip(&abuf, sizeof(uint64_t)) == -1 || ibuf_get(&abuf, &re->nexthop.v4, sizeof(re->nexthop.v4)) == -1) return (-1); re->nexthop.aid = aid; break; case AID_VPN_IPv6: if (ibuf_skip(&abuf, sizeof(uint64_t)) == -1 || ibuf_get(&abuf, &re->nexthop.v6, sizeof(re->nexthop.v6)) == -1) return (-1); re->nexthop.aid = aid; break; } break; case MRT_ATTR_AS4PATH: if (!as4) { free(re->aspath); re->aspath_len = alen; if ((re->aspath = malloc(alen)) == NULL) err(1, "malloc"); if (ibuf_get(&abuf, re->aspath, alen) == -1) return (-1); break; } /* FALLTHROUGH */ default: re->nattrs++; if (re->nattrs >= UCHAR_MAX) err(1, "too many attributes"); ap = reallocarray(re->attrs, re->nattrs, sizeof(struct mrt_attr)); if (ap == NULL) err(1, "realloc"); re->attrs = ap; ap = re->attrs + re->nattrs - 1; ibuf_rewind(&abuf); ap->attr_len = ibuf_size(&abuf); if ((ap->attr = malloc(ap->attr_len)) == NULL) err(1, "malloc"); if (ibuf_get(&abuf, ap->attr, ap->attr_len) == -1) return (-1); break; } } while (ibuf_size(buf) > 0); return (0); } void mrt_free_peers(struct mrt_peer *p) { free(p->peers); free(p->view); free(p); } void mrt_free_rib(struct mrt_rib *r) { uint16_t i, j; for (i = 0; i < r->nentries && r->entries; i++) { for (j = 0; j < r->entries[i].nattrs; j++) free(r->entries[i].attrs[j].attr); free(r->entries[i].attrs); free(r->entries[i].aspath); } free(r->entries); free(r); } u_char * mrt_aspath_inflate(struct ibuf *buf, uint16_t *newlen) { struct ibuf *asbuf; u_char *data; size_t len; *newlen = 0; asbuf = aspath_inflate(buf); if (asbuf == NULL) return NULL; len = ibuf_size(asbuf); if ((data = malloc(len)) == NULL) err(1, "malloc"); if (ibuf_get(asbuf, data, len) == -1) { ibuf_free(asbuf); return (NULL); } ibuf_free(asbuf); *newlen = len; return (data); } int mrt_extract_addr(struct ibuf *msg, struct bgpd_addr *addr, uint8_t aid) { memset(addr, 0, sizeof(*addr)); switch (aid) { case AID_INET: if (ibuf_get(msg, &addr->v4, sizeof(addr->v4)) == -1) return (-1); break; case AID_INET6: if (ibuf_get(msg, &addr->v6, sizeof(addr->v6)) == -1) return (-1); break; case AID_VPN_IPv4: /* XXX labelstack and rd missing */ if (ibuf_skip(msg, sizeof(uint64_t)) == -1 || ibuf_get(msg, &addr->v4, sizeof(addr->v4)) == -1) return (-1); break; case AID_VPN_IPv6: /* XXX labelstack and rd missing */ if (ibuf_skip(msg, sizeof(uint64_t)) == -1 || ibuf_get(msg, &addr->v6, sizeof(addr->v6)) == -1) return (-1); break; default: return (-1); } addr->aid = aid; return 0; } int mrt_extract_prefix(struct ibuf *msg, uint8_t aid, struct bgpd_addr *prefix, uint8_t *prefixlen, int verbose) { int r; switch (aid) { case AID_INET: r = nlri_get_prefix(msg, prefix, prefixlen); break; case AID_INET6: r = nlri_get_prefix6(msg, prefix, prefixlen); break; case AID_VPN_IPv4: r = nlri_get_vpn4(msg, prefix, prefixlen, 0); break; case AID_VPN_IPv6: r = nlri_get_vpn6(msg, prefix, prefixlen, 0); break; default: if (verbose) printf("unknown prefix AID %d\n", aid); return -1; } if (r == -1 && verbose) printf("failed to parse prefix of AID %d\n", aid); return r; } int mrt_parse_state(struct mrt_bgp_state *s, struct mrt_hdr *hdr, struct ibuf *msg, int verbose) { struct timespec t; uint32_t sas, das, usec; uint16_t sas16, das16, afi; uint8_t aid; t.tv_sec = ntohl(hdr->timestamp); t.tv_nsec = 0; /* handle the microsec field for _ET header */ if (ntohs(hdr->type) == MSG_PROTOCOL_BGP4MP_ET) { if (ibuf_get_n32(msg, &usec) == -1) return (-1); t.tv_nsec = usec * 1000; } switch (ntohs(hdr->subtype)) { case BGP4MP_STATE_CHANGE: if (ibuf_get_n16(msg, &sas16) == -1 || /* source as */ ibuf_get_n16(msg, &das16) == -1 || /* dest as */ ibuf_skip(msg, 2) == -1 || /* if_index */ ibuf_get_n16(msg, &afi) == -1) /* afi */ return (-1); sas = sas16; das = das16; break; case BGP4MP_STATE_CHANGE_AS4: if (ibuf_get_n32(msg, &sas) == -1 || /* source as */ ibuf_get_n32(msg, &das) == -1 || /* dest as */ ibuf_skip(msg, 2) == -1 || /* if_index */ ibuf_get_n16(msg, &afi) == -1) /* afi */ return (-1); break; default: errx(1, "mrt_parse_state: bad subtype"); } /* src & dst addr */ if ((aid = mrt_afi2aid(afi, -1, verbose)) == AID_UNSPEC) return (-1); memset(s, 0, sizeof(*s)); s->time = t; s->src_as = sas; s->dst_as = das; if (mrt_extract_addr(msg, &s->src, aid) == -1) return (-1); if (mrt_extract_addr(msg, &s->dst, aid) == -1) return (-1); /* states */ if (ibuf_get_n16(msg, &s->old_state) == -1 || ibuf_get_n16(msg, &s->new_state) == -1) return (-1); return (0); } int mrt_parse_msg(struct mrt_bgp_msg *m, struct mrt_hdr *hdr, struct ibuf *msg, int verbose) { struct timespec t; uint32_t sas, das, usec; uint16_t sas16, das16, afi; int addpath = 0; uint8_t aid; t.tv_sec = ntohl(hdr->timestamp); t.tv_nsec = 0; /* handle the microsec field for _ET header */ if (ntohs(hdr->type) == MSG_PROTOCOL_BGP4MP_ET) { if (ibuf_get_n32(msg, &usec) == -1) return (-1); t.tv_nsec = usec * 1000; } switch (ntohs(hdr->subtype)) { case BGP4MP_MESSAGE_ADDPATH: case BGP4MP_MESSAGE_LOCAL_ADDPATH: addpath = 1; /* FALLTHROUGH */ case BGP4MP_MESSAGE: case BGP4MP_MESSAGE_LOCAL: if (ibuf_get_n16(msg, &sas16) == -1 || /* source as */ ibuf_get_n16(msg, &das16) == -1 || /* dest as */ ibuf_skip(msg, 2) == -1 || /* if_index */ ibuf_get_n16(msg, &afi) == -1) /* afi */ return (-1); sas = sas16; das = das16; break; case BGP4MP_MESSAGE_AS4_ADDPATH: case BGP4MP_MESSAGE_AS4_LOCAL_ADDPATH: addpath = 1; /* FALLTHROUGH */ case BGP4MP_MESSAGE_AS4: case BGP4MP_MESSAGE_AS4_LOCAL: if (ibuf_get_n32(msg, &sas) == -1 || /* source as */ ibuf_get_n32(msg, &das) == -1 || /* dest as */ ibuf_skip(msg, 2) == -1 || /* if_index */ ibuf_get_n16(msg, &afi) == -1) /* afi */ return (-1); break; default: errx(1, "mrt_parse_msg: bad subtype"); } /* src & dst addr */ if ((aid = mrt_afi2aid(afi, -1, verbose)) == AID_UNSPEC) return (-1); memset(m, 0, sizeof(*m)); m->time = t; m->src_as = sas; m->dst_as = das; m->add_path = addpath; if (mrt_extract_addr(msg, &m->src, aid) == -1 || mrt_extract_addr(msg, &m->dst, aid) == -1) return (-1); /* msg */ ibuf_from_ibuf(&m->msg, msg); return (0); } openbgpd-8.8/src/bgpctl/util.c100644 001750 001750 00000070320 14751151130 0012054/* $OpenBSD: util.c,v 1.93 2025/02/04 18:16:56 denis Exp $ */ /* * Copyright (c) 2006 Claudio Jeker * Copyright (c) 2003, 2004 Henning Brauer * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include "bgpd.h" #include "rde.h" #include "log.h" const char * log_addr(const struct bgpd_addr *addr) { static char buf[74]; struct sockaddr *sa; socklen_t len; sa = addr2sa(addr, 0, &len); switch (addr->aid) { case AID_INET: case AID_INET6: return log_sockaddr(sa, len); case AID_VPN_IPv4: case AID_VPN_IPv6: snprintf(buf, sizeof(buf), "%s %s", log_rd(addr->rd), log_sockaddr(sa, len)); return (buf); case AID_EVPN: return log_evpnaddr(addr, sa, len); break; } return ("???"); } static const char * log_mac(const uint8_t mac[ETHER_ADDR_LEN]) { static char buf[18]; snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return (buf); } static const uint8_t zero_esi[ESI_ADDR_LEN]; static const char * log_esi(const uint8_t esi[ESI_ADDR_LEN]) { static char buf[30]; if (memcmp(esi, zero_esi, sizeof(zero_esi)) == 0) return (""); snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", esi[0], esi[1], esi[2], esi[3], esi[4], esi[5], esi[6], esi[7], esi[8], esi[9]); return (buf); } const char * log_evpnaddr(const struct bgpd_addr *addr, struct sockaddr *sa, socklen_t salen) { static char buf[138]; uint32_t vni; uint8_t len; switch(addr->evpn.type) { case EVPN_ROUTE_TYPE_2: memcpy(&vni, addr->labelstack, addr->labellen); snprintf(buf, sizeof(buf), "[2]:[%s]:[%s]:[%d]:[48]:[%s]", log_rd(addr->rd),log_esi(addr->evpn.esi), htonl(vni)>>8, log_mac(addr->evpn.mac)); if (sa != NULL) { len = strlen(buf); snprintf(buf+len, sizeof(buf)-len, ":[%d]:[%s]", sa->sa_family == AF_INET ? 32 : 128, log_sockaddr(sa, salen)); } break; case EVPN_ROUTE_TYPE_3: if (sa != NULL) { memcpy(&vni, addr->labelstack, addr->labellen); snprintf(buf, sizeof(buf), "[3]:[%s]:[%d]:[%s]", log_rd(addr->rd), sa->sa_family == AF_INET ? 32 : 128, log_sockaddr(sa, salen)); } break; default: break; } return (buf); } const char * log_in6addr(const struct in6_addr *addr) { struct sockaddr_in6 sa_in6; memset(&sa_in6, 0, sizeof(sa_in6)); sa_in6.sin6_family = AF_INET6; memcpy(&sa_in6.sin6_addr, addr, sizeof(sa_in6.sin6_addr)); #ifdef __KAME__ /* XXX thanks, KAME, for this ugliness... adopted from route/show.c */ if ((IN6_IS_ADDR_LINKLOCAL(&sa_in6.sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&sa_in6.sin6_addr) || IN6_IS_ADDR_MC_NODELOCAL(&sa_in6.sin6_addr)) && sa_in6.sin6_scope_id == 0) { uint16_t tmp16; memcpy(&tmp16, &sa_in6.sin6_addr.s6_addr[2], sizeof(tmp16)); sa_in6.sin6_scope_id = ntohs(tmp16); sa_in6.sin6_addr.s6_addr[2] = 0; sa_in6.sin6_addr.s6_addr[3] = 0; } #endif return (log_sockaddr((struct sockaddr *)&sa_in6, sizeof(sa_in6))); } const char * log_sockaddr(struct sockaddr *sa, socklen_t len) { static char buf[4][NI_MAXHOST]; static int bufidx; bufidx = (bufidx + 1) % 4; if (sa == NULL || getnameinfo(sa, len, buf[bufidx], sizeof(buf[0]), NULL, 0, NI_NUMERICHOST)) return ("(unknown)"); else return (buf[bufidx]); } const char * log_as(uint32_t as) { static char buf[11]; /* "4294967294\0" */ if (snprintf(buf, sizeof(buf), "%u", as) < 0) return ("?"); return (buf); } const char * log_rd(uint64_t rd) { static char buf[32]; struct in_addr addr; uint32_t u32; uint16_t u16; rd = be64toh(rd); switch (rd >> 48) { case EXT_COMMUNITY_TRANS_TWO_AS: u32 = rd & 0xffffffff; u16 = (rd >> 32) & 0xffff; snprintf(buf, sizeof(buf), "rd %hu:%u", u16, u32); break; case EXT_COMMUNITY_TRANS_FOUR_AS: u32 = (rd >> 16) & 0xffffffff; u16 = rd & 0xffff; snprintf(buf, sizeof(buf), "rd %s:%hu", log_as(u32), u16); break; case EXT_COMMUNITY_TRANS_IPV4: u32 = (rd >> 16) & 0xffffffff; u16 = rd & 0xffff; addr.s_addr = htonl(u32); snprintf(buf, sizeof(buf), "rd %s:%hu", inet_ntoa(addr), u16); break; default: snprintf(buf, sizeof(buf), "rd #%016llx", (unsigned long long)rd); break; } return (buf); } const struct ext_comm_pairs iana_ext_comms[] = IANA_EXT_COMMUNITIES; /* NOTE: this function does not check if the type/subtype combo is * actually valid. */ const char * log_ext_subtype(int type, uint8_t subtype) { static char etype[16]; const struct ext_comm_pairs *cp; for (cp = iana_ext_comms; cp->subname != NULL; cp++) { if ((type == cp->type || type == -1) && subtype == cp->subtype) return (cp->subname); } if (type == -1) return ("???"); snprintf(etype, sizeof(etype), "[%hhx:%hhx]", (uint8_t)type, subtype); return (etype); } const char * log_reason(const char *communication) { static char buf[(REASON_LEN - 1) * 4 + 1]; strnvis(buf, communication, sizeof(buf), VIS_NL | VIS_OCTAL); return buf; } static const char * log_expires(time_t expires) { static char buf[32]; buf[0] = '\0'; if (expires != 0) snprintf(buf, sizeof(buf), " expires %lld", (long long)expires); return buf; } const char * log_roa(struct roa *roa) { static char buf[256]; char maxbuf[32]; #if defined(__GNUC__) && __GNUC__ < 4 struct bgpd_addr addr = { .aid = roa->aid }; addr.v6 = roa->prefix.inet6; #else struct bgpd_addr addr = { .aid = roa->aid, .v6 = roa->prefix.inet6 }; #endif maxbuf[0] = '\0'; if (roa->prefixlen != roa->maxlen) snprintf(maxbuf, sizeof(maxbuf), " maxlen %u", roa->maxlen); snprintf(buf, sizeof(buf), "%s/%u%s source-as %u%s", log_addr(&addr), roa->prefixlen, maxbuf, roa->asnum, log_expires(roa->expires)); return buf; } const char * log_aspa(struct aspa_set *aspa) { static char errbuf[256]; static char *buf; static size_t len; char asbuf[16]; size_t needed; uint32_t i; /* include enough space for header and trailer */ if ((uint64_t)aspa->num > (SIZE_MAX / sizeof(asbuf) - 72)) goto fail; needed = aspa->num * sizeof(asbuf) + 72; if (needed > len) { char *nbuf; if ((nbuf = realloc(buf, needed)) == NULL) goto fail; len = needed; buf = nbuf; } snprintf(buf, len, "customer-as %s%s provider-as { ", log_as(aspa->as), log_expires(aspa->expires)); for (i = 0; i < aspa->num; i++) { snprintf(asbuf, sizeof(asbuf), "%s ", log_as(aspa->tas[i])); if (strlcat(buf, asbuf, len) >= len) goto fail; } if (strlcat(buf, "}", len) >= len) goto fail; return buf; fail: free(buf); buf = NULL; len = 0; snprintf(errbuf, sizeof(errbuf), "customer-as %s%s provider-as { ... }", log_as(aspa->as), log_expires(aspa->expires)); return errbuf; } const char * log_aspath_error(int error) { static char buf[20]; switch (error) { case AS_ERR_LEN: return "inconsistent length"; case AS_ERR_TYPE: return "unknown segment type"; case AS_ERR_BAD: return "invalid encoding"; case AS_ERR_SOFT: return "soft failure"; default: snprintf(buf, sizeof(buf), "unknown %d", error); return buf; } } const char * log_rtr_error(enum rtr_error err) { static char buf[20]; switch (err) { case NO_ERROR: return "No Error"; case CORRUPT_DATA: return "Corrupt Data"; case INTERNAL_ERROR: return "Internal Error"; case NO_DATA_AVAILABLE: return "No Data Available"; case INVALID_REQUEST: return "Invalid Request"; case UNSUPP_PROTOCOL_VERS: return "Unsupported Protocol Version"; case UNSUPP_PDU_TYPE: return "Unsupported PDU Type"; case UNK_REC_WDRAWL: return "Withdrawal of Unknown Record"; case DUP_REC_RECV: return "Duplicate Announcement Received"; case UNEXP_PROTOCOL_VERS: return "Unexpected Protocol Version"; default: snprintf(buf, sizeof(buf), "unknown %u", err); return buf; } } const char * log_policy(enum role role) { switch (role) { case ROLE_PROVIDER: return "provider"; case ROLE_RS: return "rs"; case ROLE_RS_CLIENT: return "rs-client"; case ROLE_CUSTOMER: return "customer"; case ROLE_PEER: return "peer"; default: return "unknown"; } } const char * log_capability(uint8_t capa) { static char buf[20]; switch (capa) { case CAPA_MP: return "Multiprotocol Extensions"; case CAPA_REFRESH: return "Route Refresh"; case CAPA_EXT_NEXTHOP: return "Extended Nexhop Encoding"; case CAPA_EXT_MSG: return "Extended Message"; case CAPA_ROLE: return "BGP Role"; case CAPA_RESTART: return "Graceful Restart"; case CAPA_AS4BYTE: return "4-octet AS number"; case CAPA_ADD_PATH: return "ADD-PATH"; case CAPA_ENHANCED_RR: return "Enhanced Route Refresh"; default: snprintf(buf, sizeof(buf), "unknown %u", capa); return buf; } } static const char * aspath_delim(uint8_t seg_type, int closing) { static char db[8]; switch (seg_type) { case AS_SET: if (!closing) return ("{ "); else return (" }"); case AS_SEQUENCE: return (""); case AS_CONFED_SEQUENCE: if (!closing) return ("( "); else return (" )"); case AS_CONFED_SET: if (!closing) return ("[ "); else return (" ]"); default: if (!closing) snprintf(db, sizeof(db), "!%u ", seg_type); else snprintf(db, sizeof(db), " !%u", seg_type); return (db); } } static int aspath_snprint(char *buf, size_t size, struct ibuf *in) { #define UPDATE() \ do { \ if (r < 0 || (unsigned int)r >= size) \ return (-1); \ size -= r; \ buf += r; \ } while (0) struct ibuf data; uint32_t as; int r, n = 0; uint8_t i, seg_type, seg_len; ibuf_from_ibuf(&data, in); while (ibuf_size(&data) > 0) { if (ibuf_get_n8(&data, &seg_type) == -1 || ibuf_get_n8(&data, &seg_len) == -1 || seg_len == 0) return (-1); r = snprintf(buf, size, "%s%s", n++ != 0 ? " " : "", aspath_delim(seg_type, 0)); UPDATE(); for (i = 0; i < seg_len; i++) { if (ibuf_get_n32(&data, &as) == -1) return -1; r = snprintf(buf, size, "%s", log_as(as)); UPDATE(); if (i + 1 < seg_len) { r = snprintf(buf, size, " "); UPDATE(); } } r = snprintf(buf, size, "%s", aspath_delim(seg_type, 1)); UPDATE(); } /* ensure that we have a valid C-string especially for empty as path */ *buf = '\0'; return (0); #undef UPDATE } static ssize_t aspath_strsize(struct ibuf *in) { struct ibuf buf; ssize_t total_size = 0; uint32_t as; uint8_t i, seg_type, seg_len; ibuf_from_ibuf(&buf, in); while (ibuf_size(&buf) > 0) { if (ibuf_get_n8(&buf, &seg_type) == -1 || ibuf_get_n8(&buf, &seg_len) == -1 || seg_len == 0) return (-1); if (total_size != 0) total_size += 1; total_size += strlen(aspath_delim(seg_type, 0)); for (i = 0; i < seg_len; i++) { if (ibuf_get_n32(&buf, &as) == -1) return (-1); do { total_size++; } while ((as = as / 10) != 0); } total_size += seg_len - 1; total_size += strlen(aspath_delim(seg_type, 1)); } return (total_size + 1); } int aspath_asprint(char **ret, struct ibuf *data) { ssize_t slen; if ((slen = aspath_strsize(data)) == -1) { *ret = NULL; errno = EINVAL; return (-1); } *ret = malloc(slen); if (*ret == NULL) return (-1); if (aspath_snprint(*ret, slen, data) == -1) { free(*ret); *ret = NULL; errno = EINVAL; return (-1); } return (0); } /* * Extract the asnum out of the as segment at the specified position. * Direct access is not possible because of non-aligned reads. * Only works on verified 4-byte AS paths. */ uint32_t aspath_extract(const void *seg, int pos) { const u_char *ptr = seg; uint32_t as; /* minimal pos check, return 0 since that is an invalid ASN */ if (pos < 0 || pos >= ptr[1]) return (0); ptr += 2 + sizeof(uint32_t) * pos; memcpy(&as, ptr, sizeof(uint32_t)); return (ntohl(as)); } /* * Verify that the aspath is correctly encoded. */ int aspath_verify(struct ibuf *in, int as4byte, int permit_set) { struct ibuf buf; int pos, error = 0; uint8_t seg_len, seg_type; ibuf_from_ibuf(&buf, in); if (ibuf_size(&buf) & 1) { /* odd length aspath are invalid */ error = AS_ERR_BAD; goto done; } while (ibuf_size(&buf) > 0) { if (ibuf_get_n8(&buf, &seg_type) == -1 || ibuf_get_n8(&buf, &seg_len) == -1) { error = AS_ERR_LEN; goto done; } if (seg_len == 0) { /* empty aspath segments are not allowed */ error = AS_ERR_BAD; goto done; } /* * BGP confederations should not show up but consider them * as a soft error which invalidates the path but keeps the * bgp session running. */ if (seg_type == AS_CONFED_SEQUENCE || seg_type == AS_CONFED_SET) error = AS_ERR_SOFT; /* * If AS_SET filtering (RFC6472) is on, error out on AS_SET * as well. */ if (!permit_set && seg_type == AS_SET) error = AS_ERR_SOFT; if (seg_type != AS_SET && seg_type != AS_SEQUENCE && seg_type != AS_CONFED_SEQUENCE && seg_type != AS_CONFED_SET) { error = AS_ERR_TYPE; goto done; } /* RFC 7607 - AS 0 is considered malformed */ for (pos = 0; pos < seg_len; pos++) { uint32_t as; if (as4byte) { if (ibuf_get_n32(&buf, &as) == -1) { error = AS_ERR_LEN; goto done; } } else { uint16_t tmp; if (ibuf_get_n16(&buf, &tmp) == -1) { error = AS_ERR_LEN; goto done; } as = tmp; } if (as == 0) error = AS_ERR_SOFT; } } done: return (error); /* aspath is valid but probably not loop free */ } /* * convert a 2 byte aspath to a 4 byte one. */ struct ibuf * aspath_inflate(struct ibuf *in) { struct ibuf *out; uint16_t short_as; uint8_t seg_type, seg_len; /* * Allocate enough space for the worst case. * XXX add 1 byte for the empty ASPATH case since we can't * allocate an ibuf of 0 length. */ if ((out = ibuf_open(ibuf_size(in) * 2 + 1)) == NULL) return (NULL); /* then copy the aspath */ while (ibuf_size(in) > 0) { if (ibuf_get_n8(in, &seg_type) == -1 || ibuf_get_n8(in, &seg_len) == -1 || seg_len == 0) goto fail; if (ibuf_add_n8(out, seg_type) == -1 || ibuf_add_n8(out, seg_len) == -1) goto fail; for (; seg_len > 0; seg_len--) { if (ibuf_get_n16(in, &short_as) == -1) goto fail; if (ibuf_add_n32(out, short_as) == -1) goto fail; } } return (out); fail: ibuf_free(out); return (NULL); } static const u_char addrmask[] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; /* NLRI functions to extract prefixes from the NLRI blobs */ int extract_prefix(const u_char *p, int len, void *va, uint8_t pfxlen, uint8_t max) { u_char *a = va; int plen; plen = PREFIX_SIZE(pfxlen) - 1; if (len < plen || max < plen) return -1; while (pfxlen > 0) { if (pfxlen < 8) { *a++ = *p++ & addrmask[pfxlen]; break; } else { *a++ = *p++; pfxlen -= 8; } } return (plen); } static int extract_prefix_buf(struct ibuf *buf, void *va, uint8_t pfxlen, uint8_t max) { u_char *a = va; unsigned int plen; uint8_t tmp; plen = PREFIX_SIZE(pfxlen) - 1; if (ibuf_size(buf) < plen || max < plen) return -1; while (pfxlen > 0) { if (ibuf_get_n8(buf, &tmp) == -1) return -1; if (pfxlen < 8) { *a++ = tmp & addrmask[pfxlen]; break; } else { *a++ = tmp; pfxlen -= 8; } } return (0); } int nlri_get_prefix(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen) { uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); if (pfxlen > 32) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_INET; if (extract_prefix_buf(buf, &prefix->v4, pfxlen, sizeof(prefix->v4)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_prefix6(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen) { uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); if (pfxlen > 128) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_INET6; if (extract_prefix_buf(buf, &prefix->v6, pfxlen, sizeof(prefix->v6)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_vpn4(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen, int withdraw) { int done = 0; uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_VPN_IPv4; /* label stack */ do { if (prefix->labellen + 3U > sizeof(prefix->labelstack) || pfxlen < 3 * 8) return (-1); if (withdraw) { /* on withdraw ignore the labelstack all together */ if (ibuf_skip(buf, 3) == -1) return (-1); pfxlen -= 3 * 8; break; } if (ibuf_get(buf, &prefix->labelstack[prefix->labellen], 3) == -1) return -1; if (prefix->labelstack[prefix->labellen + 2] & BGP_MPLS_BOS) done = 1; prefix->labellen += 3; pfxlen -= 3 * 8; } while (!done); /* RD */ if (pfxlen < sizeof(uint64_t) * 8 || ibuf_get_h64(buf, &prefix->rd) == -1) return (-1); pfxlen -= sizeof(uint64_t) * 8; /* prefix */ if (pfxlen > 32) return (-1); if (extract_prefix_buf(buf, &prefix->v4, pfxlen, sizeof(prefix->v4)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_vpn6(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen, int withdraw) { int done = 0; uint8_t pfxlen; if (ibuf_get_n8(buf, &pfxlen) == -1) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_VPN_IPv6; /* label stack */ do { if (prefix->labellen + 3U > sizeof(prefix->labelstack) || pfxlen < 3 * 8) return (-1); if (withdraw) { /* on withdraw ignore the labelstack all together */ if (ibuf_skip(buf, 3) == -1) return (-1); pfxlen -= 3 * 8; break; } if (ibuf_get(buf, &prefix->labelstack[prefix->labellen], 3) == -1) return (-1); if (prefix->labelstack[prefix->labellen + 2] & BGP_MPLS_BOS) done = 1; prefix->labellen += 3; pfxlen -= 3 * 8; } while (!done); /* RD */ if (pfxlen < sizeof(uint64_t) * 8 || ibuf_get_h64(buf, &prefix->rd) == -1) return (-1); pfxlen -= sizeof(uint64_t) * 8; /* prefix */ if (pfxlen > 128) return (-1); if (extract_prefix_buf(buf, &prefix->v6, pfxlen, sizeof(prefix->v6)) == -1) return (-1); *prefixlen = pfxlen; return (0); } int nlri_get_evpn(struct ibuf *buf, struct bgpd_addr *prefix, uint8_t *prefixlen) { struct ibuf evpnbuf; uint8_t nlrilen, type, pfxlen = 0, maclen = 0; if (ibuf_get_n8(buf, &type) == -1) return (-1); if (ibuf_get_n8(buf, &nlrilen) == -1) return (-1); memset(prefix, 0, sizeof(struct bgpd_addr)); prefix->aid = AID_EVPN; switch (type) { case EVPN_ROUTE_TYPE_2: if (ibuf_get_ibuf(buf, nlrilen, &evpnbuf) == -1) return (-1); prefix->evpn.type = EVPN_ROUTE_TYPE_2; /* RD */ if (ibuf_get_h64(&evpnbuf, &prefix->rd) == -1) return (-1); /* ESI */ if (ibuf_get(&evpnbuf, &prefix->evpn.esi, sizeof(prefix->evpn.esi)) == -1) return (-1); /* Ethernet Tag */ if (ibuf_get_h32(&evpnbuf, &prefix->evpn.ethtag) == -1) return (-1); /* MAC length */ if (ibuf_get_n8(&evpnbuf, &maclen) == -1) return (-1); if (maclen != 48) return (-1); /* MAC address */ if (ibuf_get(&evpnbuf, &prefix->evpn.mac, sizeof(prefix->evpn.mac)) == -1) return (-1); /* Prefix length */ if (ibuf_get_n8(&evpnbuf, &pfxlen) == -1) return (-1); /* Destination */ if (pfxlen == 0) { /* nothing */ } else if (pfxlen == 32) { prefix->evpn.aid = AID_INET; if (ibuf_get(&evpnbuf, &prefix->evpn.v4, sizeof(prefix->evpn.v4)) == -1) return (-1); } else if (pfxlen == 128) { prefix->evpn.aid = AID_INET6; if (ibuf_get(&evpnbuf, &prefix->evpn.v6, sizeof(prefix->evpn.v6)) == -1) return (-1); } else return (-1); /* VNI */ if (ibuf_size(&evpnbuf) != 3 && ibuf_size(&evpnbuf) != 6) return (-1); prefix->labellen = ibuf_size(&evpnbuf); if (ibuf_get(&evpnbuf, prefix->labelstack, prefix->labellen) == -1) return (-1); break; case EVPN_ROUTE_TYPE_3: if (ibuf_get_ibuf(buf, nlrilen, &evpnbuf) == -1) return (-1); prefix->evpn.type = EVPN_ROUTE_TYPE_3; /* RD */ if (ibuf_get_h64(&evpnbuf, &prefix->rd) == -1) return (-1); /* Ethernet Tag */ if (ibuf_get_h32(&evpnbuf, &prefix->evpn.ethtag) == -1) return (-1); /* Prefix length */ if (ibuf_get_n8(&evpnbuf, &pfxlen) == -1) return (-1); /* Destination */ if (pfxlen == 32) { prefix->evpn.aid = AID_INET; if (ibuf_get(&evpnbuf, &prefix->evpn.v4, sizeof(prefix->evpn.v4)) == -1) return (-1); } else if (pfxlen == 128) { prefix->evpn.aid = AID_INET6; if (ibuf_get(&evpnbuf, &prefix->evpn.v6, sizeof(prefix->evpn.v6)) == -1) return (-1); } else return (-1); if (ibuf_size(&evpnbuf) != 0) return (-1); break; default: return (-1); } *prefixlen = pfxlen; return (0); } static in_addr_t prefixlen2mask(uint8_t prefixlen) { if (prefixlen == 0) return (0); return (0xffffffff << (32 - prefixlen)); } /* * This function will have undefined behaviour if the passed in prefixlen is * too large for the respective bgpd_addr address family. */ int prefix_compare(const struct bgpd_addr *a, const struct bgpd_addr *b, int prefixlen) { in_addr_t mask, aa, ba; int i; uint8_t m; if (a->aid != b->aid) return (a->aid - b->aid); switch (a->aid) { case AID_VPN_IPv4: if (be64toh(a->rd) > be64toh(b->rd)) return (1); if (be64toh(a->rd) < be64toh(b->rd)) return (-1); /* FALLTHROUGH */ case AID_INET: if (prefixlen == 0) return (0); if (prefixlen > 32) return (-1); mask = htonl(prefixlen2mask(prefixlen)); aa = ntohl(a->v4.s_addr & mask); ba = ntohl(b->v4.s_addr & mask); if (aa > ba) return (1); if (aa < ba) return (-1); break; case AID_VPN_IPv6: if (be64toh(a->rd) > be64toh(b->rd)) return (1); if (be64toh(a->rd) < be64toh(b->rd)) return (-1); /* FALLTHROUGH */ case AID_INET6: if (prefixlen == 0) return (0); if (prefixlen > 128) return (-1); for (i = 0; i < prefixlen / 8; i++) if (a->v6.s6_addr[i] != b->v6.s6_addr[i]) return (a->v6.s6_addr[i] - b->v6.s6_addr[i]); i = prefixlen % 8; if (i) { m = 0xff00 >> i; if ((a->v6.s6_addr[prefixlen / 8] & m) != (b->v6.s6_addr[prefixlen / 8] & m)) return ((a->v6.s6_addr[prefixlen / 8] & m) - (b->v6.s6_addr[prefixlen / 8] & m)); } break; default: return (-1); } if (a->aid == AID_VPN_IPv4 || a->aid == AID_VPN_IPv6) { if (a->labellen > b->labellen) return (1); if (a->labellen < b->labellen) return (-1); return (memcmp(a->labelstack, b->labelstack, a->labellen)); } return (0); } void inet4applymask(struct in_addr *dest, const struct in_addr *src, int prefixlen) { struct in_addr mask; mask.s_addr = htonl(prefixlen2mask(prefixlen)); dest->s_addr = src->s_addr & mask.s_addr; } void inet6applymask(struct in6_addr *dest, const struct in6_addr *src, int prefixlen) { struct in6_addr mask; int i; memset(&mask, 0, sizeof(mask)); for (i = 0; i < prefixlen / 8; i++) mask.s6_addr[i] = 0xff; i = prefixlen % 8; if (i) mask.s6_addr[prefixlen / 8] = 0xff00 >> i; for (i = 0; i < 16; i++) dest->s6_addr[i] = src->s6_addr[i] & mask.s6_addr[i]; } void applymask(struct bgpd_addr *dest, const struct bgpd_addr *src, int prefixlen) { *dest = *src; switch (src->aid) { case AID_INET: case AID_VPN_IPv4: inet4applymask(&dest->v4, &src->v4, prefixlen); break; case AID_INET6: case AID_VPN_IPv6: inet6applymask(&dest->v6, &src->v6, prefixlen); break; } } /* address family translation functions */ const struct aid aid_vals[AID_MAX] = AID_VALS; const char * aid2str(uint8_t aid) { if (aid < AID_MAX) return (aid_vals[aid].name); return ("unknown AID"); } int aid2afi(uint8_t aid, uint16_t *afi, uint8_t *safi) { if (aid != AID_UNSPEC && aid < AID_MAX) { *afi = aid_vals[aid].afi; *safi = aid_vals[aid].safi; return (0); } return (-1); } int afi2aid(uint16_t afi, uint8_t safi, uint8_t *aid) { uint8_t i; for (i = AID_MIN; i < AID_MAX; i++) if (aid_vals[i].afi == afi && aid_vals[i].safi == safi) { *aid = i; return (0); } return (-1); } sa_family_t aid2af(uint8_t aid) { if (aid < AID_MAX) return (aid_vals[aid].af); return (AF_UNSPEC); } int af2aid(sa_family_t af, uint8_t safi, uint8_t *aid) { uint8_t i; if (safi == 0) /* default to unicast subclass */ safi = SAFI_UNICAST; for (i = AID_UNSPEC; i < AID_MAX; i++) if (aid_vals[i].af == af && aid_vals[i].safi == safi) { *aid = i; return (0); } return (-1); } static socklen_t addr2sa_in6(struct sockaddr_in6 *sin6, struct in6_addr in6, uint16_t port, uint32_t scope_id) { sin6->sin6_family = AF_INET6; memcpy(&sin6->sin6_addr, &in6, sizeof(sin6->sin6_addr)); sin6->sin6_port = htons(port); sin6->sin6_scope_id = scope_id; return (sizeof(struct sockaddr_in6)); } static socklen_t addr2sa_in(struct sockaddr_in *sin, struct in_addr in, uint16_t port) { sin->sin_family = AF_INET; sin->sin_addr.s_addr = in.s_addr; sin->sin_port = htons(port); return (sizeof(struct sockaddr_in)); } /* * Convert a struct bgpd_addr into a struct sockaddr. For VPN addresses * the included label stack is ignored and needs to be handled by the caller. */ struct sockaddr * addr2sa(const struct bgpd_addr *addr, uint16_t port, socklen_t *len) { static struct sockaddr_storage ss; struct sockaddr_in *sa_in = (struct sockaddr_in *)&ss; struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)&ss; if (addr == NULL || addr->aid == AID_UNSPEC) return (NULL); memset(&ss, 0, sizeof(ss)); switch (addr->aid) { case AID_INET: case AID_VPN_IPv4: *len = addr2sa_in(sa_in, addr->v4, port); break; case AID_INET6: case AID_VPN_IPv6: *len = addr2sa_in6(sa_in6, addr->v6, port, addr->scope_id); break; case AID_EVPN: if (addr->evpn.aid == AID_INET) *len = addr2sa_in(sa_in, addr->evpn.v4, port); else if (addr->evpn.aid == AID_INET6) *len = addr2sa_in6(sa_in6, addr->evpn.v6, port, addr->scope_id); else { *len = 0; return (NULL); } break; case AID_FLOWSPECv4: case AID_FLOWSPECv6: default: return (NULL); } return ((struct sockaddr *)&ss); } void sa2addr(struct sockaddr *sa, struct bgpd_addr *addr, uint16_t *port) { struct sockaddr_in *sa_in = (struct sockaddr_in *)sa; struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa; memset(addr, 0, sizeof(*addr)); switch (sa->sa_family) { case AF_INET: addr->aid = AID_INET; memcpy(&addr->v4, &sa_in->sin_addr, sizeof(addr->v4)); if (port) *port = ntohs(sa_in->sin_port); break; case AF_INET6: addr->aid = AID_INET6; #ifdef __KAME__ /* * XXX thanks, KAME, for this ugliness... * adopted from route/show.c */ if ((IN6_IS_ADDR_LINKLOCAL(&sa_in6->sin6_addr) || IN6_IS_ADDR_MC_LINKLOCAL(&sa_in6->sin6_addr) || IN6_IS_ADDR_MC_NODELOCAL(&sa_in6->sin6_addr)) && sa_in6->sin6_scope_id == 0) { uint16_t tmp16; memcpy(&tmp16, &sa_in6->sin6_addr.s6_addr[2], sizeof(tmp16)); sa_in6->sin6_scope_id = ntohs(tmp16); sa_in6->sin6_addr.s6_addr[2] = 0; sa_in6->sin6_addr.s6_addr[3] = 0; } #endif memcpy(&addr->v6, &sa_in6->sin6_addr, sizeof(addr->v6)); addr->scope_id = sa_in6->sin6_scope_id; /* I hate v6 */ if (port) *port = ntohs(sa_in6->sin6_port); break; } } const char * get_baudrate(unsigned long long baudrate, char *unit) { static char bbuf[16]; const unsigned long long kilo = 1000; const unsigned long long mega = 1000ULL * kilo; const unsigned long long giga = 1000ULL * mega; if (baudrate > giga) snprintf(bbuf, sizeof(bbuf), "%llu G%s", baudrate / giga, unit); else if (baudrate > mega) snprintf(bbuf, sizeof(bbuf), "%llu M%s", baudrate / mega, unit); else if (baudrate > kilo) snprintf(bbuf, sizeof(bbuf), "%llu K%s", baudrate / kilo, unit); else snprintf(bbuf, sizeof(bbuf), "%llu %s", baudrate, unit); return (bbuf); } openbgpd-8.8/src/bgpctl/json.c100644 001750 001750 00000013724 14453465437 0012076/* $OpenBSD: json.c,v 1.10 2023/06/22 09:07:04 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include "json.h" #define JSON_MAX_STACK 16 enum json_type { NONE, START, ARRAY, OBJECT }; static struct json_stack { const char *name; unsigned int count; int compact; enum json_type type; } stack[JSON_MAX_STACK]; static char indent[JSON_MAX_STACK + 1]; static int level; static int eb; static FILE *jsonfh; static void do_comma_indent(void) { char sp = '\n'; if (stack[level].compact) sp = ' '; if (stack[level].count++ > 0) { if (!eb) eb = fprintf(jsonfh, ",%c", sp) < 0; } if (stack[level].compact) return; if (!eb) eb = fprintf(jsonfh, "\t%.*s", level, indent) < 0; } static void do_name(const char *name) { if (stack[level].type == ARRAY) return; if (!eb) eb = fprintf(jsonfh, "\"%s\": ", name) < 0; } static int do_find(enum json_type type, const char *name) { int i; for (i = level; i > 0; i--) if (type == stack[i].type && strcmp(name, stack[i].name) == 0) return i; /* not found */ return -1; } void json_do_start(FILE *fh) { memset(indent, '\t', JSON_MAX_STACK); memset(stack, 0, sizeof(stack)); level = 0; stack[level].type = START; jsonfh = fh; eb = 0; eb = fprintf(jsonfh, "{\n") < 0; } int json_do_finish(void) { while (level > 0) json_do_end(); if (!eb) eb = fprintf(jsonfh, "\n}\n") < 0; return -eb; } void json_do_array(const char *name) { int i, l; char sp = '\n'; if ((l = do_find(ARRAY, name)) > 0) { /* array already in use, close element and move on */ for (i = level - l; i > 0; i--) json_do_end(); return; } /* Do not stack arrays, while allowed this is not needed */ if (stack[level].type == ARRAY) json_do_end(); if (stack[level].compact) sp = ' '; do_comma_indent(); do_name(name); if (!eb) eb = fprintf(jsonfh, "[%c", sp) < 0; if (++level >= JSON_MAX_STACK) errx(1, "json stack too deep"); stack[level].name = name; stack[level].type = ARRAY; stack[level].count = 0; /* inherit compact setting from above level */ stack[level].compact = stack[level - 1].compact; } void json_do_object(const char *name, int compact) { int i, l; char sp = '\n'; if ((l = do_find(OBJECT, name)) > 0) { /* roll back to that object and close it */ for (i = level - l; i >= 0; i--) json_do_end(); } if (compact) sp = ' '; do_comma_indent(); do_name(name); if (!eb) eb = fprintf(jsonfh, "{%c", sp) < 0; if (++level >= JSON_MAX_STACK) errx(1, "json stack too deep"); stack[level].name = name; stack[level].type = OBJECT; stack[level].count = 0; stack[level].compact = compact; } void json_do_end(void) { char c; if (stack[level].type == ARRAY) c = ']'; else if (stack[level].type == OBJECT) c = '}'; else errx(1, "json bad stack state"); if (!stack[level].compact) { if (!eb) eb = fprintf(jsonfh, "\n%.*s%c", level, indent, c) < 0; } else { if (!eb) eb = fprintf(jsonfh, " %c", c) < 0; } stack[level].name = NULL; stack[level].type = NONE; stack[level].count = 0; stack[level].compact = 0; if (level-- <= 0) errx(1, "json stack underflow"); stack[level].count++; } void json_do_printf(const char *name, const char *fmt, ...) { va_list ap; char *str; va_start(ap, fmt); if (!eb) { if (vasprintf(&str, fmt, ap) == -1) errx(1, "json printf failed"); json_do_string(name, str); free(str); } va_end(ap); } void json_do_string(const char *name, const char *v) { unsigned char c; do_comma_indent(); do_name(name); if (!eb) eb = fprintf(jsonfh, "\"") < 0; while ((c = *v++) != '\0' && !eb) { /* skip escaping '/' since our use case does not require it */ switch (c) { case '"': eb = fprintf(jsonfh, "\\\"") < 0; break; case '\\': eb = fprintf(jsonfh, "\\\\") < 0; break; case '\b': eb = fprintf(jsonfh, "\\b") < 0; break; case '\f': eb = fprintf(jsonfh, "\\f") < 0; break; case '\n': eb = fprintf(jsonfh, "\\n") < 0; break; case '\r': eb = fprintf(jsonfh, "\\r") < 0; break; case '\t': eb = fprintf(jsonfh, "\\t") < 0; break; default: if (iscntrl(c)) errx(1, "bad control character in string"); eb = putc(c, jsonfh) == EOF; break; } } if (!eb) eb = fprintf(jsonfh, "\"") < 0; } void json_do_hexdump(const char *name, void *buf, size_t len) { uint8_t *data = buf; size_t i; do_comma_indent(); do_name(name); if (!eb) eb = fprintf(jsonfh, "\"") < 0; for (i = 0; i < len; i++) if (!eb) eb = fprintf(jsonfh, "%02x", *(data + i)) < 0; if (!eb) eb = fprintf(jsonfh, "\"") < 0; } void json_do_bool(const char *name, int v) { do_comma_indent(); do_name(name); if (v) { if (!eb) eb = fprintf(jsonfh, "true") < 0; } else { if (!eb) eb = fprintf(jsonfh, "false") < 0; } } void json_do_uint(const char *name, unsigned long long v) { do_comma_indent(); do_name(name); if (!eb) eb = fprintf(jsonfh, "%llu", v) < 0; } void json_do_int(const char *name, long long v) { do_comma_indent(); do_name(name); if (!eb) eb = fprintf(jsonfh, "%lld", v) < 0; } void json_do_double(const char *name, double v) { do_comma_indent(); do_name(name); if (!eb) eb = fprintf(jsonfh, "%f", v) < 0; } openbgpd-8.8/src/bgpctl/flowspec.c100644 001750 001750 00000033417 14515663632 0012744/* $OpenBSD: flowspec.c,v 1.5 2023/10/23 13:07:44 claudio Exp $ */ /* * Copyright (c) 2023 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include "bgpd.h" #include "rde.h" /* * Extract the next component from a flowspec NLRI buffer. * Returns the length of the component including type field or -1 on failure. * Also checks that the prefix encoding is valid. */ static int flowspec_next_component(const uint8_t *buf, int len, int is_v6, int *type) { int vlen = 0; uint8_t plen, off, op; *type = 0; if (len < 1) return -1; *type = buf[vlen]; vlen++; if (*type < FLOWSPEC_TYPE_MIN || *type >= FLOWSPEC_TYPE_MAX) return -1; switch (*type) { case FLOWSPEC_TYPE_DEST: case FLOWSPEC_TYPE_SOURCE: if (!is_v6) { /* regular RFC 4271 encoding of prefixes */ if (len < vlen + 1) return -1; plen = buf[vlen]; vlen += PREFIX_SIZE(plen); if (plen > 32 || len < vlen) return -1; } else { /* special RFC 8956 encoding with extra offset */ if (len < vlen + 2) return -1; plen = buf[vlen]; off = buf[vlen + 1]; if (plen > 128 || off >= plen) return -1; vlen += PREFIX_SIZE(plen - off) + 1; /* off is extra */ if (len < vlen) return -1; } break; case FLOWSPEC_TYPE_FLOW: if (!is_v6) return -1; /* FALLTHROUGH */ default: do { if (len < vlen + 1) return -1; op = buf[vlen]; /* first component cannot have and flag set */ if (vlen == 1 && op & FLOWSPEC_OP_AND) return -1; vlen += FLOWSPEC_OP_LEN(op) + 1; if (len < vlen) return -1; } while ((op & FLOWSPEC_OP_EOL) == 0); break; } return vlen; } #define MINIMUM(a, b) ((a) < (b) ? (a) : (b)) /* * Compare two IPv4 flowspec prefix components. * Returns -1 if first prefix is preferred, 1 if second, 0 if equal. */ static int flowspec_cmp_prefix4(const uint8_t *abuf, int ablen, const uint8_t *bbuf, int bblen) { uint8_t a[4] = { 0 }, b[4] = { 0 }; int alen, blen, clen, cmp; alen = abuf[1]; blen = bbuf[1]; clen = MINIMUM(alen, blen); /* only extract the common prefix */ extract_prefix(abuf + 2, ablen - 2, &a, clen, sizeof(a)); extract_prefix(bbuf + 2, bblen - 2, &b, clen, sizeof(b)); /* lowest IP value has precedence */ cmp = memcmp(a, b, sizeof(a)); if (cmp < 0) return -1; if (cmp > 0) return 1; /* if common prefix, more specific route has precedence */ if (alen > blen) return -1; if (alen < blen) return 1; return 0; } /* * Compare two IPv6 flowspec prefix components. * Returns 1 if first prefix is preferred, -1 if second, 0 if equal. * As usual the encoding of IPv6 addresses is extra complex. */ static int flowspec_cmp_prefix6(const uint8_t *abuf, int ablen, const uint8_t *bbuf, int bblen) { uint8_t a[16] = { 0 }, b[16] = { 0 }; int alen, blen, clen, cmp; /* lowest offset has precedence */ if (abuf[2] < bbuf[2]) return -1; if (abuf[2] > bbuf[2]) return 1; /* calculate actual pattern size (len - offset) */ alen = abuf[1] - abuf[2]; blen = bbuf[1] - bbuf[2]; clen = MINIMUM(alen, blen); /* only extract the common prefix */ extract_prefix(abuf + 3, ablen - 3, &a, clen, sizeof(a)); extract_prefix(bbuf + 3, bblen - 3, &b, clen, sizeof(b)); /* lowest IP value has precedence */ cmp = memcmp(a, b, sizeof(a)); if (cmp < 0) return -1; if (cmp > 0) return 1; /* if common prefix, more specific route has precedence */ if (alen > blen) return -1; if (alen < blen) return 1; return 0; } /* * Check if the flowspec NLRI is syntactically valid. */ int flowspec_valid(const uint8_t *buf, int len, int is_v6) { int l, type, prev = 0; /* empty NLRI is invalid */ if (len == 0) return -1; while (len > 0) { l = flowspec_next_component(buf, len, is_v6, &type); if (l == -1) return -1; /* ensure that types are ordered */ if (prev >= type) return -1; prev = type; buf += l; len -= l; } if (len < 0) return -1; return 0; } /* * Compare two valid flowspec NLRI objects according to RFC 8955 & 8956. * Returns -1 if the first object has preference, 1 if not, and 0 if the * two objects are equal. */ int flowspec_cmp(const uint8_t *a, int alen, const uint8_t *b, int blen, int is_v6) { int atype, btype; int acomplen, bcomplen; int cmp; while (alen > 0 && blen > 0) { acomplen = flowspec_next_component(a, alen, is_v6, &atype); bcomplen = flowspec_next_component(b, blen, is_v6, &btype); /* should not happen */ if (acomplen == -1) return 1; if (bcomplen == -1) return -1; /* If types differ, lowest type wins. */ if (atype < btype) return -1; if (atype > btype) return 1; switch (atype) { case FLOWSPEC_TYPE_DEST: case FLOWSPEC_TYPE_SOURCE: if (!is_v6) { cmp = flowspec_cmp_prefix4(a, acomplen, b, bcomplen); } else { cmp = flowspec_cmp_prefix6(a, acomplen, b, bcomplen); } if (cmp != 0) return cmp; break; default: cmp = memcmp(a, b, MINIMUM(acomplen, bcomplen)); /* * Lowest common component prefix wins also * if both commponents are same length also lowest * string has precedence. */ if (cmp < 0) return -1; if (cmp > 0) return 1; /* * Longest component wins when common prefix is equal. * This is not really possible because EOL encoding will * always tie break on the memcmp but the RFC mandates * it (and it is cheap). */ if (acomplen > bcomplen) return -1; if (acomplen < bcomplen) return 1; break; } a += acomplen; alen -= acomplen; b += bcomplen; blen -= bcomplen; /* Rule with more components wins */ if (alen > 0 && blen <= 0) return -1; if (alen <= 0 && blen > 0) return 1; } return 0; } static void shift_right(uint8_t *dst, const uint8_t *src, int off, int len) { uint8_t carry = 0; int i; dst += off / 8; /* go to inital start point */ off %= 8; len = (len + 7) / 8; /* how much to copy in bytes */ for (i = 0; i < len; i++) { dst[i] = carry | src[i] >> off; if (off != 0) carry = src[i] << (8 - off); } dst[i] = carry; } /* * Extract a flowspec component and return its buffer and size. * Returns 1 on success, 0 if component is not present and -1 on error. */ int flowspec_get_component(const uint8_t *flow, int flowlen, int type, int is_v6, const uint8_t **buf, int *len) { int complen, t; *buf = NULL; *len = 0; do { complen = flowspec_next_component(flow, flowlen, is_v6, &t); if (complen == -1) return -1; if (type == t) break; if (type < t) return 0; flow += complen; flowlen -= complen; } while (1); *buf = flow + 1; *len = complen - 1; return 1; } /* * Extract source or destination address into provided bgpd_addr. * Returns 1 on success, 0 if no address was present, -1 on error. * Sets plen to the prefix len and olen to the offset for IPv6 case. * If olen is set to NULL when an IPv6 prefix with offset is fetched * the function will return -1. */ int flowspec_get_addr(const uint8_t *flow, int flowlen, int type, int is_v6, struct bgpd_addr *addr, uint8_t *plen, uint8_t *olen) { const uint8_t *comp; int complen, rv; memset(addr, 0, sizeof(*addr)); *plen = 0; if (olen != NULL) *olen = 0; rv = flowspec_get_component(flow, flowlen, type, is_v6, &comp, &complen); if (rv != 1) return rv; /* flowspec_get_component only returns valid encodings */ if (!is_v6) { addr->aid = AID_INET; if (extract_prefix(comp + 1, complen - 1, &addr->v4, comp[0], sizeof(addr->v4)) == -1) return -1; *plen = comp[0]; } else { uint8_t buf[16] = { 0 }; int xlen, xoff = 0; addr->aid = AID_INET6; xlen = comp[0]; if (comp[1] != 0) { if (olen == NULL) return -1; xoff = comp[1]; xlen -= xoff; } if (extract_prefix(comp + 2, complen - 2, buf, xlen, sizeof(buf)) == -1) return -1; shift_right(addr->v6.s6_addr, buf, xoff, xlen); *plen = comp[0]; if (olen != NULL) *olen = comp[1]; } return 1; } const char * flowspec_fmt_label(int type) { switch (type) { case FLOWSPEC_TYPE_DEST: return "to"; case FLOWSPEC_TYPE_SOURCE: return "from"; case FLOWSPEC_TYPE_PROTO: return "proto"; case FLOWSPEC_TYPE_PORT: case FLOWSPEC_TYPE_DST_PORT: case FLOWSPEC_TYPE_SRC_PORT: return "port"; case FLOWSPEC_TYPE_ICMP_TYPE: return "icmp-type"; case FLOWSPEC_TYPE_ICMP_CODE: return "icmp-code"; case FLOWSPEC_TYPE_TCP_FLAGS: return "flags"; case FLOWSPEC_TYPE_PKT_LEN: return "length"; case FLOWSPEC_TYPE_DSCP: return "tos"; case FLOWSPEC_TYPE_FRAG: return "fragment"; case FLOWSPEC_TYPE_FLOW: return "flow"; default: return "???"; } } static uint64_t extract_val(const uint8_t *comp, int len) { uint64_t val = 0; while (len-- > 0) { val <<= 8; val |= *comp++; } return val; } const char * flowspec_fmt_num_op(const uint8_t *comp, int complen, int *off) { static char buf[32]; uint64_t val, val2 = 0; uint8_t op, op2 = 0; int len, len2 = 0; if (*off == -1) return ""; if (complen < *off + 1) return "bad encoding"; op = comp[*off]; len = FLOWSPEC_OP_LEN(op) + 1; if (complen < *off + len) return "bad encoding"; val = extract_val(comp + *off + 1, FLOWSPEC_OP_LEN(op)); if ((op & FLOWSPEC_OP_EOL) == 0) { if (complen < *off + len + 1) return "bad encoding"; op2 = comp[*off + len]; /* * Check if this is a range specification else fall back * to basic rules. */ if (op2 & FLOWSPEC_OP_AND && (op & FLOWSPEC_OP_NUM_MASK) == FLOWSPEC_OP_NUM_GE && (op2 & FLOWSPEC_OP_NUM_MASK) == FLOWSPEC_OP_NUM_LE) { len2 = FLOWSPEC_OP_LEN(op2) + 1; val2 = extract_val(comp + *off + len + 1, FLOWSPEC_OP_LEN(op2)); } else op2 = 0; } if (op2 & FLOWSPEC_OP_AND) { /* binary range operation */ snprintf(buf, sizeof(buf), "%llu - %llu", (unsigned long long)val, (unsigned long long)val2); } else { /* unary operation */ switch (op & FLOWSPEC_OP_NUM_MASK) { case 0: snprintf(buf, sizeof(buf), "%sfalse", op & FLOWSPEC_OP_AND ? "&& " : ""); break; case FLOWSPEC_OP_NUM_EQ: snprintf(buf, sizeof(buf), "%s%llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_GT: snprintf(buf, sizeof(buf), "%s> %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_GE: snprintf(buf, sizeof(buf), "%s>= %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_LT: snprintf(buf, sizeof(buf), "%s< %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_LE: snprintf(buf, sizeof(buf), "%s<= %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case FLOWSPEC_OP_NUM_NOT: snprintf(buf, sizeof(buf), "%s!= %llu", op & FLOWSPEC_OP_AND ? "&& " : "", (unsigned long long)val); break; case 0x7: snprintf(buf, sizeof(buf), "%strue", op & FLOWSPEC_OP_AND ? "&& " : ""); break; } } if (op2 & FLOWSPEC_OP_EOL || op & FLOWSPEC_OP_EOL) *off = -1; else *off += len + len2; return buf; } static const char * fmt_flags(uint64_t val, const char *bits, char *buf, size_t blen) { int i, bi; for (i = 0, bi = 0; i < 64 && val != 0; i++) { if (val & 1) { if (bits[i] == '\0' || bits[i] == ' ') goto fail; buf[bi++] = bits[i]; } val >>= 1; } buf[bi++] = '\0'; return buf; fail: snprintf(buf, blen, "%llx", (unsigned long long)val); return buf; } const char * flowspec_fmt_bin_op(const uint8_t *comp, int complen, int *off, const char *bits) { static char buf[36], bit[17], mask[17]; uint64_t val, val2 = 0; uint8_t op, op2 = 0; int len, len2 = 0; if (*off == -1) return ""; if (complen < *off + 1) return "bad encoding"; op = comp[*off]; len = FLOWSPEC_OP_LEN(op) + 1; if (complen < *off + len) return "bad encoding"; val = extract_val(comp + *off + 1, FLOWSPEC_OP_LEN(op)); if ((op & FLOWSPEC_OP_EOL) == 0) { if (complen < *off + len + 1) return "bad encoding"; op2 = comp[*off + len]; /* * Check if this is a mask specification else fall back * to basic rules. */ if (op2 & FLOWSPEC_OP_AND && (op & FLOWSPEC_OP_BIT_MASK) == FLOWSPEC_OP_BIT_MATCH && (op2 & FLOWSPEC_OP_BIT_MASK) == FLOWSPEC_OP_BIT_NOT) { len2 = FLOWSPEC_OP_LEN(op2) + 1; val2 = extract_val(comp + *off + len + 1, FLOWSPEC_OP_LEN(op2)); } else op2 = 0; } if (op2 & FLOWSPEC_OP_AND) { val2 |= val; snprintf(buf, sizeof(buf), "%s / %s", fmt_flags(val, bits, bit, sizeof(bit)), fmt_flags(val2, bits, mask, sizeof(mask))); } else { switch (op & FLOWSPEC_OP_BIT_MASK) { case 0: snprintf(buf, sizeof(buf), "%s", fmt_flags(val, bits, bit, sizeof(bit))); break; case FLOWSPEC_OP_BIT_NOT: snprintf(buf, sizeof(buf), "/ %s", fmt_flags(val, bits, mask, sizeof(mask))); break; case FLOWSPEC_OP_BIT_MATCH: snprintf(buf, sizeof(buf), "%s / %s", fmt_flags(val, bits, bit, sizeof(bit)), fmt_flags(val, bits, mask, sizeof(mask))); break; case FLOWSPEC_OP_BIT_NOT | FLOWSPEC_OP_BIT_MATCH: snprintf(buf, sizeof(buf), "???"); break; } } if (op2 & FLOWSPEC_OP_EOL || op & FLOWSPEC_OP_EOL) *off = -1; else *off += len + len2; return buf; } openbgpd-8.8/src/bgpctl/bgpctl.8.in100644 001750 001750 00000032343 14751151130 0012707.\" $OpenBSD: bgpctl.8,v 1.112 2024/08/14 19:10:51 claudio Exp $ .\" .\" Copyright (c) 2003 Henning Brauer .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .Dd $Mdocdate: August 14 2024 $ .Dt BGPCTL 8 .Os .Sh NAME .Nm bgpctl .Nd control the BGP routing daemon .Sh SYNOPSIS .Nm bgpctl .Op Fl jnV .Op Fl s Ar socket .Ar command .Op Ar argument ... .Sh DESCRIPTION The .Nm program controls the .Xr bgpd 8 daemon. Commands may be abbreviated to the minimum unambiguous prefix; for example, .Cm s su for .Cm show summary . .Pp The options are as follows: .Bl -tag -width Ds .It Fl j Create output as JSON object. .It Fl n Show neighbors' IP addresses instead of their description. .It Fl s Ar socket Use .Ar socket to communicate with .Xr bgpd 8 instead of the default .Pa @RUNSTATEDIR@/bgpd.sock. where .Ar is the routing domain .Nm is running in. To administer .Xr bgpd 8 in a different routing domain, run .Nm in said routing domain. .It Fl V Show the version and exit. .El .Pp The commands are as follows: .Bl -tag -width xxxxxx .It Xo .Cm fib .Op Cm table Ar number .Cm couple .Xc Insert the learned routes into the specified Forwarding Information Base a.k.a. the kernel routing table. .It Xo .Cm fib .Op Cm table Ar number .Cm decouple .Xc Remove the learned routes from the specified Forwarding Information Base a.k.a. the kernel routing table. .It Cm flowspec add Ar family rule Op Cm set Ar argument ... Add the specified flowspec rule to the list of announced rules. Currently .Ar family can be either .Cm inet or .Cm inet6 . It is possible to set various path attributes with additional arguments. Adding a rule will replace an existing equal rule, including rules loaded from the configuration. See .Xr bgpd.conf 5 for information on how to write a flowspec rule. .It Cm flowspec delete Ar family rule Remove the specified flowspec rule from the list of announced rules. .It Cm flowspec flush Remove all dynamically added (i.e. with .Nm Cm flowspec add ) flowspec rules from the list of announced rules. .It Cm flowspec show Ar family Show all announced flowspec rules. .Ar family , if given, limits the output to the given address family. The supported families are .Em inet and .Em inet6 . .It Cm log brief Disable verbose debug logging. .It Cm log verbose Enable verbose debug logging. .It Cm neighbor Ar peer Cm clear Op Ar reason Stop and restart the BGP session to the specified neighbor. If a .Ar reason is provided, the .Ar reason is sent as Administrative Shutdown Communication to the neighbor. .Ar peer may be the neighbor's address, description or the word .Cm group followed by a group description. .It Cm neighbor Ar peer Cm destroy Destroy a previously cloned peer. The peer must be down before calling this function. .Ar peer may be the neighbor's address, description or the word .Cm group followed by a group description. .It Cm neighbor Ar peer Cm down Op Ar reason Take the BGP session to the specified neighbor down. If a .Ar reason is provided, the .Ar reason is sent as Administrative Shutdown Communication to the neighbor. .Ar peer may be the neighbor's address, description or the word .Cm group followed by a group description. .It Cm neighbor Ar peer Cm refresh Request the neighbor to re-send all routes. Note that the neighbor is not obliged to re-send all routes, or any routes at all, even if it announced the route refresh capability. .Ar peer may be the neighbor's address, description or the word .Cm group followed by a group description. .It Cm neighbor Ar peer Cm up Bring the BGP session to the specified neighbor up. .Ar peer may be the neighbor's address, description or the word .Cm group followed by a group description. .It Cm network add Ar prefix Op Ar argument ... Add the specified prefix to the list of announced networks. It is possible to set various path attributes with additional arguments. Adding a prefix will replace an existing equal prefix, including prefixes loaded from the configuration. .It Xo .Cm network bulk add .Op Ar argument ... .Xc Bulk add specified prefixes to the list of announced networks. Prefixes should be sent via stdin. It is possible to set various path attributes with additional arguments. .It Cm network bulk delete Bulk remove the specified prefixes from the list of announced networks. Prefixes should be sent via stdin. .It Cm network delete Ar prefix Remove the specified prefix from the list of announced networks. .It Cm network flush Remove all dynamically added (i.e. with .Nm Cm network add ) prefixes from the list of announced networks. .It Cm network mrt file Ar file filter Import networks from an MRT table dump for debugging purposes. .Ar filter can be specified similarly to the .Ar show mrt command. Only networks matching the filter will be imported. .It Cm network show Ar family Show all announced networks. .Ar family , if given, limits the output to the given address family. The supported families are .Em inet and .Em inet6 . .It Cm reload Op reason Reload the configuration file. Changes to the following neighbor options in .Xr bgpd.conf 5 only take effect when the session is reset: .Ic ipsec and .Ic tcp md5sig . .It Cm show fib Ar filter Show routes from .Xr bgpd 8 Ns 's view of the Forwarding Information Base. .Ar filter can be an IP address, in which case the route to this address is shown, or a flag: .Pp .Bl -tag -width tableXnumber -compact .It Cm bgp Show only routes originating from .Xr bgpd 8 itself. .It Cm connected Show only connected routes. .It Cm inet Show only IPv4 routes. .It Cm inet6 Show only IPv6 routes. .It Cm nexthop Show only routes required to reach a BGP nexthop. .It Cm static Show only static routes. .It Cm table Ar number Show the routing table with ID .Ar number instead of the default routing table with ID 0. .El .It Cm show interfaces Show the interface states. .It Cm show metrics Dump various BGP statistics in OpenMetrics format. .It Xo .Cm show mrt .Op Ar options .Ar filter .Xc Show routes from an MRT table dump file. .Ar filter can be an IP address, a CIDR prefix, an AS filter, a combination or nothing: .Pp .Bl -tag -width "address/len or-shorter" -compact .It Ar address Show best matching route for address. .It Ar address Ns Li / Ns Ar len Show RIB entry for this CIDR prefix. .It Xo .Ar address Ns Li / Ns Ar len .Cm all .Xc Show all entries in the specified range. .\".It Ar address/len Cm longer-prefixes .It Xo .Ar address Ns Li / Ns Ar len .Cm or-shorter .Xc Show all entries covering and including the specified prefix. .It Cm as Ar as Show all entries with .Ar as anywhere in the AS path. .It Cm empty-as Show all entries that are internal routes with no AS's in the AS path. .It Cm neighbor Ar ip Show only entries from the specified peer. .It Cm peer-as Ar as Show all entries with .Ar as as leftmost AS. .It Cm source-as Ar as Show all entries with .Ar as as rightmost AS. .It Cm transit-as Ar as Show all entries with .Ar as anywhere but rightmost. .El .Pp Additionally, the following .Ar options are defined: .Pp .Bl -tag -width "file name" -compact .It Cm detail Show more detailed output for matching routes. .It Ar family Limit the output to the given address family. .It Cm file Ar name Read the MRT dump from file .Ar name instead of using stdin. .It Cm peers Print the neighbor table of MRT TABLE_DUMP_V2 dumps. Using this on other table dumps will only show the neighbor of the first entry. .El .Pp Multiple options and filters can be used at the same time. .It Cm show neighbor Ar peer modifier Show detailed information about the neighbor identified by .Ar peer , according to the given .Ar modifier : .Pp .Bl -tag -width messages -compact .It Cm messages Show statistics about sent and received BGP messages. .It Cm terse Show statistics in an easily parseable terse format. The printed numbers are the sent and received open, sent and received notifications, sent and received updates, sent and received keepalives, and sent and received route refresh messages plus the current and maximum prefix count, the number of sent and received updates, sent and received withdraws, the neighbor's address (or subnet, for a template), AS number, and finally description. .It Cm timers Show the BGP timers. .El .Ar peer may be the neighbor's address, description or the word .Cm group followed by a group description. .It Cm show nexthop Show the list of BGP nexthops and the result of their validity check. .It Xo .Cm show rib .Op Ar options .Ar filter .Xc Show routes from the .Xr bgpd 8 Routing Information Base. .Ar filter can be an IP address, a CIDR prefix, an AS filter or nothing: .Pp .Bl -tag -width "address/len or-shorter" -compact .It Ar address Show best matching route for address. .It Ar address Ns Li / Ns Ar len Show RIB entry for this CIDR prefix. .It Xo .Ar address Ns Li / Ns Ar len .Cm all .Xc Show all entries in the specified range. .\".It Ar address/len Cm longer-prefixes .\".It Ar address/len Cm or-longer .It Xo .Ar address Ns Li / Ns Ar len .Cm or-shorter .Xc Show all entries covering and including the specified prefix. .It Cm as Ar as Show all entries with .Ar as anywhere in the AS path. .It Cm avs Pq Ic valid | unknown | invalid Show all entries with matching ASAP Validation State (AVS). .It Cm community Ar community Show all entries with community .Ar community . .It Cm empty-as Show all entries that are internal routes with no AS's in the AS path. .It Cm large-community Ar large-community Show all entries with large-community .Ar large-community . .It Cm memory Show RIB memory statistics. .It Cm neighbor Ar peer Show only entries from the specified peer. .It Cm neighbor group Ar description Show only entries from the specified peer group. .It Cm ovs Pq Ic valid | not-found | invalid Show all entries with matching Origin Validation State (OVS). .It Cm path-id Ar pathid Show only entries which match the specified .Ar pathid . Must be used together with either .Cm neighbor or .Cm out . .It Cm peer-as Ar as Show all entries with .Ar as as leftmost AS. .It Cm source-as Ar as Show all entries with .Ar as as rightmost AS. .It Cm summary This is the same as the .Ic show summary command. .It Cm table Ar rib Show only entries from the specified RIB table. .It Cm transit-as Ar as Show all entries with .Ar as anywhere but rightmost. .El .Pp Additionally, the following .Ar options are defined: .Pp .Bl -tag -width "disqualified" -compact .It Cm best Alias for .Ic selected . .It Cm detail Show more detailed output for matching routes. .It Cm disqualified Show only routes which are not eligible. .It Cm error Show only prefixes which are marked invalid and were treated as withdrawn. .It Ar family Limit the output to the given address family. .It Cm filtered Show only routes which were filtered out. Requires .Ic rde rib Loc-RIB include filtered to be set in the config. .It Cm in Show routes from the unfiltered Adj-RIB-In. The .Cm neighbor needs to be specified. .It Cm leaked Show only routes where a route leak was detected. .It Cm out Show the filtered routes sent to a neighbor. The .Cm neighbor needs to be specified. .It Cm selected Show only selected routes. .It Cm ssv Show each RIB entry as a single line, with fields separated by semicolons. Only works if .Cm detail is specified. .El .Pp Options are silently ignored when used together with .Ar summary or .Ar memory . Multiple options can be used at the same time and the .Ar neighbor filter can be combined with other filters. .It Cm show rtr Show a list of all .Em RTR sessions, including information about the session state. .It Cm show sets Show a list summarizing all .Em roa-set , .Em as-set , .Em prefix-set , and .Em origin-set tables. .It Cm show summary Show a list of all neighbors, including information about the session state and message counters: .Pp .Bl -tag -width xxxxxxxxxxxxxx -compact .It Neighbor Description of the neighbor. .It AS Autonomous system number. .It MsgRcvd Number of messages received from the neighbor. .It MsgSent Number of messages sent to the neighbor. .It OutQ Number of outgoing messages queued. .It Up/Down Number of days and hours that the session has been up. .It State/PrfRcvd State of the session / Number of routes received. The session is up if there is no information for the State column (Established is not displayed). .El .It Cm show summary terse Show a list of all neighbors, including information about the session state, in a terse format. .It Cm show tables Show a list of all currently loaded fib routing tables. .El .Sh FILES .Bl -tag -width "@RUNSTATEDIR@/bgpd.sockXXX" -compact .It Pa @SYSCONFDIR@/bgpd.conf default .Xr bgpd 8 configuration file .It Pa @RUNSTATEDIR@/bgpd.sock default .Xr bgpd 8 control socket .El .Sh SEE ALSO .Xr bgpd.conf 5 , .Xr bgpd 8 , .Xr bgplg 8 , .Xr bgplgsh 8 .Sh HISTORY The .Nm program first appeared in .Ox 3.5 . openbgpd-8.8/src/bgplgd/Makefile.am100644 001750 001750 00000003427 14576036603 0012773# # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. AM_CPPFLAGS = -I$(top_srcdir)/include AM_CPPFLAGS += -I$(top_srcdir)/src/bgpd ACLOCAL_AMFLAGS = -Im4 sbin_PROGRAMS = bgplgd man_MANS = bgplgd.8 EXTRA_DIST = bgplgd.8.in CLEANFILES = $(man_MANS) bgplgd_CFLAGS = $(AM_CFLAGS) bgplgd_CFLAGS += -DSYSCONFDIR=\"$(sysconfdir)\" bgplgd_CFLAGS += -DRUNSTATEDIR=\"$(runstatedir)\" bgplgd_CFLAGS += -DWWWRUNSTATEDIR=\"$(wwwrunstatedir)\" bgplgd_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) -lutil -lm bgplgd_LDADD += $(top_builddir)/compat/libcompat.la bgplgd_LDADD += $(top_builddir)/compat/libcompatnoopt.la bgplgd_SOURCES = bgplgd.c bgplgd_SOURCES += qs.c bgplgd_SOURCES += slowcgi.c bgplgd_DEPENDENCIES = $(man_MANS) noinst_HEADERS = bgplgd.h noinst_HEADERS += http.h noinst_HEADERS += slowcgi.h bgplgd.8: bgplgd.8.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@BGPLGD_USER[@]|$(BGPLGD_USER)|g' \ -e 's|@WWW_USER[@]|$(WWW_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ -e 's|@WWWRUNSTATEDIR[@]|$(wwwrunstatedir)|g' \ '$(srcdir)/bgplgd.8.in' >$@ openbgpd-8.8/src/bgplgd/bgplgd.h100644 001750 001750 00000004446 14730105010 0012326/* $OpenBSD: bgplgd.h,v 1.5 2024/12/03 10:38:06 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define QS_NEIGHBOR 1 #define QS_GROUP 2 #define QS_AS 3 #define QS_PREFIX 4 #define QS_COMMUNITY 5 #define QS_EXTCOMMUNITY 6 #define QS_LARGECOMMUNITY 7 #define QS_AF 8 #define QS_RIB 9 #define QS_OVS 10 #define QS_BEST 11 #define QS_ALL 12 #define QS_SHORTER 13 #define QS_ERROR 14 #define QS_AVS 15 #define QS_INVALID 16 #define QS_LEAKED 17 #define QS_FILTERED 18 #define QS_MAX 19 /* too add: empty-as, peer-as, source-as, transit-as */ #define QS_MASK_NEIGHBOR ((1 << QS_NEIGHBOR) | (1 << QS_GROUP)) #define QS_MASK_ADJRIB \ ((1 << QS_NEIGHBOR) | (1 << QS_GROUP) | (1 << QS_AS) | \ (1 << QS_PREFIX) | (1 << QS_COMMUNITY) | \ (1 << QS_EXTCOMMUNITY) | (1 << QS_LARGECOMMUNITY) | \ (1 << QS_AF) | (1 << QS_OVS) | (1 << QS_BEST) | \ (1 << QS_ALL) | (1 << QS_SHORTER) | (1 << QS_ERROR) | \ (1 << QS_AVS) | (1 << QS_INVALID) | (1 << QS_LEAKED) | \ (1 << QS_FILTERED)) #define QS_MASK_RIB (QS_MASK_ADJRIB | (1 << QS_RIB)) struct cmd; struct lg_ctx { const struct cmd *command; unsigned int qs_mask; unsigned int qs_set; union { char *string; int one; } qs_args[QS_MAX]; }; extern char *bgpctlpath; extern char *bgpctlsock; /* qs.c - query string handling */ int parse_querystring(const char *, struct lg_ctx *); size_t qs_argv(char **, size_t, size_t, struct lg_ctx *, int); /* main entry points for slowcgi */ int prep_request(struct lg_ctx *, const char *, const char *, const char *); void bgpctl_call(struct lg_ctx *); openbgpd-8.8/src/bgplgd/http.h100644 001750 001750 00000006741 14264017711 0012062/* $OpenBSD: http.h,v 1.1 2022/06/28 16:11:30 claudio Exp $ */ /* * Copyright (c) 2012 - 2015 Reyk Floeter * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ struct http_error { int error_code; const char *error_name; }; /* * HTTP status codes based on IANA assignments (2014-06-11 version): * https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml * plus legacy (306) and non-standard (420). */ #define HTTP_ERRORS { \ { 100, "Continue" }, \ { 101, "Switching Protocols" }, \ { 102, "Processing" }, \ /* 103-199 unassigned */ \ { 200, "OK" }, \ { 201, "Created" }, \ { 202, "Accepted" }, \ { 203, "Non-Authoritative Information" }, \ { 204, "No Content" }, \ { 205, "Reset Content" }, \ { 206, "Partial Content" }, \ { 207, "Multi-Status" }, \ { 208, "Already Reported" }, \ /* 209-225 unassigned */ \ { 226, "IM Used" }, \ /* 227-299 unassigned */ \ { 300, "Multiple Choices" }, \ { 301, "Moved Permanently" }, \ { 302, "Found" }, \ { 303, "See Other" }, \ { 304, "Not Modified" }, \ { 305, "Use Proxy" }, \ { 306, "Switch Proxy" }, \ { 307, "Temporary Redirect" }, \ { 308, "Permanent Redirect" }, \ /* 309-399 unassigned */ \ { 400, "Bad Request" }, \ { 401, "Unauthorized" }, \ { 402, "Payment Required" }, \ { 403, "Forbidden" }, \ { 404, "Not Found" }, \ { 405, "Method Not Allowed" }, \ { 406, "Not Acceptable" }, \ { 407, "Proxy Authentication Required" }, \ { 408, "Request Timeout" }, \ { 409, "Conflict" }, \ { 410, "Gone" }, \ { 411, "Length Required" }, \ { 412, "Precondition Failed" }, \ { 413, "Payload Too Large" }, \ { 414, "URI Too Long" }, \ { 415, "Unsupported Media Type" }, \ { 416, "Range Not Satisfiable" }, \ { 417, "Expectation Failed" }, \ { 418, "I'm a teapot" }, \ /* 419-421 unassigned */ \ { 420, "Enhance Your Calm" }, \ { 422, "Unprocessable Entity" }, \ { 423, "Locked" }, \ { 424, "Failed Dependency" }, \ /* 425 unassigned */ \ { 426, "Upgrade Required" }, \ /* 427 unassigned */ \ { 428, "Precondition Required" }, \ { 429, "Too Many Requests" }, \ /* 430 unassigned */ \ { 431, "Request Header Fields Too Large" }, \ /* 432-450 unassigned */ \ { 451, "Unavailable For Legal Reasons" }, \ /* 452-499 unassigned */ \ { 500, "Internal Server Error" }, \ { 501, "Not Implemented" }, \ { 502, "Bad Gateway" }, \ { 503, "Service Unavailable" }, \ { 504, "Gateway Timeout" }, \ { 505, "HTTP Version Not Supported" }, \ { 506, "Variant Also Negotiates" }, \ { 507, "Insufficient Storage" }, \ { 508, "Loop Detected" }, \ /* 509 unassigned */ \ { 510, "Not Extended" }, \ { 511, "Network Authentication Required" }, \ /* 512-599 unassigned */ \ { 0, NULL } \ } openbgpd-8.8/src/bgplgd/slowcgi.h100644 001750 001750 00000004040 14264017711 0012540/* $OpenBSD: slowcgi.h,v 1.1 2022/06/28 16:11:30 claudio Exp $ */ /* * Copyright (c) 2013 David Gwynne * Copyright (c) 2013 Florian Obser * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define FCGI_BEGIN_REQUEST 1 #define FCGI_ABORT_REQUEST 2 #define FCGI_END_REQUEST 3 #define FCGI_PARAMS 4 #define FCGI_STDIN 5 #define FCGI_STDOUT 6 #define FCGI_STDERR 7 #define FCGI_DATA 8 #define FCGI_GET_VALUES 9 #define FCGI_GET_VALUES_RESULT 10 #define FCGI_UNKNOWN_TYPE 11 #define FCGI_MAXTYPE (FCGI_UNKNOWN_TYPE) struct loggers { __dead void (*err)(int, const char *, ...) __attribute__((__format__ (printf, 2, 3))); __dead void (*errx)(int, const char *, ...) __attribute__((__format__ (printf, 2, 3))); void (*warn)(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void (*warnx)(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void (*info)(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void (*debug)(const char *, ...) __attribute__((__format__ (printf, 1, 2))); }; extern const struct loggers *logger; #define lerr(_e, _f...) logger->err((_e), _f) #define lerrx(_e, _f...) logger->errx((_e), _f) #define lwarn(_f...) logger->warn(_f) #define lwarnx(_f...) logger->warnx(_f) #define linfo(_f...) logger->info(_f) #define ldebug(_f...) logger->debug(_f) openbgpd-8.8/src/bgplgd/Makefile.in100644 001750 001750 00000073103 14751151141 0012770# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY, to the extent permitted by law; without # even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. @SET_MAKE@ # # Copyright (c) 2019 Brent Cook # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ false; \ elif test -n '$(MAKE_HOST)'; then \ true; \ elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ true; \ else \ false; \ fi; \ } am__make_running_with_option = \ case $${target_option-} in \ ?) ;; \ *) echo "am__make_running_with_option: internal error: invalid" \ "target option '$${target_option-}' specified" >&2; \ exit 1;; \ esac; \ has_opt=no; \ sane_makeflags=$$MAKEFLAGS; \ if $(am__is_gnu_make); then \ sane_makeflags=$$MFLAGS; \ else \ case $$MAKEFLAGS in \ *\\[\ \ ]*) \ bs=\\; \ sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ esac; \ fi; \ skip_next=no; \ strip_trailopt () \ { \ flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ }; \ for flg in $$sane_makeflags; do \ test $$skip_next = yes && { skip_next=no; continue; }; \ case $$flg in \ *=*|--*) continue;; \ -*I) strip_trailopt 'I'; skip_next=yes;; \ -*I?*) strip_trailopt 'I';; \ -*O) strip_trailopt 'O'; skip_next=yes;; \ -*O?*) strip_trailopt 'O';; \ -*l) strip_trailopt 'l'; skip_next=yes;; \ -*l?*) strip_trailopt 'l';; \ -[dEDm]) skip_next=yes;; \ -[JT]) skip_next=yes;; \ esac; \ case $$flg in \ *$$target_option*) has_opt=yes; break;; \ esac; \ done; \ test $$has_opt = yes am__make_dryrun = (target_option=n; $(am__make_running_with_option)) am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) pkgdatadir = $(datadir)/@PACKAGE@ pkgincludedir = $(includedir)/@PACKAGE@ pkglibdir = $(libdir)/@PACKAGE@ pkglibexecdir = $(libexecdir)/@PACKAGE@ am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd install_sh_DATA = $(install_sh) -c -m 644 install_sh_PROGRAM = $(install_sh) -c install_sh_SCRIPT = $(install_sh) -c INSTALL_HEADER = $(INSTALL_DATA) transform = $(program_transform_name) NORMAL_INSTALL = : PRE_INSTALL = : POST_INSTALL = : NORMAL_UNINSTALL = : PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ sbin_PROGRAMS = bgplgd$(EXEEXT) subdir = src/bgplgd ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \ $(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)" PROGRAMS = $(sbin_PROGRAMS) am_bgplgd_OBJECTS = bgplgd-bgplgd.$(OBJEXT) bgplgd-qs.$(OBJEXT) \ bgplgd-slowcgi.$(OBJEXT) bgplgd_OBJECTS = $(am_bgplgd_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = bgplgd_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(bgplgd_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false am__v_P_1 = : AM_V_GEN = $(am__v_GEN_@AM_V@) am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) am__v_GEN_0 = @echo " GEN " $@; am__v_GEN_1 = AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = ./$(DEPDIR)/bgplgd-bgplgd.Po \ ./$(DEPDIR)/bgplgd-qs.Po ./$(DEPDIR)/bgplgd-slowcgi.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ $(AM_CFLAGS) $(CFLAGS) AM_V_CC = $(am__v_CC_@AM_V@) am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) am__v_CC_0 = @echo " CC " $@; am__v_CC_1 = CCLD = $(CC) LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = SOURCES = $(bgplgd_SOURCES) DIST_SOURCES = $(bgplgd_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ *) f=$$p;; \ esac; am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; am__install_max = 40 am__nobase_strip_setup = \ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` am__nobase_strip = \ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" am__nobase_list = $(am__nobase_strip_setup); \ for p in $$list; do echo "$$p $$p"; done | \ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ if (++n[$$2] == $(am__install_max)) \ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ END { for (dir in files) print dir, files[dir] }' am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__uninstall_files_from_dir = { \ test -z "$$files" \ || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } man8dir = $(mandir)/man8 NROFF = nroff MANS = $(man_MANS) HEADERS = $(noinst_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) # Read a list of newline-separated strings from the standard input, # and print each of them once, without duplicates. Input order is # *not* preserved. am__uniquify_input = $(AWK) '\ BEGIN { nonempty = 0; } \ { items[$$0] = 1; nonempty = 1; } \ END { if (nonempty) { for (i in items) print i; }; } \ ' # Make sure the list of sources is unique. This is necessary because, # e.g., the same source file might be shared among _SOURCES variables # for different programs/libraries. am__define_uniq_tagged_files = \ list='$(am__tagged_files)'; \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CFLAGS = @AM_CFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LDFLAGS = @AM_LDFLAGS@ AR = @AR@ AUTOCONF = @AUTOCONF@ AUTOHEADER = @AUTOHEADER@ AUTOMAKE = @AUTOMAKE@ AWK = @AWK@ BGPD_USER = @BGPD_USER@ BGPLGD_USER = @BGPLGD_USER@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ CSCOPE = @CSCOPE@ CTAGS = @CTAGS@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ DLLTOOL = @DLLTOOL@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ FGREP = @FGREP@ GREP = @GREP@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ PACKAGE_NAME = @PACKAGE_NAME@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_URL = @PACKAGE_URL@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ STRIP = @STRIP@ VERSION = @VERSION@ WWW_USER = @WWW_USER@ YACC = @YACC@ YFLAGS = @YFLAGS@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ abs_top_srcdir = @abs_top_srcdir@ ac_ct_AR = @ac_ct_AR@ ac_ct_CC = @ac_ct_CC@ ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ am__include = @am__include@ am__leading_dot = @am__leading_dot@ am__quote = @am__quote@ am__tar = @am__tar@ am__untar = @am__untar@ bindir = @bindir@ build = @build@ build_alias = @build_alias@ build_cpu = @build_cpu@ build_os = @build_os@ build_vendor = @build_vendor@ builddir = @builddir@ datadir = @datadir@ datarootdir = @datarootdir@ docdir = @docdir@ dvidir = @dvidir@ exec_prefix = @exec_prefix@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ host_os = @host_os@ host_vendor = @host_vendor@ htmldir = @htmldir@ includedir = @includedir@ infodir = @infodir@ install_sh = @install_sh@ libdir = @libdir@ libexecdir = @libexecdir@ localedir = @localedir@ localstatedir = @localstatedir@ mandir = @mandir@ mkdir_p = @mkdir_p@ oldincludedir = @oldincludedir@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ wwwrunstatedir = @wwwrunstatedir@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src/bgpd ACLOCAL_AMFLAGS = -Im4 man_MANS = bgplgd.8 EXTRA_DIST = bgplgd.8.in CLEANFILES = $(man_MANS) bgplgd_CFLAGS = $(AM_CFLAGS) -DSYSCONFDIR=\"$(sysconfdir)\" \ -DRUNSTATEDIR=\"$(runstatedir)\" \ -DWWWRUNSTATEDIR=\"$(wwwrunstatedir)\" bgplgd_LDADD = $(PLATFORM_LDADD) $(PROG_LDADD) -lutil -lm \ $(top_builddir)/compat/libcompat.la \ $(top_builddir)/compat/libcompatnoopt.la bgplgd_SOURCES = bgplgd.c qs.c slowcgi.c bgplgd_DEPENDENCIES = $(man_MANS) noinst_HEADERS = bgplgd.h http.h slowcgi.h all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ && { if test -f $@; then exit 0; else break; fi; }; \ exit 1;; \ esac; \ done; \ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/bgplgd/Makefile'; \ $(am__cd) $(top_srcdir) && \ $(AUTOMAKE) --foreign src/bgplgd/Makefile Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status @case '$?' in \ *config.status*) \ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ *) \ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ esac; $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(top_srcdir)/configure: $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(ACLOCAL_M4): $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): install-sbinPROGRAMS: $(sbin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ if test -n "$$list"; then \ echo " $(MKDIR_P) '$(DESTDIR)$(sbindir)'"; \ $(MKDIR_P) "$(DESTDIR)$(sbindir)" || exit 1; \ fi; \ for p in $$list; do echo "$$p $$p"; done | \ sed 's/$(EXEEXT)$$//' | \ while read p p1; do if test -f $$p \ || test -f $$p1 \ ; then echo "$$p"; echo "$$p"; else :; fi; \ done | \ sed -e 'p;s,.*/,,;n;h' \ -e 's|.*|.|' \ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ sed 'N;N;N;s,\n, ,g' | \ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ if ($$2 == $$4) files[d] = files[d] " " $$1; \ else { print "f", $$3 "/" $$4, $$1; } } \ END { for (d in files) print "f", d, files[d] }' | \ while read type dir files; do \ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ test -z "$$files" || { \ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(sbindir)$$dir'"; \ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(sbindir)$$dir" || exit $$?; \ } \ ; done uninstall-sbinPROGRAMS: @$(NORMAL_UNINSTALL) @list='$(sbin_PROGRAMS)'; test -n "$(sbindir)" || list=; \ files=`for p in $$list; do echo "$$p"; done | \ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ -e 's/$$/$(EXEEXT)/' \ `; \ test -n "$$list" || exit 0; \ echo " ( cd '$(DESTDIR)$(sbindir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(sbindir)" && rm -f $$files clean-sbinPROGRAMS: @list='$(sbin_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ rm -f $$list || exit $$?; \ test -n "$(EXEEXT)" || exit 0; \ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ echo " rm -f" $$list; \ rm -f $$list bgplgd$(EXEEXT): $(bgplgd_OBJECTS) $(bgplgd_DEPENDENCIES) $(EXTRA_bgplgd_DEPENDENCIES) @rm -f bgplgd$(EXEEXT) $(AM_V_CCLD)$(bgplgd_LINK) $(bgplgd_OBJECTS) $(bgplgd_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgplgd-bgplgd.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgplgd-qs.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bgplgd-slowcgi.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @echo '# dummy' >$@-t && $(am__mv) $@-t $@ am--depfiles: $(am__depfiles_remade) .c.o: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ @am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ @am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< bgplgd-bgplgd.o: bgplgd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -MT bgplgd-bgplgd.o -MD -MP -MF $(DEPDIR)/bgplgd-bgplgd.Tpo -c -o bgplgd-bgplgd.o `test -f 'bgplgd.c' || echo '$(srcdir)/'`bgplgd.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgplgd-bgplgd.Tpo $(DEPDIR)/bgplgd-bgplgd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bgplgd.c' object='bgplgd-bgplgd.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -c -o bgplgd-bgplgd.o `test -f 'bgplgd.c' || echo '$(srcdir)/'`bgplgd.c bgplgd-bgplgd.obj: bgplgd.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -MT bgplgd-bgplgd.obj -MD -MP -MF $(DEPDIR)/bgplgd-bgplgd.Tpo -c -o bgplgd-bgplgd.obj `if test -f 'bgplgd.c'; then $(CYGPATH_W) 'bgplgd.c'; else $(CYGPATH_W) '$(srcdir)/bgplgd.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgplgd-bgplgd.Tpo $(DEPDIR)/bgplgd-bgplgd.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='bgplgd.c' object='bgplgd-bgplgd.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -c -o bgplgd-bgplgd.obj `if test -f 'bgplgd.c'; then $(CYGPATH_W) 'bgplgd.c'; else $(CYGPATH_W) '$(srcdir)/bgplgd.c'; fi` bgplgd-qs.o: qs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -MT bgplgd-qs.o -MD -MP -MF $(DEPDIR)/bgplgd-qs.Tpo -c -o bgplgd-qs.o `test -f 'qs.c' || echo '$(srcdir)/'`qs.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgplgd-qs.Tpo $(DEPDIR)/bgplgd-qs.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='qs.c' object='bgplgd-qs.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -c -o bgplgd-qs.o `test -f 'qs.c' || echo '$(srcdir)/'`qs.c bgplgd-qs.obj: qs.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -MT bgplgd-qs.obj -MD -MP -MF $(DEPDIR)/bgplgd-qs.Tpo -c -o bgplgd-qs.obj `if test -f 'qs.c'; then $(CYGPATH_W) 'qs.c'; else $(CYGPATH_W) '$(srcdir)/qs.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgplgd-qs.Tpo $(DEPDIR)/bgplgd-qs.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='qs.c' object='bgplgd-qs.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -c -o bgplgd-qs.obj `if test -f 'qs.c'; then $(CYGPATH_W) 'qs.c'; else $(CYGPATH_W) '$(srcdir)/qs.c'; fi` bgplgd-slowcgi.o: slowcgi.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -MT bgplgd-slowcgi.o -MD -MP -MF $(DEPDIR)/bgplgd-slowcgi.Tpo -c -o bgplgd-slowcgi.o `test -f 'slowcgi.c' || echo '$(srcdir)/'`slowcgi.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgplgd-slowcgi.Tpo $(DEPDIR)/bgplgd-slowcgi.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='slowcgi.c' object='bgplgd-slowcgi.o' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -c -o bgplgd-slowcgi.o `test -f 'slowcgi.c' || echo '$(srcdir)/'`slowcgi.c bgplgd-slowcgi.obj: slowcgi.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -MT bgplgd-slowcgi.obj -MD -MP -MF $(DEPDIR)/bgplgd-slowcgi.Tpo -c -o bgplgd-slowcgi.obj `if test -f 'slowcgi.c'; then $(CYGPATH_W) 'slowcgi.c'; else $(CYGPATH_W) '$(srcdir)/slowcgi.c'; fi` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/bgplgd-slowcgi.Tpo $(DEPDIR)/bgplgd-slowcgi.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='slowcgi.c' object='bgplgd-slowcgi.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bgplgd_CFLAGS) $(CFLAGS) -c -o bgplgd-slowcgi.obj `if test -f 'slowcgi.c'; then $(CYGPATH_W) 'slowcgi.c'; else $(CYGPATH_W) '$(srcdir)/slowcgi.c'; fi` mostlyclean-libtool: -rm -f *.lo clean-libtool: -rm -rf .libs _libs install-man8: $(man_MANS) @$(NORMAL_INSTALL) @list1=''; \ list2='$(man_MANS)'; \ test -n "$(man8dir)" \ && test -n "`echo $$list1$$list2`" \ || exit 0; \ echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \ $(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \ { for i in $$list1; do echo "$$i"; done; \ if test -n "$$list2"; then \ for i in $$list2; do echo "$$i"; done \ | sed -n '/\.8[a-z]*$$/p'; \ fi; \ } | while read p; do \ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \ echo "$$d$$p"; echo "$$p"; \ done | \ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \ sed 'N;N;s,\n, ,g' | { \ list=; while read file base inst; do \ if test "$$base" = "$$inst"; then list="$$list $$file"; else \ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \ fi; \ done; \ for i in $$list; do echo "$$i"; done | $(am__base_list) | \ while read files; do \ test -z "$$files" || { \ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \ $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \ done; } uninstall-man8: @$(NORMAL_UNINSTALL) @list=''; test -n "$(man8dir)" || exit 0; \ files=`{ for i in $$list; do echo "$$i"; done; \ l2='$(man_MANS)'; for i in $$l2; do echo "$$i"; done | \ sed -n '/\.8[a-z]*$$/p'; \ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \ dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir) ID: $(am__tagged_files) $(am__define_uniq_tagged_files); mkid -fID $$unique tags: tags-am TAGS: tags tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) set x; \ here=`pwd`; \ $(am__define_uniq_tagged_files); \ shift; \ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ test -n "$$unique" || unique=$$empty_fix; \ if test $$# -gt 0; then \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ "$$@" $$unique; \ else \ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ $$unique; \ fi; \ fi ctags: ctags-am CTAGS: ctags ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) $(am__define_uniq_tagged_files); \ test -z "$(CTAGS_ARGS)$$unique" \ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ $$unique GTAGS: here=`$(am__cd) $(top_builddir) && pwd` \ && $(am__cd) $(top_srcdir) \ && gtags -i $(GTAGS_ARGS) "$$here" cscopelist: cscopelist-am cscopelist-am: $(am__tagged_files) list='$(am__tagged_files)'; \ case "$(srcdir)" in \ [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ *) sdir=$(subdir)/$(srcdir) ;; \ esac; \ for i in $$list; do \ if test -f "$$i"; then \ echo "$(subdir)/$$i"; \ else \ echo "$$sdir/$$i"; \ fi; \ done >> $(top_builddir)/cscope.files distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am distdir-am: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ list='$(DISTFILES)'; \ dist_files=`for file in $$list; do echo $$file; done | \ sed -e "s|^$$srcdirstrip/||;t" \ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ case $$dist_files in \ */*) $(MKDIR_P) `echo "$$dist_files" | \ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ sort -u` ;; \ esac; \ for file in $$dist_files; do \ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ if test -d $$d/$$file; then \ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ if test -d "$(distdir)/$$file"; then \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ fi; \ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ else \ test -f "$(distdir)/$$file" \ || cp -p $$d/$$file "$(distdir)/$$file" \ || exit 1; \ fi; \ done check-am: all-am check: check-am all-am: Makefile $(PROGRAMS) $(MANS) $(HEADERS) installdirs: for dir in "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(man8dir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am install-exec: install-exec-am install-data: install-data-am uninstall: uninstall-am install-am: all-am @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am installcheck: installcheck-am install-strip: if test -z '$(STRIP)'; then \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ install; \ else \ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: clean-generic: -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @echo "it deletes files that may require special tools to rebuild." clean: clean-am clean-am: clean-generic clean-libtool clean-sbinPROGRAMS \ mostlyclean-am distclean: distclean-am -rm -f ./$(DEPDIR)/bgplgd-bgplgd.Po -rm -f ./$(DEPDIR)/bgplgd-qs.Po -rm -f ./$(DEPDIR)/bgplgd-slowcgi.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags dvi: dvi-am dvi-am: html: html-am html-am: info: info-am info-am: install-data-am: install-man install-dvi: install-dvi-am install-dvi-am: install-exec-am: install-sbinPROGRAMS install-html: install-html-am install-html-am: install-info: install-info-am install-info-am: install-man: install-man8 install-pdf: install-pdf-am install-pdf-am: install-ps: install-ps-am install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/bgplgd-bgplgd.Po -rm -f ./$(DEPDIR)/bgplgd-qs.Po -rm -f ./$(DEPDIR)/bgplgd-slowcgi.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic mostlyclean: mostlyclean-am mostlyclean-am: mostlyclean-compile mostlyclean-generic \ mostlyclean-libtool pdf: pdf-am pdf-am: ps: ps-am ps-am: uninstall-am: uninstall-man uninstall-sbinPROGRAMS uninstall-man: uninstall-man8 .MAKE: install-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ clean-generic clean-libtool clean-sbinPROGRAMS cscopelist-am \ ctags ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-dvi install-dvi-am install-exec \ install-exec-am install-html install-html-am install-info \ install-info-am install-man install-man8 install-pdf \ install-pdf-am install-ps install-ps-am install-sbinPROGRAMS \ install-strip installcheck installcheck-am installdirs \ maintainer-clean maintainer-clean-generic mostlyclean \ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \ uninstall-man uninstall-man8 uninstall-sbinPROGRAMS .PRECIOUS: Makefile bgplgd.8: bgplgd.8.in $(SED) \ -e 's|@BGPD_USER[@]|$(BGPD_USER)|g' \ -e 's|@BGPLGD_USER[@]|$(BGPLGD_USER)|g' \ -e 's|@WWW_USER[@]|$(WWW_USER)|g' \ -e 's|@SYSCONFDIR[@]|$(sysconfdir)|g' \ -e 's|@RUNSTATEDIR[@]|$(runstatedir)|g' \ -e 's|@WWWRUNSTATEDIR[@]|$(wwwrunstatedir)|g' \ '$(srcdir)/bgplgd.8.in' >$@ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: openbgpd-8.8/src/bgplgd/bgplgd.c100644 001750 001750 00000006706 14730105010 0012322/* $OpenBSD: bgplgd.c,v 1.4 2024/12/03 10:38:06 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include "bgplgd.h" #define NCMDARGS 5 #define OMETRIC_TYPE \ "application/openmetrics-text; version=1.0.0; charset=utf-8" const struct cmd { const char *path; char *args[NCMDARGS]; unsigned int qs_mask; int barenbr; const char *content_type; } cmds[] = { { "/interfaces", { "show", "interfaces", NULL }, 0 }, { "/memory", { "show", "rib", "memory", NULL }, 0 }, { "/neighbors", { "show", "neighbor", NULL }, QS_MASK_NEIGHBOR, 1 }, { "/nexthops", { "show", "nexthop", NULL }, 0 }, { "/rib", { "show", "rib", "detail", NULL }, QS_MASK_RIB }, { "/rib/in", { "show", "rib", "in", "detail", NULL }, QS_MASK_ADJRIB }, { "/rib/out", { "show", "rib", "out", "detail", NULL }, QS_MASK_ADJRIB }, { "/rtr", { "show", "rtr", NULL }, 0 }, { "/sets", { "show", "sets", NULL }, 0 }, { "/summary", { "show", NULL }, 0 }, { "/metrics", { "show", "metrics", NULL }, 0, 0, OMETRIC_TYPE }, { NULL } }; static int command_from_path(const char *path, struct lg_ctx *ctx) { size_t i; for (i = 0; cmds[i].path != NULL; i++) { if (strcmp(cmds[i].path, path) == 0) { ctx->command = &cmds[i]; ctx->qs_mask = cmds[i].qs_mask; return 0; } } return 404; } /* * Prepare a request into a context to call bgpctl. * Parse method, path and querystring. On failure return the correct * HTTP error code. On success 0 is returned. */ int prep_request(struct lg_ctx *ctx, const char *meth, const char *path, const char *qs) { if (meth == NULL || path == NULL) return 500; if (strcmp(meth, "GET") != 0) return 405; if (command_from_path(path, ctx) != 0) return 404; if (parse_querystring(qs, ctx) != 0) return 400; return 0; } /* * Entry point from the FastCGI handler. * This runs as an own process and must use STDOUT and STDERR. * The log functions should no longer be used here. */ void bgpctl_call(struct lg_ctx *ctx) { char *argv[64]; size_t i, argc = 0; argv[argc++] = bgpctlpath; argv[argc++] = "-j"; argv[argc++] = "-s"; argv[argc++] = bgpctlsock; for (i = 0; ctx->command->args[i] != NULL; i++) argv[argc++] = ctx->command->args[i]; argc = qs_argv(argv, argc, sizeof(argv) / sizeof(argv[0]), ctx, ctx->command->barenbr); argv[argc++] = NULL; signal(SIGPIPE, SIG_DFL); /* Write server header first */ if (ctx->command->content_type == NULL) printf("Content-type: application/json\r\n\r\n"); else printf("Content-type: %s\r\n\r\n", ctx->command->content_type); fflush(stdout); execvp(bgpctlpath, argv); err(1, "failed to execute %s", bgpctlpath); } openbgpd-8.8/src/bgplgd/qs.c100644 001750 001750 00000023314 14730105010 0011500/* $OpenBSD: qs.c,v 1.7 2024/12/03 10:38:06 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include "bgplgd.h" #include "slowcgi.h" enum qs_type { ONE, STRING, PREFIX, NUMBER, FAMILY, OVS, AVS, }; const struct qs { unsigned int qs; const char *key; enum qs_type type; } qsargs[] = { { QS_NEIGHBOR, "neighbor", STRING, }, { QS_GROUP, "group", STRING }, { QS_AS, "as", NUMBER }, { QS_PREFIX, "prefix", PREFIX }, { QS_COMMUNITY, "community", STRING }, { QS_EXTCOMMUNITY, "ext-community", STRING }, { QS_LARGECOMMUNITY, "large-community", STRING }, { QS_AF, "af", FAMILY }, { QS_RIB, "rib", STRING }, { QS_OVS, "ovs", OVS }, { QS_BEST, "best", ONE }, { QS_ALL, "all", ONE }, { QS_SHORTER, "or-shorter", ONE }, { QS_ERROR, "error", ONE }, { QS_AVS, "avs", AVS }, { QS_INVALID, "invalid", ONE }, { QS_LEAKED, "leaked", ONE }, { QS_FILTERED, "filtered", ONE }, { 0, NULL } }; const char *qs2str(unsigned int qs); static int hex(char x) { if ('0' <= x && x <= '9') return x - '0'; if ('a' <= x && x <= 'f') return x - 'a' + 10; else return x - 'A' + 10; } static char * urldecode(const char *s, size_t len) { static char buf[256]; size_t i, blen = 0; for (i = 0; i < len; i++) { if (blen >= sizeof(buf)) return NULL; if (s[i] == '+') { buf[blen++] = ' '; } else if (s[i] == '%' && i + 2 < len) { if (isxdigit((unsigned char)s[i + 1]) && isxdigit((unsigned char)s[i + 2])) { char c; c = hex(s[i + 1]) << 4 | hex(s[i + 2]); /* replace NUL chars with space */ if (c == 0) c = ' '; buf[blen++] = c; i += 2; } else buf[blen++] = s[i]; } else { buf[blen++] = s[i]; } } buf[blen] = '\0'; return buf; } static int valid_string(const char *str) { unsigned char c; while ((c = *str++) != '\0') if (!isalnum(c) && !ispunct(c) && c != ' ') return 0; return 1; } /* validate that the input is pure decimal number */ static int valid_number(const char *str) { unsigned char c; int first = 1; while ((c = *str++) != '\0') { /* special handling of 0 */ if (first && c == '0') { if (*str != '\0') return 0; } first = 0; if (!isdigit(c)) return 0; } return 1; } /* validate a prefix, does not support old 10/8 notation but that is ok */ static int valid_prefix(char *str) { struct addrinfo hints, *res; char *p; int mask; if ((p = strrchr(str, '/')) != NULL) { const char *errstr; mask = strtonum(p+1, 0, 128, &errstr); if (errstr) return 0; p[0] = '\0'; } memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_DGRAM; hints.ai_flags = AI_NUMERICHOST; if (getaddrinfo(str, NULL, &hints, &res) != 0) return 0; if (p) { if (res->ai_family == AF_INET && mask > 32) return 0; p[0] = '/'; } freeaddrinfo(res); return 1; } static int parse_value(struct lg_ctx *ctx, unsigned int qs, enum qs_type type, char *val) { /* val can only be NULL if urldecode failed. */ if (val == NULL) { lwarnx("urldecode of querystring failed"); return 400; } switch (type) { case ONE: if (strcmp("1", val) == 0) { ctx->qs_args[qs].one = 1; } else if (strcmp("0", val) == 0) { /* silently ignored */ } else { lwarnx("%s: bad value %s expected 1", qs2str(qs), val); return 400; } break; case STRING: /* limit string to limited ascii chars */ if (!valid_string(val)) { lwarnx("%s: bad string", qs2str(qs)); return 400; } ctx->qs_args[qs].string = strdup(val); if (ctx->qs_args[qs].string == NULL) { lwarn("parse_value"); return 500; } break; case NUMBER: if (!valid_number(val)) { lwarnx("%s: bad number", qs2str(qs)); return 400; } ctx->qs_args[qs].string = strdup(val); if (ctx->qs_args[qs].string == NULL) { lwarn("parse_value"); return 500; } break; case PREFIX: if (!valid_prefix(val)) { lwarnx("%s: bad prefix", qs2str(qs)); return 400; } ctx->qs_args[qs].string = strdup(val); if (ctx->qs_args[qs].string == NULL) { lwarn("parse_value"); return 500; } break; case FAMILY: if (strcasecmp("ipv4", val) == 0 || strcasecmp("ipv6", val) == 0 || strcasecmp("vpnv4", val) == 0 || strcasecmp("vpnv6", val) == 0) { ctx->qs_args[qs].string = strdup(val); if (ctx->qs_args[qs].string == NULL) { lwarn("parse_value"); return 500; } } else { lwarnx("%s: bad value %s", qs2str(qs), val); return 400; } break; case OVS: if (strcmp("not-found", val) == 0 || strcmp("valid", val) == 0 || strcmp("invalid", val) == 0) { ctx->qs_args[qs].string = strdup(val); if (ctx->qs_args[qs].string == NULL) { lwarn("parse_value"); return 500; } } else { lwarnx("%s: bad OVS value %s", qs2str(qs), val); return 400; } break; case AVS: if (strcmp("unknown", val) == 0 || strcmp("valid", val) == 0 || strcmp("invalid", val) == 0) { ctx->qs_args[qs].string = strdup(val); if (ctx->qs_args[qs].string == NULL) { lwarn("parse_value"); return 500; } } else { lwarnx("%s: bad AVS value %s", qs2str(qs), val); return 400; } break; } return 0; } int parse_querystring(const char *param, struct lg_ctx *ctx) { size_t len, i; int rv; while (param && *param) { len = strcspn(param, "="); for (i = 0; qsargs[i].key != NULL; i++) if (strncmp(qsargs[i].key, param, len) == 0) break; if (qsargs[i].key == NULL) { lwarnx("unknown querystring key %.*s", (int)len, param); return 400; } if (((1 << qsargs[i].qs) & ctx->qs_mask) == 0) { lwarnx("querystring param %s not allowed for command", qsargs[i].key); return 400; } if (((1 << qsargs[i].qs) & ctx->qs_set) != 0) { lwarnx("querystring param %s already set", qsargs[i].key); return 400; } ctx->qs_set |= (1 << qsargs[i].qs); if (param[len] != '=') { lwarnx("querystring %s without value", qsargs[i].key); return 400; } param += len + 1; len = strcspn(param, "&"); if ((rv = parse_value(ctx, qsargs[i].qs, qsargs[i].type, urldecode(param, len))) != 0) return rv; param += len; if (*param == '&') param++; } return 0; } size_t qs_argv(char **argv, size_t argc, size_t len, struct lg_ctx *ctx, int barenbr) { /* keep space for the final NULL in argv */ len -= 1; /* NEIGHBOR and GROUP are exclusive */ if (ctx->qs_set & (1 << QS_NEIGHBOR)) { if (!barenbr) if (argc < len) argv[argc++] = "neighbor"; if (argc < len) argv[argc++] = ctx->qs_args[QS_NEIGHBOR].string; } else if (ctx->qs_set & (1 << QS_GROUP)) { if (argc < len) argv[argc++] = "group"; if (argc < len) argv[argc++] = ctx->qs_args[QS_GROUP].string; } if (ctx->qs_set & (1 << QS_AS)) { if (argc < len) argv[argc++] = "source-as"; if (argc < len) argv[argc++] = ctx->qs_args[QS_AS].string; } if (ctx->qs_set & (1 << QS_COMMUNITY)) { if (argc < len) argv[argc++] = "community"; if (argc < len) argv[argc++] = ctx->qs_args[QS_COMMUNITY].string; } if (ctx->qs_set & (1 << QS_EXTCOMMUNITY)) { if (argc < len) argv[argc++] = "ext-community"; if (argc < len) argv[argc++] = ctx->qs_args[QS_EXTCOMMUNITY].string; } if (ctx->qs_set & (1 << QS_LARGECOMMUNITY)) { if (argc < len) argv[argc++] = "large-community"; if (argc < len) argv[argc++] = ctx->qs_args[QS_LARGECOMMUNITY].string; } if (ctx->qs_set & (1 << QS_AF)) { if (argc < len) argv[argc++] = ctx->qs_args[QS_AF].string; } if (ctx->qs_set & (1 << QS_RIB)) { if (argc < len) argv[argc++] = "table"; if (argc < len) argv[argc++] = ctx->qs_args[QS_RIB].string; } if (ctx->qs_set & (1 << QS_OVS)) { if (argc < len) argv[argc++] = "ovs"; if (argc < len) argv[argc++] = ctx->qs_args[QS_OVS].string; } if (ctx->qs_set & (1 << QS_AVS)) { if (argc < len) argv[argc++] = "avs"; if (argc < len) argv[argc++] = ctx->qs_args[QS_AVS].string; } /* BEST, ERROR, FILTERED, INVALID and LEAKED are exclusive */ if (ctx->qs_args[QS_BEST].one) { if (argc < len) argv[argc++] = "best"; } else if (ctx->qs_args[QS_ERROR].one) { if (argc < len) argv[argc++] = "error"; } else if (ctx->qs_args[QS_FILTERED].one) { if (argc < len) argv[argc++] = "filtered"; } else if (ctx->qs_args[QS_INVALID].one) { if (argc < len) argv[argc++] = "disqualified"; } else if (ctx->qs_args[QS_LEAKED].one) { if (argc < len) argv[argc++] = "leaked"; } /* prefix must be last for show rib */ if (ctx->qs_set & (1 << QS_PREFIX)) { if (argc < len) argv[argc++] = ctx->qs_args[QS_PREFIX].string; /* ALL and SHORTER are exclusive */ if (ctx->qs_args[QS_ALL].one) { if (argc < len) argv[argc++] = "all"; } else if (ctx->qs_args[QS_SHORTER].one) { if (argc < len) argv[argc++] = "or-shorter"; } } if (argc >= len) lwarnx("hit limit of argv in qs_argv"); return argc; } const char * qs2str(unsigned int qs) { size_t i; for (i = 0; qsargs[i].key != NULL; i++) if (qsargs[i].qs == qs) return qsargs[i].key; lerrx(1, "unknown querystring param %d", qs); } openbgpd-8.8/src/bgplgd/slowcgi.c100644 001750 001750 00000072313 14751151130 0012536/* $OpenBSD: slowcgi.c,v 1.7 2024/01/26 18:11:49 job Exp $ */ /* * Copyright (c) 2020 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons * Copyright (c) 2013 David Gwynne * Copyright (c) 2013 Florian Obser * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "slowcgi.h" #include "bgplgd.h" #include "http.h" #include "version.h" #ifndef WWW_USER #define WWW_USER "www" #endif #ifndef BGPLGD_USER #define BGPLGD_USER "_bgplgd" #endif #ifndef RUNSTATEDIR #define RUNSTATEDIR "/var/run" #endif #ifndef WWWRUNSTATEDIR #define WWWRUNSTATEDIR "/var/www/run" #endif #define TIMEOUT_DEFAULT 30 #define FCGI_CONTENT_SIZE 65535 #define FCGI_PADDING_SIZE 255 #define FCGI_RECORD_SIZE \ (sizeof(struct fcgi_record_header) + FCGI_CONTENT_SIZE + FCGI_PADDING_SIZE) #define FCGI_ALIGNMENT 8 #define FCGI_ALIGN(n) \ (((n) + (FCGI_ALIGNMENT - 1)) & ~(FCGI_ALIGNMENT - 1)) #define STDOUT_DONE 0x1 #define STDERR_DONE 0x2 #define SCRIPT_DONE 0x4 #define FCGI_REQUEST_COMPLETE 0 #define FCGI_CANT_MPX_CONN 1 #define FCGI_OVERLOADED 2 #define FCGI_UNKNOWN_ROLE 3 #define FD_RESERVE 5 #define FD_NEEDED 6 int cgi_inflight = 0; struct listener { struct event ev, pause; }; struct env_val { SLIST_ENTRY(env_val) entry; char *key; char *val; }; SLIST_HEAD(env_head, env_val); struct fcgi_record_header { uint8_t version; uint8_t type; uint16_t id; uint16_t content_len; uint8_t padding_len; uint8_t reserved; }__packed; struct fcgi_response { TAILQ_ENTRY(fcgi_response) entry; uint8_t data[FCGI_RECORD_SIZE]; size_t data_pos; size_t data_len; }; TAILQ_HEAD(fcgi_response_head, fcgi_response); struct request { LIST_ENTRY(request) entry; struct event ev; struct event resp_ev; struct event tmo; struct event script_ev; struct event script_err_ev; struct fcgi_response_head response_head; struct env_head env; uint8_t buf[FCGI_RECORD_SIZE]; size_t buf_pos; size_t buf_len; int fd; int env_count; int inflight_fds_accounted; pid_t command_pid; int command_status; int script_flags; uint16_t id; uint8_t request_started; uint8_t request_done; uint8_t timeout_fired; }; LIST_HEAD(requests_head, request); struct slowcgi_proc { struct requests_head requests; struct event ev_sigchld; }; struct fcgi_begin_request_body { uint16_t role; uint8_t flags; uint8_t reserved[5]; }__packed; struct fcgi_end_request_body { uint32_t app_status; uint8_t protocol_status; uint8_t reserved[3]; }__packed; __dead void usage(void); int slowcgi_listen(char *, struct passwd *); void slowcgi_paused(int, short, void *); int accept_reserve(int, struct sockaddr *, socklen_t *, int, volatile int *); void slowcgi_accept(int, short, void *); void slowcgi_request(int, short, void *); void slowcgi_response(int, short, void *); void slowcgi_add_response(struct request *, struct fcgi_response *); void slowcgi_timeout(int, short, void *); void slowcgi_sig_handler(int, short, void *); size_t parse_record(uint8_t * , size_t, struct request *); void parse_begin_request(uint8_t *, uint16_t, struct request *, uint16_t); void parse_params(uint8_t *, uint16_t, struct request *, uint16_t); void parse_stdin(uint8_t *, uint16_t, struct request *, uint16_t); char *env_get(struct request *, const char *); void error_response(struct request *, int); void exec_cgi(struct request *); void script_std_in(int, short, void *); void script_err_in(int, short, void *); void create_data_record(struct request *, uint8_t, const void *, size_t); void create_end_record(struct request *); void cleanup_request(struct request *); void dump_fcgi_record(const char *, struct fcgi_record_header *); void dump_fcgi_record_header(const char *, struct fcgi_record_header *); void dump_fcgi_begin_request_body(const char *, struct fcgi_begin_request_body *); void dump_fcgi_end_request_body(const char *, struct fcgi_end_request_body *); const struct loggers conslogger = { err, errx, warn, warnx, warnx, /* info */ warnx /* debug */ }; __dead void syslog_err(int, const char *, ...) __attribute__((__format__ (printf, 2, 3))); __dead void syslog_errx(int, const char *, ...) __attribute__((__format__ (printf, 2, 3))); void syslog_warn(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void syslog_warnx(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void syslog_info(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void syslog_debug(const char *, ...) __attribute__((__format__ (printf, 1, 2))); void syslog_vstrerror(int, int, const char *, va_list) __attribute__((__format__ (printf, 3, 0))); const struct loggers syslogger = { syslog_err, syslog_errx, syslog_warn, syslog_warnx, syslog_info, syslog_debug }; const struct loggers *logger = &conslogger; __dead void usage(void) { extern char *__progname; fprintf(stderr, "usage: %s [-d] [-p path] [-S socket] [-s socket] [-U user]\n", __progname); exit(1); } struct timeval timeout = { TIMEOUT_DEFAULT, 0 }; struct timeval kill_timeout = { 5, 0 }; struct slowcgi_proc slowcgi_proc; int debug = 0; int on = 1; char *fcgi_socket = WWWRUNSTATEDIR "/bgplgd.sock"; char *bgpctlpath = "bgpctl"; char *bgpctlsock = RUNSTATEDIR "/bgpd.rsock"; /* * Unveil the command we want to run. * If this has a pathname component in it, interpret as a file * and unveil the file directly. * Otherwise, look up the command in our PATH. */ static void unveil_command(const char *prog) { const char *pp; char *save, *cmd, *path; struct stat st; if (strchr(prog, '/') != NULL) { if (unveil(prog, "x") == -1) err(1, "%s: unveil", prog); return; } if (getenv("PATH") == NULL) lerrx(1, "PATH is unset"); if ((path = strdup(getenv("PATH"))) == NULL) lerr(1, NULL); save = path; while ((pp = strsep(&path, ":")) != NULL) { if (*pp == '\0') continue; if (asprintf(&cmd, "%s/%s", pp, prog) == -1) lerr(1, NULL); if (lstat(cmd, &st) == -1) { free(cmd); continue; } if (unveil(cmd, "x") == -1) lerr(1, "%s: unveil", cmd); free(cmd); break; } free(save); } int main(int argc, char *argv[]) { extern char *__progname; struct listener *l = NULL; struct passwd *pw; struct stat sb; int c, fd; const char *sock_user = WWW_USER; const char *cgi_user = BGPLGD_USER; /* * Ensure we have fds 0-2 open so that we have no fd overlaps * in exec_cgi() later. Just exit on error, we don't have enough * fds open to output an error message anywhere. */ for (c=0; c < 3; c++) { if (fstat(c, &sb) == -1) { if ((fd = open("/dev/null", O_RDWR)) != -1) { if (dup2(fd, c) == -1) exit(1); if (fd > c) close(fd); } else exit(1); } } while ((c = getopt(argc, argv, "dp:S:s:U:u:V")) != -1) { switch (c) { case 'd': debug++; break; case 'p': bgpctlpath = optarg; break; case 'S': bgpctlsock = optarg; break; case 's': fcgi_socket = optarg; break; case 'U': sock_user = optarg; break; case 'V': fprintf(stderr, "OpenBGPD %s\n", BGPD_VERSION); return 0; default: usage(); /* NOTREACHED */ } } if (geteuid() != 0) errx(1, "need root privileges"); if (!debug && daemon(0, 0) == -1) err(1, "daemon"); if (!debug) { openlog(__progname, LOG_PID|LOG_NDELAY, LOG_DAEMON); logger = &syslogger; } ldebug("sock_user: %s", sock_user); pw = getpwnam(sock_user); if (pw == NULL) lerrx(1, "no %s user", sock_user); fd = slowcgi_listen(fcgi_socket, pw); ldebug("cgi_user: %s", cgi_user); pw = getpwnam(cgi_user); if (pw == NULL) lerrx(1, "no %s user", cgi_user); if (setgroups(1, &pw->pw_gid) || setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) lerr(1, "unable to revoke privs"); unveil_command(bgpctlpath); if (pledge("stdio rpath unix proc exec", NULL) == -1) lerr(1, "pledge"); LIST_INIT(&slowcgi_proc.requests); event_init(); l = calloc(1, sizeof(*l)); if (l == NULL) lerr(1, "listener ev alloc"); event_set(&l->ev, fd, EV_READ | EV_PERSIST, slowcgi_accept, l); event_add(&l->ev, NULL); evtimer_set(&l->pause, slowcgi_paused, l); signal_set(&slowcgi_proc.ev_sigchld, SIGCHLD, slowcgi_sig_handler, &slowcgi_proc); signal_add(&slowcgi_proc.ev_sigchld, NULL); signal(SIGPIPE, SIG_IGN); event_dispatch(); return (0); } int slowcgi_listen(char *path, struct passwd *pw) { struct sockaddr_un sun; mode_t old_umask; int fd; if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0)) == -1) lerr(1, "slowcgi_listen: socket"); memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= sizeof(sun.sun_path)) lerrx(1, "socket path too long"); if (unlink(path) == -1) if (errno != ENOENT) lerr(1, "slowcgi_listen: unlink %s", path); old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH); if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) lerr(1,"slowcgi_listen: bind: %s", path); umask(old_umask); if (chown(path, pw->pw_uid, pw->pw_gid) == -1) lerr(1, "slowcgi_listen: chown: %s", path); if (listen(fd, 5) == -1) lerr(1, "listen"); ldebug("socket: %s", path); return fd; } void slowcgi_paused(int fd, short events, void *arg) { struct listener *l = arg; event_add(&l->ev, NULL); } int accept_reserve(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int reserve, volatile int *counter) { int ret; #ifdef HAVE_GETDTABLECOUNT if (getdtablecount() + reserve + ((*counter + 1) * FD_NEEDED) >= getdtablesize()) { ldebug("inflight fds exceeded"); errno = EMFILE; return -1; } #endif if ((ret = accept4(sockfd, addr, addrlen, SOCK_NONBLOCK | SOCK_CLOEXEC)) > -1) { (*counter)++; ldebug("inflight incremented, now %d", *counter); } return ret; } void slowcgi_accept(int fd, short events, void *arg) { struct listener *l; struct sockaddr_storage ss; struct timeval backoff; struct request *c; socklen_t len; int s; l = arg; backoff.tv_sec = 1; backoff.tv_usec = 0; c = NULL; len = sizeof(ss); if ((s = accept_reserve(fd, (struct sockaddr *)&ss, &len, FD_RESERVE, &cgi_inflight)) == -1) { switch (errno) { case EINTR: case EWOULDBLOCK: case ECONNABORTED: return; case EMFILE: case ENFILE: event_del(&l->ev); evtimer_add(&l->pause, &backoff); return; default: lerr(1, "accept"); } } c = calloc(1, sizeof(*c)); if (c == NULL) { lwarn("cannot calloc request"); close(s); cgi_inflight--; return; } c->fd = s; c->buf_pos = 0; c->buf_len = 0; c->request_started = 0; c->inflight_fds_accounted = 0; TAILQ_INIT(&c->response_head); event_set(&c->ev, s, EV_READ | EV_PERSIST, slowcgi_request, c); event_add(&c->ev, NULL); event_set(&c->resp_ev, s, EV_WRITE | EV_PERSIST, slowcgi_response, c); evtimer_set(&c->tmo, slowcgi_timeout, c); evtimer_add(&c->tmo, &timeout); LIST_INSERT_HEAD(&slowcgi_proc.requests, c, entry); } void slowcgi_timeout(int fd, short events, void *arg) { struct request *c = arg; int sig = SIGTERM; if (c->script_flags & SCRIPT_DONE) return; if (c->command_pid == 0) { c->command_status = SIGALRM; error_response(c, 408); return; } ldebug("timeout fired for pid %d", c->command_pid); if (c->timeout_fired) sig = SIGKILL; if (kill(c->command_pid, sig) == -1) { lwarn("kill child %d after timeout", c->command_pid); if (event_initialized(&c->script_ev)) { close(EVENT_FD(&c->script_ev)); event_del(&c->script_ev); } if (event_initialized(&c->script_err_ev)) { close(EVENT_FD(&c->script_err_ev)); event_del(&c->script_err_ev); } c->command_status = SIGALRM; c->script_flags = STDOUT_DONE | STDERR_DONE | SCRIPT_DONE; create_end_record(c); } if (c->timeout_fired++ == 0) evtimer_add(&c->tmo, &kill_timeout); } void slowcgi_sig_handler(int sig, short event, void *arg) { struct request *c; struct slowcgi_proc *p; pid_t pid; int status; p = arg; switch (sig) { case SIGCHLD: while ((pid = waitpid(WAIT_ANY, &status, WNOHANG)) > 0) { LIST_FOREACH(c, &p->requests, entry) if (c->command_pid == pid) break; if (c == NULL) { lwarnx("caught exit of unknown child %d", pid); continue; } if (WIFSIGNALED(status)) c->command_status = WTERMSIG(status); else c->command_status = WEXITSTATUS(status); ldebug("pid %d exit %s%d", pid, WIFSIGNALED(status) ? "signal " : "", c->command_status); c->script_flags |= SCRIPT_DONE; if (c->script_flags == (STDOUT_DONE | STDERR_DONE | SCRIPT_DONE)) create_end_record(c); } if (pid == -1 && errno != ECHILD) lwarn("waitpid"); break; default: lerr(1, "unexpected signal: %d", sig); break; } } void slowcgi_add_response(struct request *c, struct fcgi_response *resp) { struct fcgi_record_header *header; size_t padded_len; header = (struct fcgi_record_header*)resp->data; /* The FastCGI spec suggests to align the output buffer */ padded_len = FCGI_ALIGN(resp->data_len); if (padded_len > resp->data_len) { /* There should always be FCGI_PADDING_SIZE bytes left */ if (padded_len > FCGI_RECORD_SIZE) lerr(1, "response too long"); header->padding_len = padded_len - resp->data_len; resp->data_len = padded_len; } TAILQ_INSERT_TAIL(&c->response_head, resp, entry); event_add(&c->resp_ev, NULL); } void slowcgi_response(int fd, short events, void *arg) { struct request *c; struct fcgi_record_header *header; struct fcgi_response *resp; ssize_t n; c = arg; while ((resp = TAILQ_FIRST(&c->response_head))) { header = (struct fcgi_record_header*) resp->data; if (debug > 1) dump_fcgi_record("resp ", header); n = write(fd, resp->data + resp->data_pos, resp->data_len); if (n == -1) { if (errno == EAGAIN || errno == EINTR) return; cleanup_request(c); return; } resp->data_pos += n; resp->data_len -= n; if (resp->data_len == 0) { TAILQ_REMOVE(&c->response_head, resp, entry); free(resp); } } if (TAILQ_EMPTY(&c->response_head)) { if (c->request_done) cleanup_request(c); else event_del(&c->resp_ev); } } void slowcgi_request(int fd, short events, void *arg) { struct request *c; ssize_t n; size_t parsed; c = arg; n = read(fd, c->buf + c->buf_pos + c->buf_len, FCGI_RECORD_SIZE - c->buf_pos-c->buf_len); switch (n) { case -1: switch (errno) { case EINTR: case EAGAIN: return; default: goto fail; } break; case 0: ldebug("closed connection"); goto fail; default: break; } c->buf_len += n; /* * Parse the records as they are received. Per the FastCGI * specification, the server need only receive the FastCGI * parameter records in full; it is free to begin execution * at that point, which is what happens here. */ do { parsed = parse_record(c->buf + c->buf_pos, c->buf_len, c); c->buf_pos += parsed; c->buf_len -= parsed; } while (parsed > 0 && c->buf_len > 0); /* Make space for further reads */ if (c->buf_len > 0) { memmove(c->buf, c->buf + c->buf_pos, c->buf_len); c->buf_pos = 0; } return; fail: cleanup_request(c); } void parse_begin_request(uint8_t *buf, uint16_t n, struct request *c, uint16_t id) { /* XXX -- FCGI_CANT_MPX_CONN */ if (c->request_started) { lwarnx("unexpected FCGI_BEGIN_REQUEST, ignoring"); return; } if (n != sizeof(struct fcgi_begin_request_body)) { lwarnx("wrong size %d != %lu", n, sizeof(struct fcgi_begin_request_body)); return; } c->request_started = 1; c->id = id; SLIST_INIT(&c->env); c->env_count = 0; } void parse_params(uint8_t *buf, uint16_t n, struct request *c, uint16_t id) { struct env_val *env_entry; uint32_t name_len, val_len; if (!c->request_started) { lwarnx("FCGI_PARAMS without FCGI_BEGIN_REQUEST, ignoring"); return; } if (c->id != id) { lwarnx("unexpected id, ignoring"); return; } /* * If this is the last FastCGI parameter record, * begin execution of the CGI script. */ if (n == 0) { exec_cgi(c); return; } while (n > 0) { if (buf[0] >> 7 == 0) { name_len = buf[0]; n--; buf++; } else { if (n > 3) { name_len = ((buf[0] & 0x7f) << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]; n -= 4; buf += 4; } else return; } if (n > 0) { if (buf[0] >> 7 == 0) { val_len = buf[0]; n--; buf++; } else { if (n > 3) { val_len = ((buf[0] & 0x7f) << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]; n -= 4; buf += 4; } else return; } } else return; if (n < name_len + val_len) return; if ((env_entry = malloc(sizeof(struct env_val))) == NULL) { lwarnx("cannot allocate env_entry"); return; } if ((env_entry->key = malloc(name_len + 1)) == NULL) { lwarnx("cannot allocate env_entry->key"); free(env_entry); return; } if ((env_entry->val = malloc(val_len + 1)) == NULL) { lwarnx("cannot allocate env_entry->val"); free(env_entry->key); free(env_entry); return; } memcpy(env_entry->key, buf, name_len); buf += name_len; n -= name_len; env_entry->key[name_len] = '\0'; memcpy(env_entry->val, buf, val_len); buf += val_len; n -= val_len; env_entry->val[val_len] = '\0'; SLIST_INSERT_HEAD(&c->env, env_entry, entry); ldebug("env[%d], %s=%s", c->env_count, env_entry->key, env_entry->val); c->env_count++; } } void parse_stdin(uint8_t *buf, uint16_t n, struct request *c, uint16_t id) { if (c->id != id) { lwarnx("unexpected id, ignoring"); return; } if (n != 0) lwarnx("unexpected stdin input, ignoring"); } size_t parse_record(uint8_t *buf, size_t n, struct request *c) { struct fcgi_record_header *h; if (n < sizeof(struct fcgi_record_header)) return (0); h = (struct fcgi_record_header*) buf; if (debug > 1) dump_fcgi_record("", h); if (n < sizeof(struct fcgi_record_header) + ntohs(h->content_len) + h->padding_len) return (0); if (h->version != 1) lerrx(1, "wrong version"); switch (h->type) { case FCGI_BEGIN_REQUEST: parse_begin_request(buf + sizeof(struct fcgi_record_header), ntohs(h->content_len), c, ntohs(h->id)); break; case FCGI_PARAMS: parse_params(buf + sizeof(struct fcgi_record_header), ntohs(h->content_len), c, ntohs(h->id)); break; case FCGI_STDIN: parse_stdin(buf + sizeof(struct fcgi_record_header), ntohs(h->content_len), c, ntohs(h->id)); break; default: lwarnx("unimplemented type %d", h->type); break; } return (sizeof(struct fcgi_record_header) + ntohs(h->content_len) + h->padding_len); } char * env_get(struct request *c, const char *key) { struct env_val *env; SLIST_FOREACH(env, &c->env, entry) { if (strcmp(env->key, key) == 0) return (env->val); } return (NULL); } static const char * http_error(int *res) { const struct http_error errors[] = HTTP_ERRORS; size_t i; for (i = 0; errors[i].error_code != 0; i++) if (errors[i].error_code == *res) return errors[i].error_name; /* unknown error - change to 500 */ lwarnx("unknown http error %d", *res); *res = 500; return "Internal Server Error"; } void error_response(struct request *c, int res) { const char *type = "text/html"; const char *errstr = http_error(&res); char *buf; int len; lwarnx("HTTP status %d: %s", res, errstr); len = asprintf(&buf, "Content-Type: %s\n" "Status: %d\n" "Cache-Control: no-cache\n" "\n" "\n" "\n" " \n" " \n" " %d %s\n" " \n" " \n" "

%d %s

\n" "
\n" "
OpenBSD bgplgd
\n" " \n" "\n", type, res, type, res, errstr, res, errstr); if (len == -1) lerr(1, NULL); create_data_record(c, FCGI_STDOUT, buf, len); free(buf); c->script_flags = (STDOUT_DONE | STDERR_DONE | SCRIPT_DONE); create_end_record(c); } /* * Fork a new CGI process to handle the request, translating * between FastCGI parameter records and CGI's environment variables, * as well as between the CGI process' stdin/stdout and the * corresponding FastCGI records. */ void exec_cgi(struct request *c) { struct lg_ctx ctx = { 0 }; int s_in[2], s_out[2], s_err[2], res; pid_t pid; res = prep_request(&ctx, env_get(c, "REQUEST_METHOD"), env_get(c, "PATH_INFO"), env_get(c, "QUERY_STRING")); if (res != 0) { error_response(c, res); return; } if (pipe(s_in) == -1) lerr(1, "pipe"); if (pipe(s_out) == -1) lerr(1, "pipe"); if (pipe(s_err) == -1) lerr(1, "pipe"); cgi_inflight--; c->inflight_fds_accounted = 1; switch (pid = fork()) { case -1: c->command_status = errno; lwarn("fork"); close(s_in[0]); close(s_out[0]); close(s_err[0]); close(s_in[1]); close(s_out[1]); close(s_err[1]); c->script_flags = (STDOUT_DONE | STDERR_DONE | SCRIPT_DONE); create_end_record(c); return; case 0: /* Child process */ if (pledge("stdio rpath exec", NULL) == -1) lerr(1, "pledge"); close(s_in[0]); close(s_out[0]); close(s_err[0]); if (dup2(s_in[1], STDIN_FILENO) == -1) _exit(1); if (dup2(s_out[1], STDOUT_FILENO) == -1) _exit(1); if (dup2(s_err[1], STDERR_FILENO) == -1) _exit(1); close(s_in[1]); close(s_out[1]); close(s_err[1]); bgpctl_call(&ctx); /* should not be reached */ _exit(1); } ldebug("fork %d", pid); /* Parent process*/ close(s_in[1]); close(s_out[1]); close(s_err[1]); fcntl(s_in[0], F_SETFD, FD_CLOEXEC); fcntl(s_out[0], F_SETFD, FD_CLOEXEC); fcntl(s_err[0], F_SETFD, FD_CLOEXEC); if (ioctl(s_in[0], FIONBIO, &on) == -1) lerr(1, "script ioctl(FIONBIO)"); if (ioctl(s_out[0], FIONBIO, &on) == -1) lerr(1, "script ioctl(FIONBIO)"); if (ioctl(s_err[0], FIONBIO, &on) == -1) lerr(1, "script ioctl(FIONBIO)"); close(s_in[0]); /* close stdin, bgpctl does not expect anything */ c->command_pid = pid; event_set(&c->script_ev, s_out[0], EV_READ | EV_PERSIST, script_std_in, c); event_add(&c->script_ev, NULL); event_set(&c->script_err_ev, s_err[0], EV_READ | EV_PERSIST, script_err_in, c); event_add(&c->script_err_ev, NULL); } static void script_in(int fd, struct event *ev, struct request *c, uint8_t type) { struct fcgi_response *resp; struct fcgi_record_header *header; ssize_t n; if ((resp = calloc(1, sizeof(struct fcgi_response))) == NULL) { lwarnx("cannot malloc fcgi_response"); return; } header = (struct fcgi_record_header*) resp->data; header->version = 1; header->type = type; header->id = htons(c->id); header->padding_len = 0; header->reserved = 0; n = read(fd, resp->data + sizeof(struct fcgi_record_header), FCGI_CONTENT_SIZE); if (n == -1) { switch (errno) { case EINTR: case EAGAIN: free(resp); return; default: n = 0; /* fake empty FCGI_STD{OUT,ERR} response */ } } header->content_len = htons(n); resp->data_pos = 0; resp->data_len = n + sizeof(struct fcgi_record_header); slowcgi_add_response(c, resp); if (n == 0) { if (type == FCGI_STDOUT) c->script_flags |= STDOUT_DONE; else c->script_flags |= STDERR_DONE; if (c->script_flags == (STDOUT_DONE | STDERR_DONE | SCRIPT_DONE)) create_end_record(c); event_del(ev); close(fd); } } void script_std_in(int fd, short events, void *arg) { struct request *c = arg; script_in(fd, &c->script_ev, c, FCGI_STDOUT); } void script_err_in(int fd, short events, void *arg) { struct request *c = arg; script_in(fd, &c->script_err_ev, c, FCGI_STDERR); } void create_data_record(struct request *c, uint8_t type, const void *buf, size_t len) { struct fcgi_response *resp; struct fcgi_record_header *header; const char *d = buf; size_t n; do { if ((resp = calloc(1, sizeof(struct fcgi_response))) == NULL) { lwarnx("cannot malloc fcgi_response"); return; } header = (struct fcgi_record_header*) resp->data; header->version = 1; header->type = type; header->id = htons(c->id); header->padding_len = 0; header->reserved = 0; n = len > FCGI_CONTENT_SIZE ? FCGI_CONTENT_SIZE : len; memcpy(resp->data + sizeof(struct fcgi_record_header), d, n); header->content_len = htons(n); resp->data_pos = 0; resp->data_len = n + sizeof(struct fcgi_record_header); slowcgi_add_response(c, resp); len -= n; d += n; } while (len > 0); } void create_end_record(struct request *c) { struct fcgi_response *resp; struct fcgi_record_header *header; struct fcgi_end_request_body *end_request; if ((resp = calloc(1, sizeof(struct fcgi_response))) == NULL) { lwarnx("cannot malloc fcgi_response"); return; } header = (struct fcgi_record_header*) resp->data; header->version = 1; header->type = FCGI_END_REQUEST; header->id = htons(c->id); header->content_len = htons(sizeof(struct fcgi_end_request_body)); header->padding_len = 0; header->reserved = 0; end_request = (struct fcgi_end_request_body *) (resp->data + sizeof(struct fcgi_record_header)); end_request->app_status = htonl(c->command_status); end_request->protocol_status = FCGI_REQUEST_COMPLETE; end_request->reserved[0] = 0; end_request->reserved[1] = 0; end_request->reserved[2] = 0; resp->data_pos = 0; resp->data_len = sizeof(struct fcgi_end_request_body) + sizeof(struct fcgi_record_header); slowcgi_add_response(c, resp); c->request_done = 1; } void cleanup_request(struct request *c) { struct fcgi_response *resp; struct env_val *env_entry; evtimer_del(&c->tmo); if (event_initialized(&c->ev)) event_del(&c->ev); if (event_initialized(&c->resp_ev)) event_del(&c->resp_ev); if (event_initialized(&c->script_ev)) { close(EVENT_FD(&c->script_ev)); event_del(&c->script_ev); } if (event_initialized(&c->script_err_ev)) { close(EVENT_FD(&c->script_err_ev)); event_del(&c->script_err_ev); } close(c->fd); while (!SLIST_EMPTY(&c->env)) { env_entry = SLIST_FIRST(&c->env); SLIST_REMOVE_HEAD(&c->env, entry); free(env_entry->key); free(env_entry->val); free(env_entry); } while ((resp = TAILQ_FIRST(&c->response_head))) { TAILQ_REMOVE(&c->response_head, resp, entry); free(resp); } LIST_REMOVE(c, entry); if (! c->inflight_fds_accounted) cgi_inflight--; free(c); } void dump_fcgi_record(const char *p, struct fcgi_record_header *h) { dump_fcgi_record_header(p, h); if (h->type == FCGI_BEGIN_REQUEST) dump_fcgi_begin_request_body(p, (struct fcgi_begin_request_body *)(h + 1)); else if (h->type == FCGI_END_REQUEST) dump_fcgi_end_request_body(p, (struct fcgi_end_request_body *)(h + 1)); } void dump_fcgi_record_header(const char* p, struct fcgi_record_header *h) { ldebug("%sversion: %d", p, h->version); ldebug("%stype: %d", p, h->type); ldebug("%srequestId: %d", p, ntohs(h->id)); ldebug("%scontentLength: %d", p, ntohs(h->content_len)); ldebug("%spaddingLength: %d", p, h->padding_len); ldebug("%sreserved: %d", p, h->reserved); } void dump_fcgi_begin_request_body(const char *p, struct fcgi_begin_request_body *b) { ldebug("%srole %d", p, ntohs(b->role)); ldebug("%sflags %d", p, b->flags); } void dump_fcgi_end_request_body(const char *p, struct fcgi_end_request_body *b) { ldebug("%sappStatus: %d", p, ntohl(b->app_status)); ldebug("%sprotocolStatus: %d", p, b->protocol_status); } void syslog_vstrerror(int e, int priority, const char *fmt, va_list ap) { char *s; if (vasprintf(&s, fmt, ap) == -1) { syslog(LOG_EMERG, "unable to alloc in syslog_vstrerror"); exit(1); } syslog(priority, "%s: %s", s, strerror(e)); free(s); } __dead void syslog_err(int ecode, const char *fmt, ...) { va_list ap; va_start(ap, fmt); syslog_vstrerror(errno, LOG_CRIT, fmt, ap); va_end(ap); exit(ecode); } __dead void syslog_errx(int ecode, const char *fmt, ...) { va_list ap; va_start(ap, fmt); vsyslog(LOG_CRIT, fmt, ap); va_end(ap); exit(ecode); } void syslog_warn(const char *fmt, ...) { va_list ap; va_start(ap, fmt); syslog_vstrerror(errno, LOG_ERR, fmt, ap); va_end(ap); } void syslog_warnx(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vsyslog(LOG_ERR, fmt, ap); va_end(ap); } void syslog_info(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vsyslog(LOG_INFO, fmt, ap); va_end(ap); } void syslog_debug(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vsyslog(LOG_DEBUG, fmt, ap); va_end(ap); } openbgpd-8.8/src/bgplgd/bgplgd.8.in100644 001750 001750 00000012744 14751151130 0012662.\" $OpenBSD: bgplgd.8,v 1.12 2024/12/03 10:38:06 claudio Exp $ .\" .\" Copyright (c) 2021 Claudio Jeker .\" .\" Permission to use, copy, modify, and distribute this software for any .\" purpose with or without fee is hereby granted, provided that the above .\" copyright notice and this permission notice appear in all copies. .\" .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" .Dd $Mdocdate: December 3 2024 $ .Dt BGPLGD 8 .Os .Sh NAME .Nm bgplgd .Nd a bgpctl FastCGI server .Sh SYNOPSIS .Nm .Op Fl d .Op Fl p Ar path .Op Fl S Ar socket .Op Fl s Ar socket .Op Fl U Ar user .Op Fl V .Sh DESCRIPTION .Nm is a server which implements the FastCGI Protocol to execute .Xr bgpctl 8 commands. .Nm is a simple server that implements a simple web API to query .Xr bgpd 8 . .Pp .Nm opens a socket at .Pa @WWWRUNSTATEDIR@/bgplgd.sock , owned by @WWW_USER@, with permissions 0660. It will then drop privileges to user .Qq @BGPLGD_USER@ , .Xr unveil 2 the .Xr bgpctl 8 binary and restrict itself with .Xr pledge 2 . .Pp The options are as follows: .Bl -tag -width Ds .It Fl d Do not daemonize. If this option is specified, .Nm will run in the foreground and log to stderr. .It Fl p Ar path Use .Ar path instead of .Xr bgpctl 8 to query .Xr bgpd 8 . .It Fl S Ar socket Use .Ar socket instead of the default .Pa @RUNSTATEDIR@/bgpd.rsock to communicate with .Xr bgpd 8 . .It Fl s Ar socket Create and bind to alternative local socket at .Ar socket . .It Fl U Ar user Change the owner of .Pa @WWWRUNSTATEDIR@/bgplgd.sock to .Ar user and its primary group instead of the default @WWW_USER@. .It Fl V Show the version and exit. .El .Pp .Nm provides the following API endpoints. Unless further specified the endpoints do not take any parameters: .Pp .Bl -tag -width "/interfaces" -compact .It Pa /interfaces Show the interface states. .It Pa /memory Show RIB memory statistics. .It Pa /metrics Output various statistics in OpenMetrics format. .It Pa /neighbors Show detailed neighbors information. The output can be limited with the following parameters: .Pp .Bl -tag -width "neighbor=peer" -compact .It Cm neighbor Ns = Ns Ar peer Show information for a specific neighbor. .Ar peer may be the neighbor's address or description. .It Cm group Ns = Ns Ar name Show only entries from the specified peer group. .El .It Pa /nexthops Show the list of BGP nexthops and the result of their validity check. .It Pa /rib .It Pa /rib/in .It Pa /rib/out Show routes from the bgpd(8) Routing Information Base. For .Pa /rib/in the .Ar Adj-RIB-In will be queried and for .Pa /rib/out the .Ar Adj-RIB-out . The following parameters can be used to filter the output: .Pp .Bl -tag -width "neighbor=peer" -compact .It Cm neighbor Ns = Ns Ar peer Show information for a specific neighbor. .Ar peer may be the neighbor's address or description. .It Cm group Ns = Ns Ar name Show only entries from the specified peer group. .It Cm as Ns = Ns Ar number Show only entries with the specified source AS number. .It Cm community Ns = Ns Ar string .It Cm ext-community Ns = Ns Ar string .It Cm large-community Ns = Ns Ar string Show only entries that match the specified community. .It Xo .Ic af Ns = Ns .Pq Ic ipv4 | ipv6 | vpnv4 | vpnv6 .Xc Show only entries that match the specified address family. .It Cm rib Ns = Ns Ar name Show only entries from the RIB with name .Ar name . Can only be used with the .Pa /rib endpoint. .It Xo .Ic ovs Ns = Ns .Pq Ic valid | not-found | invalid .Xc Show only prefixes that match the specified Origin Validation State. .It Xo .Ic avs Ns = Ns .Pq Ic valid | invalid | unknown .Xc Show only prefixes that match the specified ASPA Validation State. .It Cm best Ns = Ns 1 Show only selected routes. .It Cm error Ns = Ns 1 Show only prefixes which are marked invalid and were treated as withdrawn. .It Cm filtered Ns = Ns 1 Show only prefixes which are marked filtered by the input filter. .It Cm invalid Ns = Ns 1 Show only prefixes which are not eligible. .It Cm leaked Ns = Ns 1 Show only prefixes where a route leak was detected. .It Cm prefix Ns = Ns Ar addr Show only entries that match prefix either as the best matching route or show the entry for this CIDR prefix. .It Cm all Ns = Ns 1 Show all entries in the specified prefix range. .It Cm or-shorter Ns = Ns 1 Show all entries covering and including the specified prefix. .El .It Pa /rtr Show a list of all RTR sessions. .It Pa /sets Show a list summarizing all roa-set, as-set, prefix-set, and origin-set tables. .It Pa /summary Show a list of all neighbors, including information about the session state and message counters. .El .Sh EXAMPLES Add the following to .Pa /etc/bgpd.conf to have .Xr bgpd 8 open a second, restricted, control socket: .Pp .Dl socket \&"@RUNSTATEDIR@/bgpd.rsock\&" restricted .Pp An example setup in .Xr httpd 8 is: .Bd -literal -offset indent location "/bgplgd/*" { fastcgi socket "/run/bgplgd.sock" request strip 1 } .Ed .Sh SEE ALSO .Xr bgpctl 8 , .Xr bgpd 8 , .Xr httpd 8 .Sh HISTORY The .Nm server first appeared in .Ox 7.2 . .Sh AUTHORS .An Claudio Jeker Aq Mt claudio@openbsd.org