Skip to content

Commit

Permalink
pkg/pillar: honor NtpServerExclusively option
Browse files Browse the repository at this point in the history
which makes pillar ignore NTP servers provided by
the DHCP server on that particular interface

Signed-off-by: Christoph Ostarek <[email protected]>
  • Loading branch information
christoph-zededa committed Dec 4, 2024
1 parent eb228dc commit c151136
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
8 changes: 8 additions & 0 deletions pkg/pillar/cmd/zedagent/parseconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,7 @@ func parseOneSystemAdapterConfig(getconfigCtx *getconfigContext,
port.DNSServers = network.DNSServers
// Need to be careful since zedcloud can feed us bad Dhcp type
port.Dhcp = network.Dhcp
port.IgnoreDhcpNtpServers = network.IgnoreDhcpNtpServers
switch port.Dhcp {
case types.DhcpTypeStatic:
if sysAdapter.Addr == "" {
Expand Down Expand Up @@ -2260,6 +2261,13 @@ func parseIpspecNetworkXObject(ipspec *zconfig.Ipspec, config *types.NetworkXObj
if len(ntpServers) > 0 && ntpServers[0] != "" {
config.NTPServers = ntpServers
}

config.IgnoreDhcpNtpServers = false
dhcpOptionsIgnore := ipspec.GetDhcpOptionsIgnore()
if dhcpOptionsIgnore != nil {
config.IgnoreDhcpNtpServers = dhcpOptionsIgnore.NtpServerExclusively
}

for _, dsStr := range ipspec.GetDns() {
ds := net.ParseIP(dsStr)
if ds == nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/pillar/dpcmanager/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (m *DpcManager) updateDNS() {
m.deviceNetStatus.Ports[ix].DomainName = port.DomainName
m.deviceNetStatus.Ports[ix].DNSServers = port.DNSServers
m.deviceNetStatus.Ports[ix].ConfiguredNtpServers = port.NTPServers
m.deviceNetStatus.Ports[ix].IgnoreDhcpNtpServers = port.IgnoreDhcpNtpServers
// Prefer errors recorded by DPC verification.
// New errors are recorded from this function only when there is none yet
// (HasError() == false).
Expand Down
2 changes: 1 addition & 1 deletion pkg/pillar/scripts/device-steps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ get_ntp_servers_from_nim() {
# Select dynamic (from DHCP) NTP sources
ntp_dynamic=$(jq -r -c \
'.Ports[] |
select(.DhcpNtpServers != null) |
select(.DhcpNtpServers != null and .IgnoreDhcpNtpServers == false) |
.DhcpNtpServers | .[]' $INPUTFILE)

# Concat all in one string
Expand Down
1 change: 1 addition & 0 deletions pkg/pillar/types/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type NetworkPortStatus struct {
Type NetworkType // IPv4 or IPv6 or Dual stack
Subnet net.IPNet
ConfiguredNtpServers []string // This comes from network configuration
IgnoreDhcpNtpServers bool
DomainName string
DNSServers []net.IP // If not set we use Gateway as DNS server
DhcpNtpServers []net.IP // This comes from DHCP done on uplink port
Expand Down
28 changes: 15 additions & 13 deletions pkg/pillar/types/dpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,7 @@ type NetworkPortConfig struct {
WirelessCfg WirelessConfig
// TestResults - Errors from parsing plus success/failure from testing
TestResults
IgnoreDhcpNtpServers bool
}

// EVE-defined port labels.
Expand Down Expand Up @@ -1059,19 +1060,20 @@ func (config DevicePortConfigList) LogKey() string {
// from protobuf API into DevicePortConfig.
// XXX replace by inline once we have device model
type NetworkXObjectConfig struct {
UUID uuid.UUID
Type NetworkType
Dhcp DhcpType // If DhcpTypeStatic or DhcpTypeClient use below
Subnet net.IPNet
Gateway net.IP
DomainName string
NTPServers []string
DNSServers []net.IP // If not set we use Gateway as DNS server
DhcpRange IPRange
DNSNameToIPList []DNSNameToIP // Used for DNS and ACL ipset
Proxy *ProxyConfig
WirelessCfg WirelessConfig
MTU uint16
UUID uuid.UUID
Type NetworkType
Dhcp DhcpType // If DhcpTypeStatic or DhcpTypeClient use below
Subnet net.IPNet
Gateway net.IP
DomainName string
NTPServers []string
IgnoreDhcpNtpServers bool
DNSServers []net.IP // If not set we use Gateway as DNS server
DhcpRange IPRange
DNSNameToIPList []DNSNameToIP // Used for DNS and ACL ipset
Proxy *ProxyConfig
WirelessCfg WirelessConfig
MTU uint16
// Any errors from the parser
// ErrorAndTime provides SetErrorNow() and ClearError()
ErrorAndTime
Expand Down

0 comments on commit c151136

Please sign in to comment.