Skip to content

Commit

Permalink
Merge branch 'main' into v0.3
Browse files Browse the repository at this point in the history
Incorporate v0.2.1 changes into v0.3 release candidates
  • Loading branch information
synackd committed Dec 11, 2024
2 parents 6f1bfe3 + b1d1a31 commit f4efbb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
19 changes: 5 additions & 14 deletions coresmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (
cache *Cache
baseURL *url.URL
bootScriptBaseURL *url.URL
hostnamePrefix string
leaseDuration time.Duration
)

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

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

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

// Parse hostname prefix
hostnamePrefix = strings.Trim(args[3], `"'`)
log.Infof("hostname prefix: %s", hostnamePrefix)
if hostnamePrefix == "" {
log.Info("no hostname prefix set, defaulting to 'nid'")
hostnamePrefix = "nid"
}

// Create new Cache using fourth argument (cache validity duration) and new SmdClient
// pointer
log.Debug("generating new Cache")
cache, err = NewCache(args[4], smdClient)
cache, err = NewCache(args[3], smdClient)
if err != nil {
return nil, fmt.Errorf("failed to create new cache: %w", err)
}

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

// Set client hostname
if ifaceInfo.Type == "Node" {
resp.Options.Update(dhcpv4.OptHostName(fmt.Sprintf("%s%04d", hostnamePrefix, ifaceInfo.CompNID)))
resp.Options.Update(dhcpv4.OptHostName(fmt.Sprintf("nid%04d", ifaceInfo.CompNID)))
}

// Set root path to this server's IP
Expand Down
18 changes: 16 additions & 2 deletions coresmd/tftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,33 @@ func startTFTPServer(directory string) {

func readHandler(directory string) func(string, io.ReaderFrom) error {
return func(filename string, rf io.ReaderFrom) error {
var raddr string
ot, ok := rf.(tftp.OutgoingTransfer)
if !ok {
log.Error("unable to get remote address, setting to (unknown)")
raddr = "(unknown)"
} else {
ra := ot.RemoteAddr()
raptr := &ra
raddr = raptr.IP.String()
}
if filename == defaultScriptName {
log.Infof("tftp: %s requested default script")
var sr ScriptReader
_, err := rf.ReadFrom(sr)
nbytes, err := rf.ReadFrom(sr)
log.Infof("tftp: sent %d bytes of default script to %s", nbytes, raddr)
return err
}
log.Infof("tftp: %s requested file %s", raddr, filename)
filePath := filepath.Join(directory, filename)
file, err := os.Open(filePath)
if err != nil {
return err
}
defer file.Close()

_, err = rf.ReadFrom(file)
nbytes, err := rf.ReadFrom(file)
log.Infof("tftp: sent %d bytes of file %s to %s", nbytes, filename, raddr)
return err
}
}
9 changes: 3 additions & 6 deletions resources/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ server4:
# address if name servers are not configured.
# 3. (OPTIONAL) Path to CA cert used for TLS with the SMD base URL. If
# there is already a trusted certificate, this can be blank ("").
# 4. Node hostname prefix. The hostnames given to nodes will be of the
# format "<prefix><nid>". If this argument is blank, "nid" is used as
# the prefix. <nid> is the node ID number, 0-padded to four places.
# 5. Cache validity duration. Coresmd uses a pull-through cache to store
# 4. Cache validity duration. Coresmd uses a pull-through cache to store
# network information and this is the duration to refresh that cache.
# 6. Lease duration.
- coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt '' 30s 1h
# 5. Lease duration.
- coresmd: https://foobar.openchami.cluster http://172.16.0.253:8081 /root_ca/root_ca.crt 30s 1h

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

0 comments on commit f4efbb1

Please sign in to comment.