forked from lf-edge/eve
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist MAC generator ID used by a given app
Persisting MAC address generator ID avoids changing MAC addresses for already deployed apps, even when the option network.local.legacy.mac.address is changed by the user. Only newly deployed apps will apply the latest config change and use the most recently selected MAC generator. This is backported from master, commit 7c742f2, but highly adjusted to 9.4, witch pre-refactoring zedrouter code. Signed-off-by: Milan Lenco <milan@zededa.com>
- Loading branch information
1 parent
e3caac8
commit 6920a3e
Showing
4 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2023 Zededa, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Back-ported code for persisting of MAC address generator ID per app. | ||
// This code is adjusted specifically for 9.4. In newer EVE versions, | ||
// this is implemented using objtonum package which is not yet in 9.4. | ||
// We have to be careful here and replicate the format of persisted data | ||
// to match newer EVE versions and enable seamless upgrades. | ||
|
||
package zedrouter | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/lf-edge/eve/pkg/pillar/types" | ||
uuid "github.com/satori/go.uuid" | ||
) | ||
|
||
func getAppMacGeneratorID(ctx *zedrouterContext, appUUID uuid.UUID) (int, error) { | ||
rawItem, err := ctx.pubAppMACGenerator.Get(appUUID.String()) | ||
if err != nil { | ||
log.Errorf("failed to get published MAC generator ID for app %v: %v", | ||
appUUID, err) | ||
return 0, err | ||
} | ||
item, ok := rawItem.(types.AppMACGenerator) | ||
if !ok { | ||
return 0, fmt.Errorf("invalid item type: %T, expected AppMACGenerator", rawItem) | ||
} | ||
return item.Number, nil | ||
} | ||
|
||
func publishAppMacGeneratorID(ctx *zedrouterContext, appUUID uuid.UUID, macGenID int) error { | ||
now := time.Now() | ||
item := types.AppMACGenerator{ | ||
UuidToNum: types.UuidToNum{ | ||
UUID: appUUID, | ||
CreateTime: now, | ||
LastUseTime: now, | ||
InUse: true, | ||
NumType: "appMACGenerator", | ||
Number: macGenID, | ||
}, | ||
} | ||
err := ctx.pubAppMACGenerator.Publish(item.Key(), item) | ||
if err != nil { | ||
log.Errorf("failed to publish MAC generator ID for app %v: %v", | ||
appUUID, err) | ||
} | ||
return err | ||
} | ||
|
||
func unpublishAppMacGeneratorID(ctx *zedrouterContext, appUUID uuid.UUID) error { | ||
err := ctx.pubAppMACGenerator.Unpublish(appUUID.String()) | ||
if err != nil { | ||
log.Errorf("failed to un-publish MAC generator ID for app %v: %v", | ||
appUUID, err) | ||
} | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters