#define REQ_SHUTDOWN 62
#define REQ_ONOFFLINE 63
#define REQ_ADD_SOURCE 64
-#define N_REQUEST_TYPES 65
+#define REQ_NTP_SOURCE_NAME 65
+#define N_REQUEST_TYPES 66
/* Structure used to exchange timespecs independent of time_t size */
typedef struct {
int32_t EOR;
} REQ_NTPData;
+typedef struct {
+ IPAddr ip_addr;
+ int32_t EOR;
+} REQ_NTPSourceName;
+
/* ================================================== */
#define PKT_TYPE_CMD_REQUEST 1
REQ_ReselectDistance reselect_distance;
REQ_SmoothTime smoothtime;
REQ_NTPData ntp_data;
+ REQ_NTPData ntp_source_name;
} data; /* Command specific parameters */
/* Padding used to prevent traffic amplification. It only defines the
#define RPY_NTP_DATA 16
#define RPY_MANUAL_TIMESTAMP2 17
#define RPY_MANUAL_LIST2 18
-#define N_REPLY_TYPES 19
+#define RPY_NTP_SOURCE_NAME 19
+#define N_REPLY_TYPES 20
/* Status codes */
#define STT_SUCCESS 0
int32_t EOR;
} RPY_NTPData;
+typedef struct {
+ int8_t name[256];
+ int32_t EOR;
+} RPY_NTPSourceName;
+
typedef struct {
uint8_t version;
uint8_t pkt_type;
RPY_Activity activity;
RPY_Smoothing smoothing;
RPY_NTPData ntp_data;
+ RPY_NTPSourceName ntp_source_name;
} data; /* Reply specific parameters */
} CMD_Reply;
PERMIT_AUTH, /* SHUTDOWN */
PERMIT_AUTH, /* ONOFFLINE */
PERMIT_AUTH, /* ADD_SOURCE */
+ PERMIT_OPEN, /* NTP_SOURCE_NAME */
};
/* ================================================== */
SCH_QuitProgram();
}
+/* ================================================== */
+
+static void
+handle_ntp_source_name(CMD_Request *rx_message, CMD_Reply *tx_message)
+{
+ IPAddr addr;
+ char *name;
+
+ UTI_IPNetworkToHost(&rx_message->data.ntp_data.ip_addr, &addr);
+ name = NSR_GetName(&addr);
+
+ if (!name) {
+ tx_message->status = htons(STT_NOSUCHSOURCE);
+ return;
+ }
+
+ tx_message->reply = htons(RPY_NTP_SOURCE_NAME);
+
+ /* Avoid compiler warning */
+ if (strlen(name) >= sizeof (tx_message->data.ntp_source_name.name))
+ memcpy(tx_message->data.ntp_source_name.name, name,
+ sizeof (tx_message->data.ntp_source_name.name));
+ else
+ strncpy((char *)tx_message->data.ntp_source_name.name, name,
+ sizeof (tx_message->data.ntp_source_name.name));
+}
+
/* ================================================== */
/* Read a packet and process it */
handle_onoffline(&rx_message, &tx_message);
break;
+ case REQ_NTP_SOURCE_NAME:
+ handle_ntp_source_name(&rx_message, &tx_message);
+ break;
+
default:
DEBUG_LOG("Unhandled command %d", rx_command);
tx_message.status = htons(STT_FAILED);
/* ================================================== */
+char *
+NSR_GetName(IPAddr *address)
+{
+ NTP_Remote_Address remote_addr;
+ int slot, found;
+ SourceRecord *record;
+
+ remote_addr.ip_addr = *address;
+ remote_addr.port = 0;
+
+ find_slot(&remote_addr, &slot, &found);
+ if (!found)
+ return NULL;
+
+ record = get_record(slot);
+ if (record->name)
+ return record->name;
+
+ return UTI_IPToString(&record->remote_addr->ip_addr);
+}
+
+/* ================================================== */
+
/* This routine is called by ntp_io when a new packet arrives off the network,
possibly with an authentication tail */
void
/* Procedure to get local reference ID corresponding to a source */
extern uint32_t NSR_GetLocalRefid(IPAddr *address);
+/* Procedure to get the name of a source. If the source doesn't have a name,
+ it returns a temporary string containing formatted address. */
+extern char *NSR_GetName(IPAddr *address);
+
/* This routine is called by ntp_io when a new packet arrives off the network */
extern void NSR_ProcessRx(NTP_Remote_Address *remote_addr, NTP_Local_Address *local_addr,
NTP_Local_Timestamp *rx_ts, NTP_Packet *message, int length);
REQ_LENGTH_ENTRY(null, null), /* SHUTDOWN */
REQ_LENGTH_ENTRY(null, null), /* ONOFFLINE */
REQ_LENGTH_ENTRY(ntp_source, null), /* ADD_SOURCE */
+ REQ_LENGTH_ENTRY(ntp_source_name,
+ ntp_source_name), /* NTP_SOURCE_NAME */
};
static const uint16_t reply_lengths[] = {
RPY_LENGTH_ENTRY(ntp_data), /* NTP_DATA */
RPY_LENGTH_ENTRY(manual_timestamp), /* MANUAL_TIMESTAMP2 */
RPY_LENGTH_ENTRY(manual_list), /* MANUAL_LIST2 */
+ RPY_LENGTH_ENTRY(ntp_source_name), /* NTP_SOURCE_NAME */
};
/* ================================================== */