systemd

package
v0.0.0-...-8c1da76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package systemd defines several utilities to interact with systemd.

ResolvedMonitor:

Index

Constants

View Source
const (
	// SuccessState is the string returned by systemd-resolved when a DNS query is successful.
	// Other states: https://github.com/systemd/systemd/blob/main/src/resolve/resolved-dns-transaction.c#L3608
	SuccessState = "success"

	// DNSTypeA A
	DNSTypeA = 1
	// DNSTypeAAAA AAAA
	DNSTypeAAAA = 28
	// DNSTypeCNAME cname
	DNSTypeCNAME = 5
	// DNSTypeSOA soa
	DNSTypeSOA = 6
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AnswerMonitorResponse

type AnswerMonitorResponse struct {
	Raw     string `json:"raw"`
	RR      RRType `json:"rr"`
	Ifindex int    `json:"ifindex"`
}

AnswerMonitorResponse represents the DNS answer of a DNS query.

type KeyType

type KeyType struct {
	Name  string `json:"name"`
	Class int    `json:"class"`
	Type  int    `json:"type"`
}

KeyType holds question that generated the answer

answer: [{
	"rr": {
		"key": {
			"class": 1,
			"type": 28,
			"name": "images.site.com"
		},
		"address": [100, 13, 45, 111]
	},
	"raw": "DFJFKE343443EFKEREKET=",
	"ifindex": 3
}]

type MonitorResponse

type MonitorResponse struct {
	State    string                    `json:"state"`
	Question []QuestionMonitorResponse `json:"question"`
	// CollectedQuestions
	// "collectedQuestions":[{"class":1,"type":1,"name":"translate.google.com"}]
	Answer    []AnswerMonitorResponse `json:"answer"`
	Continues bool                    `json:"continues"`
}

MonitorResponse represents the systemd-resolved protocol message sent over the wire, that holds the answer to a DNS query.

type QuestionMonitorResponse

type QuestionMonitorResponse struct {
	Name  string `json:"name"`
	Class int    `json:"class"`
	Type  int    `json:"type"`
}

QuestionMonitorResponse represents a DNS query

"question": [{"class": 1, "type": 28,"name": "images.site.com"}],

type RRType

type RRType struct {
	Name    string                  `json:"name"`
	Address []byte                  `json:"address"`
	Key     QuestionMonitorResponse `json:"key"`
}

RRType represents a DNS answer if the response is a CNAME, Address will be nil, and Name a domain name.

type ResolvedMonitor

type ResolvedMonitor struct {
	Ctx    context.Context
	Cancel context.CancelFunc

	// connection with the systemd-resolved unix socket:
	// /run/systemd/resolve/io.systemd.Resolve.Monitor
	Conn *varlink.Connection
	// channel where all the DNS respones will be sent
	ChanResponse chan *MonitorResponse

	// error channel to signal any problem
	ChanConnError chan error
	// contains filtered or unexported fields
}

ResolvedMonitor represents a systemd-resolved monitor

func NewResolvedMonitor

func NewResolvedMonitor() (*ResolvedMonitor, error)

NewResolvedMonitor returns a new ResolvedMonitor object. With this object you can passively read DNS answers.

func (*ResolvedMonitor) Close

func (r *ResolvedMonitor) Close()

Close closes the unix socket with systemd-resolved

func (*ResolvedMonitor) Connect

func (r *ResolvedMonitor) Connect() (*varlink.Connection, error)

Connect opens a unix socket with systemd-resolved

func (*ResolvedMonitor) Exit

func (r *ResolvedMonitor) Exit() chan error

Exit returns a channel to listen for connection errors.

func (*ResolvedMonitor) GetDNSResponses

func (r *ResolvedMonitor) GetDNSResponses() chan *MonitorResponse

GetDNSResponses returns a channel that you can use to read responses.

func (*ResolvedMonitor) Subscribe

func (r *ResolvedMonitor) Subscribe() error

Subscribe sends the instruction to systemd-resolved to start monitoring DNS answers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL