Skip to content

Commit

Permalink
Merge pull request #315 from lec-bit/release-0.3
Browse files Browse the repository at this point in the history
[release-0.3]Fix the issue of incorrect domain matching
  • Loading branch information
kmesh-bot committed May 11, 2024
2 parents 521f0f2 + cfe9cb3 commit f0523f2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions bpf/kmesh/include/route_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ static inline Route__RouteConfiguration *map_lookup_route_config(const char *rou
}

static inline int virtual_host_match_check(Route__VirtualHost *virt_host,
address_t *addr, ctx_buff_t *ctx, struct bpf_mem_ptr *uri)
address_t *addr, ctx_buff_t *ctx, struct bpf_mem_ptr *host)
{
int i;
void *domains = NULL;
void *domain = NULL;
void *ptr;
__u32 ptr_length;

if (!uri)
if (!host)
return 0;

ptr = _(uri->ptr);
ptr = _(host->ptr);
if (!ptr)
return 0;

ptr_length = _(uri->size);
ptr_length = _(host->size);

if (!virt_host->domains)
return 0;
Expand Down Expand Up @@ -105,8 +105,8 @@ static inline Route__VirtualHost *virtual_host_match(Route__RouteConfiguration *
void *ptrs = NULL;
Route__VirtualHost *virt_host = NULL;
Route__VirtualHost *virt_host_allow_any = NULL;
char uri_key[4] = {'U', 'R', 'I', '\0'};
struct bpf_mem_ptr *uri;
char host_key[5] = {'H', 'o', 's', 't', '\0'};
struct bpf_mem_ptr *host;

if (route_config->n_virtual_hosts <= 0 || route_config->n_virtual_hosts > KMESH_PER_VIRT_HOST_NUM) {
BPF_LOG(WARN, ROUTER_CONFIG, "invalid virt hosts num=%d\n", route_config->n_virtual_hosts);
Expand All @@ -119,9 +119,9 @@ static inline Route__VirtualHost *virtual_host_match(Route__RouteConfiguration *
return NULL;
}

uri = bpf_get_msg_header_element(uri_key);
if (!uri) {
BPF_LOG(ERR, ROUTER_CONFIG, "failed to get URI in msg\n");
host = bpf_get_msg_header_element(host_key);
if (!host) {
BPF_LOG(ERR, ROUTER_CONFIG, "failed to get Host in msg\n");
return NULL;
}

Expand All @@ -139,11 +139,11 @@ static inline Route__VirtualHost *virtual_host_match(Route__RouteConfiguration *
continue;
}

if (virtual_host_match_check(virt_host, addr, ctx, uri))
if (virtual_host_match_check(virt_host, addr, ctx, host))
return virt_host;
}
// allow_any as the default virt_host
if (virt_host_allow_any && virtual_host_match_check(virt_host_allow_any, addr, ctx, uri))
if (virt_host_allow_any && virtual_host_match_check(virt_host_allow_any, addr, ctx, host))
return virt_host_allow_any;
return NULL;
}
Expand Down

0 comments on commit f0523f2

Please sign in to comment.