Skip to content

Commit 6b05e20

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#7902
1 parent 24503b0 commit 6b05e20

2 files changed

Lines changed: 24 additions & 3 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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,41 @@ 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 {
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+
3141
js.set_string(
32-
attribute.attribute_type.to_string().as_str(),
42+
&key,
3343
attribute.attribute_value.to_string().as_str(),
3444
)?;
3545

3646
if let Some(numeric_value) = attribute.numeric_value {
3747
js.set_uint(
38-
format!("{}_raw", attribute.attribute_type).as_str(),
48+
format!("{}_raw", key).as_str(),
3949
numeric_value as u64,
4050
)?;
4151
} else if let Some(hex_value) = &attribute.hex_value {
4252
js.set_string(
43-
format!("{}_raw", attribute.attribute_type).as_str(),
53+
format!("{}_raw", key).as_str(),
4454
hex_value,
4555
)?;
4656
}
57+
58+
*idx += 1;
59+
4760
}
4861

4962
return Ok(());

0 commit comments

Comments
 (0)