Skip to content

Commit

Permalink
feat(generator/client): make use of inline rule-set
Browse files Browse the repository at this point in the history
Signed-off-by: Tianling Shen <[email protected]>
  • Loading branch information
1715173329 committed Jan 10, 2025
1 parent ac06c6a commit 21b4a8b
Showing 1 changed file with 51 additions and 28 deletions.
79 changes: 51 additions & 28 deletions root/etc/homeproxy/scripts/generate_client.uc
Original file line number Diff line number Diff line change
Expand Up @@ -373,37 +373,32 @@ config.dns = {

if (!isEmpty(main_node)) {
/* Main DNS */
let default_final_dns = 'default-dns';
if (dns_server !== wan_dns) {
push(config.dns.servers, {
tag: 'main-dns',
address: !match(dns_server, /:\/\//) ? 'tcp://' + (validation('ip6addr', dns_server) ? `[${dns_server}]` : dns_server) : dns_server,
strategy: (ipv6_support !== '1') ? 'ipv4_only' : null,
address_resolver: 'default-dns',
address_strategy: (ipv6_support !== '1') ? 'ipv4_only' : null,
detour: 'main-out'
});

default_final_dns = 'main-dns';
}
config.dns.final = default_final_dns;
push(config.dns.servers, {
tag: 'main-dns',
address: !match(dns_server, /:\/\//) ? 'tcp://' + (validation('ip6addr', dns_server) ? `[${dns_server}]` : dns_server) : dns_server,
strategy: (ipv6_support !== '1') ? 'ipv4_only' : null,
address_resolver: 'default-dns',
address_strategy: (ipv6_support !== '1') ? 'ipv4_only' : null,
detour: 'main-out'
});
config.dns.final = 'main-dns';

/* Avoid DNS loop */
push(config.dns.rules, {
outbound: 'any',
server: 'default-dns'
});

if (direct_domain_list)
if (length(direct_domain_list))
push(config.dns.rules, {
domain_keyword: direct_domain_list,
server: 'default-dns'
rule_set: 'direct-domain',
server: (routing_mode === 'bypass_mainland_china' ) ? 'china-dns' : 'default-dns'
});

/* Filter out SVCB/HTTPS queries for "exquisite" Apple devices */
if (routing_mode === 'gfwlist' || proxy_domain_list)
if (routing_mode === 'gfwlist' || length(proxy_domain_list))
push(config.dns.rules, {
domain_keyword: (routing_mode !== 'gfwlist') ? proxy_domain_list : null,
rule_set: (routing_mode !== 'gfwlist') ? 'proxy-domain' : null,
query_type: [64, 65],
server: 'block-dns'
});
Expand All @@ -415,10 +410,10 @@ if (!isEmpty(main_node)) {
detour: 'direct-out'
});

if (proxy_domain_list)
if (length(proxy_domain_list))
push(config.dns.rules, {
domain_keyword: proxy_domain_list,
server: default_final_dns
rule_set: 'proxy-domain',
server: 'main-dns'
});

push(config.dns.rules, {
Expand All @@ -440,6 +435,7 @@ if (!isEmpty(main_node)) {
server: 'china-dns'
});
}

} else if (!isEmpty(default_outbound)) {
/* DNS servers */
uci.foreach(uciconfig, ucidnsserver, (cfg) => {
Expand Down Expand Up @@ -590,11 +586,13 @@ config.outbounds = [
if (!isEmpty(main_node)) {
const main_node_cfg = uci.get_all(uciconfig, main_node) || {};
push(config.outbounds, generate_outbound(main_node_cfg));
config.outbounds[length(config.outbounds)-1].domain_strategy = (ipv6_support !== '1') ? 'prefer_ipv4' : null;
config.outbounds[length(config.outbounds)-1].tag = 'main-out';

if (dedicated_udp_node) {
const main_udp_node_cfg = uci.get_all(uciconfig, main_udp_node) || {};
push(config.outbounds, generate_outbound(main_udp_node_cfg));
config.outbounds[length(config.outbounds)-1].domain_strategy = (ipv6_support !== '1') ? 'prefer_ipv4' : null;
config.outbounds[length(config.outbounds)-1].tag = 'main-udp-out';
}
} else if (!isEmpty(default_outbound)) {
Expand Down Expand Up @@ -648,12 +646,10 @@ config.route = {

/* Routing rules */
if (!isEmpty(main_node)) {
/* Direct list */
if (length(direct_domain_list))
push(config.route.rules, {
domain_keyword: direct_domain_list,
outbound: 'direct-out'
});
push(config.route.rules, {
rule_set: 'direct-domain',
outbound: 'direct-out'
});

/* Main UDP out */
if (dedicated_udp_node)
Expand All @@ -665,6 +661,30 @@ if (!isEmpty(main_node)) {
config.route.final = 'main-out';

/* Rule set */
/* Direct list */
if (length(direct_domain_list))
push(config.route.rule_set, {
type: 'inline',
tag: 'direct-domain',
rules: [
{
domain_keyword: direct_domain_list,
}
]
});

/* Proxy list */
if (length(proxy_domain_list))
push(config.route.rule_set, {
type: 'inline',
tag: 'proxy-domain',
rules: [
{
domain_keyword: proxy_domain_list,
}
]
});

if (routing_mode === 'bypass_mainland_china') {
push(config.route.rule_set, {
type: 'remote',
Expand All @@ -688,6 +708,9 @@ if (!isEmpty(main_node)) {
download_detour: 'main-out'
});
}

if (isEmpty(config.route.rule_set))
config.route.rule_set = null;
} else if (!isEmpty(default_outbound)) {
uci.foreach(uciconfig, uciroutingrule, (cfg) => {
if (cfg.enabled !== '1')
Expand Down

0 comments on commit 21b4a8b

Please sign in to comment.