add hosts support for dns

This commit is contained in:
ginuerzh
2022-01-19 16:33:27 +08:00
parent 1e613fc2e6
commit f357117056
11 changed files with 212 additions and 53 deletions

View File

@ -164,11 +164,11 @@ func buildConfigFromCmd(services, nodes stringList) (*config.Config, error) {
if len(ss) != 2 {
continue
}
hostsCfg.Entries = append(
hostsCfg.Entries,
config.HostConfig{
IP: ss[0],
Hostname: ss[1],
hostsCfg.Mappings = append(
hostsCfg.Mappings,
config.HostMappingConfig{
Hostname: ss[0],
IP: ss[1],
},
)
}

View File

@ -340,7 +340,14 @@ func bypassFromConfig(cfg *config.BypassConfig) bypass.Bypass {
if cfg == nil {
return nil
}
return bypass.NewBypassPatterns(cfg.Reverse, cfg.Matchers...)
return bypass.NewBypassPatterns(
cfg.Reverse,
cfg.Matchers,
bypass.LoggerBypassOption(log.WithFields(map[string]interface{}{
"kind": "bypass",
"bypass": cfg.Name,
})),
)
}
func resolverFromConfig(cfg *config.ResolverConfig) (resolver.Resolver, error) {
@ -371,12 +378,16 @@ func resolverFromConfig(cfg *config.ResolverConfig) (resolver.Resolver, error) {
}
func hostsFromConfig(cfg *config.HostsConfig) hostspkg.HostMapper {
if cfg == nil || len(cfg.Entries) == 0 {
if cfg == nil || len(cfg.Mappings) == 0 {
return nil
}
hosts := hostspkg.NewHosts()
hosts.Logger = log.WithFields(map[string]interface{}{
"kind": "hosts",
"hosts": cfg.Name,
})
for _, host := range cfg.Entries {
for _, host := range cfg.Mappings {
if host.IP == "" || host.Hostname == "" {
continue
}