monitor_netlink.c revision 90acbcf20b5f896ca8f631923afe946c90d90de7
/*
SSSD - Service monitor - netlink support
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Parts of this code were borrowed from NetworkManager
Copyright (C) 2010 Red Hat
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 <http://www.gnu.org/licenses/>.
*/
#include <talloc.h>
#include <tevent.h>
#define __USE_GNU /* needed for struct ucred */
#include <unistd.h>
#include <fcntl.h>
#ifdef HAVE_LIBNL
#include <linux/rtnetlink.h>
#include <netlink/handlers.h>
#endif
/* Linux header file confusion causes this to be undefined. */
#ifndef SOL_NETLINK
#define SOL_NETLINK 270
#endif
#ifdef HAVE_LIBNL_OLDER_THAN_1_1
#define nlw_get_fd nl_handle_get_fd
#define nlw_recvmsgs_default nl_recvmsgs_def
#define nlw_get_pid nl_handle_get_pid
#define nlw_object_match nl_object_match
#define NLW_OK NL_PROCEED
#else
#define nlw_get_fd nl_socket_get_fd
#define nlw_get_pid nl_socket_get_local_port
#endif
struct netlink_ctx {
#ifdef HAVE_LIBNL
#endif
void *cb_data;
};
#ifdef HAVE_LIBNL
static int netlink_ctx_destructor(void *ptr)
{
struct netlink_ctx *nlctx;
return 0;
}
/*******************************************************************
* Wrappers for different capabilities of different libnl versions
*******************************************************************/
const struct sockaddr_nl *snl,
{
bool accept_msg = false;
return false;
}
/* Accept any messages from the kernel */
accept_msg = true;
}
/* And any multicast message directed to our netlink PID, since multicast
* currently requires CAP_ADMIN to use.
*/
accept_msg = true;
}
if (accept_msg == false) {
}
return accept_msg;
}
{
bool is_link_object = true;
filter = rtnl_link_alloc();
if (!filter) {
DEBUG(0, ("Allocation error!\n"));
is_link_object = false;
}
/* Ensure it's a link object */
is_link_object = false;
}
return is_link_object;
}
{
#ifndef HAVE_NL_SET_PASSCRED
return EOK; /* not available in this version */
#else
#endif
}
{
int ret;
if (ret != 0) {
return ret;
}
#else
int group = RTNLGRP_LINK;
errno = 0;
if (ret < 0) {
return ret;
}
#endif
return 0;
}
/*******************************************************************
* Callbacks for validating and receiving messages
*******************************************************************/
#ifdef HAVE_LIBNL_OLDER_THAN_1_1
void *arg)
{
return NL_SKIP;
}
return NLW_OK;
}
#else
{
const struct sockaddr_nl *snl;
return NL_SKIP;
}
return NL_SKIP;
}
return NLW_OK;
}
#endif
#ifdef HAVE_LIBNL_OLDER_THAN_1_1
void *arg)
{
return NLW_OK;
}
#else
{
return NLW_OK;
}
#endif
{
#ifndef HAVE_NL_SOCKET_MODIFY_CB
#else
#endif
if (ret != 0) {
return ret;
}
#ifndef HAVE_NL_SOCKET_MODIFY_CB
#else
#endif
if (ret != 0) {
return ret;
}
return ret;
}
{
int flags;
int ifidx;
if (!nlw_is_link_object(obj)) return;
/* IFF_LOWER_UP is the indicator of carrier status */
if (flags & IFF_LOWER_UP) {
} else {
}
}
{
int ret;
return;
}
return;
}
}
/*******************************************************************
* Set up the netlink library
*******************************************************************/
struct netlink_ctx **_nlctx)
{
struct netlink_ctx *nlctx;
int ret;
int nlfd;
unsigned flags;
/* allocate the libnl handle and register the default filter set */
nl_geterror()));
goto fail;
}
/* Register our custom message validation filter */
if (ret != 0) {
goto fail;
}
/* Try to start talking to netlink */
if (ret != 0) {
goto fail;
}
if (ret != 0) {
goto fail;
}
/* Subscribe to the LINK group for internal carrier signals */
if (ret != 0) {
goto fail;
}
errno = 0;
if (ret < 0) {
goto fail;
}
goto fail;
}
return EOK;
fail:
return ret;
}
#else /* HAVE_LIBNL not defined */
struct netlink_ctx **_nlctx)
{
return EOK;
}
#endif