Skip to content

gvforwarder: code cleanups#552

Merged
openshift-merge-bot[bot] merged 3 commits intocontainers:mainfrom
cfergeau:gvforwarder
Sep 24, 2025
Merged

gvforwarder: code cleanups#552
openshift-merge-bot[bot] merged 3 commits intocontainers:mainfrom
cfergeau:gvforwarder

Conversation

@cfergeau
Copy link
Copy Markdown
Collaborator

This PR does minor cleanups to gvforwarder code, mainly to use newer features available in recent go versions.
It also add missing error reporting in one code path.

The `contains` helper is now part of the `slices` package

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
This error path returned from `rx` but did not report an error as all the other error paths.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
This should help understand what gvforwarder is doing when it does not work as expected.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
@vyasgun
Copy link
Copy Markdown
Member

vyasgun commented Sep 16, 2025

Looks good to me!

/approve

@@ -177,7 +175,7 @@ func rx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
}

if n < 0 || n > math.MaxUint16 {
Copy link
Copy Markdown
Collaborator

@lstocchi lstocchi Sep 22, 2025

Choose a reason for hiding this comment

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

i wonder if it is actually possible for n to be less than 0 or we can remove it from the if clause.

By reading the func description it seems not "It returns the number of bytes read (0 <= n <= len(p)) and any error encountered."

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.

This check is needed to make static code checkers happy, they are not sophisticated enough to know what tap.Read can return. If I remove the if n < 0 check:

$ git diff
diff --git a/cmd/vm/main_linux.go b/cmd/vm/main_linux.go
index 550e0418..cd53c724 100644
--- a/cmd/vm/main_linux.go
+++ b/cmd/vm/main_linux.go
@@ -174,7 +174,7 @@ func rx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
                        log.Info(packet.String())
                }
 
-               if n < 0 || n > math.MaxUint16 {
+               if n > math.MaxUint16 {
                        errCh <- fmt.Errorf("invalid frame length (%d > %d)", n, math.MaxUint16)
                        return
                }

$ make cross-lint
GOOS=linux make lint
make[1] : on entre dans le répertoire « /var/home/teuf/dev/gvisor-tap-vsock »
"/var/home/teuf/dev/gvisor-tap-vsock/tools/bin"/golangci-lint run
cmd/vm/main_linux.go:181:45: G115: integer overflow conversion int -> uint16 (gosec)
		binary.LittleEndian.PutUint16(size, uint16(n))
		                                          ^
1 issues:
* gosec: 1
make[1]: *** [Makefile:49: lint] Error 1
make[1] : on quitte le répertoire « /var/home/teuf/dev/gvisor-tap-vsock »
make: *** [Makefile:53: cross-lint] Error 2

@cfergeau
Copy link
Copy Markdown
Collaborator Author

(This needs a /lgtm to be automatically merged by the tide bot)

@lstocchi
Copy link
Copy Markdown
Collaborator

/lgtm
/approve

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Sep 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cfergeau, lstocchi, vyasgun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 1568bb9 into containers:main Sep 24, 2025
22 checks passed
@cfergeau cfergeau deleted the gvforwarder branch September 25, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants