Skip to content

Commit f45ae0b

Browse files
committed
ntp: create tx for all modes; log version, mode and stratum
Add logging for version, mode and stratum as these will be the first keywords we will add. Ticket: OISF#8425
1 parent 866ae5c commit f45ae0b

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

etc/schema.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5573,10 +5573,22 @@
55735573
"type": "object",
55745574
"additionalProperties": false,
55755575
"properties": {
5576+
"mode": {
5577+
"type": "integer",
5578+
"description": "The mode of the NTP message"
5579+
},
55765580
"reference_id": {
55775581
"type": "integer",
55785582
"description": "Identifies specific server or reference clock"
5579-
}
5583+
},
5584+
"stratum": {
5585+
"type": "integer",
5586+
"description": "Indicates distance from the reference clock"
5587+
},
5588+
"version": {
5589+
"type": "integer",
5590+
"description": "The NTP version number, typically 3 or 4"
5591+
}
55805592
}
55815593
},
55825594
"snmp": {

rust/src/ntp/log.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use crate::jsonbuilder::{JsonBuilder, JsonError};
2020

2121
fn log(jb: &mut JsonBuilder, tx: &NTPTransaction) -> Result<(), JsonError> {
2222
jb.open_object("ntp")?;
23+
jb.set_uint("version", tx.version)?;
24+
jb.set_uint("mode", tx.mode)?;
25+
jb.set_uint("stratum", tx.stratum)?;
2326
jb.set_uint("reference_id", tx.reference_id)?;
2427
jb.close()?;
2528
Ok(())

rust/src/ntp/ntp.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ pub struct NTPTransaction {
6161
/// The NTP reference ID
6262
pub reference_id: u32,
6363

64+
pub version: u8,
65+
pub mode: u8,
66+
pub stratum: u8,
67+
6468
/// The internal transaction id
6569
id: u64,
6670

@@ -97,14 +101,23 @@ impl NTPState {
97101
match parse_ntp(i) {
98102
Ok((_, ref msg)) => {
99103
// SCLogDebug!("parse_ntp: {:?}",msg);
100-
let (mode, ref_id) = match msg {
101-
NtpPacket::V3(pkt) => (pkt.mode, pkt.ref_id),
102-
NtpPacket::V4(pkt) => (pkt.mode, pkt.ref_id),
104+
let tx = match msg {
105+
NtpPacket::V3(p) => {
106+
let mut tx = self.new_tx(direction, p.ref_id);
107+
tx.version = 3;
108+
tx.mode = p.mode.0;
109+
tx.stratum = p.stratum;
110+
tx
111+
}
112+
NtpPacket::V4(p) => {
113+
let mut tx = self.new_tx(direction, p.ref_id);
114+
tx.version = 4;
115+
tx.mode = p.mode.0;
116+
tx.stratum = p.stratum;
117+
tx
118+
}
103119
};
104-
if mode == NtpMode::SymmetricActive || mode == NtpMode::Client {
105-
let tx = self.new_tx(direction, ref_id);
106-
self.transactions.push(tx);
107-
}
120+
self.transactions.push(tx);
108121
0
109122
}
110123
Err(Err::Incomplete(_)) => {
@@ -158,6 +171,7 @@ impl NTPTransaction {
158171
reference_id,
159172
id,
160173
tx_data: applayer::AppLayerTxData::for_direction(direction),
174+
..Default::default()
161175
}
162176
}
163177
}

0 commit comments

Comments
 (0)