Skip to content

Commit

Permalink
Merge branch 'main' into add_musl_compile_flag_main
Browse files Browse the repository at this point in the history
  • Loading branch information
yinjiping authored Jan 24, 2025
2 parents 5d3bbc9 + 9cfd1e6 commit 3c737b8
Show file tree
Hide file tree
Showing 27 changed files with 380 additions and 251 deletions.
5 changes: 5 additions & 0 deletions agent/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ thiserror = "1.0"
time = "0.3.9"
tokio = { version = "1.20.1", features = ["full"] }
tonic = "0.8.1"
tunnel = { path = "plugins/tunnel" }
wasmtime = "12.0.1"
wasmtime-wasi = "12.0.1"
zstd = "0.13.2"
Expand Down
59 changes: 59 additions & 0 deletions agent/crates/public/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,20 @@ pub const TCP_DST_OFFSET: usize = IPV4_PACKET_SIZE + tcp::DST_OFFSET; // 36
pub const TCP6_SRC_OFFSET: usize = IPV6_PACKET_SIZE + tcp::SRC_OFFSET; // 54
pub const TCP6_DST_OFFSET: usize = IPV6_PACKET_SIZE + tcp::DST_OFFSET; // 56

pub const LE_IPV4_PROTO_TYPE_I: u16 = 0x0008; // 0x0008's LittleEndian
pub const LE_IPV6_PROTO_TYPE_I: u16 = 0xDD86; // 0x86dd's LittleEndian
pub const LE_ERSPAN_PROTO_TYPE_II: u16 = 0xBE88; // 0x88BE's LittleEndian
pub const LE_ERSPAN_PROTO_TYPE_III: u16 = 0xEB22; // 0x22EB's LittleEndian
pub const LE_VXLAN_PROTO_UDP_DPORT: u16 = 0xB512; // 0x12B5(4789)'s LittleEndian
pub const LE_GPE_VXLAN_PROTO_UDP_DPORT: u16 = 0xB612; // 0x12B6(4790)'s LittleEndian
pub const LE_VXLAN_PROTO_UDP_DPORT2: u16 = 0x1821; // 0x2118(8472)'s LittleEndian
pub const LE_VXLAN_PROTO_UDP_DPORT3: u16 = 0x801A; // 0x1A80(6784)'s LittleEndian
pub const LE_TRANSPARENT_ETHERNET_BRIDGEING: u16 = 0x5865; // 0x6558(25944)'s LittleEndian
pub const LE_GENEVE_PROTO_UDP_DPORT: u16 = 0xc117; // 0x17c1(6081)'s LittleEndian

pub const VXLAN_FLAGS: u8 = 8;
pub const TUNNEL_TIER_LIMIT: u8 = 2;

pub const VXLAN_FLAGS_OFFSET: usize = UDP_PACKET_SIZE + vxlan::FLAGS_OFFSET;
pub const VXLAN_SEQ_OFFSET: usize = UDP_PACKET_SIZE + vxlan::SEQUENCE_OFFSET;
pub const VXLAN_VNI_OFFSET: usize = UDP_PACKET_SIZE + vxlan::VNI_OFFSET;
Expand All @@ -366,6 +380,51 @@ pub const VXLAN6_SEQ_OFFSET: usize = UDP6_PACKET_SIZE + vxlan::SEQUENCE_OFFSET;
pub const VXLAN6_VNI_OFFSET: usize = UDP6_PACKET_SIZE + vxlan::VNI_OFFSET;
pub const VXLAN6_DIRECTION_OFFSET: usize = UDP6_PACKET_SIZE + vxlan::DIRECTION_OFFSET;

// GPE_VXLAN:
//
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |R|R|Ver|I|P|B|O| Reserved |Next Protocol |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | VXLAN Network Identifier (VNI) | Reserved |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
pub const GPE_VXLAN_FLAGS_INSTANCE_MASK: u8 = 0x8;
pub const GPE_VXLAN_FLAGS_PROTOCOL_MASK: u8 = 0x4;
pub const GPE_VXLAN_FLAGS_VERSION_MASK: u8 = 0x30;

pub const GPE_VXLAN_NEXT_PROTOCOL_NSH: u8 = 4;

pub const GPE_VXLAN_FLAGS_OFFSET: usize = 0;
pub const GPE_VXLAN_NEXT_PROTOCOL_OFFSET: usize = 3;
pub const GPE_VXLAN_VNI_OFFSET: usize = 4;

pub const GPE_VXLAN_HEADER_SIZE: usize = 8;
pub const GEP_VXLAN_GRE_HEADER_SIZE: usize = 8;

// NSH(Network Service Header):
//
// 0 1 2 3
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// |Ver|O|U| TTL | Length |U|U|U|U|MD Type| Next Protocol |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | Service Path Header |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// | |
// ~ Context Header(s) ~
// | |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
pub const NSH_HEADER_SIZE: usize = 8;

pub const NSH_FLAGS_OFFSET: usize = 0;
pub const NSH_NEXT_PROTOCOL_OFFSET: usize = 3;

pub const NSH_FLAGS_BITS_MASK: u16 = 0xf000;
pub const NSH_FLAGS_LENGTH_MASK: u16 = 0x3f;

pub const NSH_NEXT_PROTOCOL_IPV4: u8 = 1;

pub const GRE4_PROTO_OFFSET: usize = IPV4_PACKET_SIZE + erspan::GRE_PROTO_OFFSET;
pub const GRE6_PROTO_OFFSET: usize = IPV6_PACKET_SIZE + erspan::GRE_PROTO_OFFSET;

Expand Down
8 changes: 8 additions & 0 deletions agent/plugins/tunnel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "tunnel"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
48 changes: 48 additions & 0 deletions agent/plugins/tunnel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 Yunshan Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pub fn decapsulate_gpe_vxlan(_packet: &mut [u8], _l2_len: usize) -> Option<(usize, u32)> {
None
}

pub fn decapsulate_erspan(
_packet: &[u8],
_l2_len: usize,
_flags: u16,
_gre_protocol_type: u16,
_ip_header_size: usize,
) -> Option<(usize, u32)> {
None
}

pub fn decapsulate_teb(
_packet: &[u8],
_l2_len: usize,
_flags: u16,
_ip_header_size: usize,
) -> Option<(usize, u32)> {
None
}

pub fn decapsulate_tencent_gre(
_packet: &mut [u8],
_l2_len: usize,
_flags: u16,
_gre_protocol_type: u16,
_ip_header_size: usize,
) -> Option<(usize, u32)> {
None
}
Binary file removed agent/resources/test/common/gre-nokey.pcap
Binary file not shown.
Binary file removed agent/resources/test/common/tencent-gre.pcap
Binary file not shown.
Binary file added agent/resources/test/common/vxlan-nsh.pcap
Binary file not shown.
Loading

0 comments on commit 3c737b8

Please sign in to comment.