Skip to content

Commit 55de269

Browse files
maiquebcathay4t
authored andcommitted
vxlan: fix port-range attribute marshalling
Since we were not updating the `buffer` variable when writing to it, the "max" part of the range was over-writing the "min", which caused the netlink message to be considered invalid. By adjusting the buffer to where we write, the netlink add message was properly processed, and the link successfully created. Unit tests were added to assert the expected behavior. Signed-off-by: Miguel Duarte Barroso <[email protected]>
1 parent ce406b2 commit 55de269

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/rtnl/link/nlas/link_infos.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl Nla for InfoVxlan {
782782
Port(ref value) => BigEndian::write_u16(buffer, *value),
783783
PortRange(ref range) => {
784784
BigEndian::write_u16(buffer, range.0);
785-
BigEndian::write_u16(buffer, range.1)
785+
BigEndian::write_u16(&mut buffer[2..], range.1)
786786
}
787787
}
788788
}
@@ -2498,4 +2498,52 @@ mod tests {
24982498
nlas.as_slice().emit(&mut vec);
24992499
assert_eq!(&vec[..], &VXLAN[..]);
25002500
}
2501+
2502+
lazy_static! {
2503+
static ref VXLAN_INFO_WITH_PORT_RANGE: Vec<InfoVxlan> =
2504+
vec![InfoVxlan::Id(10), InfoVxlan::PortRange((9000, 9050)),];
2505+
}
2506+
2507+
#[rustfmt::skip]
2508+
static VXLAN_WITH_PORT_RANGE: [u8; 32] = [
2509+
0x0a, 0x00, // length = 10
2510+
0x01, 0x00, // type = 1 = IFLA_INFO_KIND
2511+
0x76, 0x78, 0x6C, 0x61, 0x6E, // V = "vxlan\0"
2512+
0x00, 0x00, 0x00, // padding
2513+
0x14, 0x00, // length = 20
2514+
0x02, 0x00, // type = 2 = IFLA_INFO_DATA
2515+
0x08, 0x00, // length - 8
2516+
0x01, 0x00, // type = 1 = IFLA_VXLAN_ID
2517+
0x0A, 0x00, // id = 0x0A = 10
2518+
0x00, 0x00, // padding
2519+
0x08, 0x00, // length = 6
2520+
0x0A, 0x00, // type = 10 = IFLA_VXLAN_PORT_RANGE
2521+
0x23, 0x28, // min port: 9000
2522+
0x23, 0x5a // max port: 9050
2523+
];
2524+
2525+
#[test]
2526+
fn emit_info_vxlan_with_port_range() {
2527+
let nlas = vec![
2528+
Info::Kind(InfoKind::Vxlan),
2529+
Info::Data(InfoData::Vxlan(VXLAN_INFO_WITH_PORT_RANGE.clone())),
2530+
];
2531+
2532+
assert_eq!(nlas.as_slice().buffer_len(), VXLAN_WITH_PORT_RANGE.len());
2533+
2534+
let mut vec = vec![0xff; VXLAN_WITH_PORT_RANGE.len()];
2535+
nlas.as_slice().emit(&mut vec);
2536+
assert_eq!(&vec[..], &VXLAN_WITH_PORT_RANGE[..]);
2537+
}
2538+
2539+
#[test]
2540+
fn parse_info_vxlan_with_port_range() {
2541+
let nla = NlaBuffer::new_checked(&VXLAN_WITH_PORT_RANGE[..]).unwrap();
2542+
let parsed = VecInfo::parse(&nla).unwrap().0;
2543+
let expected = vec![
2544+
Info::Kind(InfoKind::Vxlan),
2545+
Info::Data(InfoData::Vxlan(VXLAN_INFO_WITH_PORT_RANGE.clone())),
2546+
];
2547+
assert_eq!(expected, parsed);
2548+
}
25012549
}

0 commit comments

Comments
 (0)