Skip to content

Commit f4efbb1

Browse files
committed
Merge branch 'main' into v0.3
Incorporate v0.2.1 changes into v0.3 release candidates
2 parents 6f1bfe3 + b1d1a31 commit f4efbb1

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

coresmd/main.go

+5-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ var (
3737
cache *Cache
3838
baseURL *url.URL
3939
bootScriptBaseURL *url.URL
40-
hostnamePrefix string
4140
leaseDuration time.Duration
4241
)
4342

@@ -49,8 +48,8 @@ func setup4(args ...string) (handler.Handler4, error) {
4948
log.Infof("initializing coresmd/coresmd %s (%s), built %s", version.Version, version.GitCommit, version.BuildTime)
5049

5150
// Ensure all required args were passed
52-
if len(args) != 6 {
53-
return nil, errors.New("expected 6 arguments: base URL, boot script base URL, CA certificate path, hostname prefix, cache duration, lease duration")
51+
if len(args) != 5 {
52+
return nil, errors.New("expected 5 arguments: base URL, boot script base URL, CA certificate path, cache duration, lease duration")
5453
}
5554

5655
// Create new SmdClient using first argument (base URL)
@@ -82,25 +81,17 @@ func setup4(args ...string) (handler.Handler4, error) {
8281
log.Infof("CA certificate path was empty, not setting")
8382
}
8483

85-
// Parse hostname prefix
86-
hostnamePrefix = strings.Trim(args[3], `"'`)
87-
log.Infof("hostname prefix: %s", hostnamePrefix)
88-
if hostnamePrefix == "" {
89-
log.Info("no hostname prefix set, defaulting to 'nid'")
90-
hostnamePrefix = "nid"
91-
}
92-
9384
// Create new Cache using fourth argument (cache validity duration) and new SmdClient
9485
// pointer
9586
log.Debug("generating new Cache")
96-
cache, err = NewCache(args[4], smdClient)
87+
cache, err = NewCache(args[3], smdClient)
9788
if err != nil {
9889
return nil, fmt.Errorf("failed to create new cache: %w", err)
9990
}
10091

10192
// Set lease duration from fifth argument
10293
log.Debug("setting lease duration")
103-
leaseDuration, err = time.ParseDuration(args[5])
94+
leaseDuration, err = time.ParseDuration(args[4])
10495
if err != nil {
10596
return nil, fmt.Errorf("failed to parse lease duration: %w", err)
10697
}
@@ -140,7 +131,7 @@ func Handler4(req, resp *dhcpv4.DHCPv4) (*dhcpv4.DHCPv4, bool) {
140131

141132
// Set client hostname
142133
if ifaceInfo.Type == "Node" {
143-
resp.Options.Update(dhcpv4.OptHostName(fmt.Sprintf("%s%04d", hostnamePrefix, ifaceInfo.CompNID)))
134+
resp.Options.Update(dhcpv4.OptHostName(fmt.Sprintf("nid%04d", ifaceInfo.CompNID)))
144135
}
145136

146137
// Set root path to this server's IP

coresmd/tftp.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,33 @@ func startTFTPServer(directory string) {
3131

3232
func readHandler(directory string) func(string, io.ReaderFrom) error {
3333
return func(filename string, rf io.ReaderFrom) error {
34+
var raddr string
35+
ot, ok := rf.(tftp.OutgoingTransfer)
36+
if !ok {
37+
log.Error("unable to get remote address, setting to (unknown)")
38+
raddr = "(unknown)"
39+
} else {
40+
ra := ot.RemoteAddr()
41+
raptr := &ra
42+
raddr = raptr.IP.String()
43+
}
3444
if filename == defaultScriptName {
45+
log.Infof("tftp: %s requested default script")
3546
var sr ScriptReader
36-
_, err := rf.ReadFrom(sr)
47+
nbytes, err := rf.ReadFrom(sr)
48+
log.Infof("tftp: sent %d bytes of default script to %s", nbytes, raddr)
3749
return err
3850
}
51+
log.Infof("tftp: %s requested file %s", raddr, filename)
3952
filePath := filepath.Join(directory, filename)
4053
file, err := os.Open(filePath)
4154
if err != nil {
4255
return err
4356
}
4457
defer file.Close()
4558

46-
_, err = rf.ReadFrom(file)
59+
nbytes, err := rf.ReadFrom(file)
60+
log.Infof("tftp: sent %d bytes of file %s to %s", nbytes, filename, raddr)
4761
return err
4862
}
4963
}

resources/config.example.yaml

+3-6
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ server4:
4343
# address if name servers are not configured.
4444
# 3. (OPTIONAL) Path to CA cert used for TLS with the SMD base URL. If
4545
# there is already a trusted certificate, this can be blank ("").
46-
# 4. Node hostname prefix. The hostnames given to nodes will be of the
47-
# format "<prefix><nid>". If this argument is blank, "nid" is used as
48-
# the prefix. <nid> is the node ID number, 0-padded to four places.
49-
# 5. Cache validity duration. Coresmd uses a pull-through cache to store
46+
# 4. Cache validity duration. Coresmd uses a pull-through cache to store
5047
# network information and this is the duration to refresh that cache.
51-
# 6. Lease duration.
52-
- coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt '' 30s 1h
48+
# 5. Lease duration.
49+
- coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt 30s 1h
5350

5451
# Any requests reaching this point are unknown to SMD and it is up to the
5552
# administrator to decide how to handle unknown packets.

0 commit comments

Comments
 (0)