Skip to content

Commit c56a795

Browse files
committed
re-enable Config.Global.LocalIP
1 parent 93d46c3 commit c56a795

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

config.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,17 @@ func RepairConfig(cfg *Config) error {
676676
}
677677
codec.SetReaderSize(*cfg.Global.ReadBufferSize)
678678

679+
// nic -> ip
680+
if err := repairServiceIPWithNic(cfg); err != nil {
681+
return err
682+
}
683+
684+
// Set empty ip to "0.0.0.0" to prevent malformed key matching
685+
// for passed listeners during hot restart.
686+
const defaultIP = "0.0.0.0"
687+
setDefault(&cfg.Global.LocalIP, defaultIP)
688+
setDefault(&cfg.Server.Admin.IP, cfg.Global.LocalIP)
689+
679690
// protocol network ip empty
680691
for _, serviceCfg := range cfg.Server.Service {
681692
setDefault(&serviceCfg.Protocol, cfg.Server.Protocol)
@@ -714,17 +725,11 @@ func RepairConfig(cfg *Config) error {
714725

715726
// repairServiceIPWithNic repairs the Config when service ip is empty according to the nic.
716727
func repairServiceIPWithNic(cfg *Config) error {
717-
// Set empty ip to "0.0.0.0" to prevent malformed key matching
718-
// for passed listeners during hot restart.
719-
const defaultIP = "0.0.0.0"
720728
for index, item := range cfg.Server.Service {
721729
if item.IP == "" {
722730
ip := getIP(item.Nic)
723-
if ip == "" {
724-
if item.Nic != "" {
725-
return fmt.Errorf("can't find service IP by the NIC: %s", item.Nic)
726-
}
727-
ip = defaultIP
731+
if ip == "" && item.Nic != "" {
732+
return fmt.Errorf("can't find service IP by the NIC: %s", item.Nic)
728733
}
729734
cfg.Server.Service[index].IP = ip
730735
}
@@ -733,11 +738,8 @@ func repairServiceIPWithNic(cfg *Config) error {
733738

734739
if cfg.Server.Admin.IP == "" {
735740
ip := getIP(cfg.Server.Admin.Nic)
736-
if ip == "" {
737-
if cfg.Server.Admin.Nic != "" {
738-
return fmt.Errorf("can't find admin IP by the NIC: %s", cfg.Server.Admin.Nic)
739-
}
740-
ip = defaultIP
741+
if ip == "" && cfg.Server.Admin.Nic != "" {
742+
return fmt.Errorf("can't find admin IP by the NIC: %s", cfg.Server.Admin.Nic)
741743
}
742744
cfg.Server.Admin.IP = ip
743745
}

0 commit comments

Comments
 (0)