diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-07-15 15:06:54 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-07-15 15:06:54 +0200 |
commit | 278842dd72b5dcdda5d418f9e7bb4d288c0e909d (patch) | |
tree | b0e077a3b30241d07abe65cae22e09f4aaa4e3ea | |
parent | 7d16964c3ebb9e7beee89ad96f824470f7ab5346 (diff) | |
download | busybox-w32-278842dd72b5dcdda5d418f9e7bb4d288c0e909d.tar.gz busybox-w32-278842dd72b5dcdda5d418f9e7bb4d288c0e909d.tar.bz2 busybox-w32-278842dd72b5dcdda5d418f9e7bb4d288c0e909d.zip |
ntpd: add support for -I IFACE
function old new delta
packed_usage 29908 29947 +39
ntp_init 428 460 +32
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 71/0) Total: 71 bytes
Signed-off-by: Nikolaus Froehlich <nikolaus@mathematik.uni-marburg.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ntpd.c | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/networking/ntpd.c b/networking/ntpd.c index 59607ed23..cfe695631 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c | |||
@@ -29,7 +29,7 @@ | |||
29 | */ | 29 | */ |
30 | 30 | ||
31 | //usage:#define ntpd_trivial_usage | 31 | //usage:#define ntpd_trivial_usage |
32 | //usage: "[-dnqNw"IF_FEATURE_NTPD_SERVER("l")"] [-S PROG] [-p PEER]..." | 32 | //usage: "[-dnqNw"IF_FEATURE_NTPD_SERVER("l -I IFACE")"] [-S PROG] [-p PEER]..." |
33 | //usage:#define ntpd_full_usage "\n\n" | 33 | //usage:#define ntpd_full_usage "\n\n" |
34 | //usage: "NTP client/server\n" | 34 | //usage: "NTP client/server\n" |
35 | //usage: "\n -d Verbose" | 35 | //usage: "\n -d Verbose" |
@@ -39,6 +39,7 @@ | |||
39 | //usage: "\n -w Do not set time (only query peers), implies -n" | 39 | //usage: "\n -w Do not set time (only query peers), implies -n" |
40 | //usage: IF_FEATURE_NTPD_SERVER( | 40 | //usage: IF_FEATURE_NTPD_SERVER( |
41 | //usage: "\n -l Run as server on port 123" | 41 | //usage: "\n -l Run as server on port 123" |
42 | //usage: "\n -I IFACE Bind server to IFACE, implies -l" | ||
42 | //usage: ) | 43 | //usage: ) |
43 | //usage: "\n -S PROG Run PROG after stepping time, stratum change, and every 11 mins" | 44 | //usage: "\n -S PROG Run PROG after stepping time, stratum change, and every 11 mins" |
44 | //usage: "\n -p PEER Obtain time from PEER (may be repeated)" | 45 | //usage: "\n -p PEER Obtain time from PEER (may be repeated)" |
@@ -283,6 +284,7 @@ enum { | |||
283 | OPT_p = (1 << 5), | 284 | OPT_p = (1 << 5), |
284 | OPT_S = (1 << 6), | 285 | OPT_S = (1 << 6), |
285 | OPT_l = (1 << 7) * ENABLE_FEATURE_NTPD_SERVER, | 286 | OPT_l = (1 << 7) * ENABLE_FEATURE_NTPD_SERVER, |
287 | OPT_I = (1 << 8) * ENABLE_FEATURE_NTPD_SERVER, | ||
286 | /* We hijack some bits for other purposes */ | 288 | /* We hijack some bits for other purposes */ |
287 | OPT_qq = (1 << 31), | 289 | OPT_qq = (1 << 31), |
288 | }; | 290 | }; |
@@ -301,6 +303,7 @@ struct globals { | |||
301 | llist_t *ntp_peers; | 303 | llist_t *ntp_peers; |
302 | #if ENABLE_FEATURE_NTPD_SERVER | 304 | #if ENABLE_FEATURE_NTPD_SERVER |
303 | int listen_fd; | 305 | int listen_fd; |
306 | char *if_name; | ||
304 | # define G_listen_fd (G.listen_fd) | 307 | # define G_listen_fd (G.listen_fd) |
305 | #else | 308 | #else |
306 | # define G_listen_fd (-1) | 309 | # define G_listen_fd (-1) |
@@ -2092,13 +2095,19 @@ static NOINLINE void ntp_init(char **argv) | |||
2092 | 2095 | ||
2093 | /* Parse options */ | 2096 | /* Parse options */ |
2094 | peers = NULL; | 2097 | peers = NULL; |
2095 | opt_complementary = "dd:p::wn"; /* d: counter; p: list; -w implies -n */ | 2098 | opt_complementary = "dd:p::wn" /* -d: counter; -p: list; -w implies -n */ |
2099 | IF_FEATURE_NTPD_SERVER(":Il"); /* -I implies -l */ | ||
2096 | opts = getopt32(argv, | 2100 | opts = getopt32(argv, |
2097 | "nqNx" /* compat */ | 2101 | "nqNx" /* compat */ |
2098 | "wp:S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ | 2102 | "wp:S:"IF_FEATURE_NTPD_SERVER("l") /* NOT compat */ |
2103 | IF_FEATURE_NTPD_SERVER("I:") /* compat */ | ||
2099 | "d" /* compat */ | 2104 | "d" /* compat */ |
2100 | "46aAbgL", /* compat, ignored */ | 2105 | "46aAbgL", /* compat, ignored */ |
2101 | &peers, &G.script_name, &G.verbose); | 2106 | &peers,&G.script_name, |
2107 | #if ENABLE_FEATURE_NTPD_SERVER | ||
2108 | &G.if_name, | ||
2109 | #endif | ||
2110 | &G.verbose); | ||
2102 | 2111 | ||
2103 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ | 2112 | // if (opts & OPT_x) /* disable stepping, only slew is allowed */ |
2104 | // G.time_was_stepped = 1; | 2113 | // G.time_was_stepped = 1; |
@@ -2130,18 +2139,22 @@ static NOINLINE void ntp_init(char **argv) | |||
2130 | /* -l but no peers: "stratum 1 server" mode */ | 2139 | /* -l but no peers: "stratum 1 server" mode */ |
2131 | G.stratum = 1; | 2140 | G.stratum = 1; |
2132 | } | 2141 | } |
2133 | if (!(opts & OPT_n)) { | ||
2134 | bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv); | ||
2135 | logmode = LOGMODE_NONE; | ||
2136 | } | ||
2137 | #if ENABLE_FEATURE_NTPD_SERVER | 2142 | #if ENABLE_FEATURE_NTPD_SERVER |
2138 | G_listen_fd = -1; | 2143 | G_listen_fd = -1; |
2139 | if (opts & OPT_l) { | 2144 | if (opts & OPT_l) { |
2140 | G_listen_fd = create_and_bind_dgram_or_die(NULL, 123); | 2145 | G_listen_fd = create_and_bind_dgram_or_die(NULL, 123); |
2146 | if (opts & OPT_I) { | ||
2147 | if (setsockopt_bindtodevice(G_listen_fd, G.if_name)) | ||
2148 | xfunc_die(); | ||
2149 | } | ||
2141 | socket_want_pktinfo(G_listen_fd); | 2150 | socket_want_pktinfo(G_listen_fd); |
2142 | setsockopt(G_listen_fd, IPPROTO_IP, IP_TOS, &const_IPTOS_LOWDELAY, sizeof(const_IPTOS_LOWDELAY)); | 2151 | setsockopt(G_listen_fd, IPPROTO_IP, IP_TOS, &const_IPTOS_LOWDELAY, sizeof(const_IPTOS_LOWDELAY)); |
2143 | } | 2152 | } |
2144 | #endif | 2153 | #endif |
2154 | if (!(opts & OPT_n)) { | ||
2155 | bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv); | ||
2156 | logmode = LOGMODE_NONE; | ||
2157 | } | ||
2145 | /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */ | 2158 | /* I hesitate to set -20 prio. -15 should be high enough for timekeeping */ |
2146 | if (opts & OPT_N) | 2159 | if (opts & OPT_N) |
2147 | setpriority(PRIO_PROCESS, 0, -15); | 2160 | setpriority(PRIO_PROCESS, 0, -15); |