rtnl: remove dependency on config.h.

Change the rtnl_get_ts_label() function to accept the name of the master
interface and the buffer for the slave interface directly instead of the
struct interface from config.h.

Also, rename the function to rtnl_get_ts_device().

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
master
Miroslav Lichvar 2018-04-13 17:11:56 +02:00 committed by Richard Cochran
parent 29cd088347
commit 742f878821
4 changed files with 14 additions and 13 deletions

View File

@ -948,7 +948,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
c->timestamping = timestamping; c->timestamping = timestamping;
required_modes = clock_required_modes(c); required_modes = clock_required_modes(c);
STAILQ_FOREACH(iface, &config->interfaces, list) { STAILQ_FOREACH(iface, &config->interfaces, list) {
rtnl_get_ts_label(iface); rtnl_get_ts_device(iface->name, iface->ts_label);
ensure_ts_label(iface); ensure_ts_label(iface);
sk_get_ts_info(iface->ts_label, &iface->ts_info); sk_get_ts_info(iface->ts_label, &iface->ts_info);
if (iface->ts_info.valid && if (iface->ts_info.valid &&

2
nsm.c
View File

@ -267,7 +267,7 @@ static int nsm_open(struct nsm *nsm, struct config *cfg)
int count = 0; int count = 0;
STAILQ_FOREACH(iface, &cfg->interfaces, list) { STAILQ_FOREACH(iface, &cfg->interfaces, list) {
rtnl_get_ts_label(iface); rtnl_get_ts_device(iface->name, iface->ts_label);
if (iface->ts_label[0] == '\0') { if (iface->ts_label[0] == '\0') {
strncpy(iface->ts_label, iface->name, MAX_IFNAME_SIZE); strncpy(iface->ts_label, iface->name, MAX_IFNAME_SIZE);
} }

10
rtnl.c
View File

@ -43,13 +43,13 @@ int rtnl_close(int fd)
return close(fd); return close(fd);
} }
static void rtnl_get_ts_label_callback(void *ctx, int linkup, int ts_index) static void rtnl_get_ts_device_callback(void *ctx, int linkup, int ts_index)
{ {
int *dst = ctx; int *dst = ctx;
*dst = ts_index; *dst = ts_index;
} }
int rtnl_get_ts_label(struct interface *iface) int rtnl_get_ts_device(char *device, char *ts_device)
{ {
int err, fd; int err, fd;
int ts_index = -1; int ts_index = -1;
@ -58,13 +58,13 @@ int rtnl_get_ts_label(struct interface *iface)
if (fd < 0) if (fd < 0)
return fd; return fd;
err = rtnl_link_query(fd, iface->name); err = rtnl_link_query(fd, device);
if (err) { if (err) {
goto no_info; goto no_info;
} }
rtnl_link_status(fd, iface->name, rtnl_get_ts_label_callback, &ts_index); rtnl_link_status(fd, device, rtnl_get_ts_device_callback, &ts_index);
if (ts_index > 0 && if_indextoname(ts_index, iface->ts_label)) if (ts_index > 0 && if_indextoname(ts_index, ts_device))
err = 0; err = 0;
else else
err = -1; err = -1;

11
rtnl.h
View File

@ -20,8 +20,6 @@
#ifndef HAVE_RTNL_H #ifndef HAVE_RTNL_H
#define HAVE_RTNL_H #define HAVE_RTNL_H
#include "config.h"
typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index); typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index);
/** /**
@ -32,11 +30,14 @@ typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index);
int rtnl_close(int fd); int rtnl_close(int fd);
/** /**
* Get interface ts_label information * Get name of the slave interface which timestamps packets going through
* @param iface struct interface. * a master interface (e.g. bond0)
* @param device Name of the master interface.
* @param ts_device Buffer for the name of the slave interface, which must be
* at least IF_NAMESIZE bytes long.
* @return Zero on success, or -1 on error. * @return Zero on success, or -1 on error.
*/ */
int rtnl_get_ts_label(struct interface *iface); int rtnl_get_ts_device(char *device, char *ts_device);
/** /**
* Request the link status from the kernel. * Request the link status from the kernel.