File: interface.c

package info (click to toggle)
linuxptp 4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,536 kB
  • sloc: ansic: 26,119; sh: 92; makefile: 87
file content (102 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
 * @file interface.c
 * @brief Implements network interface data structures.
 * @note Copyright (C) 2020 Richard Cochran <richardcochran@gmail.com>
 * @note SPDX-License-Identifier: GPL-2.0+
 */
#include <stdlib.h>
#include <string.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 sk_if_info if_info;
	int vclock;
};

struct interface *interface_create(const char *name)
{
	struct interface *iface;

	iface = calloc(1, sizeof(struct interface));
	if (!iface) {
		return NULL;
	}
	strncpy(iface->name, name, MAX_IFNAME_SIZE);
	strncpy(iface->ts_label, name, MAX_IFNAME_SIZE);
	iface->vclock = -1;

	return iface;
}

void interface_destroy(struct interface *iface)
{
	free(iface);
}

int interface_get_tsinfo(struct interface *iface)
{
	return sk_get_ts_info(iface->ts_label, &iface->ts_info);
}

int interface_get_ifinfo(struct interface *iface)
{
	return sk_get_if_info(iface->ts_label, &iface->if_info);
}

const char *interface_label(struct interface *iface)
{
	return iface->ts_label;
}

bool interface_ifinfo_valid(struct interface *iface)
{
       return iface->if_info.valid ? true : false;
}


const char *interface_name(struct interface *iface)
{
	return iface->name;
}

int interface_phc_index(struct interface *iface)
{
	return iface->ts_info.phc_index;
}

void interface_set_label(struct interface *iface, const char *label)
{
	strncpy(iface->ts_label, label, MAX_IFNAME_SIZE);
}

bool interface_tsinfo_valid(struct interface *iface)
{
	return iface->ts_info.valid ? true : false;
}

bool interface_tsmodes_supported(struct interface *iface, int modes)
{
	if ((iface->ts_info.so_timestamping & modes) == modes) {
		return true;
	}
	return false;
}

void interface_set_vclock(struct interface *iface, int vclock)
{
	iface->vclock = vclock;
}

int interface_get_vclock(struct interface *iface)
{
	return iface->vclock;
}

uint64_t interface_bitperiod(struct interface *iface)
{
	return iface->if_info.iface_bit_period;
}