kowarp

package module
v0.0.0-...-b0b8b3c Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

Kowabunga

About

This is Kowarp, Kowabunga VRRP (Virtual Router Redundancy Protocol) implementation library.

Build Status GoSec Status GovulnCheck Status Coverage Status GoReport GoCode time tracker Code lines Comments COCOMO

Current Releases

Project Release Badge
Kowarp Kowabunga Release

Local testing

To test kowarp in a non-kowabunga environment and load a virtual router manually:

Replace the following (*Kowarp) loadConfig with the following code and build it (replace yours IPs and config up to your desires):

func (*Kowarp) loadTestConfig() ([]*virtualRouter, error) {
	var (
		peer_ips []net.IP
		priority uint8
		vrs      []*virtualRouter
	)
	ips := []string{"10.69.64.139", "10.69.64.140"}
	localip := getLocalIP()

	for _, ip := range ips {
		if ip != localip {
			peer_ips = append(peer_ips, net.ParseIP(ip))
		}
	}

	if localip == ips[0] {
		priority = 255
	} else {
		priority = 0
	}
	ip, err := netlink.ParseAddr("10.69.68.141/24")
	vips := []netlink.Addr{*ip}

	advitf, _ := findFirstPrivateInterface()
	vr, err := NewVirtualRouter(1, peer_ips, priority, vips, 100, advitf.Name, advitf.Name, net.ParseIP(localip), false, nil)
	if err != nil {
		return nil, err
	}
	vrs = append(vrs, vr)

	klog.Infof("Loaded VR : \n%#v", *vr)
	return vrs, nil
}

func getLocalIP() string {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return ""
	}
	for _, address := range addrs {
		// check the address type and if it is not a loopback the display it
		if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.IsPrivate() {
			if ipnet.IP.To4() != nil {
				return ipnet.IP.String()
			}
		}
	}
	return ""
}

License

Licensed under Apache License, Version 2.0, see LICENSE.

Documentation

Index

Constants

View Source
const (
	KowabungaVRRPDefaultAdvertisementInterval uint16 = 100 //in centisecond
	KowabungaVRRPDefaultRouteMetric           int    = 50
)
View Source
const (
	KowabungaVRRPVersion        uint8                 = 15
	KowabungaVRRPAuthNoAuth     KowabungaVRRPAuthType = 0x00 // No Authentication
	KowabungaVRRPAuthReserved1  KowabungaVRRPAuthType = 0x01 // Reserved field 1
	KowabungaVRRPAuthReserved2  KowabungaVRRPAuthType = 0x02 // Reserved field 2
	KowabungaVRRPTTL            uint8                 = 255
	KowabungaVRRPIPv4BaseLength uint16                = 8
	VRRPReservedProtocolId      uint16                = 112
)
View Source
const (
	BroadcastAddress              = "ff:ff:ff:ff:ff:ff"
	KowabungaVRRPMulticastAddress = "224.0.0.18"
)
View Source
const (
	ErrorKowarpNotRoot = "Kowarp is not running with root privileges"
)

Variables

View Source
var KowabungaVRRPVMacPrefix = "00-00-5E-00-01-"
View Source
var VRRPNetworkBroker vrrpNet = vrrpNet{
	// contains filtered or unexported fields
}
View Source
var VirtualRouters map[uint8]*virtualRouter

Functions

func NewVirtualRouter

func NewVirtualRouter(
	id uint8,
	peers []net.IP,
	priority uint8,
	ipAddrs []netlink.Addr,
	advertisementInterval uint16,
	advertisementInterfaceName string,
	vrrpInterfaceName string,
	preferredSourceIP net.IP,
	useVmac bool,
	virtualRoutes []VirtualRoute) (*virtualRouter, error)

func VRRPConn

func VRRPConn(src net.IP, isForMulticastTarget bool) (*net.IPConn, error)

Prepare Multicast OR Unicast

func VRRPMulticastReaderConn

func VRRPMulticastReaderConn(multicastAddress, local net.IP) (*net.IPConn, error)

Types

type EVENT

type EVENT byte
const (
	SHUTDOWN EVENT = iota
	START
	DOWN
)

type KowabungaVRRP

type KowabungaVRRP struct {
	Version      uint8             // The version field specifies the VRRP protocol version of this packet (v255 KowabungaCustom)
	Type         KowabungaVRRPType // The type field specifies the type of this VRRP packet.  The only type defined is ADVERTISEMENT
	VirtualRtrID uint8             // identifies the virtual router this packet is reporting status for
	Priority     uint8             // specifies the sending VRRP router's priority for the virtual router (100 = default)
	CountIPAddr  uint8             // The number of IP addresses contained in this VRRP advertisement.
	AdverInt     uint16            // The Advertisement interval indicates the time interval (in centiseconds) between ADVERTISEMENTS.  The default must be 100 centiseconds (1 second).
	Checksum     uint16            // used to detect data corruption in the VRRP message.
	IPAddresses  []net.IP          // one or more IP addresses associated with the virtual router. Specified in the CountIPAddr field.
	// contains filtered or unexported fields
}

KowabungaVRRP represents an VRRP v15 message. Derived from VRRP3 impl. IPV4 only 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | IPv4 Fields | ... ... | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Version| Type | Virtual Rtr ID| Priority |Count IPvX Addr| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |(rsvd) | Max Adver Int | Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | + + | IPvX Address(es) | + + + + + + + + | | + + | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

func (*KowabungaVRRP) DecodeFromBytes

func (v *KowabungaVRRP) DecodeFromBytes(data []byte) error

func (*KowabungaVRRP) Serialize

func (v *KowabungaVRRP) Serialize(source, dest *net.IP, computeChecksum bool) ([]byte, error)

computeChecksum=true to send packet computeChecksum=false when receive

func (*KowabungaVRRP) ValidateChecksum

func (v *KowabungaVRRP) ValidateChecksum(source, dest *net.IP) (bool, uint16, error)

type KowabungaVRRPAuthType

type KowabungaVRRPAuthType uint8

func (KowabungaVRRPAuthType) String

func (v KowabungaVRRPAuthType) String() string

type KowabungaVRRPType

type KowabungaVRRPType uint8
const (
	KowabungaVRRPAdvertisement KowabungaVRRPType = 0x01 // router advertisement
)

func (KowabungaVRRPType) String

func (v KowabungaVRRPType) String() string

String conversions for VRRP message types

type Kowarp

type Kowarp struct{}

func (*Kowarp) LoadAndConfigureRouters

func (k *Kowarp) LoadAndConfigureRouters(routinesErrorsFeedback chan<- error)

func (*Kowarp) Run

func (k *Kowarp) Run()

type PseudoHeader

type PseudoHeader struct {
	SourceAddress      net.IP
	DestinationAddress net.IP
	// contains filtered or unexported fields
}

Pseudo header required for checksum computation. see RFC2460

func (PseudoHeader) Serialize

func (header PseudoHeader) Serialize() []byte

type RxBroker

type RxBroker struct {
	// contains filtered or unexported fields
}
var VRRPBroker *RxBroker = &RxBroker{
	registerVirtualRouters:   make(chan *virtualRouter),
	deregisterVirtualRouters: make(chan *virtualRouter),
	packet:                   make(chan *KowabungaVRRP),
	event:                    make(chan EVENT),
}

func (*RxBroker) Run

func (rb *RxBroker) Run(routineUnhandledError chan error)

func (*RxBroker) Stop

func (rb *RxBroker) Stop()

type STATE

type STATE byte
const (
	INIT STATE = iota
	MASTER
	BACKUP
)

type VirtualRoute

type VirtualRoute struct {
	Destination net.IPNet
	Gateway     net.IP
	Interface   net.Interface
	Metric      int
}

func (*VirtualRoute) Equal

func (r1 *VirtualRoute) Equal(r2 *VirtualRoute) bool

Directories

Path Synopsis
cmd
kowarp command

Jump to

Keyboard shortcuts

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