lpm

package
v0.1.1-r1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package lpm wraps RTE LPM library.

Please refer to DPDK Programmer's Guide for reference and caveats.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindExisting

func FindExisting(name string, ptr interface{}) error

FindExisting finds an existing LPM object and return a pointer to it.

Specify pointer to *LPM or *LPM6 in ptr to find respective object by its memzone name.

Example
package main

import (
	"github.com/rksawyer/go-dpdk/lpm"
)

func main() {
	// find LPM for IPv4 lookups.
	var myLPM *lpm.LPM
	if err := lpm.FindExisting("my_lpm_object", &myLPM); err != nil {
		panic(err)
	}

	// find LPM6 for IPv6 lookups.
	var myLPM6 *lpm.LPM6
	if err := lpm.FindExisting("my_lpm6_object", &myLPM6); err != nil {
		panic(err)
	}
}

Types

type Config

type Config struct {
	MaxRules    uint32
	NumberTbl8s uint32
	Flags       int
}

Config is used to configure LPM object while creation.

type Config6

type Config6 struct {
	MaxRules    uint32
	NumberTbl8s uint32
	Flags       int
}

Config6 is used to configure LPM6 object while creation.

type LPM

type LPM C.struct_rte_lpm

LPM is an RTE Longest Prefix Match lookup object.

func Create

func Create(name string, socket int, cfg *Config) (*LPM, error)

Create an LPM object.

Specify name as an LPM object name, socket_id as a NUMA socket ID for LPM table memory allocation and config as a structure containing the configuration.

Returns handle to LPM object on success, and errno value:

E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
E_RTE_SECONDARY - function was called from a secondary process instance
EINVAL - invalid parameter passed to function
ENOSPC - the maximum number of memzones has already been allocated
EEXIST - a memzone with the same name already exists
ENOMEM - no appropriate memory area found in which to create memzone

func (*LPM) Add

func (r *LPM) Add(ipnet netip.Prefix, nextHop uint32) error

Add a rule to LPM object. Panics if ipnet is not IPv4 subnet.

ip/prefix is an IP address/subnet to add, nextHop is a value associated with added IP subnet.

func (*LPM) Delete

func (r *LPM) Delete(ipnet netip.Prefix) error

Delete a rule from LPM object. Panics if ipnet is not IPv4 subnet.

func (*LPM) DeleteAll

func (r *LPM) DeleteAll()

DeleteAll removes all rules from LPM object.

func (*LPM) Free

func (r *LPM) Free()

Free an LPM object.

func (*LPM) IsRulePresent

func (r *LPM) IsRulePresent(ipnet netip.Prefix, nextHop *uint32) (bool, error)

IsRulePresent checks if a rule present in the LPM and returns nextHop if it is. Panics if ipnet is not IPv4 subnet.

func (*LPM) Lookup

func (r *LPM) Lookup(ip netip.Addr) (uint32, error)

Lookup an IP in LPM object. Panics if ip is not IPv4 subnet.

type LPM6

type LPM6 C.struct_rte_lpm6

LPM6 is an RTE Longest Prefix Match lookup object.

func Create6

func Create6(name string, socket int, cfg *Config6) (*LPM6, error)

Create6 an LPM6 object.

Specify name as an LPM6 object name, socket_id as a NUMA socket ID for LPM6 table memory allocation and config as a structure containing the configuration.

Returns handle to LPM6 object on success, and errno value:

E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
E_RTE_SECONDARY - function was called from a secondary process instance
EINVAL - invalid parameter passed to function
ENOSPC - the maximum number of memzones has already been allocated
EEXIST - a memzone with the same name already exists
ENOMEM - no appropriate memory area found in which to create memzone

func (*LPM6) Add

func (r *LPM6) Add(ipnet netip.Prefix, nextHop uint32) error

Add a rule to LPM6 object.

ip/prefix is an IP address/subnet to add, nextHop is a value associated with added IP subnet. Panics if ip is not IPv6.

func (*LPM6) Delete

func (r *LPM6) Delete(ipnet netip.Prefix) error

Delete a rule from LPM6 object. Panics if ip is not IPv6.

func (*LPM6) DeleteAll

func (r *LPM6) DeleteAll()

DeleteAll removes all rules from LPM6 object.

func (*LPM6) Free

func (r *LPM6) Free()

Free an LPM6 object.

func (*LPM6) IsRulePresent

func (r *LPM6) IsRulePresent(ipnet netip.Prefix, nextHop *uint32) (bool, error)

IsRulePresent checks if a rule present in the LPM6 and returns nextHop if it is. Panics if ip is not IPv6.

func (*LPM6) Lookup

func (r *LPM6) Lookup(ip netip.Addr) (uint32, error)

Lookup an IP in LPM6 object. Panics if ip is not IPv6.

Jump to

Keyboard shortcuts

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