Generated Go code for working with Manufacturer Usage Descriptions (MUDs).
This repository contains a package with generated Go code for working with Manufacturer Usage Descriptions (MUDs, RFC 8520). The code is generated by openconfig/ygot which uses openconfig/goyang for parsing and compiling YANG files. The (required) YANG files were sourced from yangmodels/yang.
Import the generated code as a library:
go get github.com/hslatman/go-mudyangAnd use it:
package main
import (
"fmt"
"io/ioutil"
"github.com/hslatman/go-mudyang"
)
func main() {
json, _ := ioutil.ReadFile("./examples/lightbulb2000.json")
mud := &mudyang.Mudfile{}
if err := mudyang.Unmarshal([]byte(json), mud); err != nil {
panic(fmt.Errorf("failed to unmarshal JSON: %w", err))
}
println(*mud.Mud.MudUrl)
println(*mud.Mud.MudVersion)
println(mud.Mud.MudSignature)
for k, v := range loadd.Acls.Acl {
println(k, v)
}
}The mud CLI application is available at https://github.com/hslatman/mud-cli.
Several example MUD files are provided in this repository
- lightbulb2000.json. The example from RFC 8520.
- amazonEchoMud.json. Source: https://iotanalytics.unsw.edu.au/mudprofiles (with modifications)
- wemoswitchMud.json. Source: https://iotanalytics.unsw.edu.au/mudprofiles (with modifications)
- invalidAmazonEchoMud.json. Source: https://iotanalytics.unsw.edu.au/mudprofiles (without modifications)
There are also examples for the transparency, ol and tls extensions.
The MUD files for Amazon Echo and the WeMo Switch have been manually updated to conform to the current version of the RFC and/or make them valid MUD files according to the code generated by openconfig/ygot. These changes included changing the following fields:
- ietf-access-control-list:access-lists -> ietf-access-control-list:acls
- ethernet-acl-type -> eth-acl-type
- ethertypes hex string values to integers
The openconfig/ygot/generator is used as a go tool to generate the Go code.
It can be used as follows:
# run the generate Mage target
$ mage generateThere's a small caveat to running this command, though:
When an invalid mudyang.go file is generated, Go will complain about this in the next run.
This can be fixed by resetting the changes and making sure that all input files are OK.
- Add yangmodels/yang as a git submodule, or a different solution for obtaining new versions of YANG definitions.
- Add (more) tests?
- Add utility functions in a wrapper of
mudyang? - Look into path structs functionality of ygot generator