Skip to content

Golang implementation of the nmsg network message encapsulation library

License

Notifications You must be signed in to change notification settings

farsightsec/go-nmsg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

05293d5 · Oct 19, 2023

History

31 Commits
Oct 19, 2023
Sep 27, 2023
Sep 27, 2023
Sep 17, 2019
Sep 17, 2019
Feb 9, 2021
Sep 5, 2023
Sep 5, 2023
Sep 17, 2019
Feb 9, 2021
Oct 19, 2023
Oct 19, 2023
Sep 17, 2019
Sep 17, 2019
Sep 17, 2019
Sep 17, 2019
Feb 9, 2021
Jun 6, 2023
Feb 9, 2021
Sep 17, 2019
Sep 5, 2023
Feb 9, 2021
Feb 9, 2021
Feb 9, 2021
Feb 9, 2021
Sep 27, 2023
Jun 8, 2023
Sep 17, 2019
Sep 17, 2019
Sep 17, 2019
Feb 9, 2021
Oct 19, 2023
Oct 19, 2023

Repository files navigation

Pure Golang NMSG Library

go-nmsg is a pure go implementation of the NMSG container and payload format used by the C nmsg toolkit and library.

Synopsis

import "github.com/farsightsec/go-nmsg"
import "github.com/farsightsec/go-nmsg/nmsg_base"

var r io.Reader
var w io.Writer
...
input := nmsg.NewInput(r, mtu)
output := nmsg.BufferedOutput(w)
output.SetMaxSize(nmsg.MaxContainerSize, 0)

for {
	payload, err := input.Recv()
	if err != nil {
		if nmsg.IsDataError(err) {
			continue
		}
		break
	}
	message := payload.Message()

	switch message.(type) {
	case *nmsg_base.Dnstap:
		// process dnstap
		// write copy to output
		output.Send(payload)
	}
}

output.Close()

Requirements

go-nmsg requires the following open source libraries:

"google.golang.org/protobuf/proto"
"github.com/dnstap/golang-dnstap"

Limitations

go-nmsg can pack and unpack the protobuf structure of an NMSG payload, and the protobuf structure of the data contained in the payload. It does not implement the full functionality of the C libnmsg message modules, such as:

  • Advanced field types (e.g., a protobuf []byte as an IP address)
  • Generated fields
  • Formatting of fields for presentation and JSON output

Applications needing such functionality in go should use the cgo-nmsg package included in this distribution under:

"github.com/farsightsec/go-nmsg/cgo-nmsg"