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

Fix DBus for VRRP instances without a configured interface #2338

Merged
merged 3 commits into from
Sep 12, 2023
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
5 changes: 5 additions & 0 deletions doc/man/man5/keepalived.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,11 @@ possibly following any cleanup actions needed.
# (default: org.keepalived.Vrrp1)
\fBdbus_service_name \fRSERVICE_NAME

# String to use for DBus path when VRRP instance has no interface configured
# Useful if your system has an interface named "none"!
# (default: "none")
\fBdbus_no_interface_name \fRNAME

# Specify the default username/groupname to run scripts under.
# If this option is not specified, the user defaults to keepalived_script
# if that user exists, otherwise the uid/gid under which keepalived is running.
Expand Down
5 changes: 5 additions & 0 deletions keepalived/core/global_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
#ifdef _WITH_JSON_
#include "global_json.h"
#endif
#ifdef _WITH_DBUS_
#include "vrrp_dbus.h"
#endif

/* global vars */
data_t *global_data = NULL;
Expand Down Expand Up @@ -417,6 +420,7 @@ free_global_data(data_t * data)
#endif
#ifdef _WITH_DBUS_
FREE_CONST_PTR(data->dbus_service_name);
FREE_CONST_PTR(data->dbus_no_interface_name);
#endif
#ifndef _ONE_PROCESS_DEBUG_
FREE_CONST_PTR(data->reload_check_config);
Expand Down Expand Up @@ -779,6 +783,7 @@ dump_global_data(FILE *fp, data_t * data)
#ifdef _WITH_DBUS_
conf_write(fp, " DBus %s", data->enable_dbus ? "enabled" : "disabled");
conf_write(fp, " DBus service name = %s", data->dbus_service_name ? data->dbus_service_name : "");
conf_write(fp, " DBus no interface name = %s", data->dbus_no_interface_name ? data->dbus_no_interface_name : dbus_no_interface_name);
#endif
conf_write(fp, " Script security %s", script_security ? "enabled" : "disabled");
if (!get_default_script_user(&uid, &gid))
Expand Down
13 changes: 13 additions & 0 deletions keepalived/core/global_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,18 @@ dbus_service_name_handler(const vector_t *strvec)
FREE_CONST_PTR(global_data->dbus_service_name);
global_data->dbus_service_name = set_value(strvec);
}

static void
dbus_no_interface_name_handler(const vector_t *strvec)
{
if (vector_size(strvec) < 2) {
report_config_error(CONFIG_GENERAL_ERROR, "dbus_no_interface_name missing - ignoring");
return;
}

FREE_CONST_PTR(global_data->dbus_no_interface_name);
global_data->dbus_no_interface_name = set_value(strvec);
}
#endif

static void
Expand Down Expand Up @@ -2474,6 +2486,7 @@ init_global_keywords(bool global_active)
#ifdef _WITH_DBUS_
install_keyword("enable_dbus", &enable_dbus_handler);
install_keyword("dbus_service_name", &dbus_service_name_handler);
install_keyword("dbus_no_interface_name", &dbus_no_interface_name_handler);
#endif
install_keyword("script_user", &script_user_handler);
install_keyword("enable_script_security", &script_security_handler);
Expand Down
1 change: 0 additions & 1 deletion keepalived/core/keepalived_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -2004,7 +2004,6 @@ netlink_if_link_filter(__attribute__((unused)) struct sockaddr_nl *snl, struct n
if (tb[IFLA_IFNAME] == NULL)
return -1;
name = (char *)RTA_DATA(tb[IFLA_IFNAME]);
log_message(LOG_INFO, "Got netlink new message for %s", name);

/* Skip it if already exists */
ifp = if_get_by_ifname(name, IF_CREATE_NETLINK);
Expand Down
1 change: 1 addition & 0 deletions keepalived/include/global_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ typedef struct _data {
#ifdef _WITH_DBUS_
bool enable_dbus;
const char *dbus_service_name;
const char *dbus_no_interface_name;
#endif
#ifdef _WITH_VRRP_
unsigned vrrp_netlink_cmd_rcv_bufs;
Expand Down
1 change: 1 addition & 0 deletions keepalived/include/vrrp_dbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "vrrp.h"
#include "list_head.h"

extern const char *dbus_no_interface_name;

void dbus_send_state_signal(vrrp_t *);
void dbus_remove_object(const vrrp_t *);
Expand Down
26 changes: 17 additions & 9 deletions keepalived/vrrp/vrrp_dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t startup_cond = PTHREAD_COND_INITIALIZER;

/* Global file variables */
static const char * const no_interface = "none";
const char *dbus_no_interface_name = "none";
static GDBusNodeInfo *vrrp_introspection_data = NULL;
static GDBusNodeInfo *vrrp_instance_introspection_data = NULL;
static GDBusConnection *global_connection;
Expand Down Expand Up @@ -207,13 +207,18 @@ static vrrp_t * __attribute__ ((pure))
get_vrrp_instance(const char *ifname, int vrid, int family)
{
vrrp_t *vrrp;
bool no_if = !strcmp(ifname, dbus_no_interface_name);

list_for_each_entry(vrrp, &vrrp_data->vrrp, e_list) {
if (vrrp->ifp &&
vrrp->vrid == vrid &&
vrrp->family == family &&
!valid_path_cmp(VRRP_CONFIGURED_IFP(vrrp)->ifname, ifname))
return vrrp;
if (vrrp->vrid == vrid &&
vrrp->family == family) {
if (no_if) {
if (!vrrp->ifp)
return vrrp;
} else if (vrrp->ifp &&
!valid_path_cmp(VRRP_CONFIGURED_IFP(vrrp)->ifname, ifname))
return vrrp;
}
}

return NULL;
Expand Down Expand Up @@ -520,7 +525,7 @@ dbus_create_object_params(const char *instance_name, const char *interface_name,
static void
dbus_create_object(vrrp_t *vrrp)
{
dbus_create_object_params(vrrp->iname, vrrp->ifp ? IF_NAME(VRRP_CONFIGURED_IFP(vrrp)) : no_interface, vrrp->vrid, vrrp->family, false);
dbus_create_object_params(vrrp->iname, vrrp->ifp ? IF_NAME(VRRP_CONFIGURED_IFP(vrrp)) : dbus_no_interface_name, vrrp->vrid, vrrp->family, false);
}

static bool
Expand Down Expand Up @@ -692,6 +697,9 @@ dbus_main(void *param)
return free_wait();
}

if (global_data->dbus_no_interface_name)
dbus_no_interface_name = global_data->dbus_no_interface_name;

service_name = global_data->dbus_service_name ? global_data->dbus_service_name : DBUS_SERVICE_NAME;
owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
service_name,
Expand Down Expand Up @@ -736,7 +744,7 @@ dbus_send_state_signal(vrrp_t *vrrp)
if (global_connection == NULL)
return;

object_path = dbus_object_create_path_instance(vrrp->ifp ? IF_NAME(VRRP_CONFIGURED_IFP(vrrp)) : no_interface, vrrp->vrid, vrrp->family);
object_path = dbus_object_create_path_instance(vrrp->ifp ? IF_NAME(VRRP_CONFIGURED_IFP(vrrp)) : dbus_no_interface_name, vrrp->vrid, vrrp->family);

args = g_variant_new("(u)", vrrp->state);
dbus_emit_signal(global_connection, object_path, DBUS_VRRP_INSTANCE_INTERFACE, "VrrpStatusChange", args);
Expand Down Expand Up @@ -867,7 +875,7 @@ dbus_reload(const list_head_t *o, const list_head_t *n)
const char *n_name;
bool match_found;

n_name = vrrp_n->ifp ? VRRP_CONFIGURED_IFP(vrrp_n)->ifname : no_interface;
n_name = vrrp_n->ifp ? VRRP_CONFIGURED_IFP(vrrp_n)->ifname : dbus_no_interface_name;

/* Try and find an instance with same vrid/family/interface that existed before and now */
match_found = false;
Expand Down
Loading