@@ -12,8 +12,8 @@ use std::str::FromStr;
12
12
#[ derive( Debug , Serialize , Deserialize , PartialEq , Clone ) ]
13
13
#[ serde( rename_all = "snake_case" ) ]
14
14
pub enum TcpConnectionField {
15
- SourceIp ( IpAlias ) ,
16
- DestinationIp ( IpAlias ) ,
15
+ SourceIp ( Vec < String > ) ,
16
+ DestinationIp ( Vec < String > ) ,
17
17
SourcePort ( Vec < u32 > ) ,
18
18
DestinationPort ( Vec < u32 > ) ,
19
19
Protocol ( Vec < String > ) ,
@@ -43,7 +43,7 @@ impl TcpConnectionField {
43
43
FirewallRuleDirection :: Out => item. destination_ip . as_ref ( ) ,
44
44
} ;
45
45
if let Some ( ip) = ip_opt. and_then ( |ip| IpAddr :: from_str ( ip) . ok ( ) ) {
46
- Some ( FirewallCompareType :: Ip ( ( ip, a . to_ips ( context) . await ?) ) )
46
+ Some ( FirewallCompareType :: Ip ( ( ip, to_ips ( a , context) . await ?) ) )
47
47
} else {
48
48
None
49
49
}
@@ -54,7 +54,7 @@ impl TcpConnectionField {
54
54
FirewallRuleDirection :: Out => item. source_ip . as_ref ( ) ,
55
55
} ;
56
56
if let Some ( ip) = ip_opt. and_then ( |ip| IpAddr :: from_str ( ip) . ok ( ) ) {
57
- Some ( FirewallCompareType :: Ip ( ( ip, a . to_ips ( context) . await ?) ) )
57
+ Some ( FirewallCompareType :: Ip ( ( ip, to_ips ( a , context) . await ?) ) )
58
58
} else {
59
59
None
60
60
}
@@ -105,36 +105,28 @@ impl<'a> PredicateEvaluator for &'a AppGuardTcpConnection {
105
105
}
106
106
}
107
107
108
- #[ derive( Debug , Serialize , Deserialize , PartialEq , Clone ) ]
109
- #[ serde( untagged) ]
110
- pub enum IpAlias {
111
- Name ( String ) ,
112
- Addresses ( Vec < String > ) ,
113
- }
108
+ async fn to_ips ( vec : & Vec < String > , context : & AppContext ) -> Option < Vec < IpNetwork > > {
109
+ let mut ret_val = Vec :: new ( ) ;
114
110
115
- impl IpAlias {
116
- async fn to_ips ( & self , context : & AppContext ) -> Option < Vec < IpNetwork > > {
117
- match self {
118
- IpAlias :: Name ( name) => {
119
- let token = context. root_token_provider . get ( ) . await . ok ( ) ?. jwt . clone ( ) ;
120
- context
121
- . datastore
122
- . clone ( )
123
- . get_ip_aliases ( token, name)
124
- . await
125
- . ok ( )
126
- }
127
- IpAlias :: Addresses ( addresses) => {
128
- let mut ipnetworks = Vec :: new ( ) ;
129
- for address in addresses {
130
- if let Ok ( cidr) = IpNetwork :: from_str ( address) {
131
- ipnetworks. push ( cidr) ;
132
- }
133
- }
134
- Some ( ipnetworks)
135
- }
111
+ for a in vec {
112
+ if let Ok ( cidr) = IpNetwork :: from_str ( a) {
113
+ ret_val. push ( cidr) ;
114
+ } else {
115
+ // alias
116
+ let token = context. root_token_provider . get ( ) . await . ok ( ) ?. jwt . clone ( ) ;
117
+ let Ok ( cidrs) = context
118
+ . datastore
119
+ . clone ( )
120
+ . get_ip_aliases ( token, a)
121
+ . await
122
+ else {
123
+ continue ;
124
+ } ;
125
+ ret_val. extend ( cidrs) ;
136
126
}
137
127
}
128
+
129
+ Some ( ret_val)
138
130
}
139
131
140
132
// #[cfg(test)]
0 commit comments