[Git][NTPsec/ntpsec][master] In the config parser, factor out type/unit lookup into addr_from_typeunit()...
Eric S. Raymond
gitlab at mg.gitlab.com
Sat Nov 4 17:28:52 UTC 2017
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
ced7b325 by Eric S. Raymond at 2017-11-04T13:26:34-04:00
In the config parser, factor out type/unit lookup into addr_from_typeunit()...
...so we can generalize use for type/unit specifications.
- - - - -
2 changed files:
- include/ntp_config.h
- ntpd/ntp_parser.y
Changes:
=====================================
include/ntp_config.h
=====================================
--- a/include/ntp_config.h
+++ b/include/ntp_config.h
@@ -239,6 +239,7 @@ void * concat_gen_fifos(void *first, void *second);
? HEAD_FIFO(*(pf)) \
: NULL)
+address_node *addr_from_typeunit(char *type, int unit);
peer_node *create_peer_node(int hmode, address_node *addr,
attr_val_fifo *options);
unpeer_node *create_unpeer_node(address_node *addr);
=====================================
ntpd/ntp_parser.y
=====================================
--- a/ntpd/ntp_parser.y
+++ b/ntpd/ntp_parser.y
@@ -930,21 +930,8 @@ refclock_command
: T_Refclock T_String optional_unit option_list
{
#ifdef REFCLOCK
- peer_node *my_node;
- address_node *fakeaddr;
- char addrbuf[1025]; /* NI_MAXHOSTS on Linux */
- int dtype;
-
- for (dtype = 1; dtype < (int)num_refclock_conf; dtype++)
- if (refclock_conf[dtype]->basename != NULL && strcasecmp(refclock_conf[dtype]->basename, $2) == 0)
- goto foundit;
- msyslog(LOG_ERR, "CONFIG: Unknown driver name %s", $2);
- exit(1);
- foundit:
- snprintf(addrbuf, sizeof(addrbuf),
- "127.127.%d.%d", dtype, $3);
- fakeaddr = create_address_node(estrdup(addrbuf),AF_INET);
- my_node = create_peer_node(T_Server, fakeaddr, $4);
+ address_node *fakeaddr = addr_from_typeunit($2, $3);
+ peer_node *my_node = create_peer_node(T_Server, fakeaddr, $4);
APPEND_G_FIFO(cfgt.peers, my_node);
#endif /* REFCLOCK */
}
@@ -1398,6 +1385,24 @@ number
%%
+#ifdef REFCLOCK
+address_node *
+addr_from_typeunit(char *type, int unit)
+{
+ char addrbuf[1025]; /* NI_MAXHOSTS on Linux */
+ int dtype;
+
+ for (dtype = 1; dtype < (int)num_refclock_conf; dtype++)
+ if (refclock_conf[dtype]->basename != NULL && strcasecmp(refclock_conf[dtype]->basename, type) == 0)
+ goto foundit;
+ msyslog(LOG_ERR, "CONFIG: Unknown driver name %s", type);
+ exit(1);
+foundit:
+ snprintf(addrbuf, sizeof(addrbuf), "127.127.%d.%d", dtype, unit);
+ return create_address_node(estrdup(addrbuf), AF_INET);
+}
+#endif /* REFCLOCK */
+
void
yyerror(
const char *msg
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/ced7b325506be8094845cafb9dde277e720e1169
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/ced7b325506be8094845cafb9dde277e720e1169
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20171104/6bee27c8/attachment.html>
More information about the vc
mailing list