ripebulk

package
v0.0.0-...-6169d9b Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultBaseURL is the RIPE FTP base URL for split dumps
	DefaultBaseURL = "https://ftp.ripe.net/ripe/dbase/split"

	// Dump file names
	InetnumFile      = "ripe.db.inetnum.gz"
	OrganisationFile = "ripe.db.organisation.gz"
)

Variables

This section is empty.

Functions

func AddrToUint32

func AddrToUint32(addr netip.Addr) uint32

AddrToUint32 converts netip.Addr to uint32 (big-endian)

func OpenGzipFile

func OpenGzipFile(path string) (io.ReadCloser, error)

OpenGzipFile opens a gzipped file and returns a reader

func ParseOrganisations

func ParseOrganisations(r io.Reader) (map[string]Organisation, error)

ParseOrganisations parses RIPE organisation objects from a reader

func PrefixToRange

func PrefixToRange(prefix netip.Prefix) (start, end uint32, err error)

PrefixToRange converts a CIDR prefix to inclusive [start, end] uint32 range

func Uint32ToAddr

func Uint32ToAddr(ip uint32) netip.Addr

Uint32ToAddr converts a uint32 to netip.Addr (big-endian)

Types

type Database

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

Database manages the RIPE bulk data index

func BuildDatabase

func BuildDatabase(path string, inetnums []Inetnum, orgs map[string]Organisation) (*Database, error)

BuildDatabase creates a new RIPE bulk database from parsed data

func OpenDatabase

func OpenDatabase(path string) (*Database, error)

OpenDatabase opens an existing RIPE bulk database with default cache size

func OpenDatabaseWithCache

func OpenDatabaseWithCache(path string, cacheSize int) (*Database, error)

OpenDatabaseWithCache opens with custom cache size (in bytes)

func (*Database) Close

func (d *Database) Close() error

Close closes the database

func (*Database) GetMetadata

func (d *Database) GetMetadata() (*Metadata, error)

GetMetadata retrieves database metadata

func (*Database) GetOrganisation

func (d *Database) GetOrganisation(orgID string) (*Organisation, error)

GetOrganisation retrieves an organisation by ID

func (*Database) IterateRanges

func (d *Database) IterateRanges(fn func(Inetnum) error) error

IterateRanges iterates over all inetnum ranges

func (*Database) LookupIP

func (d *Database) LookupIP(ip netip.Addr) (*Match, error)

LookupIP finds the most specific inetnum that contains an IP address

func (*Database) LookupPrefix

func (d *Database) LookupPrefix(prefix netip.Prefix) (*Match, error)

LookupPrefix finds the most specific inetnum that fully covers a prefix

func (*Database) NewIterator

func (d *Database) NewIterator() iterator.Iterator

NewIterator creates a new range iterator for advanced use cases

type Error

type Error string

Error types for RIPE bulk operations

const (
	ErrNotFound       Error = "no matching inetnum found"
	ErrInvalidIP      Error = "invalid IP address"
	ErrInvalidRange   Error = "invalid IP range"
	ErrParseError     Error = "RPSL parse error"
	ErrDatabaseClosed Error = "database is closed"
	ErrFetchFailed    Error = "failed to fetch RIPE dump"
)

func (Error) Error

func (e Error) Error() string

type FetchResult

type FetchResult struct {
	FilePath     string    // Local path to the downloaded file
	LastModified time.Time // Last-Modified header from server
	Size         int64     // File size in bytes
	Cached       bool      // True if file was already cached (not downloaded)
}

FetchResult contains the result of a fetch operation

type Fetcher

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

Fetcher handles downloading RIPE split dumps

func NewFetcher

func NewFetcher(baseURL, cacheDir string) *Fetcher

NewFetcher creates a new RIPE dump fetcher

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, filename string) (*FetchResult, error)

Fetch downloads a RIPE dump file with conditional request support

func (*Fetcher) FetchAll

func (f *Fetcher) FetchAll(ctx context.Context) (inetnumPath, orgPath string, err error)

FetchAll downloads both inetnum and organisation dumps

type Inetnum

type Inetnum struct {
	Start   uint32   // Start IP (big-endian uint32)
	End     uint32   // End IP (big-endian uint32, inclusive)
	OrgID   string   // Organisation ID (e.g., "ORG-EA123-RIPE")
	Status  string   // Status (e.g., ASSIGNED-PA, SUB-ALLOCATED-PA, ALLOCATED-PA, LEGACY)
	Country string   // Country code (2-letter ISO, may be empty)
	Netname string   // Network name
	Descr   string   // Description (often contains organization name)
	Remarks []string // Remarks (for extracting organization info when OrgID is missing)
}

Inetnum represents an IPv4 range from RIPE inetnum object

func ParseInetnums

func ParseInetnums(r io.Reader) ([]Inetnum, error)

ParseInetnums parses RIPE inetnum objects from a reader

type Match

type Match struct {
	Start        netip.Addr   // Start IP of the matching inetnum
	End          netip.Addr   // End IP of the matching inetnum
	Prefix       netip.Prefix // Original query prefix
	OrgID        string       // Organisation ID
	OrgName      string       // Organisation name (resolved from OrgID)
	OrgType      string       // Organisation type
	Status       string       // RIPE status
	Country      string       // Country code
	Netname      string       // Network name
	MatchedAt    time.Time    // When this lookup was performed
	FullyCovered bool         // True if inetnum fully covers the query prefix
}

Match represents the result of a prefix lookup

type Metadata

type Metadata struct {
	SchemaVersion      int       // Database schema version
	BuildTime          time.Time // When the database was built
	InetnumCount       int64     // Number of inetnum objects indexed
	OrgCount           int64     // Number of organisation objects indexed
	InetnumSerial      string    // RIPE serial/version of inetnum dump
	OrganisationSerial string    // RIPE serial/version of organisation dump
	SourceURL          string    // Base URL where dumps were fetched from
}

Metadata stores build information

type Organisation

type Organisation struct {
	OrgID   string // Primary key (e.g., "ORG-EA123-RIPE")
	OrgName string // Human-readable name
	OrgType string // RIR, LIR, OTHER, etc.
}

Organisation represents a RIPE organisation object

Jump to

Keyboard shortcuts

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