Skip to content

Extend prefix_filter to work in relay mode for RA and NDP#390

Open
lqf96 wants to merge 1 commit intoopenwrt:masterfrom
lqf96:extended-prefix-filter
Open

Extend prefix_filter to work in relay mode for RA and NDP#390
lqf96 wants to merge 1 commit intoopenwrt:masterfrom
lqf96:extended-prefix-filter

Conversation

@lqf96
Copy link
Copy Markdown

@lqf96 lqf96 commented Mar 17, 2026

Background

See #385 for details.

Changes

General

  • Change the naming of pio_filter_* to prefix_filter_*, since the prefix_filter will no longer be used just for RA.
  • Added IN6_MATCH_PREFIX_FILTER alongside ADDR_MATCH_PREFIX_FILTER to test if a single IPv6 address is in the prefix filter.

NDP

  • Apply prefix_filter to neighbor solicitation from downstream in handle_solicit.
  • Apply prefix_filter to neighbor and interface address updates on upstream interface in ndp_netevent_cb.

RA

  • Apply prefix_filter to filter out PIO and RIO from upstream RA in forward_router_advertisement.
  • Removing PIO and RIO from RA requires editing the RA message before sending it downstream. For this purpose, a utility called iov_builder is added to odhcpd to solve the problem of applying small edits to a received message before sending it again. See below for the details and usage of this tool.
  • Because of the need of editing the RA message for potential PIO and RIO exclusion, and also because how iov_builder works, forward_router_advertisement is rewritten to perform option look-up and modification together in the per-interface loop, instead of doing so separately in the current implementation. The modifications for options other than PIO and RIO are kept intact.

iov_builder

  • iov_builder is a utility to apply small edits to an existing message stored in the buffer.
  • It ultimately generates an iovec array pointing to chunks of the original message or chunks to added data. The iovec array can then be written or sent through vector I/O.
  • Use odhcpd_iov_builder_init to initalize an iov_builder. It takes a iovec array called iov_buf as well as its iov_capacity, and pointer to the original message data. It initializes the internal editing pointer current_iov_base to data, set the current chunk length current_iov_len to 0 and inclusion include_iov to false.
  • Use odhcpd_iov_builder_append to add an arbitrary iovec to the builder. This is a low-level tool. If the iov_buf is full the function returns 1.
  • Use odhcpd_iov_builder_advance to add a chunk from the original message to the iov_builder. This advances the internal editing pointer by chunk_len. If include_chunk is set to false, the chunk is not added to iov_buf but is instead skipped.
  • Use odhcpd_iov_builder_finalize to finalize the edition in the end. You can now use iov_buf and iov_count for any vectored I/O.

Questions

  • Do we need to consider the case of service reload for NDP relay? Right now in ndp_netevent_cb both addition and deletion are guarded on the prefix_filter check. But this might not work if the user changes the prefix_filter to a more specific prefix and then reload.
  • The updated forward_router_advertisement function has lower efficiency and may need to allocate for more memory due to the need of editing RA message. I thought about this but couldn't come up with a better approach here. Let me know what you think about this and if there is a better solution. It might be OK since NDP relay doesn't happen a lot unless you have many devices in your network

@lqf96
Copy link
Copy Markdown
Author

lqf96 commented Mar 17, 2026

Some information about testing: I tested this patch today on my router and can confirm that prefix_filter works for NDP, and regular RA forwarding still works. However I haven't tested RA prefix_filter because in my situation there is nothing in the RA to filter. I would appreciate if anyone can test it in their environment.

@lqf96 lqf96 force-pushed the extended-prefix-filter branch from c1eb6a9 to addc36b Compare March 21, 2026 19:39
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.

1 participant