Blame rtnl.h

Packit 9c3e7e
/**
Packit 9c3e7e
 * @file rtnl.h
Packit 9c3e7e
 * @brief Interface link status via RT netlink
Packit 9c3e7e
 * @note Copyright (C) 2012 Richard Cochran <richardcochran@gmail.com>
Packit 9c3e7e
 *
Packit 9c3e7e
 * This program is free software; you can redistribute it and/or modify
Packit 9c3e7e
 * it under the terms of the GNU General Public License as published by
Packit 9c3e7e
 * the Free Software Foundation; either version 2 of the License, or
Packit 9c3e7e
 * (at your option) any later version.
Packit 9c3e7e
 *
Packit 9c3e7e
 * This program is distributed in the hope that it will be useful,
Packit 9c3e7e
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 9c3e7e
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 9c3e7e
 * GNU General Public License for more details.
Packit 9c3e7e
 *
Packit 9c3e7e
 * You should have received a copy of the GNU General Public License along
Packit 9c3e7e
 * with this program; if not, write to the Free Software Foundation, Inc.,
Packit 9c3e7e
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Packit 9c3e7e
 */
Packit 9c3e7e
#ifndef HAVE_RTNL_H
Packit 9c3e7e
#define HAVE_RTNL_H
Packit 9c3e7e
Packit 9c3e7e
typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Close a RT netlink socket.
Packit 9c3e7e
 * @param fd  A socket obtained via rtnl_open().
Packit 9c3e7e
 * @return    Zero on success, non-zero otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int rtnl_close(int fd);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Get name of the slave interface which timestamps packets going through
Packit 9c3e7e
 * a master interface (e.g. bond0)
Packit 9c3e7e
 * @param device    Name of the master interface.
Packit 9c3e7e
 * @param ts_device Buffer for the name of the slave interface, which must be
Packit 9c3e7e
 *                  at least IF_NAMESIZE bytes long.
Packit 9c3e7e
 * @return          Zero on success, or -1 on error.
Packit 9c3e7e
 */
Packit 9c3e7e
int rtnl_get_ts_device(char *device, char *ts_device);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Request the link status from the kernel.
Packit 9c3e7e
 * @param fd     A socket obtained via rtnl_open().
Packit 9c3e7e
 * @param device Interface name. Request all iface's status if set NULL.
Packit 9c3e7e
 * @return       Zero on success, non-zero otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int rtnl_link_query(int fd, char *device);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Read kernel messages looking for a link up/down events.
Packit 9c3e7e
 * @param fd     Readable socket obtained via rtnl_open().
Packit 9c3e7e
 * @param device The device which we need to get link info.
Packit 9c3e7e
 * @param cb     Callback function to be invoked on each event.
Packit 9c3e7e
 * @param ctx    Private context passed to the callback.
Packit 9c3e7e
 * @return       Zero on success, non-zero otherwise.
Packit 9c3e7e
 */
Packit 9c3e7e
int rtnl_link_status(int fd, char *device, rtnl_callback cb, void *ctx);
Packit 9c3e7e
Packit 9c3e7e
/**
Packit 9c3e7e
 * Open a RT netlink socket for monitoring link state.
Packit 9c3e7e
 * @return    A valid socket, or -1 on error.
Packit 9c3e7e
 */
Packit 9c3e7e
int rtnl_open(void);
Packit 9c3e7e
Packit 9c3e7e
#endif