Skip to content

Commit 1074e65

Browse files
authored
Merge pull request kmesh-net#1245 from weli-l/ads/bookinfo
fix bookinfo issue 553
2 parents 6cf231c + f57bd38 commit 1074e65

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

bpf/kmesh/ads/include/route_config.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@ static inline Route__RouteConfiguration *map_lookup_route_config(const char *rou
2929
}
3030

3131
static 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

Comments
 (0)