Convert call sites to the proper method for getting interface names.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2020-02-09 07:24:19 -08:00
parent 380ee349f6
commit 34945679fe
10 changed files with 47 additions and 40 deletions

21
clock.c
View File

@ -849,7 +849,7 @@ int clock_required_modes(struct clock *c)
static void ensure_ts_label(struct interface *iface)
{
if (iface->ts_label[0] == '\0')
strncpy(iface->ts_label, iface->name, MAX_IFNAME_SIZE);
strncpy(iface->ts_label, interface_name(iface), MAX_IFNAME_SIZE);
}
struct clock *clock_create(enum clock_type type, struct config *config,
@ -960,13 +960,13 @@ struct clock *clock_create(enum clock_type type, struct config *config,
c->timestamping = timestamping;
required_modes = clock_required_modes(c);
STAILQ_FOREACH(iface, &config->interfaces, list) {
rtnl_get_ts_device(iface->name, iface->ts_label);
rtnl_get_ts_device(interface_name(iface), iface->ts_label);
ensure_ts_label(iface);
sk_get_ts_info(iface->ts_label, &iface->ts_info);
if (iface->ts_info.valid &&
((iface->ts_info.so_timestamping & required_modes) != required_modes)) {
pr_err("interface '%s' does not support "
"requested timestamping mode", iface->name);
pr_err("interface '%s' does not support requested timestamping mode",
interface_name(iface));
return NULL;
}
}
@ -996,7 +996,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
if (strcmp(config_get_string(config, NULL, "clockIdentity"),
"000000.0000.000000") == 0) {
if (generate_clock_identity(&c->dds.clockIdentity,
iface->name)) {
interface_name(iface))) {
pr_err("failed to generate a clock identity");
return NULL;
}
@ -1011,19 +1011,20 @@ struct clock *clock_create(enum clock_type type, struct config *config,
/* Configure the UDS. */
snprintf(udsif->name, sizeof(udsif->name), "%s",
config_get_string(config, NULL, "uds_address"));
if (config_set_section_int(config, udsif->name,
if (config_set_section_int(config, interface_name(udsif),
"announceReceiptTimeout", 0)) {
return NULL;
}
if (config_set_section_int(config, udsif->name,
if (config_set_section_int(config, interface_name(udsif),
"delay_mechanism", DM_AUTO)) {
return NULL;
}
if (config_set_section_int(config, udsif->name,
if (config_set_section_int(config, interface_name(udsif),
"network_transport", TRANS_UDS)) {
return NULL;
}
if (config_set_section_int(config, udsif->name, "delay_filter_length", 1)) {
if (config_set_section_int(config, interface_name(udsif),
"delay_filter_length", 1)) {
return NULL;
}
@ -1147,7 +1148,7 @@ struct clock *clock_create(enum clock_type type, struct config *config,
/* Create the ports. */
STAILQ_FOREACH(iface, &config->interfaces, list) {
if (clock_add_port(c, phc_device, phc_index, timestamping, iface)) {
pr_err("failed to open port %s", iface->name);
pr_err("failed to open port %s", interface_name(iface));
return NULL;
}
}

View File

@ -775,15 +775,15 @@ int config_read(const char *name, struct config *cfg)
if (parse_setting_line(line, &option, &value)) {
fprintf(stderr, "could not parse line %d in %s section\n",
line_num, current_section == GLOBAL_SECTION ?
"global" : current_port->name);
"global" : interface_name(current_port));
goto parse_error;
}
check_deprecated_options(&option);
parser_res = parse_item(cfg, 0, current_section == GLOBAL_SECTION ?
NULL : current_port->name, option, value);
NULL : interface_name(current_port),
option, value);
switch (parser_res) {
case PARSED_OK:
break;
@ -791,7 +791,7 @@ int config_read(const char *name, struct config *cfg)
fprintf(stderr, "unknown option %s at line %d in %s section\n",
option, line_num,
current_section == GLOBAL_SECTION ? "global" :
current_port->name);
interface_name(current_port));
goto parse_error;
case BAD_VALUE:
fprintf(stderr, "%s is a bad value for option %s at line %d\n",
@ -820,10 +820,12 @@ parse_error:
struct interface *config_create_interface(const char *name, struct config *cfg)
{
struct interface *iface;
const char *ifname;
/* only create each interface once (by name) */
STAILQ_FOREACH(iface, &cfg->interfaces, list) {
if (0 == strncmp(name, iface->name, MAX_IFNAME_SIZE))
ifname = interface_name(iface);
if (0 == strncmp(name, ifname, MAX_IFNAME_SIZE))
return iface;
}

View File

@ -57,13 +57,13 @@ all: $(PRG)
ptp4l: $(OBJ)
nsm: config.o $(FILTERS) hash.o msg.o nsm.o phc.o print.o \
nsm: config.o $(FILTERS) hash.o interface.o msg.o nsm.o phc.o print.o \
rtnl.o sk.o $(TRANSP) tlv.o tsproc.o util.o version.o
pmc: config.o hash.o msg.o phc.o pmc.o pmc_common.o print.o sk.o tlv.o \
$(TRANSP) util.o version.o
pmc: config.o hash.o interface.o msg.o phc.o pmc.o pmc_common.o print.o sk.o \
tlv.o $(TRANSP) util.o version.o
phc2sys: clockadj.o clockcheck.o config.o hash.o msg.o \
phc2sys: clockadj.o clockcheck.o config.o hash.o interface.o msg.o \
phc.o phc2sys.o pmc_common.o print.o $(SERVOS) sk.o stats.o \
sysoff.o tlv.o $(TRANSP) util.o version.o
@ -71,7 +71,7 @@ hwstamp_ctl: hwstamp_ctl.o version.o
phc_ctl: phc_ctl.o phc.o sk.o util.o clockadj.o sysoff.o print.o version.o
snmp4lptp: config.o hash.o msg.o phc.o pmc_common.o print.o sk.o \
snmp4lptp: config.o hash.o interface.o msg.o phc.o pmc_common.o print.o sk.o \
snmp4lptp.o tlv.o $(TRANSP) util.o
$(CC) $^ $(LDFLAGS) $(LOADLIBES) $(LDLIBS) $(snmplib) -o $@

9
nsm.c
View File

@ -262,14 +262,15 @@ static void nsm_help(FILE *fp)
static int nsm_open(struct nsm *nsm, struct config *cfg)
{
enum transport_type transport;
const char *ifname, *name;
struct interface *iface;
const char *name;
int count = 0;
STAILQ_FOREACH(iface, &cfg->interfaces, list) {
rtnl_get_ts_device(iface->name, iface->ts_label);
ifname = interface_name(iface);
rtnl_get_ts_device(ifname, iface->ts_label);
if (iface->ts_label[0] == '\0') {
strncpy(iface->ts_label, iface->name, MAX_IFNAME_SIZE);
strncpy(iface->ts_label, ifname, MAX_IFNAME_SIZE);
}
count++;
}
@ -278,7 +279,7 @@ static int nsm_open(struct nsm *nsm, struct config *cfg)
return -1;
}
iface = STAILQ_FIRST(&cfg->interfaces);
nsm->name = name = iface->name;
nsm->name = name = interface_name(iface);
nsm->cfg = cfg;
transport = config_get_int(cfg, name, "network_transport");

View File

@ -352,7 +352,7 @@ struct pmc *pmc_create(struct config *cfg, enum transport_type transport_type,
strncpy(iface.name, iface_name, MAX_IFNAME_SIZE);
if (iface.ts_label[0] == '\0') {
strncpy(iface.ts_label, iface.name, MAX_IFNAME_SIZE);
strncpy(iface.ts_label, interface_name(&iface), MAX_IFNAME_SIZE);
}
if (transport_open(pmc->transport, &iface,

19
port.c
View File

@ -1717,10 +1717,13 @@ int port_initialize(struct port *p)
if (p->bmca == BMCA_NOOP) {
port_set_delay_tmo(p);
}
if (p->fda.fd[FD_RTNL] == -1)
if (p->fda.fd[FD_RTNL] == -1) {
p->fda.fd[FD_RTNL] = rtnl_open();
if (p->fda.fd[FD_RTNL] >= 0)
rtnl_link_query(p->fda.fd[FD_RTNL], p->iface->name);
}
if (p->fda.fd[FD_RTNL] >= 0) {
const char *ifname = interface_name(p->iface);
rtnl_link_query(p->fda.fd[FD_RTNL], ifname);
}
}
port_nrate_initialize(p);
@ -2974,10 +2977,10 @@ struct port *port_open(const char *phc_device,
}
p->phc_index = phc_index;
p->jbod = config_get_int(cfg, interface->name, "boundary_clock_jbod");
transport = config_get_int(cfg, interface->name, "network_transport");
p->master_only = config_get_int(cfg, interface->name, "masterOnly");
p->bmca = config_get_int(cfg, interface->name, "BMCA");
p->jbod = config_get_int(cfg, interface_name(interface), "boundary_clock_jbod");
transport = config_get_int(cfg, interface_name(interface), "network_transport");
p->master_only = config_get_int(cfg, interface_name(interface), "masterOnly");
p->bmca = config_get_int(cfg, interface_name(interface), "BMCA");
if (p->bmca == BMCA_NOOP && transport != TRANS_UDS) {
if (p->master_only) {
@ -3013,7 +3016,7 @@ struct port *port_open(const char *phc_device,
}
}
p->name = interface->name;
p->name = interface_name(interface);
p->iface = interface;
p->asymmetry = config_get_int(cfg, p->name, "delayAsymmetry");
p->asymmetry <<= 16;

View File

@ -60,7 +60,7 @@ struct tc_txd {
struct port {
LIST_ENTRY(port) list;
char *name;
const char *name;
struct interface *iface;
struct clock *clock;
struct transport *trp;

2
udp.c
View File

@ -154,9 +154,9 @@ static int udp_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type ts_type)
{
struct udp *udp = container_of(t, struct udp, t);
const char *name = interface_name(iface);
uint8_t event_dscp, general_dscp;
int efd, gfd, ttl;
char *name = iface->name;
ttl = config_get_int(t->cfg, name, "udp_ttl");
udp->mac.len = 0;

2
udp6.c
View File

@ -164,9 +164,9 @@ static int udp6_open(struct transport *t, struct interface *iface,
struct fdarray *fda, enum timestamp_type ts_type)
{
struct udp6 *udp6 = container_of(t, struct udp6, t);
const char *name = interface_name(iface);
uint8_t event_dscp, general_dscp;
int efd, gfd, hop_limit;
char *name = iface->name;
hop_limit = config_get_int(t->cfg, name, "udp_ttl");
udp6->mac.len = 0;

8
uds.c
View File

@ -55,11 +55,11 @@ static int uds_close(struct transport *t, struct fdarray *fda)
static int uds_open(struct transport *t, struct interface *iface, struct fdarray *fda,
enum timestamp_type tt)
{
int fd, err;
struct sockaddr_un sa;
struct uds *uds = container_of(t, struct uds, t);
char *uds_path = config_get_string(t->cfg, NULL, "uds_address");
char *name = iface->name;
struct uds *uds = container_of(t, struct uds, t);
const char *name = interface_name(iface);
struct sockaddr_un sa;
int fd, err;
fd = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (fd < 0) {