From b3d8f9ccc5c3c3aac8e204fef27077004d87418b Mon Sep 17 00:00:00 2001 From: Xu Yang Date: Thu, 28 Mar 2024 18:54:12 -0600 Subject: [PATCH] add CIDR format to warewulf.conf parse Signed-off-by: Xu Yang --- CHANGELOG.md | 1 + internal/pkg/config/root.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f0a18d5e..bba1562ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Block unprivileged requests for arbitrary overlays in secure mode. #1215 - Fix installation docs to use github.com/warewulf instead of github.com/hpcng. #1219 +- Fix the issue that warewulf.conf parse does not support CIDR format. #1130 ### Security diff --git a/internal/pkg/config/root.go b/internal/pkg/config/root.go index 97f26b98a..c24e84e7e 100644 --- a/internal/pkg/config/root.go +++ b/internal/pkg/config/root.go @@ -101,6 +101,19 @@ func (conf *RootConf) Parse(data []byte) error { if len(conf.TFTP.IpxeBinaries) == 0 { conf.TFTP.IpxeBinaries = defIpxe } + + // check whether ip addr is CIDR type and configure related fields as required + if ip, network, err := net.ParseCIDR(conf.Ipaddr); err == nil { + conf.Ipaddr = ip.String() + if conf.Network == "" { + conf.Network = network.IP.String() + } + if conf.Netmask == "" { + mask := network.Mask + conf.Netmask = fmt.Sprintf("%d.%d.%d.%d", mask[0], mask[1], mask[2], mask[3]) + } + } + return nil }