Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vrrp: always add a keepalived entry to rt_addrprotos is none exists #2488

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ AC_ARG_WITH(iproute-usr-dir,
[AS_HELP_STRING([--with-iproute-usr-dir=PATH_TO_CONFIG_FILES], [specify usr directory iproute2 uses for config files])])
AC_ARG_WITH(iproute-etc-dir,
[AS_HELP_STRING([--with-iproute-etc-dir=PATH_TO_CONFIG_FILES], [specify etc directory iproute2 uses for config files])])
AC_ARG_ENABLE(update-rt-addrprotos-file,
[AS_HELP_STRING([--enable-update-rt-addrprotos-file], [update iproute rt_addrprotos file if no entry for keepalived])])
AC_ARG_ENABLE(strict-config-checks,
[AS_HELP_STRING([--enable-strict-config-checks], [build with strict configuration checking])])
AC_ARG_ENABLE(hardening,
Expand Down Expand Up @@ -2795,14 +2793,6 @@ AS_IF([test .${iproute_usr_dir} != . ],
add_config_opt([IPROUTE_USR_DIR=$iproute_usr_dir])
])

AS_IF([test .${enable_update_rt_addrprotos_file} = ."yes"],
[
AC_DEFINE([UPDATE_RT_ADDRPROTOS_FILE], [ 1 ], [update iproute2 rt_addrprotos file])
echo You probably do not want to use this option\; it is better to create an
echo entry in /etc/iproute2/rt_addrprotos, or add keepalived.conf with a relevant
echo entry in /etc/iproute2/rt_addrprotos.d if your version of iproute2 is \>= 6.12.
])

dnl - Check type of rlim_t for printf() - this check needs to be late on
dnl - since _FILE_OFFSET_BITS (set when using netsnmp) alters sizeof(rlim_t)
SAV_CFLAGS="$CFLAGS"
Expand Down Expand Up @@ -3533,9 +3523,6 @@ echo "Strict config checks : ${STRICT_CONFIG}"
echo "Build documentation : ${HAVE_SPHINX_BUILD}"
echo "iproute usr directory : ${iproute_usr_dir}"
echo "iproute etc directory : ${iproute_etc_dir}"
if test .${enable_update_rt_addrprotos_file} = .yes; then
echo "update rt_addrprotos : Yes"
fi
if test ${ENABLE_STACKTRACE} = Yes; then
echo "Stacktrace support : Yes"
fi
Expand Down
4 changes: 0 additions & 4 deletions keepalived/vrrp/vrrp_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,6 @@ vrrp_terminate_phase2(int exit_status)

clear_rt_names();

#if HAVE_DECL_IFA_PROTO && defined UPDATE_RT_ADDRPROTOS_FILE
remove_created_addrprotos_file();
#endif

if (global_data->vrrp_notify_fifo.fd != -1)
notify_fifo_close(&global_data->notify_fifo, &global_data->vrrp_notify_fifo);

Expand Down
50 changes: 6 additions & 44 deletions lib/rttables.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
#include <linux/if_addr.h>
#include <dirent.h>
#include <errno.h>
#if HAVE_DECL_IFA_PROTO && defined UPDATE_RT_ADDRPROTOS_FILE
#if HAVE_DECL_IFA_PROTO
#include <unistd.h>
#endif
#ifdef HAVE_SYS_STAT_H
Expand Down Expand Up @@ -186,12 +186,6 @@ static LIST_HEAD_INITIALIZE(rt_scopes);

static char ret_buf[11]; /* uint32_t in decimal */

#if HAVE_DECL_IFA_PROTO && defined UPDATE_RT_ADDRPROTOS_FILE
static const char *created_addrprotos_file;
static const char *created_addrprotos_dir;
bool updated_addrprotos_file;
#endif

static void
free_rt_entry(rt_entry_t *rte)
{
Expand Down Expand Up @@ -597,7 +591,6 @@ get_rttables_addrproto(uint32_t id)
return get_entry(id, &rt_scopes, RT_ADDRPROTOS_FILE, rtscope_default, 255);
}

#ifdef UPDATE_RT_ADDRPROTOS_FILE
static void
write_addrproto_config(const char *name, uint32_t val)
{
Expand Down Expand Up @@ -631,18 +624,16 @@ write_addrproto_config(const char *name, uint32_t val)
sscanf(v, "%d.%d.%d", &ver_maj, &ver_min, &ver_rel);
if (ver_maj >= 7 || (ver_maj == 6 && ver_min >= 12)) {
dir = IPROUTE_ETC_DIR "/" RT_ADDRPROTOS_FILE ".d";
path = IPROUTE_ETC_DIR "/" RT_ADDRPROTOS_FILE ".d/keepalived_private.conf" ;
} else if (ver_maj == 6 && ver_min >= 3) {
path = IPROUTE_ETC_DIR "/" RT_ADDRPROTOS_FILE ".d/keepalived.conf" ;
} else if (ver_maj == 6 && ver_min >= 3)
path = IPROUTE_ETC_DIR "/" RT_ADDRPROTOS_FILE;
} else
else
return;

stat(IPROUTE_ETC_DIR, &statbuf);
if (dir) {
if (!mkdir(dir, statbuf.st_mode & ~S_IFMT)) { // This may fail if the directory already exists
created_addrprotos_dir = dir;
if (!mkdir(dir, statbuf.st_mode & ~S_IFMT)) // This may fail if the directory already exists
chmod(dir, statbuf.st_mode & ~S_IFMT);
}
} else {
/* Check if rt_addrprotos file exists */
file_exists = !stat(path, &statbuf);
Expand All @@ -654,20 +645,10 @@ write_addrproto_config(const char *name, uint32_t val)
if (!file_exists)
chmod(path, statbuf.st_mode & ~S_IFMT & ~(S_IXUSR | S_IXGRP | S_IXOTH));

if (dir || !file_exists) {
fputs("# File created by keepalived - feel free to remove it\n", fp);
fprintf(fp, "%u\t%s\n", val, name);
} else
fprintf(fp, "%u\t%s\t# entry added by keepalived - feel free to remove it\n", val, name);
fprintf(fp, "%u\t%s\t# added by keepalived\n", val, name);

fclose(fp);

if (!file_exists)
created_addrprotos_file = path;
else
updated_addrprotos_file = true;
}
#endif

bool
create_rttables_addrproto(const char *name, uint8_t *id)
Expand Down Expand Up @@ -703,31 +684,12 @@ create_rttables_addrproto(const char *name, uint8_t *id)

list_add_tail(&rte->e_list, &rt_addrprotos);

#ifdef UPDATE_RT_ADDRPROTOS_FILE
/* Save the entry so iproute can use it */
write_addrproto_config(name, *id);
#endif

return true;
}

#ifdef UPDATE_RT_ADDRPROTOS_FILE
void
remove_created_addrprotos_file(void)
{
if (created_addrprotos_file) {
unlink(created_addrprotos_file);

if (created_addrprotos_dir)
rmdir(created_addrprotos_dir);
} else if (updated_addrprotos_file) {
if (system("sed -i -e '/keepalived/d' " IPROUTE_ETC_DIR "/" RT_ADDRPROTOS_FILE)) {
/* Dummy to aviod unused result warning */
}
}
}
#endif

bool
find_rttables_addrproto(const char *name, uint8_t *id)
{
Expand Down
3 changes: 0 additions & 3 deletions lib/rttables.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,5 @@ extern const char *get_rttables_scope(uint32_t);
extern const char *get_rttables_group(uint32_t);
#endif
extern const char *get_rttables_rtntype(uint8_t);
#if HAVE_DECL_IFA_PROTO && defined UPDATE_RT_ADDRPROTOS_FILE
extern void remove_created_addrprotos_file(void);
#endif

#endif
Loading