feat(outbound): sync DNS outbound config with Xray core changes

Rename the DNS rule wire key qtype to qType (reading the legacy qtype on parse for back-compat), add the new rCode response-code field for the return action (omitted when zero), and rename the reject action to return. Align the DNS rule action set across the form dropdown, schema, and adapter to the core's valid values (direct/drop/return/hijack), dropping the never-valid rejectIPv4/rejectIPv6 entries.
This commit is contained in:
MHSanaei committed 2026-06-01 10:24:35 +02:00 Unverified
1 parent 32f96298f8
commit 2bb9ed1cda
6 files changed
+42 -25

No files matched your search

+13 -11
View File
@@ -292,19 +292,20 @@ function blackholeFromWire(raw: Raw) {
function dnsRuleFromWire(raw: unknown): DnsRuleForm {
const r = asObject(raw);
const qtype = Array.isArray(r.qtype)
? r.qtype.map((x) => String(x)).join(',')
: typeof r.qtype === 'number'
? String(r.qtype)
: asString(r.qtype);
const rawQType = r.qType ?? r.qtype;
const qType = Array.isArray(rawQType)
? rawQType.map((x) => String(x)).join(',')
: typeof rawQType === 'number'
? String(rawQType)
: asString(rawQType);
const domain = Array.isArray(r.domain)
? r.domain.map((x) => asString(x)).join(',')
: asString(r.domain);
const action = asString(r.action, 'direct');
const validAction = ['direct', 'reject', 'rejectIPv4', 'rejectIPv6'].includes(action)
const validAction = ['direct', 'drop', 'return', 'hijack'].includes(action)
? action
: 'direct';
return { action: validAction as DnsRuleForm['action'], qtype, domain };
return { action: validAction as DnsRuleForm['action'], qType, domain, rCode: asNumber(r.rCode, 0) };
}
function dnsFromWire(raw: Raw): DnsOutboundFormSettings {
@@ -536,16 +537,17 @@ function blackholeToWire(s: { type: '' | 'none' | 'http' }) {
}
function dnsRuleToWire(r: DnsRuleForm) {
const action = ['direct', 'reject', 'rejectIPv4', 'rejectIPv6'].includes(r.action)
const action = ['direct', 'drop', 'return', 'hijack'].includes(r.action)
? r.action
: 'direct';
const result: Raw = { action };
const qtype = r.qtype.trim();
if (qtype) {
result.qtype = /^\d+$/.test(qtype) ? Number(qtype) : qtype;
const qType = r.qType.trim();
if (qType) {
result.qType = /^\d+$/.test(qType) ? Number(qType) : qType;
}
const domains = r.domain.split(',').map((d) => d.trim()).filter(Boolean);
if (domains.length > 0) result.domain = domains;
if (r.rCode > 0) result.rCode = r.rCode;
return result;
}
@@ -35,7 +35,7 @@ export default function DnsFields() {
size="small"
type="primary"
icon={<PlusOutlined />}
onClick={() => add({ action: 'direct', qtype: '', domain: '' })}
onClick={() => add({ action: 'direct', qType: '', domain: '', rCode: 0 })}
/>
</Form.Item>
{fields.map((field, index) => (
@@ -54,12 +54,15 @@ export default function DnsFields() {
options={DNSRuleActions.map((a) => ({ value: a, label: a }))}
/>
</Form.Item>
<Form.Item label="QType" name={[field.name, 'qtype']}>
<Form.Item label="QType" name={[field.name, 'qType']}>
<Input placeholder="1,3,23-24" />
</Form.Item>
<Form.Item label={t('domainName')} name={[field.name, 'domain']}>
<Input placeholder="domain:example.com" />
</Form.Item>
<Form.Item label="RCode" name={[field.name, 'rCode']}>
<InputNumber min={0} max={65535} style={{ width: '100%' }} />
</Form.Item>
</div>
))}
</>
+4 -3
View File
@@ -29,7 +29,7 @@ import {
// the adapter wraps them as { reverse: { tag, sniffing } } on the wire.
// - blackhole `type` ('' | 'none' | 'http') is flat; the adapter wraps it
// as { response: { type } } on the wire (omitted when empty).
// - DNS rules carry `qtype` and `domain` as comma-joined strings (matches
// - DNS rules carry `qType` and `domain` as comma-joined strings (matches
// the legacy DNSRule UI). The adapter normalizes them on submit.
//
// All flat-form settings types are documented inline so the adapter has a
@@ -186,12 +186,13 @@ export const BlackholeOutboundFormSettingsSchema = z.object({
});
export type BlackholeOutboundFormSettings = z.infer<typeof BlackholeOutboundFormSettingsSchema>;
// DNS rules: form holds qtype + domain as joined strings (the legacy UI
// DNS rules: form holds qType + domain as joined strings (the legacy UI
// binds to <Input>). Adapter parses them on submit per the DNSRule class.
export const DnsRuleFormSchema = z.object({
action: DNSRuleActionSchema.default('direct'),
qtype: z.string().default(''),
qType: z.string().default(''),
domain: z.string().default(''),
rCode: z.number().int().min(0).max(65535).default(0),
});
export type DnsRuleForm = z.infer<typeof DnsRuleFormSchema>;
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff. Show more