vpn

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: GPL-3.0 Imports: 13 Imported by: 0

README

VPN

a Virtual Private Network library

Example

peer1

packetConn, err := net.ListenPacket("udp", "192.168.3.99:22334")
if err != nil {
    panic(err)
}

tunic, err := tun.Create(nic.Config{MTU: 1428, IPv4: "10.10.10.2/24"})
if err != nil {
    panic(err)
}
vnic := nic.VirtualNIC{NIC: tunic}
vnic.AddPeer("10.10.10.1", "", &net.UDPAddr{IP: net.ParseIP("192.168.3.98", Port: 22335)})

ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()

err := vpn.New(vpn.Config{MTU: 1428}).Run(ctx, vnic, packetConn)
if err != nil {
    panic(err)
}

peer2

packetConn, err := net.ListenPacket("udp", "192.168.3.98:22335")
if err != nil {
    panic(err)
}

tunic, err := tun.Create(nic.Config{MTU: 1428, IPv4: "10.10.10.1/24"})
if err != nil {
    panic(err)
}
vnic := nic.VirtualNIC{NIC: tunic}
vnic.AddPeer("10.10.10.2", "", &net.UDPAddr{IP: net.ParseIP("192.168.3.99", Port: 22334)})

ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()

err := vpn.New(vpn.Config{MTU: 1428}).Run(ctx, vnic, packetConn)
if err != nil {
    panic(err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	MTU              int
	InboundHandlers  []InboundHandler
	OutboundHandlers []OutboundHandler
	OnRouteAdd       func(net.IPNet, net.IP)
	OnRouteRemove    func(net.IPNet, net.IP)
}

type InboundHandler

type InboundHandler interface {
	Name() string
	In(*nic.Packet) *nic.Packet
}

type OutboundHandler

type OutboundHandler interface {
	Name() string
	Out(*nic.Packet) *nic.Packet
}

type VPN

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

func New

func New(cfg Config) *VPN

func (*VPN) Run

func (vpn *VPN) Run(ctx context.Context, nic *nic.VirtualNIC, packetConn net.PacketConn) error

Directories

Path Synopsis
nic
tun

Jump to

Keyboard shortcuts

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