client checks kernel module in /sys/module for WSL2 bridge networking (#17306)
This commit is contained in:
parent
aa1b33d157
commit
c26f01eefd
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
client: check kernel module in `/sys/module` to help with WSL2 bridge networking
|
||||
```
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue