#define REQ_ADD_PEER3 61
#define REQ_SHUTDOWN 62
#define REQ_ONOFFLINE 63
-#define N_REQUEST_TYPES 64
+#define REQ_ADD_SOURCE 64
+#define N_REQUEST_TYPES 65
/* Structure used to exchange timespecs independent of time_t size */
typedef struct {
int32_t EOR;
} REQ_Ac_Check;
+/* Source types in NTP source requests */
+#define REQ_ADDSRC_SERVER 1
+#define REQ_ADDSRC_PEER 2
+
/* Flags used in NTP source requests */
#define REQ_ADDSRC_ONLINE 0x1
#define REQ_ADDSRC_AUTOOFFLINE 0x2
#define REQ_ADDSRC_BURST 0x100
typedef struct {
+ uint32_t type;
IPAddr ip_addr;
uint32_t port;
int32_t minpoll;
/* ================================================== */
static int
-process_cmd_add_server_or_peer(CMD_Request *msg, char *line)
+process_cmd_add_source(CMD_Request *msg, char *line)
{
CPS_NTP_Source data;
IPAddr ip_addr;
- int result = 0, status;
- const char *opt_name;
+ int result = 0, status, type;
+ const char *opt_name, *word;
+ msg->command = htons(REQ_ADD_SOURCE);
+
+ word = line;
+ line = CPS_SplitWord(line);
+
+ if (!strcmp(word, "server")) {
+ type = REQ_ADDSRC_SERVER;
+ } else if (!strcmp(word, "peer")) {
+ type = REQ_ADDSRC_PEER;
+ } else {
+ LOG(LOGS_ERR, "Invalid syntax for add command");
+ return 0;
+ }
+
status = CPS_ParseNTPSourceAdd(line, &data);
switch (status) {
case 0:
break;
}
+ msg->data.ntp_source.type = htonl(type);
msg->data.ntp_source.port = htonl((unsigned long) data.port);
UTI_IPHostToNetwork(&ip_addr, &msg->data.ntp_source.ip_addr);
msg->data.ntp_source.minpoll = htonl(data.params.minpoll);
/* ================================================== */
-static int
-process_cmd_add_server(CMD_Request *msg, char *line)
-{
- msg->command = htons(REQ_ADD_SERVER3);
- return process_cmd_add_server_or_peer(msg, line);
-}
-
-/* ================================================== */
-
-static int
-process_cmd_add_peer(CMD_Request *msg, char *line)
-{
- msg->command = htons(REQ_ADD_PEER3);
- return process_cmd_add_server_or_peer(msg, line);
-}
-
-/* ================================================== */
-
static int
process_cmd_delete(CMD_Request *msg, char *line)
{
} else if (!strcmp(command, "activity")) {
do_normal_submit = 0;
ret = process_cmd_activity(line);
- } else if (!strcmp(command, "add") && !strncmp(line, "peer", 4)) {
- do_normal_submit = process_cmd_add_peer(&tx_message, CPS_SplitWord(line));
- } else if (!strcmp(command, "add") && !strncmp(line, "server", 6)) {
- do_normal_submit = process_cmd_add_server(&tx_message, CPS_SplitWord(line));
+ } else if (!strcmp(command, "add")) {
+ do_normal_submit = process_cmd_add_source(&tx_message, line);
} else if (!strcmp(command, "allow")) {
if (!strncmp(line, "all", 3)) {
do_normal_submit = process_cmd_allowall(&tx_message, CPS_SplitWord(line));
PERMIT_AUTH, /* ADD_PEER3 */
PERMIT_AUTH, /* SHUTDOWN */
PERMIT_AUTH, /* ONOFFLINE */
+ PERMIT_AUTH, /* ADD_SOURCE */
};
/* ================================================== */
/* ================================================== */
static void
-handle_add_source(NTP_Source_Type type, CMD_Request *rx_message, CMD_Reply *tx_message)
+handle_add_source(CMD_Request *rx_message, CMD_Reply *tx_message)
{
NTP_Remote_Address rem_addr;
+ NTP_Source_Type type;
SourceParameters params;
NSR_Status status;
+ switch (ntohl(rx_message->data.ntp_source.type)) {
+ case REQ_ADDSRC_SERVER:
+ type = NTP_SERVER;
+ break;
+ case REQ_ADDSRC_PEER:
+ type = NTP_PEER;
+ break;
+ default:
+ tx_message->status = htons(STT_INVALID);
+ return;
+ }
+
UTI_IPNetworkToHost(&rx_message->data.ntp_source.ip_addr, &rem_addr.ip_addr);
rem_addr.port = (unsigned short)(ntohl(rx_message->data.ntp_source.port));
params.minpoll = ntohl(rx_message->data.ntp_source.minpoll);
handle_cmdaccheck(&rx_message, &tx_message);
break;
- case REQ_ADD_SERVER3:
- handle_add_source(NTP_SERVER, &rx_message, &tx_message);
- break;
-
- case REQ_ADD_PEER3:
- handle_add_source(NTP_PEER, &rx_message, &tx_message);
+ case REQ_ADD_SOURCE:
+ handle_add_source(&rx_message, &tx_message);
break;
case REQ_DEL_SOURCE:
REQ_LENGTH_ENTRY(ntp_data, ntp_data), /* NTP_DATA */
{ 0, 0 }, /* ADD_SERVER2 */
{ 0, 0 }, /* ADD_PEER2 */
- REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SERVER3 */
- REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_PEER3 */
+ { 0, 0 }, /* ADD_SERVER3 */
+ { 0, 0 }, /* ADD_PEER3 */
REQ_LENGTH_ENTRY(null, null), /* SHUTDOWN */
REQ_LENGTH_ENTRY(null, null), /* ONOFFLINE */
+ REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SOURCE */
};
static const uint16_t reply_lengths[] = {