Skip to content

Commit

Permalink
Revert "BACKENDS: Move the netlink watching to the backends"
Browse files Browse the repository at this point in the history
This reverts commit cfc1400.
  • Loading branch information
aplopez committed May 2, 2024
1 parent cfc1400 commit 5d73e79
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 87 deletions.
8 changes: 4 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ if BUILD_SELINUX
endif

dist_noinst_HEADERS = \
src/monitor/monitor.h \
src/sss_iface/sbus_sss_arguments.h \
src/sss_iface/sbus_sss_client_async.h \
src/sss_iface/sbus_sss_client_properties.h \
Expand Down Expand Up @@ -746,6 +747,7 @@ dist_noinst_HEADERS = \
src/responder/kcm/secrets/secrets.h \
src/responder/kcm/secrets/sec_pvt.h \
src/util/nss_dl_load.h \
src/monitor/monitor.h \
src/responder/common/responder.h \
src/responder/common/responder_packet.h \
src/responder/common/cache_req/cache_req.h \
Expand Down Expand Up @@ -841,7 +843,6 @@ dist_noinst_HEADERS = \
src/providers/data_provider/dp_iface.h \
src/providers/backend.h \
src/providers/be_dyndns.h \
src/providers/be_netlink.h \
src/providers/be_ptask_private.h \
src/providers/be_ptask.h \
src/providers/be_refresh.h \
Expand Down Expand Up @@ -1524,12 +1525,14 @@ endif
sssd_SOURCES = \
src/monitor/monitor.c \
src/monitor/monitor_bootstrap.c \
src/monitor/monitor_netlink.c \
src/confdb/confdb_setup.c \
src/util/nscd.c \
$(NULL)
sssd_LDADD = \
$(SSSD_LIBS) \
$(INOTIFY_LIBS) \
$(LIBNL_LIBS) \
$(KEYUTILS_LIBS) \
$(SSSD_INTERNAL_LTLIBS) \
libsss_iface.la \
Expand Down Expand Up @@ -1835,7 +1838,6 @@ sssd_be_SOURCES = \
src/providers/data_provider_opts.c \
src/providers/data_provider_callbacks.c \
src/providers/be_dyndns.c \
src/providers/be_netlink.c \
src/providers/be_ptask.c \
src/providers/be_refresh.c \
src/providers/data_provider/dp.c \
Expand All @@ -1862,7 +1864,6 @@ sssd_be_LDADD = \
$(SSSD_LIBS) \
$(CARES_LIBS) \
$(PAM_LIBS) \
$(LIBNL_LIBS) \
$(SSSD_INTERNAL_LTLIBS) \
libsss_iface.la \
libsss_sbus.la \
Expand Down Expand Up @@ -2125,7 +2126,6 @@ libdlopen_test_providers_la_LIBADD = \
$(PAM_LIBS) \
$(SSSD_LIBS) \
$(CARES_LIBS) \
$(LIBNL_LIBS) \
$(SSSD_INTERNAL_LTLIBS) \
libsss_iface.la \
libsss_sbus.la \
Expand Down
45 changes: 40 additions & 5 deletions src/monitor/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "confdb/confdb.h"
#include "confdb/confdb_setup.h"
#include "db/sysdb.h"
#include "monitor/monitor.h"
#include "sss_iface/sss_iface_async.h"

#ifdef HAVE_SYSTEMD
Expand All @@ -66,11 +67,6 @@
*/
#define KRB5_RCACHE_DIR_DISABLE "__LIBKRB5_DEFAULTS__"

/* for detecting if NSCD is running */
#ifndef NSCD_SOCKET_PATH
#define NSCD_SOCKET_PATH "/var/run/nscd/socket"
#endif

int cmdline_debug_level;
int cmdline_debug_timestamps;
int cmdline_debug_microseconds;
Expand Down Expand Up @@ -115,6 +111,7 @@ struct mt_ctx {
struct mt_svc *svc_list;
bool check_children;
bool services_started;
struct netlink_ctx *nlctx;
struct sss_sigchild_ctx *sigchld_ctx;
bool pid_file_created;
bool is_daemon;
Expand Down Expand Up @@ -153,6 +150,21 @@ static int mark_service_as_started(struct mt_svc *svc);

static int monitor_cleanup(void);

static void network_status_change_cb(void *cb_data)
{
struct mt_svc *iter;
struct mt_ctx *ctx = (struct mt_ctx *) cb_data;

DEBUG(SSSDBG_TRACE_INTERNAL, "A networking status change detected "
"signaling providers to reset offline status\n");
for (iter = ctx->svc_list; iter; iter = iter->next) {
/* Don't signal services, only providers */
if (iter->provider) {
service_signal_reset_offline(iter);
}
}
}

static int add_svc_conn_spy(struct mt_svc *svc);

static int service_not_found(const char *svc_name,
Expand Down Expand Up @@ -1589,6 +1601,7 @@ static void monitor_sbus_connected(struct tevent_req *req)
{
struct mt_ctx *ctx;
struct sss_domain_info *dom;
bool disable_netlink;
int num_providers;
errno_t ret;

Expand Down Expand Up @@ -1634,6 +1647,28 @@ static void monitor_sbus_connected(struct tevent_req *req)
goto done;
}

ret = confdb_get_bool(ctx->cdb,
CONFDB_MONITOR_CONF_ENTRY,
CONFDB_MONITOR_DISABLE_NETLINK,
false, &disable_netlink);

if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
"Failed to read disable_netlink from confdb: [%d] %s\n",
ret, sss_strerror(ret));
goto done;
}

if (disable_netlink == false) {
ret = setup_netlink(ctx, ctx->ev, network_status_change_cb,
ctx, &ctx->nlctx);
if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
"Cannot set up listening for network notifications\n");
goto done;
}
}

/* start providers */
num_providers = 0;
for (dom = ctx->domains; dom; dom = get_next_domain(dom, 0)) {
Expand Down
22 changes: 13 additions & 9 deletions src/providers/be_netlink.h → src/monitor/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _DP_NETLINK_H_
#define _DP_NETLINK_H_
#ifndef _MONITOR_H_
#define _MONITOR_H_

#include <talloc.h>
#include <tevent.h>
/* for detecting if NSCD is running */
#ifndef NSCD_SOCKET_PATH
#define NSCD_SOCKET_PATH "/var/run/nscd/socket"
#endif

/* from be_netlink.c */
struct be_netlink_ctx;
struct mt_ctx;

/* from monitor_netlink.c */
struct netlink_ctx;

typedef void (*network_change_cb)(void *);

int netlink_watch(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int setup_netlink(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
network_change_cb change_cb, void *cb_data,
struct be_netlink_ctx **_nlctx);
struct netlink_ctx **_nlctx);

#endif /* _DP_MONITOR_H */
#endif /* _MONITOR_H */
37 changes: 18 additions & 19 deletions src/providers/be_netlink.c → src/monitor/monitor_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <unistd.h>
#include <fcntl.h>

#include "providers/be_netlink.h"
#include "monitor/monitor.h"
#include "util/util.h"

#ifdef HAVE_LIBNL
Expand Down Expand Up @@ -102,7 +102,7 @@ enum nlw_msg_type {
NLW_OTHER
};

struct be_netlink_ctx {
struct netlink_ctx {
#ifdef HAVE_LIBNL
struct nlw_handle *nlp;
#endif
Expand All @@ -115,8 +115,8 @@ struct be_netlink_ctx {
#ifdef HAVE_LIBNL
static int netlink_ctx_destructor(void *ptr)
{
struct be_netlink_ctx *nlctx;
nlctx = talloc_get_type(ptr, struct be_netlink_ctx);
struct netlink_ctx *nlctx;
nlctx = talloc_get_type(ptr, struct netlink_ctx);

nlw_destroy_handle(nlctx->nlp);
return 0;
Expand Down Expand Up @@ -469,7 +469,7 @@ static int nlw_groups_subscribe(struct nlw_handle *nlp, int *groups)

static int event_msg_recv(struct nl_msg *msg, void *arg)
{
struct be_netlink_ctx *ctx = (struct be_netlink_ctx *) arg;
struct netlink_ctx *ctx = (struct netlink_ctx *) arg;
struct nlmsghdr *hdr;
const struct sockaddr_nl *snl;
struct ucred *creds;
Expand Down Expand Up @@ -631,7 +631,7 @@ static bool route_is_multicast(struct rtnl_route *route_obj)
static void route_msg_handler(struct nl_object *obj, void *arg)
{
struct rtnl_route *route_obj;
struct be_netlink_ctx *ctx = (struct be_netlink_ctx *) arg;
struct netlink_ctx *ctx = (struct netlink_ctx *) arg;

if (!nlw_is_route_object(obj)) return;

Expand Down Expand Up @@ -672,7 +672,7 @@ static void addr_msg_debug_print(struct rtnl_addr *addr_obj)
static void addr_msg_handler(struct nl_object *obj, void *arg)
{
int err;
struct be_netlink_ctx *ctx = (struct be_netlink_ctx *) arg;
struct netlink_ctx *ctx = (struct netlink_ctx *) arg;
struct rtnl_addr *addr_obj;
struct nl_addr *local_addr;
struct sockaddr_in sa4;
Expand All @@ -688,9 +688,9 @@ static void addr_msg_handler(struct nl_object *obj, void *arg)

local_addr = rtnl_addr_get_local(addr_obj);
if (local_addr == NULL) {
DEBUG(SSSDBG_MINOR_FAILURE,
"Received RTM_NEWADDR with no address\n");
return;
DEBUG(SSSDBG_MINOR_FAILURE,
"Received RTM_NEWADDR with no address\n");
return;
}

switch (nl_addr_get_family(local_addr)) {
Expand Down Expand Up @@ -736,7 +736,7 @@ static void addr_msg_handler(struct nl_object *obj, void *arg)

static void link_msg_handler(struct nl_object *obj, void *arg)
{
struct be_netlink_ctx *ctx = (struct be_netlink_ctx *) arg;
struct netlink_ctx *ctx = (struct netlink_ctx *) arg;
struct rtnl_link *link_obj;
unsigned int flags;
char str_flags[512];
Expand Down Expand Up @@ -765,7 +765,7 @@ static void link_msg_handler(struct nl_object *obj, void *arg)
static void netlink_fd_handler(struct tevent_context *ev, struct tevent_fd *fde,
uint16_t flags, void *data)
{
struct be_netlink_ctx *nlctx = talloc_get_type(data, struct be_netlink_ctx);
struct netlink_ctx *nlctx = talloc_get_type(data, struct netlink_ctx);
int ret;

if (!nlctx || !nlctx->nlp) {
Expand All @@ -786,17 +786,17 @@ static void netlink_fd_handler(struct tevent_context *ev, struct tevent_fd *fde,
* Set up the netlink library
*******************************************************************/

int netlink_watch(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int setup_netlink(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
network_change_cb change_cb, void *cb_data,
struct be_netlink_ctx **_nlctx)
struct netlink_ctx **_nlctx)
{
struct be_netlink_ctx *nlctx;
struct netlink_ctx *nlctx;
int ret;
int nlfd;
int groups[] = { RTNLGRP_LINK, RTNLGRP_IPV4_ROUTE, RTNLGRP_IPV6_ROUTE,
RTNLGRP_IPV4_IFADDR, RTNLGRP_IPV6_IFADDR, 0 };

nlctx = talloc_zero(mem_ctx, struct be_netlink_ctx);
nlctx = talloc_zero(mem_ctx, struct netlink_ctx);
if (!nlctx) return ENOMEM;
talloc_set_destructor((TALLOC_CTX *) nlctx, netlink_ctx_destructor);

Expand Down Expand Up @@ -863,7 +863,6 @@ int netlink_watch(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
goto fail;
}

DEBUG(SSSDBG_TRACE_LIBS, "Netlink watching is enabled\n");
*_nlctx = nlctx;
return EOK;

Expand All @@ -873,9 +872,9 @@ int netlink_watch(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
}

#else /* HAVE_LIBNL not defined */
int netlink_watch(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int setup_netlink(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
network_change_cb change_cb, void *cb_data,
struct be_netlink_ctx **_nlctx)
struct netlink_ctx **_nlctx)
{
if (_nlctx) *_nlctx = NULL;
return EOK;
Expand Down
2 changes: 0 additions & 2 deletions src/providers/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "providers/data_provider.h"
#include "providers/fail_over.h"
#include "providers/be_netlink.h"
#include "providers/be_refresh.h"
#include "providers/data_provider/dp.h"
#include "util/child_common.h"
Expand Down Expand Up @@ -105,7 +104,6 @@ struct be_ctx {
struct be_ptask *check_if_online_ptask;

struct be_refresh_ctx *refresh_ctx;
struct be_netlink_ctx *nlctx;

size_t check_online_ref_count;
int check_online_retry_delay;
Expand Down
49 changes: 1 addition & 48 deletions src/providers/data_provider_be.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,48 +526,6 @@ static int watch_config_files(struct be_ctx *ctx)
return EOK;
}

static void network_status_change_cb(void *cb_data)
{
struct be_ctx *ctx = (struct be_ctx *) cb_data;

check_if_online(ctx, 1);
}


static int watch_netlink(struct be_ctx *ctx)
{
int ret;
bool disable_netlink;

ret = confdb_get_bool(ctx->cdb,
CONFDB_MONITOR_CONF_ENTRY,
CONFDB_MONITOR_DISABLE_NETLINK,
false, &disable_netlink);

if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
"Failed to read %s from confdb: [%d] %s\n",
CONFDB_MONITOR_DISABLE_NETLINK,
ret, sss_strerror(ret));
return ret;
}


if (disable_netlink) {
DEBUG(SSS_LOG_NOTICE, "Netlink watching is disabled\n");
} else {
ret = netlink_watch(ctx, ctx->ev, network_status_change_cb,
ctx, &ctx->nlctx);
if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
"Failed to set up listener for network status changes\n");
return ret;
}
}

return EOK;
}

static errno_t
be_register_monitor_iface(struct sbus_connection *conn, struct be_ctx *be_ctx)
{
Expand Down Expand Up @@ -719,17 +677,12 @@ errno_t be_process_init(TALLOC_CTX *mem_ctx,
goto done;
}

/* Set up watchers for system config files and the net links */
/* Set up watchers for system config files */
ret = watch_config_files(be_ctx);
if (ret != EOK) {
goto done;
}

ret = watch_netlink(be_ctx);
if (ret != EOK) {
goto done;
}

ret = sss_monitor_register_service(be_ctx, be_ctx->conn,
be_ctx->identity, DATA_PROVIDER_VERSION,
MT_SVC_PROVIDER);
Expand Down

0 comments on commit 5d73e79

Please sign in to comment.