ike: don't log duplicate attributes

Track what attributes have been logged and skip over duplicate
attributes to avoid having duplicate fields in the JSON object, which
is invalid JSON.

This is lossy, subsequent attributes are lost.

Ticket: #7923
(cherry picked from commit 35464150de)
pull/14093/head
Jason Ish 1 month ago
parent fa15ebf7ff
commit f85944511a

@ -22,14 +22,24 @@ use crate::ike::parser::{ExchangeType, IsakmpPayloadType, SaAttribute};
use crate::jsonbuilder::{JsonBuilder, JsonError};
use num_traits::FromPrimitive;
use std;
use std::collections::HashSet;
use std::convert::TryFrom;
const LOG_EXTENDED: u32 = 0x01;
fn add_attributes(transform: &Vec<SaAttribute>, js: &mut JsonBuilder) -> Result<(), JsonError> {
let mut logged: HashSet<String> = HashSet::new();
for attribute in transform {
let key = attribute.attribute_type.to_string();
if logged.contains(&key) {
continue;
}
logged.insert(key.clone());
js.set_string(
attribute.attribute_type.to_string().as_str(),
&key,
attribute.attribute_value.to_string().as_str(),
)?;

Loading…
Cancel
Save