MCPcopy
hub / github.com/lxc/incus / UpdateDNSMasqStatic

Function UpdateDNSMasqStatic

internal/server/network/network_utils.go:425–599  ·  view source on GitHub ↗

UpdateDNSMasqStatic rebuilds the DNSMasq static allocations.

(s *state.State, networkName string)

Source from the content-addressed store, hash-verified

423
424// UpdateDNSMasqStatic rebuilds the DNSMasq static allocations.
425func UpdateDNSMasqStatic(s *state.State, networkName string) error {
426 // We don't want to race with ourselves here.
427 dnsmasq.ConfigMutex.Lock()
428 defer dnsmasq.ConfigMutex.Unlock()
429
430 // Get all the networks.
431 var networks []string
432 if networkName == "" {
433 var err error
434
435 err = s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
436 // Pass api.ProjectDefaultName here, as currently dnsmasq (bridged) networks do not support projects.
437 networks, err = tx.GetNetworks(ctx, api.ProjectDefaultName)
438
439 return err
440 })
441 if err != nil {
442 return err
443 }
444 } else {
445 networks = []string{networkName}
446 }
447
448 // Get all the instances.
449 insts, err := instance.LoadNodeAll(s, instancetype.Any)
450 if err != nil {
451 return err
452 }
453
454 // Build a list of dhcp host entries.
455 entries := map[string][][]string{}
456 for _, inst := range insts {
457 // Go through all its devices (including profiles).
458 for deviceName, d := range inst.ExpandedDevices() {
459 // Skip uninteresting entries.
460 if d["type"] != "nic" {
461 continue
462 }
463
464 nicType, err := nictype.NICType(s, inst.Project().Name, d)
465 if err != nil || nicType != "bridged" {
466 continue
467 }
468
469 // Temporarily populate parent from network setting if used.
470 if d["network"] != "" {
471 d["parent"] = d["network"]
472 }
473
474 // Skip devices not connected to managed networks.
475 if !slices.Contains(networks, d["parent"]) {
476 continue
477 }
478
479 // Fill in the hwaddr from volatile.
480 d, err = inst.FillNetworkDevice(deviceName, d)
481 if err != nil {
482 continue

Callers 4

RenameMethod · 0.92
RenameMethod · 0.92
setupMethod · 0.85

Calls 15

LoadNodeAllFunction · 0.92
NICTypeFunction · 0.92
IsTrueFunction · 0.92
StaticAllocationFileNameFunction · 0.92
DHCPStaticAllocationFunction · 0.92
PathExistsFunction · 0.92
InstanceFunction · 0.92
ErrorfFunction · 0.92
DebugfFunction · 0.92
UpdateStaticEntryFunction · 0.92
KillFunction · 0.92
ErrorfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…