-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87f362d
commit 4052801
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,5 +38,6 @@ pub mod usbpcap; | |
pub mod vlan; | ||
pub mod sll; | ||
pub mod sll2; | ||
pub mod vxlan; | ||
|
||
pub mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright (c) 2023 Stephen Doyle | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! A VXLAN packet abstraction. | ||
|
||
use alloc::vec::Vec; | ||
|
||
use pnet_macros::packet; | ||
use pnet_macros_support::types::*; | ||
|
||
/// Virtual eXtensible Local Area Network (VXLAN) | ||
/// | ||
/// See [RFC 7348](https://datatracker.ietf.org/doc/html/rfc7348) | ||
/// | ||
/// VXLAN Header: | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
/// |R|R|R|R|I|R|R|R| Reserved | | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
/// | VXLAN Network Identifier (VNI) | Reserved | | ||
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
#[packet] | ||
pub struct Vxlan { | ||
pub flags: u8, | ||
pub reserved1: u24be, | ||
pub vni: u24be, | ||
pub reserved2: u8, | ||
#[payload] | ||
pub payload: Vec<u8>, | ||
} | ||
|
||
#[test] | ||
fn vxlan_packet_test() { | ||
let mut packet = [0u8;8]; | ||
{ | ||
let mut vxlan_header = MutableVxlanPacket::new(&mut packet[..]).unwrap(); | ||
vxlan_header.set_flags(0x08); | ||
assert_eq!(vxlan_header.get_flags(), 0x08); | ||
vxlan_header.set_vni(0x123456); | ||
assert_eq!(vxlan_header.get_vni(), 0x123456); | ||
} | ||
|
||
let ref_packet = [ | ||
0x08, // I flag | ||
0x00, 0x00, 0x00, // Reserved | ||
0x12, 0x34, 0x56, // VNI | ||
0x00 // Reserved | ||
]; | ||
assert_eq!(&ref_packet[..], &packet[..]); | ||
} |