Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client checks kernel module in /sys/module for WSL2 bridge networking #17306

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/17306.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
client: check kernel module in `/sys/module` to help with WSL2 bridge networking
```
16 changes: 16 additions & 0 deletions client/fingerprint/bridge_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ func (f *BridgeFingerprint) detect(module string) error {
// accumulate errors from every place we might find the module
var errs error

// Check if the module is in /sys/modules
sysfsModulePath := fmt.Sprintf("/sys/module/%s", module)
if err := f.findDir(sysfsModulePath); err != nil {
errs = multierror.Append(errs, err)
} else {
return nil
}

// check if the module has been dynamically loaded
dynamicPath := "/proc/modules"
if err := f.searchFile(module, dynamicPath, f.regexp(dynamicModuleRe, module)); err != nil {
Expand Down Expand Up @@ -89,6 +97,14 @@ func (f *BridgeFingerprint) detect(module string) error {
return errs
}

func (f *BridgeFingerprint) findDir(dirname string) error {
if _, err := os.Stat(dirname); err != nil {
return fmt.Errorf("failed to find %s: %v", dirname, err)
} else {
return nil
}
}

func (f *BridgeFingerprint) searchFile(module, filename string, re *regexp.Regexp) error {
file, err := os.Open(filename)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions client/fingerprint/bridge_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func TestBridgeFingerprint_detect(t *testing.T) {
ci.Parallel(t)

f := &BridgeFingerprint{logger: testlog.HCLogger(t)}
require.NoError(t, f.detect("ip_tables"))
require.NoError(t, f.detect("kernel")) // kernel should be there.

err := f.detect("nonexistentmodule")
require.Error(t, err)
require.Contains(t, err.Error(), "3 errors occurred")
require.Contains(t, err.Error(), "4 errors occurred")
}

func writeFile(t *testing.T, prefix, content string) string {
Expand Down