feat: support custom ComponentID for Windows TAP device configuration

This commit is contained in:
eWloYW8
2025-09-21 15:14:27 +08:00
committed by ginuerzh
parent 1c1f092a14
commit eae322c7ba
3 changed files with 22 additions and 16 deletions
+1
View File
@@ -12,5 +12,6 @@ type Config struct {
Net string Net string
MTU int MTU int
Gateway string Gateway string
ComponentID string
Routes []Route Routes []Route
} }
+5
View File
@@ -25,6 +25,7 @@ func (l *tapListener) parseMetadata(md mdata.Metadata) (err error) {
route = "route" route = "route"
routes = "routes" routes = "routes"
gateway = "gw" gateway = "gw"
componentID = "componentID"
) )
config := &tap_util.Config{ config := &tap_util.Config{
@@ -32,10 +33,14 @@ func (l *tapListener) parseMetadata(md mdata.Metadata) (err error) {
Net: mdutil.GetString(md, netKey), Net: mdutil.GetString(md, netKey),
MTU: mdutil.GetInt(md, mtu), MTU: mdutil.GetInt(md, mtu),
Gateway: mdutil.GetString(md, gateway), Gateway: mdutil.GetString(md, gateway),
ComponentID: mdutil.GetString(md, componentID),
} }
if config.MTU <= 0 { if config.MTU <= 0 {
config.MTU = DefaultMTU config.MTU = DefaultMTU
} }
if config.ComponentID == "" {
config.ComponentID = "tap0901"
}
gw := net.ParseIP(config.Gateway) gw := net.ParseIP(config.Gateway)
+1 -1
View File
@@ -17,7 +17,7 @@ func (l *tapListener) createTap() (dev io.ReadWriteCloser, name string, ip net.I
ifce, err := water.New(water.Config{ ifce, err := water.New(water.Config{
DeviceType: water.TAP, DeviceType: water.TAP,
PlatformSpecificParams: water.PlatformSpecificParams{ PlatformSpecificParams: water.PlatformSpecificParams{
ComponentID: "tap0901", ComponentID: l.md.config.ComponentID,
InterfaceName: l.md.config.Name, InterfaceName: l.md.config.Name,
Network: l.md.config.Net, Network: l.md.config.Net,
}, },