rewrite

package
v0.107.67 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package rewrite implements DNS Rewrites storage and request matching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.107.65

type Config struct {
	// logger is used for logging storage processes.  It must not be nil.
	Logger *slog.Logger

	// Rewrites stores the rewrite entries.  It must not be nil.
	Rewrites []*Item

	// ListID is used as an identifier of the underlying rules list.
	ListID int
}

Config is the configuration for DefaultStorage.

type DefaultStorage

type DefaultStorage struct {
	// contains filtered or unexported fields
}

DefaultStorage is the default storage for rewrite rules.

func NewDefaultStorage

func NewDefaultStorage(conf *Config) (s *DefaultStorage, err error)

NewDefaultStorage returns new rewrites storage. conf must not be nil.

func (*DefaultStorage) Add

func (s *DefaultStorage) Add(item *Item) (err error)

Add implements the Storage interface for *DefaultStorage.

func (*DefaultStorage) List

func (s *DefaultStorage) List() (items []*Item)

List implements the Storage interface for *DefaultStorage.

func (*DefaultStorage) MatchRequest

func (s *DefaultStorage) MatchRequest(dReq *urlfilter.DNSRequest) (rws []*rules.DNSRewrite)

MatchRequest implements the Storage interface for *DefaultStorage.

func (*DefaultStorage) Remove

func (s *DefaultStorage) Remove(item *Item) (err error)

Remove implements the Storage interface for *DefaultStorage.

type Item

type Item struct {
	// Domain is the domain pattern for which this rewrite should work.
	Domain string `yaml:"domain"`

	// Answer is the IP address, canonical name, or one of the special
	// values: "A" or "AAAA".
	Answer string `yaml:"answer"`
}

Item is a single DNS rewrite record.

type Storage

type Storage interface {
	// MatchRequest returns matching dnsrewrites for the specified request.
	MatchRequest(dReq *urlfilter.DNSRequest) (rws []*rules.DNSRewrite)

	// Add adds item to the storage.
	Add(item *Item) (err error)

	// Remove deletes item from the storage.
	Remove(item *Item) (err error)

	// List returns all items from the storage.
	List() (items []*Item)
}

Storage is a storage for rewrite rules.

Jump to

Keyboard shortcuts

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