Skip to content

Commit

Permalink
feat: Memcached ebpf support
Browse files Browse the repository at this point in the history
  • Loading branch information
rvql committed Oct 12, 2024
1 parent 575d89d commit 0e08c31
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 137 deletions.
3 changes: 2 additions & 1 deletion agent/src/bin/deepflow-agent-ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ struct EbpfArgs {
///
/// App Protocol: All(0), Other(1),
/// HTTP1(20), HTTP2(21), Dubbo(40), SofaRPC(43),
/// MySQL(60), PostGreSQL(61), Oracle(62), Redis(80),
/// MySQL(60), PostGreSQL(61), Oracle(62), Memcached(63),
/// Redis(80),
/// Kafka(100), MQTT(101), DNS(120), TLS(121),
///
/// eg: deepflow-agent-ctl ebpf datadump --proto 20
Expand Down
4 changes: 2 additions & 2 deletions agent/src/common/l7_protocol_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,8 @@ impl L7ProtocolChecker for L7ProtocolBitmap {
}
}

impl From<&Vec<String>> for L7ProtocolBitmap {
fn from(vs: &Vec<String>) -> Self {
impl From<&[String]> for L7ProtocolBitmap {
fn from(vs: &[String]) -> Self {
let mut bitmap = L7ProtocolBitmap(0);
for v in vs.iter() {
if let Ok(p) = L7ProtocolParser::try_from(v.as_str()) {
Expand Down
27 changes: 26 additions & 1 deletion agent/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use tokio::runtime::Runtime;

use crate::common::l7_protocol_log::L7ProtocolParser;
use crate::dispatcher::recv_engine::DEFAULT_BLOCK_SIZE;
use crate::flow_generator::{DnsLog, OracleLog, TlsLog};
use crate::flow_generator::{DnsLog, MemcachedLog, OracleLog, TlsLog};
#[cfg(any(target_os = "linux", target_os = "android"))]
use crate::platform::{get_container_id, OsAppTag, ProcessData};
use crate::{
Expand Down Expand Up @@ -1500,6 +1500,7 @@ impl Default for ApplicationProtocolInference {
"MySQL".to_string(),
"PostgreSQL".to_string(),
"Oracle".to_string(),
"Memcached".to_string(),
"Redis".to_string(),
"MongoDB".to_string(),
"Kafka".to_string(),
Expand Down Expand Up @@ -3087,6 +3088,7 @@ impl UserConfig {
const DEFAULT_DNS_PORTS: &'static str = "53,5353";
const DEFAULT_TLS_PORTS: &'static str = "443,6443";
const DEFAULT_ORACLE_PORTS: &'static str = "1521";
const DEFAULT_MEMCACHED_PORTS: &'static str = "11211";
const PACKET_FANOUT_MODE_MAX: u32 = 7;

pub fn get_fast_path_map_size(&self, mem_size: u64) -> usize {
Expand Down Expand Up @@ -3155,6 +3157,20 @@ impl UserConfig {
Self::DEFAULT_ORACLE_PORTS.to_string(),
);
}
let memcached_str = L7ProtocolParser::Memcached(MemcachedLog::default()).as_str();
// memcached default only parse 11211 port. when l7_protocol_ports config without MEMCACHED, need to reserve the memcached default config.
if !self
.processors
.request_log
.filters
.port_number_prefilters
.contains_key(memcached_str)
{
new.insert(
memcached_str.to_string(),
Self::DEFAULT_MEMCACHED_PORTS.to_string(),
);
}

new
}
Expand Down Expand Up @@ -3816,6 +3832,7 @@ impl YamlConfig {
const DEFAULT_DNS_PORTS: &'static str = "53,5353";
const DEFAULT_TLS_PORTS: &'static str = "443,6443";
const DEFAULT_ORACLE_PORTS: &'static str = "1521";
const DEFAULT_MEMCACHED_PORTS: &'static str = "11211";
const PACKET_FANOUT_MODE_MAX: u32 = 7;
const DEFAULT_L7_PROTOCOL_ENABLED: [&'static str; 7] =
["HTTP", "HTTP2", "MySQL", "Redis", "Kafka", "DNS", "TLS"];
Expand Down Expand Up @@ -4087,6 +4104,14 @@ impl YamlConfig {
Self::DEFAULT_ORACLE_PORTS.to_string(),
);
}
let memcached_str = L7ProtocolParser::Memcached(MemcachedLog::default()).as_str();
// memcached default only parse 11211 port. when l7_protocol_ports config without MEMCACHED, need to reserve the memcached default config.
if !self.l7_protocol_ports.contains_key(memcached_str) {
new.insert(
memcached_str.to_string(),
Self::DEFAULT_MEMCACHED_PORTS.to_string(),
);
}

new
}
Expand Down
24 changes: 12 additions & 12 deletions agent/src/config/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,11 @@ impl From<(&UserConfig, &DynamicConfig)> for FlowConfig {
packet_sequence_flag: conf.processors.packet.tcp_header.header_fields_flag, // Enterprise Edition Feature: packet-sequence
packet_sequence_block_size: conf.processors.packet.tcp_header.block_size, // Enterprise Edition Feature: packet-sequence
l7_protocol_enabled_bitmap: L7ProtocolBitmap::from(
&conf
.processors
conf.processors
.request_log
.application_protocol_inference
.enabled_protocols,
.enabled_protocols
.as_slice(),
),
l7_protocol_parse_port_bitmap: Arc::new(conf.get_protocol_port_parse_bitmap()),
plugins: PluginConfig {
Expand Down Expand Up @@ -639,11 +639,11 @@ impl From<(&UserConfig, &DynamicConfig)> for FlowConfig {
.oracle
.clone(),
obfuscate_enabled_protocols: L7ProtocolBitmap::from(
&conf
.processors
conf.processors
.request_log
.tag_extraction
.obfuscate_protocols,
.obfuscate_protocols
.as_slice(),
),
server_ports: conf
.processors
Expand Down Expand Up @@ -1919,11 +1919,11 @@ impl TryFrom<(Config, UserConfig, DynamicConfig)> for ModuleConfig {
&conf.processors.request_log.tag_extraction.http_endpoint,
),
obfuscate_enabled_protocols: L7ProtocolBitmap::from(
&conf
.processors
conf.processors
.request_log
.tag_extraction
.obfuscate_protocols,
.obfuscate_protocols
.as_slice(),
),
l7_log_blacklist: conf.processors.request_log.filters.tag_filters.clone(),
l7_log_blacklist_trie: {
Expand Down Expand Up @@ -2057,11 +2057,11 @@ impl TryFrom<(Config, UserConfig, DynamicConfig)> for ModuleConfig {
MacAddr::ZERO
},
l7_protocol_enabled_bitmap: L7ProtocolBitmap::from(
&conf
.processors
conf.processors
.request_log
.application_protocol_inference
.enabled_protocols,
.enabled_protocols
.as_slice(),
),
l7_protocol_parse_port_bitmap: Arc::new(conf.get_protocol_port_parse_bitmap()),
l7_protocol_ports: conf.get_protocol_port(),
Expand Down
1 change: 1 addition & 0 deletions agent/src/ebpf/kernel/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ enum traffic_protocol {
PROTO_MYSQL = 60,
PROTO_POSTGRESQL = 61,
PROTO_ORACLE = 62,
PROTO_MEMCACHED = 63,
PROTO_REDIS = 80,
PROTO_MONGO = 81,
PROTO_KAFKA = 100,
Expand Down
Loading

0 comments on commit 0e08c31

Please sign in to comment.