client

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package client is a PPPoE client lib

Index

Constants

View Source
const (
	// StateInitial is the initial ZouPPP state
	StateInitial uint32 = iota
	// StateDialing is when ZouPPP is dialing
	StateDialing
	// StateOpen is after ZouPPP finished dialing, successfully reached open for all enabled NCP
	StateOpen
	// StateClosing is when ZouPPP is closing
	StateClosing
	// StateClosed is when ZouPPP is closed
	StateClosed
)
View Source
const DefaultPPPIfNameTemplate = "zouppp@ID"

DefaultPPPIfNameTemplate is the default PPP interface name

View Source
const VarName = "@ID"

VarName is the placeholder in PPPIfName/RID/CID/UserName/Password of Setup that will be replaced by client id

Variables

This section is empty.

Functions

func CollectResults

func CollectResults(setup *Setup, resultch chan *ResultSummary)

CollectResults use setup.ResultCh to collect dialup results, and generate a ResultSummary in the end, send it via resultch

func NewDefaultZouPPPLogger

func NewDefaultZouPPPLogger(logl LoggingLvl) (*zap.Logger, error)

NewDefaultZouPPPLogger create a default logger with specified log level

Types

type Config

type Config struct {
	Mac   net.HardwareAddr
	VLANs etherconn.VLANs

	RID       string
	CID       string
	UserName  string
	Password  string
	PPPIfName string
	// contains filtered or unexported fields
}

Config hold client specific configuration

func GenClientConfigurations

func GenClientConfigurations(setup *Setup) ([]*Config, error)

GenClientConfigurations creates clients specific configruations per setup

type DHCP6Cfg added in v0.2.0

type DHCP6Cfg struct {
	Mac            net.HardwareAddr
	NeedPD, NeedNA bool
	Debug          bool
}

DHCP6Cfg hold configuration for DHCP6Clnt

type DHCP6Clnt added in v0.2.0

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

DHCP6Clnt is a DHCPv6 client

func NewDHCP6Clnt added in v0.2.0

func NewDHCP6Clnt(conn net.PacketConn, cfg *DHCP6Cfg, localLLA net.IP) (*DHCP6Clnt, error)

NewDHCP6Clnt creates a new DHCPv6 client, using conn as transport, cfg holds the the configuration, localLLA is used for local link local address for DHCPv6 msg

func (*DHCP6Clnt) Dial added in v0.2.0

func (dc *DHCP6Clnt) Dial() error

Dial completes a DHCPv6 exchange with server

type DialResult

type DialResult struct {
	// R is the result
	R Result
	// PPPoEEP is the PPPOEEndpoint, identify the ZouPPP
	PPPoEEP *pppoe.Endpoint
	// StartTime is when dailing starts
	StartTime time.Time
	// DialFinishTime is when dailing finishes
	DialFinishTime time.Time
}

DialResult contains ZouPPP dailing result info

type LoggingLvl

type LoggingLvl uint

LoggingLvl is the logging level of client

const (
	// LogLvlErr only log error msg
	LogLvlErr LoggingLvl = iota
	// LogLvlInfo logs error + info msg
	LogLvlInfo
	// LogLvlDebug logs error + info + debug msg
	LogLvlDebug
)

func (LoggingLvl) MarshalText added in v0.3.0

func (lvl LoggingLvl) MarshalText() (text []byte, err error)

func (*LoggingLvl) UnmarshalText added in v0.3.0

func (lvl *LoggingLvl) UnmarshalText(text []byte) error

type Result

type Result int

Result is the ZouPPP dial result

const (
	// ResultSuccess means dialing succeed
	ResultSuccess Result = iota
	// ResultFailure means dialing failed
	ResultFailure
)

func (Result) String

func (er Result) String() string

type ResultSummary

type ResultSummary struct {
	// Total is the total number of sessions
	Total uint
	// Success is the total number of sessions suceessfully finished dailup
	Success uint
	// Failed is the total number of sessions failed to finish dailup
	Failed uint
	// LessThanTenSecond is the total number of sessions suceessfully finished dailup within 10 seconds
	LessThanTenSecond uint
	// Shortest is the amount of time that fastest session finishes dialup successfully
	Shortest time.Duration
	// Longest is the amount of time that the slowest session finishes dialup successfully
	Longest time.Duration
	// SuccessTotalTime is the total amount of time of all success session finish dialup
	SuccessTotalTime time.Duration
	// TotalTime is the total amount of time of all session finish dialup
	TotalTime time.Duration
	// AvgSuccessTime is the average amount of time of a success session finish dialup
	AvgSuccessTime time.Duration
	// contains filtered or unexported fields
}

ResultSummary is the summary stats of dialup results

func (ResultSummary) String

func (rs ResultSummary) String() string

type Setup

type Setup struct {

	// Ifname is the binding intereface name
	Ifname string `alias:"i" usage:"listening interface name"`
	// NumOfClients is the number of clients to be created
	NumOfClients uint `alias:"n" usage:"number of PPPoE clients"`
	// StartMAC is the starting mac address for all the sessions
	StartMAC net.HardwareAddr `alias:"mac" usage:"start MAC address"`
	// MacStep is the mac address step to increase for each session
	MacStep uint `usage:"MAC step to increase for each client"`
	// StartVLANs is the starting vlans for all the sessions
	StartVLANs etherconn.VLANs `alias:"vlan" usage:"start VLAN id, could be Dot1q or QinQ"`
	// VLANStep is the vlan step to increase for each session
	VLANStep uint `usage:"VLAN step to increase for each client"`
	// ExcludedVLANs is the slice of vlan id to skip, apply to all layer of vlans
	ExcludedVLANs []uint16 `usage:"a list of excluded VLAN id, apply to all layer of vlans"`
	// Interval is the amount of time to wait between launching each session
	Interval time.Duration `usage:"amount of time to wait between launching each session"`
	LogLevel LoggingLvl    `alias:"l" usage:"log levl, err|info|debug"`
	// if Apply is true, then create a PPP interface with assigned addresses; could be set to false if only to test protocol
	Apply bool `usage:"if Apply is true, then create a PPP interface with assigned addresses; could be set to false if only to test protocol"`
	// number of Retries
	Retry   uint          `usage:"number of setup retry"`
	Timeout time.Duration `usage:"setup timeout"`
	// AuthProto is the authenticaiton protocol to use, e.g. lcp.ProtoCHAP
	AuthProto lcp.PPPProtocolNumber `usage:"auth protocol, PAP or CHAP"`

	// RID is the BBF remote-id PPPoE tag
	RID string `usage:"BBF remote-id"`
	// CID is the BBF circuit-id PPPoE tag
	CID string `usage:"BBF circuit-id"`
	// UserName for PAP/CHAP auth
	UserName string `alias:"u" usage:"PAP/CHAP username"`
	// Password for PAP/CHAP auth
	Password string `alias:"p" usage:"PAP/CHAP password"`
	// the name of PPP interface created after successfully dialing
	PPPIfName string `usage:"name of PPP interface created after successfully dialing, must contain @ID"`
	// Run IPCP if true
	IPv4 bool `alias:"v4" usage:"run IPCP"`
	// Run IPv6CP if true
	IPv6 bool `alias:"v6" usage:"run IPv6CP"`
	// run DHCPv6 over PPP if true
	DHCPv6IANA bool `usage:"run DHCPv6 over PPP to get an IANA address"`
	DHCPv6IAPD bool `usage:"run DHCPv6 over PPP to get an IAPD prefix"`
	// enable profiling for dev
	Profiling bool `usage:"enable profiling, dev use only"`
	// use XDP to forward packet
	XDP bool `usage:"use XDP to forward packet"`
	// contains filtered or unexported fields
}

Setup holds common configruation for creating one or mulitple ZouPPP sessions

func DefaultSetup

func DefaultSetup() *Setup

DefaultSetup returns a Setup with following defaults: - no vlan, use the mac of interface ifname - no debug - single client - CHAP, IPv4 only

func (*Setup) Close added in v0.3.0

func (setup *Setup) Close()

func (*Setup) Init added in v0.3.0

func (setup *Setup) Init() error

func (*Setup) Logger

func (setup *Setup) Logger() *zap.Logger

type ZouPPP

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

ZouPPP represents a single PPPoE/PPP client session

func NewZouPPP

func NewZouPPP(econn *etherconn.EtherConn, cfg *Config,
	options ...ZouPPPModifier) (zou *ZouPPP, err error)

NewZouPPP creates a new ZouPPP instance, dialwg is done when dial finishes, sessionwg is done when whole session terminates after dailing succeeds

func (*ZouPPP) Close added in v0.1.3

func (zou *ZouPPP) Close()

Close shutdown the client

func (*ZouPPP) Dial

func (zou *ZouPPP) Dial(ctx context.Context)

Dial dial PPPoE/LCP/PAPorCHAP/NCPs

func (*ZouPPP) GetV6LLA added in v0.2.0

func (zou *ZouPPP) GetV6LLA() (net.IP, error)

GetV6LLA returns the IPv6 LLA the compsoed of negotiated interface-id via IPv6CP

type ZouPPPModifier

type ZouPPPModifier func(zou *ZouPPP)

ZouPPPModifier is a function provides addtional configuration for NewZouPPP()

func WithDialWG

func WithDialWG(wg *sync.WaitGroup) ZouPPPModifier

WithDialWG specifies a WaitGroup, which will be done after ZouPPP finishes dialing

func WithSessionWG

func WithSessionWG(wg *sync.WaitGroup) ZouPPPModifier

WithSessionWG specifies a WaitGroup, which will be done after closed after reach open state

Jump to

Keyboard shortcuts

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