Categorygithub.com/Marlinski/go-openvpn
modulepackage
0.0.0-20200311102559-6e5b34bf722a
Repository: https://github.com/marlinski/go-openvpn.git
Documentation: pkg.go.dev

# README

go-openvpvn

go-openvpn is a lightweight golang library to start and monitor an openvpn tunnel. It essentially just wraps around the openvpn process and interacts with it using the management interface. Right now only openvpn client configuration has been implemented and tested.

It supports the following features:

  • simple API
  • use an existing openvpn configuration
  • override the config file settings programmatically
  • go channel to receive events:
    • tunnel status (up/down)
    • openvpn statistics
  • send management command

Import

import (
	"github.com/Marlinski/go-openvpn"
	"github.com/Marlinski/go-openvpn/events"
)

Basic example

The following code shows how to run a simple openvpn:

cfg := openvpn.LoadConfig(m.iface, "test.ovpn") // openvpn config file
cfg.SetLogStd(true)                             // log openvpn standard output and error
cfg.Set("dev", "tun-test)                       // passed to the openvpn command line parameter --dev tun-test

channel := processEvents()                      // event loop
ctrl    := cfg.Run(channel)                     // run openvpvn, it returns a controller 

And the event loop processor:

func processEvents() chan events.OpenvpnEvent {
    channel := make(chan events.OpenvpnEvent)       // channel to process the events 

    go func() {
        for {
            e := <-channel
            if e.Code() == events.OpenvpnEventUp {
                // tunnel is up
            }
            if e.Code() == events.OpenvpnEventDown {
                // tunnel is down
            }
        }
    }()

    return channel
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

LoadConfig sets the openvpn config.
NewConfig return an empty config.

# Constants

al the states.
al the states.
al the states.
al the states.

# Variables

# Structs

Config is the openvpn configuration in the form of parameters to the command line.
Controller provides API to control the openvpn connection.
Manager manages the management interface for a single openvpn config.
ManagerInterface holds the parameters for the interface Message received from the interface are routed through the eventChannel and processed by the manager state Response to command send to the interface are routed to the respChannel and processed by the mux holder.
StateMgmtBasic basic state separates events in three category for better visibility: - message - signal - events.
StateMgmtConnected listen for openvpn command.
StateMgmtDisconnected connected state.
StateMgmtIdle idle state.
StateMgmtWaitConnect wait for a connection from openvpn management.

# Interfaces

ManagerState for management.

# Type aliases

EventHandler handles general event.
MgmtStateCode are the different machine states.
MsgHandler handles openvpn management message.
SignalHandler handles general signal.