interface: Hide the implementation details.

Now that a complete functional API is in place, there is no need to expose
the inner workings of the network interface data type.  This patch converts
it into an opaque type while leaving the list marker visible to users
through a simple form of "friendly exposition".

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2020-02-10 21:05:42 -08:00
parent 66dc3167e3
commit a8f742528e
5 changed files with 21 additions and 7 deletions

View File

@ -47,6 +47,10 @@
#define N_CLOCK_PFD (N_POLLFD + 1) /* one extra per port, for the fault timer */ #define N_CLOCK_PFD (N_POLLFD + 1) /* one extra per port, for the fault timer */
#define POW2_41 ((double)(1ULL << 41)) #define POW2_41 ((double)(1ULL << 41))
struct interface {
STAILQ_ENTRY(interface) list;
};
struct port { struct port {
LIST_ENTRY(port) list; LIST_ENTRY(port) list;
}; };

View File

@ -32,6 +32,10 @@
#include "print.h" #include "print.h"
#include "util.h" #include "util.h"
struct interface {
STAILQ_ENTRY(interface) list;
};
enum config_section { enum config_section {
GLOBAL_SECTION, GLOBAL_SECTION,
UC_MTAB_SECTION, UC_MTAB_SECTION,

View File

@ -7,6 +7,13 @@
#include <stdlib.h> #include <stdlib.h>
#include "interface.h" #include "interface.h"
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;
};
struct interface *interface_create(const char *name) struct interface *interface_create(const char *name)
{ {
struct interface *iface; struct interface *iface;

View File

@ -17,13 +17,8 @@
#error if_namesize larger than expected. #error if_namesize larger than expected.
#endif #endif
/** Defines a network interface, with PTP options. */ /** Opaque type */
struct interface { 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;
};
/** /**
* Creates an instance of an interface. * Creates an instance of an interface.

4
nsm.c
View File

@ -35,6 +35,10 @@
#define IFMT "\n\t\t" #define IFMT "\n\t\t"
#define NSM_NFD 3 #define NSM_NFD 3
struct interface {
STAILQ_ENTRY(interface) list;
};
struct nsm { struct nsm {
struct config *cfg; struct config *cfg;
struct fdarray fda; struct fdarray fda;