offloader

package
v0.0.0-...-1e0ddcb Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// we have default class IN with uint16 "1"
	DefaultClassIN = 1

	// a length of key for dns name used to
	// validate fqdn in import code
	DefaultQnameMaxLength = 48
)
View Source
const (
	JericoMetricsPacketRX    = 0
	JericoMetricsPacketTX    = 1
	JericoMetricsPacketPass  = 2
	JericoMetricsPacketError = 3

	JericoMetricsMax = 63
)
View Source
const (
	ActionRemove = 0
	ActionCreate = 1
)
View Source
const (
	// metric counter for example plugin
	MetricNameCounter = "counter"

	// monitor class for check
	MonitorClass = "offloader"
)
View Source
const (
	// plugin name is used by controller to link
	// code and configuration
	NamePlugin = "offloader"

	// some predefined values, in seconds
	DefaultWatcherInterval = 20
)
View Source
const (
	// default interface to bind if no options
	// provided
	DefaultInterface = "lo"

	// default bpf object file
	DefaultPath = "/usr/lib/yadns-xdp.bpf.o"

	// default pin path, for now we have to check
	// if it exists - use it, if not, create a path
	DefaultOffloaderPinPath = "/sys/fs/bpf/xdp/globals"

	// Response case flags: AA, RD, MBZ
	FlagAA  = "AA"
	FlagRD  = "RD"
	FlagMBZ = "MBZ"

	// prefix used for bpf program flag name
	PrefixFlag = "yadns_xdp_resp_flag_"

	// a list of constants to set
	BpfConstantRespRandomTTL = "yadns_xdp_resp_random_ttl"

	BpfConstantMetricsEnabled = "yadns_xdp_bpf_metrics_enabled"
	BpfConstantXdpcapEnabled  = "yadns_xdp_bpf_xdpcap_enabled"
	BpfConstantBpfDyrun       = "yadns_xdp_bpf_dryrun"

	// a list of loader mode, could be
	// primary or secondary, via "auto"
	LoaderModePrimary = 100

	// secondary mode also could be set
	// via "auto"
	LoaderModeSecondary = 101

	// default pin path for exported hook
	// from primary
	DefaultHookPinPath = "/sys/fs/bpf/xdp/bpftail-call/xdpcap_hook"

	// default list of xdp actions to set
	DefaultAction = xdpPass

	// default binary IP
	DefaultIPBinary = "/usr/sbin/ip"

	// a list of mode loader
	LoaderConfigModePrimary = "primary"

	LoaderConfigModeSecondary = "secondary"

	LoaderConfigModeAuto = "auto"

	//default value for dst address as value
	DefaultDstValue = 0
)
View Source
const (
	JericoRuntimeConfigDryrun = 0
)

Variables

This section is empty.

Functions

func ActionAsString

func ActionAsString(action int) string

func LoaderModeAsString

func LoaderModeAsString(mode int) string

func StringAsXdpAction

func StringAsXdpAction(action string) xdpAction

func XdpActionAsString

func XdpActionAsString(action xdpAction) string

Types

type BpfMetrics

type BpfMetrics interface {
	MapName() string
	LoadPinnedMap() error
	Close() error

	Entries() ([64]uint64, error)
	ZeroAll() error
}

type ControlBpfReq

type ControlBpfReq struct {
	Dryrun    bool     `json:"dryrun"`
	Option    string   `json:"option"`
	Value     bool     `json:"value"`
	ValueList []string `json:"values,omitempty"`
}

func (*ControlBpfReq) AsJSON

func (c *ControlBpfReq) AsJSON() []byte

func (*ControlBpfReq) AsString

func (c *ControlBpfReq) AsString() string

type IPNet

type IPNet struct {
	IP   netip.Addr
	Mask uint32
	Bits int
}

func NewIPNetFromIP4

func NewIPNetFromIP4(addr TDnsDaddr4) IPNet

func NewIPNetFromIP6

func NewIPNetFromIP6(addr TDnsDaddr6) IPNet

func (*IPNet) AsDNSDaddr4

func (m *IPNet) AsDNSDaddr4() TDnsDaddr4

func (*IPNet) AsDNSDaddr6

func (m *IPNet) AsDNSDaddr6() TDnsDaddr6

func (*IPNet) AsString

func (m *IPNet) AsString() string

func (*IPNet) UnmarshalText

func (m *IPNet) UnmarshalText(text []byte) error

type JericoRuntimeConfig

type JericoRuntimeConfig struct {
	Mp *ebpf.Map `ebpf:"yadns_xdp_runtime_config"`

	PinPath string
}

func (*JericoRuntimeConfig) Close

func (m *JericoRuntimeConfig) Close() error

func (*JericoRuntimeConfig) Entries

func (m *JericoRuntimeConfig) Entries() ([]uint32, error)

func (*JericoRuntimeConfig) LoadPinnedMap

func (m *JericoRuntimeConfig) LoadPinnedMap() error

func (*JericoRuntimeConfig) MapName

func (m *JericoRuntimeConfig) MapName() string

func (*JericoRuntimeConfig) Update

func (m *JericoRuntimeConfig) Update(key uint32, value uint32) error

type PassMap

type PassMap interface {
	MapName() string
	LoadPinnedMap() error
	Entries() (map[string]TAddr, error)
	Close() error

	Update(prefix TAddr) error
	// Create(prefix IPNet) error
	Remove(prefix TAddr) error
}

type PassMap4

type PassMap4 struct {
	Mp *ebpf.Map `ebpf:"daddr4_pass"`

	PinPath string
}

func (*PassMap4) Close

func (m *PassMap4) Close() error

func (*PassMap4) Entries

func (m *PassMap4) Entries() (map[string]TAddr, error)

func (*PassMap4) LoadPinnedMap

func (m *PassMap4) LoadPinnedMap() error

func (*PassMap4) MapName

func (m *PassMap4) MapName() string

func (*PassMap4) Remove

func (m *PassMap4) Remove(prefix TAddr) error

func (*PassMap4) Update

func (m *PassMap4) Update(prefix TAddr) error

type PassMap6

type PassMap6 struct {
	Mp *ebpf.Map `ebpf:"daddr6_pass"`

	PinPath string
}

func (*PassMap6) Close

func (m *PassMap6) Close() error

func (*PassMap6) Entries

func (m *PassMap6) Entries() (map[string]TAddr, error)

func (*PassMap6) LoadPinnedMap

func (m *PassMap6) LoadPinnedMap() error

func (*PassMap6) MapName

func (m *PassMap6) MapName() string

func (*PassMap6) Remove

func (m *PassMap6) Remove(prefix TAddr) error

func (*PassMap6) Update

func (m *PassMap6) Update(prefix TAddr) error

type PerfHistorgram

type PerfHistorgram struct {
	Mp *ebpf.Map `ebpf:"yadns_xdp_perf"`

	PinPath string
}

func (*PerfHistorgram) Close

func (m *PerfHistorgram) Close() error

func (*PerfHistorgram) Entries

func (m *PerfHistorgram) Entries() ([64]uint64, error)

func (*PerfHistorgram) Keys

func (m *PerfHistorgram) Keys() ([64]uint32, error)

func (*PerfHistorgram) LoadPinnedMap

func (m *PerfHistorgram) LoadPinnedMap() error

func (*PerfHistorgram) MapName

func (m *PerfHistorgram) MapName() string

func (*PerfHistorgram) Update

func (m *PerfHistorgram) Update(key uint32, value uint64) error

func (*PerfHistorgram) Zero

func (m *PerfHistorgram) Zero(key uint32) error

func (*PerfHistorgram) ZeroAll

func (m *PerfHistorgram) ZeroAll() error

type PerfMetrics

type PerfMetrics struct {
	Mp *ebpf.Map `ebpf:"yadns_xdp_metrics"`

	PinPath string
}

func (*PerfMetrics) Close

func (m *PerfMetrics) Close() error

func (*PerfMetrics) Entries

func (m *PerfMetrics) Entries() ([64]uint64, error)

func (*PerfMetrics) Keys

func (m *PerfMetrics) Keys() ([64]uint32, error)

func (*PerfMetrics) LoadPinnedMap

func (m *PerfMetrics) LoadPinnedMap() error

func (*PerfMetrics) MapName

func (m *PerfMetrics) MapName() string

func (*PerfMetrics) Update

func (m *PerfMetrics) Update(key uint32, value uint64) error

func (*PerfMetrics) Zero

func (m *PerfMetrics) Zero(key uint32) error

func (*PerfMetrics) ZeroAll

func (m *PerfMetrics) ZeroAll() error

type RREntry

type RREntry interface {
	// functions hidden
	AsRawString() string

	QnameAsBytes() []byte

	Qname() RRQname
	Qtype() uint16

	Qdata() string

	QTTL() uint32

	IP() netip.Addr
}

type RREntryA

type RREntryA struct {
	RRKey
	RRValueA
}

func (RREntryA) AsRawString

func (m RREntryA) AsRawString() string

func (RREntryA) IP

func (m RREntryA) IP() netip.Addr

func (RREntryA) QTTL

func (m RREntryA) QTTL() uint32

func (RREntryA) Qdata

func (m RREntryA) Qdata() string

func (RREntryA) Qname

func (m RREntryA) Qname() RRQname

func (RREntryA) QnameAsBytes

func (m RREntryA) QnameAsBytes() []byte

func (RREntryA) Qtype

func (m RREntryA) Qtype() uint16

type RREntryAAAA

type RREntryAAAA struct {
	RRKey
	RRValueAAAA
}

func (RREntryAAAA) AsRawString

func (m RREntryAAAA) AsRawString() string

func (RREntryAAAA) IP

func (m RREntryAAAA) IP() netip.Addr

func (RREntryAAAA) QTTL

func (m RREntryAAAA) QTTL() uint32

func (RREntryAAAA) Qdata

func (m RREntryAAAA) Qdata() string

func (RREntryAAAA) Qname

func (m RREntryAAAA) Qname() RRQname

func (RREntryAAAA) QnameAsBytes

func (m RREntryAAAA) QnameAsBytes() []byte

func (RREntryAAAA) Qtype

func (m RREntryAAAA) Qtype() uint16

type RRKey

type RRKey struct {
	// question type and class
	Qtype  uint16 `json:"qtype"`
	Qclass uint16 `json:"qclass"`

	// a qname to match, see qname definition
	// #define MAX_DNS_NAME_LENGTH 256
	Qname RRQname `json:"qname"`
}

func (*RRKey) AsRawString

func (t *RRKey) AsRawString() string

type RRMap

type RRMap interface {
	MapName() string
	LoadPinnedMap() error
	Close() error

	Remove(qname RRQname, qtype uint16) error
	Create(qname RRQname, qtype uint16, ttl uint32, ip netip.Addr) error
	Update(qname RRQname, qtype uint16, ttl uint32, ip netip.Addr) error

	Lookup(qname RRQname, qtype uint16) (RREntry, error)

	Entries() ([]RREntry, error)
}

type RRMapA

type RRMapA struct {
	Mp *ebpf.Map `ebpf:"yadns_xdp_rr_a"`

	PinPath string
}

func (*RRMapA) Close

func (m *RRMapA) Close() error

func (*RRMapA) Create

func (m *RRMapA) Create(qname RRQname, qtype uint16, ttl uint32, ip netip.Addr) error

func (*RRMapA) Entries

func (m *RRMapA) Entries() ([]RREntry, error)

func (*RRMapA) LoadPinnedMap

func (m *RRMapA) LoadPinnedMap() error

func (*RRMapA) Lookup

func (m *RRMapA) Lookup(qname RRQname, qtype uint16) (RREntry, error)

func (*RRMapA) MapName

func (m *RRMapA) MapName() string

func (*RRMapA) Remove

func (m *RRMapA) Remove(qname RRQname, qtype uint16) error

func (*RRMapA) Update

func (m *RRMapA) Update(qname RRQname, qtype uint16, ttl uint32, ip netip.Addr) error

type RRMapAAAA

type RRMapAAAA struct {
	Mp *ebpf.Map `ebpf:"yadns_xdp_rr_aaaa"`

	PinPath string
}

func (*RRMapAAAA) Close

func (m *RRMapAAAA) Close() error

func (*RRMapAAAA) Create

func (m *RRMapAAAA) Create(qname RRQname, qtype uint16, ttl uint32, ip netip.Addr) error

func (*RRMapAAAA) Entries

func (m *RRMapAAAA) Entries() ([]RREntry, error)

func (*RRMapAAAA) LoadPinnedMap

func (m *RRMapAAAA) LoadPinnedMap() error

func (*RRMapAAAA) Lookup

func (m *RRMapAAAA) Lookup(qname RRQname, qtype uint16) (RREntry, error)

func (*RRMapAAAA) MapName

func (m *RRMapAAAA) MapName() string

func (*RRMapAAAA) Remove

func (m *RRMapAAAA) Remove(qname RRQname, qtype uint16) error

func (*RRMapAAAA) Update

func (m *RRMapAAAA) Update(qname RRQname, qtype uint16, ttl uint32, ip netip.Addr) error

type RRQname

type RRQname [48]byte

a length of array should be in sync with map in BPF program. I order to limit program variability is could be 256, 128, 96. 64, 48, 32

func (*RRQname) AsByteString

func (t *RRQname) AsByteString() string

func (*RRQname) AsString

func (t *RRQname) AsString() string

func (*RRQname) MaxLength

func (t *RRQname) MaxLength() byte

type RRValue

type RRValue interface {
	AsRawString() string
}

type RRValueA

type RRValueA struct {
	// unsigned long s_addr, use As4() for
	// ip4 address to fill
	Addr [4]byte `json:"addr"`

	// TTL for answer
	TTL uint32 `json:"ttl"`
}

We have here ipv4 32bit value

func (*RRValueA) AsRawString

func (t *RRValueA) AsRawString() string

type RRValueAAAA

type RRValueAAAA struct {
	// use As16() for conversion
	Addr [16]byte `json:"addr"`

	// TTL for answer
	TTL uint32 `json:"ttl"`
}

func (*RRValueAAAA) AsRawString

func (t *RRValueAAAA) AsRawString() string

type RuntimeConfigOptions

type RuntimeConfigOptions struct {
	BpfConstantBpfDyrun bool
}

type Switches

type Switches struct {
	// should it be global switch or local
	Dryrun bool
}

command line switches

type TAddr

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

func NewAddr

func NewAddr(network IPNet, value uint8) TAddr

func (*TAddr) Network

func (t *TAddr) Network() *IPNet

func (*TAddr) Value

func (t *TAddr) Value() uint8

type TConfigControls

type TConfigControls struct {
	// if controller should check and mount bppfs
	Bpffs bool `json:"bpffs" yaml:"bpffs"`

	// if we should set memlock to unlimit
	UnlimitMemlock bool `json:"unlimit-memlock" yaml:"unlimit-memlock"`
}

type TConfigLoader

type TConfigLoader struct {

	// mode could be "primary" "secondary", auto"
	Mode string `json:"mode" yaml:"mode"`

	// hook options for "secondary" mode
	Hook THookLoader `json:"hook" yaml:"hook"`
}

type TConfigNetdev

type TConfigNetdev struct {
	Address   string            `json:"address"`
	Broadcast string            `json:"broadcast"`
	Flags     []string          `json:"flags"`
	Group     string            `json:"group"`
	Ifindex   int               `json:"ifindex"`
	Ifname    string            `json:"ifname"`
	Mtu       int               `json:"mtu"`
	Operstate string            `json:"operstate"`
	Xdp       *TConfigNetdevXdp `json:"xdp"`
}

type TConfigNetdevProg

type TConfigNetdevProg struct {
	ID    int    `json:"id"`
	Jited int    `json:"jited"`
	Tag   string `json:"tag"`
}

type TConfigNetdevXdp

type TConfigNetdevXdp struct {
	Mode int               `json:"mode"`
	Prog TConfigNetdevProg `json:"prog"`

	Attached []TConfigNetdevXdp `json:"attached"`
}

type TConfigOptions

type TConfigOptions struct {
	// interface
	Interface string `json:"interface" yaml:"interface"`

	// requests DSTS for IP6 and IP4 dst addresses
	// to match VS processing
	Addrs []string `json:"addrs" yaml:"addrs"`

	// I hope that we will need only one bpf program
	// to handle traffic
	Path string `json:"path" yaml:"path"`

	// pinpath
	PinPath string `json:"pinpath" yaml:"pinpath"`

	// bpf option dryrun
	BpfDryrun bool `json:"bpf-dryrun" yaml:"bpf-dryrun"`

	// bpf option to enable xdpcap hook call
	BpfXdpcap bool `json:"bpf-xdpcap" yaml:"bpf-xdpcap"`

	// enable of disable bpf perf
	BpfMetrics bool `json:"bpf-metrics" yaml:"bpf-metrics"`

	// if xdp should generate random TTL (it could be
	// used in ns-cache responses)
	ResponseRandomTTL bool `json:"response-random-ttl" yaml:"response-random-ttl"`

	// response flags, AA, RD, RA, MBZ
	ResponseFlags []string `json:"response-flags" yaml:"response-flags"`
}

func (*TConfigOptions) String

func (t *TConfigOptions) String() string

type TDnsDaddr4

type TDnsDaddr4 struct {
	// prefix of the network
	PrefixLen uint32

	// in V6 version we have 16 bytes slice
	Addr [4]byte
}

type TDnsDaddr6

type TDnsDaddr6 struct {
	// prefix of the network
	PrefixLen uint32

	// in V6 version we have 16 bytes slice
	Addr [16]byte
}

type THookLoader

type THookLoader struct {

	// hook pinpath
	PinPath string `json:"pinpath" yaml:"pinpath"`

	// index pinpath
	Index []int `json:"index" yaml:"index"`
}

type TOffloaderPlugin

type TOffloaderPlugin struct {

	// some common attributes for all plugins, global
	// configuration ref, name and type
	plugins.Plugin
	// contains filtered or unexported fields
}

func NewPlugin

func NewPlugin(options *plugins.PluginOptions) (*TOffloaderPlugin, error)

func (*TOffloaderPlugin) GetXdpService

func (t *TOffloaderPlugin) GetXdpService() *TXdpService

func (*TOffloaderPlugin) L

func (*TOffloaderPlugin) Monitor

func (t *TOffloaderPlugin) Monitor(m *monitor.TMonitorPlugin)

func (*TOffloaderPlugin) MountBpffs

func (t *TOffloaderPlugin) MountBpffs() error

func (*TOffloaderPlugin) Run

func (t *TOffloaderPlugin) Run(ctx context.Context, overrides *plugins.OverrideOptions) error

func (*TOffloaderPlugin) SetBpfOptions

func (t *TOffloaderPlugin) SetBpfOptions(ctx echo.Context) error

func (*TOffloaderPlugin) SetClientBpfOptions

func (t *TOffloaderPlugin) SetClientBpfOptions(options *ControlBpfReq) error

func (*TOffloaderPlugin) SetupMethods

func (t *TOffloaderPlugin) SetupMethods(group *echo.Group)

func (*TOffloaderPlugin) Stop

func (t *TOffloaderPlugin) Stop() error

func (*TOffloaderPlugin) TickServer

func (t *TOffloaderPlugin) TickServer(ctx context.Context) error

type TOffloaderPluginConfig

type TOffloaderPluginConfig struct {
	// could be disabled
	Enabled bool `json:"enabled" yaml:"enabled"`

	// bpf controls for some cases
	Controls TConfigControls `json:"controls" yaml:"controls"`

	// bpf xdp options
	Options TConfigOptions `json:"options" yaml:"options"`

	// XDP loader options, by default we have primary mode
	Loader TConfigLoader `json:"loader" yaml:"loader"`
}

type TPerfValue

type TPerfValue struct {
	// a counter number in a cell of
	// historgram (counts of time)
	Counter uint64
}

type TXdpCiliumBinary

type TXdpCiliumBinary struct {

	// used in load and assign bpf call
	// also could be set with maps
	Program *ebpf.Program `ebpf:"xdp_dns"`

	// a list of ebpf maps for each type RR
	MapA RRMapA

	MapAAAA RRMapAAAA

	// a list of maps with dst addr
	MapPass4 PassMap4
	MapPass6 PassMap6
}

type TXdpService

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

func NewXdpService

func NewXdpService(p *TOffloaderPlugin) (*TXdpService, error)

func (*TXdpService) ApplyActions

func (t *TXdpService) ApplyActions(name string, passmap PassMap,
	actions map[int][]TAddr) error

func (*TXdpService) AttachHook

func (t *TXdpService) AttachHook(hookMap *ebpf.Map, fd int, index int) error

taken for xdpcap no good way to check if a program is already attached, as Create() doesn't work on prog array maps We could check if values are present for keys, but that's not atomic with writing a value anyways

func (*TXdpService) DetectLoaderMode

func (t *TXdpService) DetectLoaderMode(netdev string) (int, error)

func (*TXdpService) GetConfiguredActions

func (t *TXdpService) GetConfiguredActions(src map[string]TAddr,
	dst map[string]TAddr) map[int][]TAddr

T.B.D. adding value compare

func (*TXdpService) GetConfiguredIP

func (t *TXdpService) GetConfiguredIP(name string) (map[string]TAddr, error)

func (*TXdpService) GetPassMaps

func (t *TXdpService) GetPassMaps(tag string, names []string) (map[string]map[string]TAddr, map[string]PassMap, error)

func (*TXdpService) GetRuntimeConfigMap

func (t *TXdpService) GetRuntimeConfigMap() ([]uint32, error)

func (*TXdpService) Run

func (t *TXdpService) Run(ctx context.Context) error

func (*TXdpService) SecondaryAttachHook

func (t *TXdpService) SecondaryAttachHook(fd int) error

func (*TXdpService) SetDryrun

func (t *TXdpService) SetDryrun(dryrun bool) error

func (*TXdpService) Stop

func (t *TXdpService) Stop() error

func (*TXdpService) SyncPassMap

func (t *TXdpService) SyncPassMap(tag string, names []string, srcs map[string]map[string]TAddr) error

func (*TXdpService) SyncRuntimeConfigMap

func (t *TXdpService) SyncRuntimeConfigMap(options *RuntimeConfigOptions) error

type TXdpServiceFlags

type TXdpServiceFlags struct {
	// some xdp attach flags
	Flags link.XDPAttachFlags
}

Jump to

Keyboard shortcuts

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