Skip to content

Migrate iptables and ebtables usages to nftables#2561

Open
dxapd wants to merge 3 commits into
google:mainfrom
dxapd:nftables-migration
Open

Migrate iptables and ebtables usages to nftables#2561
dxapd wants to merge 3 commits into
google:mainfrom
dxapd:nftables-migration

Conversation

@dxapd
Copy link
Copy Markdown
Collaborator

@dxapd dxapd commented May 13, 2026

Also adds a basic networking test and a workaround bazel arg to disable sandboxing to run locally (since some of the upstream images don't have the fix yet)

b/500704721

@dxapd dxapd added go Pull requests that update Go code kokoro:run Run e2e tests. labels May 13, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label May 13, 2026
@dxapd dxapd force-pushed the nftables-migration branch from cb48537 to 2701129 Compare May 13, 2026 19:58
@dxapd dxapd added the kokoro:run Run e2e tests. label May 13, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label May 13, 2026
@dxapd dxapd force-pushed the nftables-migration branch from ce11181 to c8108ec Compare May 14, 2026 01:25
@dxapd dxapd force-pushed the nftables-migration branch from c8108ec to 2187c3a Compare May 14, 2026 18:33
@dxapd dxapd added the kokoro:run Run e2e tests. label May 14, 2026
@GoogleCuttlefishTesterBot GoogleCuttlefishTesterBot removed the kokoro:run Run e2e tests. label May 14, 2026
@dxapd dxapd marked this pull request as ready for review May 14, 2026 18:35
@dxapd dxapd requested a review from Databean May 14, 2026 18:35

handle_file="${cuttlefish_run_dir}/${type}-${id}.handle"

if [ "$op" = "add" ]; then
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also use a case statement?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup

elif [ "$op" = "delete" ]; then
if [ -f "$handle_file" ]; then
# Find the handle file and use it to clean things up.
handle=$(cat "$handle_file")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: $(< "$handle_file")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL

return 1
fi
# Add the rule and store the handle.
handle=$(nft -a -e add rule "$family" "$table" "$chain" "$contents" | awk '/# handle/ {print $NF}')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add Depends entries for newly added tools, in this case nft and awk:

Depends: adduser,
binfmt-support [arm64],
bridge-utils,
curl,
dnsmasq-base,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Comment on lines +135 to +136
local handle_file=""
local handle=""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the variable declarations for handle and handle_file be combined with the first assignment, or at least declared more closely?

https://google.github.io/styleguide/shellguide.html#s7.5-use-local-variables does mention though that

Declaration and assignment must be separate statements when the assignment value is provided by a command substitution; as the local builtin does not propagate the exit code from the command substitution.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my first instinct says that if all of the possible variables are declared at the top of the function, in the case of a language like bash, it would make it easier to reason about the function body (since then you already know all of the variables you're going to see), what do you think?

Comment on lines +111 to +112
// Discover an IP address of the host that the guest can ping to verify default routing.
func discoverPingableHostIP(t *testing.T) string {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of pinging a standard publicly available IP address like 8.8.8.8?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose this IP because it'd be pingable even if the host's network is down but tbh internet access is a prerequisite so 8.8.8.8 would let us skip this entire step and simplify the test case so i might as well do that

Comment on lines +31 to +36
}{
{
branch: "aosp-android-latest-release",
target: "aosp_cf_x86_64_only_phone-userdebug",
},
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case for git_main as well.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

Comment thread e2etests/cvd/common/common.go
return 1
fi
# Add the rule and store the handle.
handle=$(nft -a -e add rule "$family" "$table" "$chain" "$contents" | awk '/# handle/ {print $NF}')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to awk is using nft -j to output JSON and parsing it. This has the advantage of of relying on the documented json output format, rather than the current output format, which is more of an implementation detail. JSON parsing is easier with a tool like jq, but using that has the downside of a new package depenency.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's a bit fragile like this. i'll weigh how to do that..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants