2020-02-09 22:52:49 +08:00
|
|
|
/**
|
|
|
|
* @file interface.h
|
|
|
|
* @brief Implements network interface data structures.
|
|
|
|
* @note Copyright (C) 2020 Richard Cochran <richardcochran@gmail.com>
|
|
|
|
* @note SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
#ifndef HAVE_INTERFACE_H
|
|
|
|
#define HAVE_INTERFACE_H
|
|
|
|
|
2020-02-10 07:48:51 +08:00
|
|
|
#include <stdbool.h>
|
2020-02-09 22:52:49 +08:00
|
|
|
#include <sys/queue.h>
|
|
|
|
#include "sk.h"
|
|
|
|
|
|
|
|
#define MAX_IFNAME_SIZE 108 /* = UNIX_PATH_MAX */
|
|
|
|
|
|
|
|
#if (IF_NAMESIZE > MAX_IFNAME_SIZE)
|
|
|
|
#error if_namesize larger than expected.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Defines a network interface, with PTP options. */
|
|
|
|
struct interface {
|
|
|
|
STAILQ_ENTRY(interface) list;
|
|
|
|
char name[MAX_IFNAME_SIZE + 1];
|
|
|
|
char ts_label[MAX_IFNAME_SIZE + 1];
|
|
|
|
struct sk_ts_info ts_info;
|
|
|
|
};
|
|
|
|
|
2020-02-11 12:55:38 +08:00
|
|
|
/**
|
|
|
|
* Creates an instance of an interface.
|
|
|
|
* @param name The device which indentifies this interface.
|
|
|
|
* @return A pointer to an interface instance on success, NULL otherwise.
|
|
|
|
*/
|
|
|
|
struct interface *interface_create(const char *name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys an instance of an interface.
|
|
|
|
* @param iface A pointer obtained via interface_create().
|
|
|
|
*/
|
|
|
|
void interface_destroy(struct interface *iface);
|
|
|
|
|
2020-02-10 03:40:24 +08:00
|
|
|
/**
|
|
|
|
* Ensures that an interface has a proper time stamping label.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
*/
|
|
|
|
void interface_ensure_tslabel(struct interface *iface);
|
|
|
|
|
2020-02-10 03:14:42 +08:00
|
|
|
/**
|
|
|
|
* Populate the time stamping information of a given interface.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @return zero on success, negative on failure.
|
|
|
|
*/
|
|
|
|
int interface_get_tsinfo(struct interface *iface);
|
|
|
|
|
2020-02-10 02:56:54 +08:00
|
|
|
/**
|
|
|
|
* Obtain the time stamping label of a network interface. This can be
|
|
|
|
* different from the name of the interface when bonding is in effect.
|
|
|
|
*
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @return The time stamping device name of the network interface.
|
|
|
|
*/
|
|
|
|
const char *interface_label(struct interface *iface);
|
|
|
|
|
2020-02-09 23:22:52 +08:00
|
|
|
/**
|
|
|
|
* Obtains the name of a network interface.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @return The device name of the network interface.
|
|
|
|
*/
|
|
|
|
const char *interface_name(struct interface *iface);
|
|
|
|
|
2020-02-10 07:34:22 +08:00
|
|
|
/**
|
|
|
|
* Obtains the index of a PTP Hardware Clock device from a network interface.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @return The PHC index of the interface.
|
|
|
|
*/
|
|
|
|
int interface_phc_index(struct interface *iface);
|
|
|
|
|
2020-02-10 06:55:34 +08:00
|
|
|
/**
|
|
|
|
* Set the time stamping label of a given interface.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @param name The desired label for the interface.
|
|
|
|
*/
|
|
|
|
void interface_set_label(struct interface *iface, const char *label);
|
|
|
|
|
2020-02-10 05:26:24 +08:00
|
|
|
/**
|
|
|
|
* Set the name of a given interface.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @param name The desired name for the interface.
|
|
|
|
*/
|
|
|
|
void interface_set_name(struct interface *iface, const char *name);
|
2020-02-09 22:52:49 +08:00
|
|
|
|
2020-02-10 07:48:51 +08:00
|
|
|
/**
|
|
|
|
* Tests whether an interface's time stamping information is valid or not.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @return True if the time stamping information is valid, false otherwise.
|
|
|
|
*/
|
|
|
|
bool interface_tsinfo_valid(struct interface *iface);
|
|
|
|
|
2020-02-10 08:06:21 +08:00
|
|
|
/**
|
|
|
|
* Tests whether an interface supports a set of given time stamping modes.
|
|
|
|
* @param iface The interface of interest.
|
|
|
|
* @param modes Bit mask of SOF_TIMESTAMPING_ flags.
|
|
|
|
* @return True if the time stamping modes are supported, false otherwise.
|
|
|
|
*/
|
|
|
|
bool interface_tsmodes_supported(struct interface *iface, int modes);
|
|
|
|
|
2020-02-10 05:26:24 +08:00
|
|
|
#endif
|