Skip to content

codec-dns: Fix query OPCODE bit offset and mask - #17314

Merged
normanmaurer merged 2 commits into
netty:4.2from
hyperxpro:dns-query-opcode-shift
Aug 24, 2026
Merged

normanmaurer merged 2 commits into
netty:4.2from
hyperxpro:dns-query-opcode-shift

Conversation

@hyperxpro

Copy link
Copy Markdown
Contributor

Motivation:

RFC 1035 section 4.1.1 puts the OPCODE in bits 14-11. DnsQueryEncoder shifted by 14 and masked with 0xFF, so every non-QUERY opcode was corrupted on the wire: NOTIFY silently became QUERY, IQUERY and UPDATE became opcode 8, and STATUS set QR, making the query a response. The response encoder and both decoders already used bits 14-11.

Modification:

Encode the OPCODE as (opCode & 0xF) << 11. Add tests over all five DnsOpCode constants: the round-trip, the exact flags word with and without RD, and an out of range opcode.

Result:

Non-QUERY opcodes are encoded where RFC 1035 puts them and round-trip through the decoder. This fixes the OPCODE field only; UPDATE still cannot be sent, because the prerequisite and update sections are dropped.

@testlens-app

testlens-app Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 185895f
▶️ Tests: 428224 executed
🟡 Checks: 22/24 completed


Learn more about TestLens at testlens.app/docs.

@normanmaurer normanmaurer added this to the 4.2.18.Final milestone Aug 24, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Aug 24, 2026
@normanmaurer
normanmaurer merged commit bec5856 into netty:4.2 Aug 24, 2026
22 of 23 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #17315

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Aug 24, 2026
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17316

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Aug 24, 2026
normanmaurer added a commit that referenced this pull request Aug 24, 2026
Auto-port of #17314 to 4.1
Cherry-picked commit: bec5856

---
Motivation:

RFC 1035 section 4.1.1 puts the OPCODE in bits 14-11. `DnsQueryEncoder`
shifted by 14 and masked with `0xFF`, so every non-QUERY opcode was
corrupted on the wire: NOTIFY silently became QUERY, IQUERY and UPDATE
became opcode 8, and STATUS set QR, making the query a response. The
response encoder and both decoders already used bits 14-11.


Modification:

Encode the OPCODE as `(opCode & 0xF) << 11`. Add tests over all five
DnsOpCode constants: the round-trip, the exact flags word with and
without RD, and an out of range opcode.

Result:

Non-QUERY opcodes are encoded where RFC 1035 puts them and round-trip
through the decoder. This fixes the OPCODE field only; UPDATE still
cannot be sent, because the prerequisite and update sections are
dropped.

---------

Co-authored-by: Aayush Atharva <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Aug 24, 2026
Auto-port of #17314 to 5.0
Cherry-picked commit: bec5856

---
Motivation:

RFC 1035 section 4.1.1 puts the OPCODE in bits 14-11. `DnsQueryEncoder`
shifted by 14 and masked with `0xFF`, so every non-QUERY opcode was
corrupted on the wire: NOTIFY silently became QUERY, IQUERY and UPDATE
became opcode 8, and STATUS set QR, making the query a response. The
response encoder and both decoders already used bits 14-11.


Modification:

Encode the OPCODE as `(opCode & 0xF) << 11`. Add tests over all five
DnsOpCode constants: the round-trip, the exact flags word with and
without RD, and an out of range opcode.

Result:

Non-QUERY opcodes are encoded where RFC 1035 puts them and round-trip
through the decoder. This fixes the OPCODE field only; UPDATE still
cannot be sent, because the prerequisite and update sections are
dropped.

---------

Co-authored-by: Aayush Atharva <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
@hyperxpro
hyperxpro deleted the dns-query-opcode-shift branch August 26, 2026 10:28
@normanmaurer normanmaurer mentioned this pull request Oct 1, 2026
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…#17316)

Auto-port of netty#17314 to 4.1
Cherry-picked commit: bec5856

---
Motivation:

RFC 1035 section 4.1.1 puts the OPCODE in bits 14-11. `DnsQueryEncoder`
shifted by 14 and masked with `0xFF`, so every non-QUERY opcode was
corrupted on the wire: NOTIFY silently became QUERY, IQUERY and UPDATE
became opcode 8, and STATUS set QR, making the query a response. The
response encoder and both decoders already used bits 14-11.


Modification:

Encode the OPCODE as `(opCode & 0xF) << 11`. Add tests over all five
DnsOpCode constants: the round-trip, the exact flags word with and
without RD, and an out of range opcode.

Result:

Non-QUERY opcodes are encoded where RFC 1035 puts them and round-trip
through the decoder. This fixes the OPCODE field only; UPDATE still
cannot be sent, because the prerequisite and update sections are
dropped.

---------

Co-authored-by: Aayush Atharva <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants