@@ -29,15 +29,16 @@ static inline Route__RouteConfiguration *map_lookup_route_config(const char *rou
2929}
3030
3131static inline int
32- virtual_host_match_check (Route__VirtualHost * virt_host , address_t * addr , ctx_buff_t * ctx , struct bpf_mem_ptr * host )
32+ virtual_host_match_check (Route__VirtualHost * virt_host , char * addr , ctx_buff_t * ctx , struct bpf_mem_ptr * host )
3333{
3434 int i ;
3535 void * domains = NULL ;
3636 void * domain = NULL ;
3737 void * ptr ;
3838 __u32 ptr_length ;
39+ long target_length = bpf_strnlen (addr , BPF_DATA_MAX_LEN );
3940
40- if (!host )
41+ if (!host || ! addr )
4142 return 0 ;
4243
4344 ptr = _ (host -> ptr );
@@ -67,6 +68,10 @@ virtual_host_match_check(Route__VirtualHost *virt_host, address_t *addr, ctx_buf
6768
6869 if (bpf_strnstr (ptr , domain , ptr_length ) != NULL ) {
6970 return 1 ;
71+ } else {
72+ if (bpf__strncmp (addr , target_length , domain ) == 0 ) {
73+ return 1 ;
74+ }
7075 }
7176 }
7277
@@ -91,6 +96,13 @@ virtual_host_match(Route__RouteConfiguration *route_config, address_t *addr, ctx
9196 Route__VirtualHost * virt_host_allow_any = NULL ;
9297 char host_key [5 ] = {'H' , 'o' , 's' , 't' , '\0' };
9398 struct bpf_mem_ptr * host ;
99+ uint32_t dst_ip ;
100+ char * dst_ip_str ;
101+
102+ if (!addr )
103+ return 0 ;
104+ dst_ip = addr -> ipv4 ;
105+ dst_ip_str = ip2str (& dst_ip , true);
94106
95107 if (route_config -> n_virtual_hosts <= 0 || route_config -> n_virtual_hosts > KMESH_PER_VIRT_HOST_NUM ) {
96108 BPF_LOG (WARN , ROUTER_CONFIG , "invalid virt hosts num=%d\n" , route_config -> n_virtual_hosts );
@@ -123,11 +135,11 @@ virtual_host_match(Route__RouteConfiguration *route_config, address_t *addr, ctx
123135 continue ;
124136 }
125137
126- if (virtual_host_match_check (virt_host , addr , ctx , host ))
138+ if (virtual_host_match_check (virt_host , dst_ip_str , ctx , host ))
127139 return virt_host ;
128140 }
129141 // allow_any as the default virt_host
130- if (virt_host_allow_any && virtual_host_match_check (virt_host_allow_any , addr , ctx , host ))
142+ if (virt_host_allow_any && virtual_host_match_check (virt_host_allow_any , dst_ip_str , ctx , host ))
131143 return virt_host_allow_any ;
132144 return NULL ;
133145}
@@ -311,7 +323,7 @@ static inline char *select_weight_cluster(Route__RouteAction *route_act)
311323 }
312324
313325 if (cluster_name != NULL ) {
314- BPF_LOG (DEBUG , ROUTER_CONFIG , "select cluster, name %s\n" , cluster_name );
326+ BPF_LOG (DEBUG , ROUTER_CONFIG , "selected cluster: %s\n" , cluster_name );
315327 return cluster_name ;
316328 }
317329
0 commit comments