Commit e517a144 authored by nanahira's avatar nanahira

update redirect

parent aaee2431
......@@ -18,7 +18,7 @@ interface_switch_china -A u_{{gw.isp}}_china {{gw.selectionMark}}
interface_switch_oversea -A u_{{gw.isp}}_oversea {{gw.selectionMark}}
restore_mark_switch -A {{gw.selectionMark}}
{% endif %}
interface_switch_redirect -A {{gw.selectionMark}} {{gw.redirectPort}}
interface_switch_redirect -A {{gw.selectionMark}} {{gw.redirectServerPort}}
{% endif %}
{% endfor %}
......
......@@ -71,7 +71,8 @@ interface_switch_oversea() {
interface_switch_redirect() {
OPTION=$1
MARK=$2
REDIR_PORT=$3
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i mc+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports 80,443,21,22,23,8080,8443 -j DNAT --to-destination {{address}}:$REDIR_PORT
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i ocs+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports 80,443,21,22,23,8080,8443 -j DNAT --to-destination {{address}}:$REDIR_PORT
REDIR_SERVER_PORT=$3
REDIR_TARGET_PORTS=$4
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i mc+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports $REDIR_TARGET_PORTS -m multiport ! --dports {{allRedirectServerPorts}} -j DNAT --to-destination {{address}}:$REDIR_PORT
$IPTABLES_EXEC -t nat "$OPTION" NEXTGEN_SWITCH -m mark --mark $MARK -i ocs+ -m set --match-set mycard src -m set ! --match-set mycard dst -p tcp -m multiport --dports $REDIR_TARGET_PORTS -m multiport ! --dports {{allRedirectServerPorts}} -j DNAT --to-destination {{address}}:$REDIR_PORT
}
......@@ -102,19 +102,23 @@ class InventoryBuilder {
const gateways = await this.load('gateways2');
for (let gateway of gateways) {
gateway.isCN = this.hosts[gateway.router] && this.hosts[gateway.router].location.startsWith('CN');
gateway.hidden = !!gateway.hidden;
for (const boolField of ['hidden', 'redirectAllPorts']) {
gateway[boolField] = !!gateway[boolField]
}
if (gateway.mark) {
gateway.selectionMark = gateway.mark + 50;
gateway.redirectPort = gateway.mark + 60000;
gateway.redirectServerPort = gateway.mark + 60000;
} else {
gateway.selectionMark = 0;
gateway.redirectPort = 60100;
gateway.redirectServerPort = 60100;
}
gateway.redirectTargetPorts = gateway.redirectAllPorts ? '1:65535' : this.vars.redirectTargetPorts.replace(/-/g, ':');
}
return gateways;
}
async main() {
this.vars = await this.loadUtilities();
this.hosts = _.keyBy(await this.load('nextgen2'), 'name');
this.gateways = _.mapValues(_.groupBy(await this.loadGateways(), 'router'), g => _.keyBy(g, 'isp'));
this.gatewayGroups = await this.load('gateway groups') as GatewayGroup[];
......@@ -139,7 +143,6 @@ class InventoryBuilder {
if (process.env.LIMIT_LINKS) {
this.linksLimit = process.env.LIMIT_LINKS.split(",");
}
this.vars = await this.loadUtilities();
const inventoryValue = { wg: { hosts: Object.fromEntries(Object.values(this.hosts).map(host => [host.name, this.getHostConnectionInfo(host)])) } };
await fs.promises.writeFile('result/inventory.yaml', YAML.stringify(inventoryValue));
// console.log(Object.values(this.hosts));
......@@ -263,13 +266,17 @@ class InventoryBuilder {
};
}
const redirectAvailableGateways = Object.values(this.gateways[host.name]).filter(gateway => !gateway.hidden);
const gostConfig: GostConfig = {
Routes: Object.values(this.gateways[host.name]).filter(gateway => !gateway.hidden).map(gateway => ({
ServeNodes: [`red://${host.address}:${gateway.redirectPort}`],
Routes: redirectAvailableGateways.map(gateway => ({
ServeNodes: [`red://${host.address}:${gateway.redirectServerPort}`],
Mark: gateway.selectionMark as number,
}))
};
const allRedirectServerPorts = redirectAvailableGateways.map(gateway => gateway.redirectServerPort).join(',');
if (gostConfig.Routes.length) {
host.gostConfig = gostConfig;
host.dockerServices.services.gost = {
......@@ -355,6 +362,7 @@ class InventoryBuilder {
iptables_type: host.iptables || 'auto',
gostConfig,
installGost: !!gostConfig,
allRedirectServerPorts,
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment