diff --git a/leaf/src/app/router.rs b/leaf/src/app/router.rs index 389ff6c..017c070 100644 --- a/leaf/src/app/router.rs +++ b/leaf/src/app/router.rs @@ -105,6 +105,32 @@ impl Condition for IpCidrMatcher { } } +struct InboundTagMatcher { + values: Vec, +} + +impl InboundTagMatcher { + fn new(tags: &mut protobuf::RepeatedField) -> Self { + let mut values = Vec::new(); + for t in tags.iter_mut() { + values.push(std::mem::take(t)); + } + Self { values } + } +} + +impl Condition for InboundTagMatcher { + fn apply(&self, sess: &Session) -> bool { + for v in &self.values { + if v == &sess.inbound_tag { + debug!("[{}] matches inbound tag [{}]", &sess.inbound_tag, v); + return true; + } + } + false + } +} + struct NetworkMatcher { values: Vec, } @@ -437,6 +463,10 @@ impl Router { cond_and.add(Box::new(NetworkMatcher::new(&mut rr.networks))); } + if rr.inbound_tags.len() > 0 { + cond_and.add(Box::new(InboundTagMatcher::new(&mut rr.inbound_tags))); + } + if cond_and.is_empty() { warn!("empty rule at target {}", rr.target_tag); continue; diff --git a/leaf/src/config/conf/config.rs b/leaf/src/config/conf/config.rs index f9945f6..31741e1 100644 --- a/leaf/src/config/conf/config.rs +++ b/leaf/src/config/conf/config.rs @@ -590,7 +590,7 @@ pub fn from_lines(lines: Vec>) -> Result { match rule.type_field.as_str() { "IP-CIDR" | "DOMAIN" | "DOMAIN-SUFFIX" | "DOMAIN-KEYWORD" | "GEOIP" | "EXTERNAL" - | "PORT-RANGE" | "NETWORK" => { + | "PORT-RANGE" | "NETWORK" | "INBOUND-TAG" => { rule.filter = Some(params[1].to_string()); } _ => {} @@ -1120,6 +1120,9 @@ pub fn to_internal(conf: &mut Config) -> Result { "NETWORK" => { rule.networks.push(ext_filter); } + "INBOUND-TAG" => { + rule.inbound_tags.push(ext_filter); + } _ => {} } rules.push(rule); diff --git a/leaf/src/config/internal/config.proto b/leaf/src/config/internal/config.proto index 4a07e15..57a6560 100644 --- a/leaf/src/config/internal/config.proto +++ b/leaf/src/config/internal/config.proto @@ -207,6 +207,7 @@ message Router { repeated Mmdb mmdbs = 4; repeated string port_ranges = 5; repeated string networks = 6; + repeated string inbound_tags = 7; } repeated Rule rules = 1; diff --git a/leaf/src/config/internal/config.rs b/leaf/src/config/internal/config.rs index 9aa87d1..a7ea8d2 100644 --- a/leaf/src/config/internal/config.rs +++ b/leaf/src/config/internal/config.rs @@ -4728,6 +4728,7 @@ pub struct Router_Rule { pub mmdbs: ::protobuf::RepeatedField, pub port_ranges: ::protobuf::RepeatedField<::std::string::String>, pub networks: ::protobuf::RepeatedField<::std::string::String>, + pub inbound_tags: ::protobuf::RepeatedField<::std::string::String>, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -4785,6 +4786,13 @@ impl Router_Rule { pub fn get_networks(&self) -> &[::std::string::String] { &self.networks } + + // repeated string inbound_tags = 7; + + + pub fn get_inbound_tags(&self) -> &[::std::string::String] { + &self.inbound_tags + } } impl ::protobuf::Message for Router_Rule { @@ -4824,6 +4832,9 @@ impl ::protobuf::Message for Router_Rule { 6 => { ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.networks)?; }, + 7 => { + ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.inbound_tags)?; + }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; }, @@ -4856,6 +4867,9 @@ impl ::protobuf::Message for Router_Rule { for value in &self.networks { my_size += ::protobuf::rt::string_size(6, &value); }; + for value in &self.inbound_tags { + my_size += ::protobuf::rt::string_size(7, &value); + }; my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); my_size @@ -4884,6 +4898,9 @@ impl ::protobuf::Message for Router_Rule { for v in &self.networks { os.write_string(6, &v)?; }; + for v in &self.inbound_tags { + os.write_string(7, &v)?; + }; os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) } @@ -4932,6 +4949,7 @@ impl ::protobuf::Clear for Router_Rule { self.mmdbs.clear(); self.port_ranges.clear(); self.networks.clear(); + self.inbound_tags.clear(); self.unknown_fields.clear(); } }