-
Notifications
You must be signed in to change notification settings - Fork 265
feat: allow mapping multiple domain names to single ip #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
6792b95
c045ace
8b8a68a
14b6919
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,6 +342,15 @@ struct { | |
// __uint(pinning, LIBBPF_PIN_BY_NAME); | ||
} domain_routing_map SEC(".maps"); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_LRU_HASH); | ||
__type(key, __be32[4]); | ||
__type(value, struct domain_routing); | ||
__uint(max_entries, MAX_DOMAIN_ROUTING_NUM); | ||
/// NOTICE: No persistence. | ||
// __uint(pinning, LIBBPF_PIN_BY_NAME); | ||
} domain_bump_map SEC(".maps"); | ||
|
||
struct ip_port_proto { | ||
__u32 ip[4]; | ||
__be16 port; | ||
|
@@ -650,6 +659,8 @@ static int route_loop_cb(__u32 index, void *data) | |
// proxy Subrule is like: domain(suffix:baidu.com, suffix:google.com) Match | ||
// set is like: suffix:baidu.com | ||
struct domain_routing *domain_routing; | ||
struct domain_routing *domain_bump; | ||
bool need_control_plane_routing = false; | ||
|
||
if (unlikely(index / 32 >= MAX_MATCH_SET_LEN / 32)) { | ||
ctx->result = -EFAULT; | ||
|
@@ -756,8 +767,21 @@ static int route_loop_cb(__u32 index, void *data) | |
|
||
// We use key instead of k to pass checker. | ||
if (domain_routing && | ||
(domain_routing->bitmap[index / 32] >> (index % 32)) & 1) | ||
(domain_routing->bitmap[index / 32] >> (index % 32)) & 1) { | ||
// All domains mapeed by the current IP address are matched. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: typo mapeed |
||
ctx->goodsubrule = true; | ||
} else { | ||
// Get domain bump bitmap. | ||
domain_bump = bpf_map_lookup_elem(&domain_bump_map, | ||
ctx->params->daddr); | ||
if (domain_bump && | ||
(domain_bump->bitmap[index / 32] >> (index % 32)) & 1) { | ||
ctx->goodsubrule = true; | ||
// The current IP has mapped domains that match this rule, but not all of them do. | ||
// jump to control plane. | ||
need_control_plane_routing = true; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这一段逻辑也应该更新到 routing_matcher_userspace.go:Match() ? |
||
break; | ||
case MatchType_ProcessName: | ||
#ifdef __DEBUG_ROUTING | ||
|
@@ -833,7 +857,7 @@ static int route_loop_cb(__u32 index, void *data) | |
} else { | ||
bool must = ctx->must || match_set->must; | ||
|
||
if (!must && ctx->isdns) { | ||
if ((!must && ctx->isdns) || need_control_plane_routing) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
ctx->result = | ||
(__s64)OUTBOUND_CONTROL_PLANE_ROUTING | | ||
((__s64)match_set->mark << 8) | | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
似乎有点浪费 cpu 了,大部分用户的规则都不会超过 100 条吧,这里 MaxMatchSetLen 是 1024,可以做个短路 break