Skip to content

Commit ca8916c

Browse files
committed
ike: suffix duplicate attributes with an index
The attributes in a proposal are an array so its possible to have duplicate values, even if not within spec. To address this in a backwards compatible way, suffix duplicates with their index. The first seen attribute will not have a suffix, but the first duplicate attribute type will have suffix 1, etc. For example: "client": { "proposals": [ { "sa_life_duration": "Unknown", "sa_life_duration_raw": 86400, "sa_life_duration_1": "Unknown", "sa_life_duration_1_raw": 65535 } } } Ticket: OISF#7923
1 parent dae9264 commit ca8916c

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

etc/schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,6 +2563,14 @@
25632563
"sa_life_type_raw": {
25642564
"type": "integer"
25652565
}
2566+
},
2567+
"patternProperties": {
2568+
"^sa_life_duration_[0-9]+$": {
2569+
"type": "string"
2570+
},
2571+
"^sa_life_duration_[0-9]+_raw$": {
2572+
"type": "integer"
2573+
}
25662574
}
25672575
}
25682576
}

rust/src/ike/logger.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,34 @@ use crate::ike::parser::{ExchangeType, IsakmpPayloadType, SaAttribute};
2222
use crate::jsonbuilder::{JsonBuilder, JsonError};
2323
use num_traits::FromPrimitive;
2424
use std;
25+
use std::collections::HashMap;
2526
use std::convert::TryFrom;
2627

2728
const LOG_EXTENDED: u32 = 0x01;
2829

2930
fn add_attributes(transform: &Vec<SaAttribute>, js: &mut JsonBuilder) -> Result<(), JsonError> {
31+
let mut logged: HashMap<String, usize> = HashMap::new();
32+
3033
for attribute in transform {
31-
js.set_string(
32-
attribute.attribute_type.to_string().as_str(),
33-
attribute.attribute_value.to_string().as_str(),
34-
)?;
34+
let mut key = attribute.attribute_type.to_string();
35+
let idx = logged.entry(key.clone()).or_insert(0);
36+
37+
if *idx > 0 {
38+
key = format!("{}_{}", key, idx);
39+
}
40+
41+
js.set_string(&key, &attribute.attribute_value.to_string())?;
3542

3643
if let Some(numeric_value) = attribute.numeric_value {
37-
js.set_uint(
38-
format!("{}_raw", attribute.attribute_type).as_str(),
39-
numeric_value as u64,
40-
)?;
44+
js.set_uint(&format!("{}_raw", key), numeric_value as u64)?;
4145
} else if let Some(hex_value) = &attribute.hex_value {
42-
js.set_string(
43-
format!("{}_raw", attribute.attribute_type).as_str(),
44-
hex_value,
45-
)?;
46+
js.set_string(&format!("{}_raw", key), hex_value)?;
4647
}
48+
49+
*idx += 1;
4750
}
4851

49-
return Ok(());
52+
Ok(())
5053
}
5154

5255
fn log_ike(

0 commit comments

Comments
 (0)