Przeglądaj źródła

daemon/config: move MTU to BridgeConfig

This option is only used for the default bridge network; let's move the
field to that struct to make it clearer what it's used for.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 lat temu
rodzic
commit
b8220f5d0d

+ 1 - 1
cmd/dockerd/config.go

@@ -30,7 +30,7 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) error {
 	flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri")
 
 	flags.Var(opts.NewNamedMapMapOpts("default-network-opts", conf.DefaultNetworkOpts, nil), "default-network-opt", "Default network options")
-	flags.IntVar(&conf.Mtu, "mtu", conf.Mtu, `Set the MTU for the default "bridge" network`)
+	flags.IntVar(&conf.MTU, "mtu", conf.MTU, `Set the MTU for the default "bridge" network`)
 	if runtime.GOOS == "windows" {
 		// The mtu option is not used on Windows, but it has been available since
 		// "forever" (and always silently ignored). We hide the flag for now,

+ 3 - 4
daemon/config/config.go

@@ -151,7 +151,6 @@ type CommonConfig struct {
 	GraphDriver           string   `json:"storage-driver,omitempty"`
 	GraphOptions          []string `json:"storage-opts,omitempty"`
 	Labels                []string `json:"labels,omitempty"`
-	Mtu                   int      `json:"mtu,omitempty"`
 	NetworkDiagnosticPort int      `json:"network-diagnostic-port,omitempty"`
 	Pidfile               string   `json:"pidfile,omitempty"`
 	RawLogs               bool     `json:"raw-logs,omitempty"`
@@ -280,7 +279,7 @@ func New() (*Config, error) {
 			MaxConcurrentDownloads: DefaultMaxConcurrentDownloads,
 			MaxConcurrentUploads:   DefaultMaxConcurrentUploads,
 			MaxDownloadAttempts:    DefaultDownloadAttempts,
-			Mtu:                    DefaultNetworkMtu,
+			BridgeConfig:           BridgeConfig{MTU: DefaultNetworkMtu},
 			NetworkConfig: NetworkConfig{
 				NetworkControlPlaneMTU: DefaultNetworkMtu,
 				DefaultNetworkOpts:     make(map[string]map[string]string),
@@ -615,8 +614,8 @@ func Validate(config *Config) error {
 	}
 
 	// TODO(thaJeztah) Validations below should not accept "0" to be valid; see Validate() for a more in-depth description of this problem
-	if config.Mtu < 0 {
-		return errors.Errorf("invalid default MTU: %d", config.Mtu)
+	if config.MTU < 0 {
+		return errors.Errorf("invalid default MTU: %d", config.MTU)
 	}
 	if config.MaxConcurrentDownloads < 0 {
 		return errors.Errorf("invalid max concurrent downloads: %d", config.MaxConcurrentDownloads)

+ 1 - 0
daemon/config/config_linux.go

@@ -37,6 +37,7 @@ type BridgeConfig struct {
 	commonBridgeConfig
 
 	// Fields below here are platform specific.
+	MTU                         int    `json:"mtu,omitempty"`
 	DefaultIP                   net.IP `json:"ip,omitempty"`
 	IP                          string `json:"bip,omitempty"`
 	DefaultGatewayIPv4          net.IP `json:"default-gateway,omitempty"`

+ 3 - 3
daemon/config/config_test.go

@@ -286,7 +286,7 @@ func TestValidateConfigurationErrors(t *testing.T) {
 			name: "negative MTU",
 			config: &Config{
 				CommonConfig: CommonConfig{
-					Mtu: -10,
+					BridgeConfig: BridgeConfig{MTU: -10},
 				},
 			},
 			expectedErr: "invalid default MTU: -10",
@@ -440,10 +440,10 @@ func TestValidateConfiguration(t *testing.T) {
 		},
 		{
 			name:  "with mtu",
-			field: "Mtu",
+			field: "MTU",
 			config: &Config{
 				CommonConfig: CommonConfig{
-					Mtu: 1234,
+					BridgeConfig: BridgeConfig{MTU: 1234},
 				},
 			},
 		},

+ 5 - 1
daemon/config/config_windows.go

@@ -19,6 +19,10 @@ const (
 // configuration.
 type BridgeConfig struct {
 	commonBridgeConfig
+
+	// MTU is not actually used on Windows, but the --mtu option has always
+	// been there on Windows (but ignored).
+	MTU int `json:"mtu,omitempty"`
 }
 
 // Config defines the configuration of a docker daemon.
@@ -48,7 +52,7 @@ func (conf *Config) IsSwarmCompatible() error {
 
 // ValidatePlatformConfig checks if any platform-specific configuration settings are invalid.
 func (conf *Config) ValidatePlatformConfig() error {
-	if conf.Mtu != 0 && conf.Mtu != DefaultNetworkMtu {
+	if conf.MTU != 0 && conf.MTU != DefaultNetworkMtu {
 		log.G(context.TODO()).Warn(`WARNING: MTU for the default network is not configurable on Windows, and this option will be ignored.`)
 	}
 	return nil

+ 1 - 1
daemon/daemon_unix.go

@@ -930,7 +930,7 @@ func initBridgeDriver(controller *libnetwork.Controller, config *config.Config)
 	netOption := map[string]string{
 		bridge.BridgeName:         bridgeName,
 		bridge.DefaultBridge:      strconv.FormatBool(true),
-		netlabel.DriverMTU:        strconv.Itoa(config.Mtu),
+		netlabel.DriverMTU:        strconv.Itoa(config.MTU),
 		bridge.EnableIPMasquerade: strconv.FormatBool(config.BridgeConfig.EnableIPMasq),
 		bridge.EnableICC:          strconv.FormatBool(config.BridgeConfig.InterContainerCommunication),
 	}