awsrouter

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package awsrouter abstracts network resources in AWS. It create new types similar to AWS types, but with a few additions. Once the types are created and populated, they can operate without AWS access.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTgwRouteTableNotFound      = errors.New("awsrouter: transit gateway route table not found")
	ErrTgwRouteTableRouteNotFound = errors.New("awsrouter: transit gateway route table route not found")
	ErrTgwAttachmetInPath         = errors.New("awsrouter: attachmet is already in the path")
)

Functions

func ExportRouteTableRoutesCsv

func ExportRouteTableRoutesCsv(w *csv.Writer, tgwrt TgwRouteTable) error

ExportRouteTableRoutesCsv creates a CSV with all the routes in one Tgw Route Table.

func ExportTgwRoutesExcel

func ExportTgwRoutesExcel(tgws []*Tgw, folder fs.FileInfo) error

ExportTgwRoutesExcel creates a Excel with all the routes in all Tgw Route Tables. Each sheet on the Excel is a Tgw Route Table, each route is a route.

func GetNamesFromTags

func GetNamesFromTags(tags []types.Tag) (string, error)

getNamesFromTags returns the name tags if exist, if not it will signal with an error.

Types

type AttPath

type AttPath struct {
	// The list of attachments in the path, from source to destination.
	Path []*TgwAttachment

	// The source route table.
	SrcRouteTable TgwRouteTable

	// The destination route table.
	DstRouteTable TgwRouteTable

	// The Transit Gateway of this path.
	Tgw *Tgw
	// contains filtered or unexported fields
}

AttPath is a list of TgwAttachments that represent the path from a source to a destination. The first element is the source attachment, the last element is the destination attachment. There can be 2 or more attachments in the path, but 2 or 3 are common values. No two elements are the same, because that would be a loop.

func NewAttPath

func NewAttPath() *AttPath

NewAttPath builds a AttPath.

func (AttPath) String

func (attPath AttPath) String() string

String for a AttPath returns a string with the path.

func (*AttPath) Walk

func (attPath *AttPath) Walk(ctx context.Context, api ports.AWSRouter, src, dst net.IP) error

Walk will do a packet walk from the src to dst and updates the field Path. The function will walk from one attachment to the next, until it reaches the dst. There is a limit of 10 hops. If the limit is reached, the function will return an error. TODO: allow the option to increase the depth of the walk, right now is 10.

type Tgw

type Tgw struct {
	ID          string
	Name        string
	RouteTables []*TgwRouteTable
	Data        types.TransitGateway
}

Tgw is the main data-structure, holds ID, Name, a list of TgwRouteTable and other TGW info. Represents a Transit Gateway in AWS.

func GetAllTgws

func GetAllTgws(ctx context.Context, api ports.AWSRouter) ([]*Tgw, error)

GetAllTgws returns a list of all the Transit Gateways in the account for specific region

func NewTgw

func NewTgw(tgw types.TransitGateway) *Tgw

Build a Tgw from a aws TGW.

func UpdateRouting

func UpdateRouting(ctx context.Context, api ports.AWSRouter) ([]*Tgw, error)

UpdateRouting this functions is a helper that will update all routing information from AWS, returning a list of Tgw. The function will try to gather all the Route Tables and all the routes in the Route Tables. The function will return an error if it fails to gather a Transit Gateway or a Route Table, but it will continue if it fails to gather a route.

func (*Tgw) Bytes

func (t *Tgw) Bytes() []byte

Bytes returns the JSON representation of the Tgw as a slice of bytes.

func (*Tgw) GetDirectlyConnectedAttachment

func (t *Tgw) GetDirectlyConnectedAttachment(ipAddress net.IP) (TgwRouteTable, []*TgwAttachment, error)

GetDirectlyConnectedAttachment returns the route and attachment that is directly connected to the ipAddress. In the case of ECMP we can have more than one attachment per route. In the majority of the cases we will have only one attachment per route. If we have two or more attachments this function is unable will return the first attachment and the route table associated to it.

func (*Tgw) GetTgwRouteTableByID

func (t *Tgw) GetTgwRouteTableByID(id string) (*TgwRouteTable, error)

func (*Tgw) UpdateRouteTables

func (t *Tgw) UpdateRouteTables(ctx context.Context, api ports.AWSRouter) error

UpdateRouteTables updates the field TgwRouteTables on a Tgw. An error will stop the processing returning the error wrapped.

func (*Tgw) UpdateTgwRouteTablesAttachments

func (t *Tgw) UpdateTgwRouteTablesAttachments(ctx context.Context, api ports.AWSRouter) error

UpdateTgwRouteTablesAttachments updates the Attachments of a TgwRouteTable.

func (*Tgw) UpdateTgwRoutes

func (t *Tgw) UpdateTgwRoutes(ctx context.Context, api ports.AWSRouter) error

UpdateTgwRoutes updates the routes of a route table.

TODO: Add some sentinel error message to notify if a the calls to UpdateTgwRoutes fail. TODO: add testing and include race condition detection.

Each Tgw has a list of TgwRouteTables, each RouteTable gets is own goroutine.

type TgwAttachment

type TgwAttachment struct {
	// The ID of the attachment.
	ID string

	// The ID of the resource where this attachment terminates.
	ResourceID string

	// The type of the resource where this attachment terminates.
	// Common values are: vpc, vpn, direct-connect ...
	Type string

	// The name of the TGW Attachment.
	Name string
}

TgwAttachments holds the data of a Transit Gateway Attachment.

type TgwRouteTable

type TgwRouteTable struct {
	ID          string
	Name        string
	Data        types.TransitGatewayRouteTable
	Routes      []types.TransitGatewayRoute
	Attachments []*TgwAttachment
}

TgwRouteTable holds the Route Table ID, a list of routes and other RouteTable info. Represents a Route Table of a Transit Gateway in AWS.

func FilterRouteTableRoutesPerPrefix

func FilterRouteTableRoutesPerPrefix(rts []*TgwRouteTable, prefix net.IPNet) ([]TgwRouteTable, error)

FilterRouteTableRoutesPerPrefix returns only the routes in the route table that match specific prefix. Every Route Table has only one route per prefix. The return list is created out of new TgwRouteTable structs, that copy only the matching route to the new table.

func TgwRouteTableSelectionPriority

func TgwRouteTableSelectionPriority(rts []*TgwRouteTable, src net.IP) (*TgwRouteTable, error)

TgwRouteTableSelectionPriority select the best route table from a list of TgwRouteTables to the specific destination.

func (TgwRouteTable) BestRouteToIP

func (t TgwRouteTable) BestRouteToIP(ipAddress net.IP) (types.TransitGatewayRoute, error)

BestRouteToIP returns the best route to a given IP address for a given TgwRouteTable. Only one route can be the best route, and is returned. If no route is found, the function returns the empty TransitGatewayRoute.

func (*TgwRouteTable) Bytes

func (t *TgwRouteTable) Bytes() []byte

Bytes returns the JSON representation of the TgwRouteTable as a slice of bytes.

func (*TgwRouteTable) GetAttachmentName added in v0.1.5

func (t *TgwRouteTable) GetAttachmentName(attachmentID string) string

GetAttachmentName returns the name of the attachment that has the given ID.

func (*TgwRouteTable) PrintRoutesInTable

func (t *TgwRouteTable) PrintRoutesInTable()

PrintRoutesInTable creates a table to print the routes in a route table.

func (*TgwRouteTable) UpdateAttachments

func (t *TgwRouteTable) UpdateAttachments(ctx context.Context, attachments *ec2.GetTransitGatewayRouteTableAssociationsOutput) error

Update the attachments of a TgwRouteTable.

Jump to

Keyboard shortcuts

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