hooks

package
v2.0.0-alpha56 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: Apache-2.0 Imports: 44 Imported by: 0

README

Hooks Package Documentation

The hooks package contains the user-space Go code responsible for loading eBPF hooks and eBPF maps, which are used to instrument the user API. This package is utilized by the CLI commands. Additionally, it launches proxy on a defined port to capture egress calls.

Documentation

Index

Constants

View Source
const (
	// TODO : Remove hard-coded container & network name.
	KeployContainerName = "keploy-v2"
	KeployNetworkName   = "keploy-network"
)

Variables

View Source
var (
	ErrInterrupted    = errors.New("exited with interrupt")
	ErrCommandError   = errors.New("exited due to command error")
	ErrUnExpected     = errors.New("an unexpected error occurred")
	ErrDockerError    = errors.New("an error occurred while using docker client")
	ErrFailedUnitTest = errors.New("test failure occured when running keploy tests along with unit tests")
)

Define custom error variables

View Source
var Emoji = "\U0001F430" + " Keploy:"
View Source
var PerfEventReaders []*perf.Reader
View Source
var RingEventReaders []*ringbuf.Reader

Functions

func ConvertIPToUint32

func ConvertIPToUint32(ipStr string) (uint32, error)

ConvertIPToUint32 converts a string representation of an IPv4 address to a 32-bit integer.

func LogAny

func LogAny(value string) error

LogAny appends input of any type to a logs.txt file in the current directory

func NewLocalDb

func NewLocalDb(schemaMap map[string]map[string]string) (*localDb, error)

func NewLocalDbSchema

func NewLocalDbSchema(tableAndIndexMap map[string]map[string]string) *memdb.DBSchema

Types

type Hook

type Hook struct {
	platform.TestCaseDB
	// contains filtered or unexported fields
}

func NewHook

func NewHook(db platform.TestCaseDB, mainRoutineId int, logger *zap.Logger) (*Hook, error)

func (*Hook) AppendMocks

func (h *Hook) AppendMocks(m *models.Mock, ctx context.Context) error

func (*Hook) CleanProxyEntry

func (h *Hook) CleanProxyEntry(srcPort uint16)

func (*Hook) DeleteConfigMock

func (h *Hook) DeleteConfigMock(mock *models.Mock) (bool, error)

func (*Hook) DeleteTcsMock

func (h *Hook) DeleteTcsMock(mock *models.Mock) (bool, error)

func (*Hook) GetConfigMocks

func (h *Hook) GetConfigMocks() ([]*models.Mock, error)

func (*Hook) GetDestinationInfo

func (h *Hook) GetDestinationInfo(srcPort uint16) (*structs.DestInfo, error)

GetDestinationInfo retrieves destination information associated with a source port.

func (*Hook) GetProxyPort

func (h *Hook) GetProxyPort() uint32

func (*Hook) GetTcsMocks

func (h *Hook) GetTcsMocks() ([]*models.Mock, error)

func (*Hook) GetUserIP

func (h *Hook) GetUserIP() string

to access the IP address of the hook

func (*Hook) IsDockerRelatedCmd

func (h *Hook) IsDockerRelatedCmd(cmd string) (bool, string)

It checks if the cmd is related to docker or not, it also returns if its a docker compose file

func (*Hook) IsUsrAppTerminateInitiated

func (h *Hook) IsUsrAppTerminateInitiated() bool

func (*Hook) LaunchPerfBufferConsumers

func (h *Hook) LaunchPerfBufferConsumers(connectionFactory *connection.Factory)

LaunchPerfBufferConsumers launches socket events

func (*Hook) LaunchUserApplication

func (h *Hook) LaunchUserApplication(appCmd, appContainer, appNetwork string, Delay uint64, buildDelay time.Duration, isUnitTestIntegration bool) error

func (*Hook) LoadHooks

func (h *Hook) LoadHooks(appCmd, appContainer string, pid uint32, ctx context.Context, filters *models.Filters) error

LoadHooks is used to attach the eBPF hooks into the linux kernel. Hooks are attached for outgoing and incoming network requests.

proxyPorts is used for redirecting outgoing network calls to the unoccupied proxy server.

$BPF_CLANG and $BPF_CFLAGS are set by the Makefile.

func (*Hook) PrintRedirectProxyMap

func (h *Hook) PrintRedirectProxyMap()

// printing the whole map

func (*Hook) Recover

func (h *Hook) Recover(id int)

func (*Hook) ResetDeps

func (h *Hook) ResetDeps() int

func (*Hook) SendAppPid

func (h *Hook) SendAppPid(pid uint32) error

SendAppPid sends the application's process ID (PID) to the kernel. This function is used when running Keploy tests along with unit tests of the application.

func (*Hook) SendKeployPid

func (h *Hook) SendKeployPid(kPid uint32) error

func (*Hook) SendKeployServerPort

func (h *Hook) SendKeployServerPort(port uint32) error

SendKeployServerPort sends the keploy graphql server port to be filtered in the eBPF program.

func (*Hook) SendNameSpaceId

func (h *Hook) SendNameSpaceId(key uint32, inode uint64) error

This function is helpful when user application in running inside a docker container.

func (*Hook) SendPassThroughPorts

func (h *Hook) SendPassThroughPorts(filterPorts []uint) error

SendPassThroughPorts sends the destination ports of the server which should not be intercepted by keploy proxy.

func (*Hook) SendProxyInfo

func (h *Hook) SendProxyInfo(ip4, port uint32, ip6 [4]uint32) error

This function sends the IP and Port of the running proxy in the eBPF program.

func (*Hook) SetConfigMocks

func (h *Hook) SetConfigMocks(m []*models.Mock) error

func (*Hook) SetKeployModeInKernel

func (h *Hook) SetKeployModeInKernel(mode uint32)

func (*Hook) SetProxyPort

func (h *Hook) SetProxyPort(port uint32)

func (*Hook) SetTcsMocks

func (h *Hook) SetTcsMocks(m []*models.Mock) error

func (*Hook) Stop

func (h *Hook) Stop(forceStop bool)

func (*Hook) StopUserApplication

func (h *Hook) StopUserApplication()

StopUserApplication stops the user application

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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