Skip to content

hslatman/go-mudyang

Repository files navigation

go-mudyang

Generated Go code for working with Manufacturer Usage Descriptions (MUDs).

Description

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.

Usage

Library

Import the generated code as a library:

go get github.com/hslatman/go-mudyang

And 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)
	}
}

CLI

The mud CLI application is available at https://github.com/hslatman/mud-cli.

Examples

Several example MUD files are provided in this repository

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

Development

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 generate

There'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.

TODOs

  • 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

About

Generated Go code for working with Manufacturer Usage Descriptions (MUDs).

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages