lcp

package
v1.1.3 Latest Latest
Warning

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

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

Documentation

Overview

Package lcp implements LCP, IPCP and IPv6CP protocols

Index

Constants

This section is empty.

Variables

View Source
var IPv6LinkLocalPrefix = []byte{0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

IPv6LinkLocalPrefix is the IPv6 Link Local prefix

Functions

func NewRejectPacket

func NewRejectPacket() func(b []byte) *ppp.Packet

NewRejectPacket returns a new LCP over PPP packet to reject a specified packet with an invalid protocol.

Types

type Blacklist added in v1.1.0

type Blacklist interface {
	Add(ip []net.IP) error
	Remove(ip []net.IP) error
	IsValid(ip net.IP) bool
}

type CHAPAuthAlg

type CHAPAuthAlg uint8

CHAPAuthAlg is the auth algorithm of CHAP

const (
	AlgNone            CHAPAuthAlg = 0x00
	AlgCHAPwithMD5     CHAPAuthAlg = 0x05
	AlgSHA1            CHAPAuthAlg = 0x06
	AlgCHAPwithSHA256  CHAPAuthAlg = 0x07
	AlgCHAPwithSHA3256 CHAPAuthAlg = 0x08
	AlgMSCHAP          CHAPAuthAlg = 0x80
	AlgMSCHAP2         CHAPAuthAlg = 0x81
)

List of CHAP algorithms

func (CHAPAuthAlg) String

func (alg CHAPAuthAlg) String() string

type DefaultBlacklist added in v1.1.0

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

func NewDefaultBlacklist added in v1.1.0

func NewDefaultBlacklist() *DefaultBlacklist

func (*DefaultBlacklist) Add added in v1.1.0

func (b *DefaultBlacklist) Add(ip []net.IP) error

Add adds an IP address that needs to be skipped if assigned by the AC.

func (*DefaultBlacklist) IsValid added in v1.1.0

func (b *DefaultBlacklist) IsValid(ip net.IP) bool

IsValid returns true if the specified IP is not in the blacklist.

func (*DefaultBlacklist) Remove added in v1.1.0

func (b *DefaultBlacklist) Remove(ip []net.IP) error

Remove removes an IP address from existing blacklist, if present.

type DefaultIP6CPRule

type DefaultIP6CPRule struct {
	IfID atomic.Uint64
	// contains filtered or unexported fields
}

DefaultIP6CPRule implements both OwnOptionRule and PeerOptionRule interface, negotiating only interface-id option.

func NewDefaultIP6CPRule

func NewDefaultIP6CPRule(mac net.HardwareAddr) *DefaultIP6CPRule

NewDefaultIP6CPRule returns a new DefaultIP6CPRule. It uses an interface-id option that is derived from MAC address.

func (*DefaultIP6CPRule) GetOption

func (r *DefaultIP6CPRule) GetOption(t uint8) Option

GetOption implements OwnOptionRule interface, return nil if t is not interface-id

func (*DefaultIP6CPRule) GetOptions

func (r *DefaultIP6CPRule) GetOptions() []Option

GetOptions implements OwnOptionRule interface, return own interface id

func (*DefaultIP6CPRule) HandlerConfNAK

func (r *DefaultIP6CPRule) HandlerConfNAK(received []Option) error

HandlerConfNAK implements OwnOptionRule interface, generate a new interface-id if interface-id is NAK-ed.

func (*DefaultIP6CPRule) HandlerConfRej

func (r *DefaultIP6CPRule) HandlerConfRej(received []Option)

HandlerConfRej implements OwnOptionRule interface, if interface-id is rejected, then setting own interface-id to nil

func (*DefaultIP6CPRule) HandlerConfReq

func (r *DefaultIP6CPRule) HandlerConfReq(received []Option) (nak, reject []Option)

HandlerConfReq implements PeerOptionRule interface, section 4.1 of RFC5072 in terms of NAK or REJECT peer's interface-id.

type DefaultIPCPOwnRule

type DefaultIPCPOwnRule struct {
	Addr          net.IP
	DNS           net.IP
	SecondaryDNS  net.IP
	NBNS          net.IP
	SecondaryNBNS net.IP
	// contains filtered or unexported fields
}

DefaultIPCPOwnRule is the default OwnOptionRule for the IPCP protocol, it implements OwnOptionRule interface

func NewDefaultIPCPOwnRule

func NewDefaultIPCPOwnRule(blacklist Blacklist) *DefaultIPCPOwnRule

NewDefaultIPCPOwnRule returns a new DefaultIPCPOwnRule, with all addresses set to 0.0.0.0

func (*DefaultIPCPOwnRule) GetOption

func (own *DefaultIPCPOwnRule) GetOption(o byte) Option

GetOption implements OwnOptionRule interface;

func (*DefaultIPCPOwnRule) GetOptions

func (own *DefaultIPCPOwnRule) GetOptions() (r []Option)

GetOptions implements OwnOptionRule interface; a field will not be included as own option if it is nil

func (*DefaultIPCPOwnRule) HandlerConfNAK

func (own *DefaultIPCPOwnRule) HandlerConfNAK(received []Option) error

HandlerConfNAK handles Conf nak packet. Option in conf-nak will be used as own value in next conf-req.

func (*DefaultIPCPOwnRule) HandlerConfRej

func (own *DefaultIPCPOwnRule) HandlerConfRej(received []Option)

HandlerConfRej handles Conf reject packet. Option in conf-reject will not be included in next conf-req.

type DefaultIPCPPeerRule

type DefaultIPCPPeerRule struct{}

DefaultIPCPPeerRule is the default PeerOptionRule implementation. It ignores all peer options.

func (*DefaultIPCPPeerRule) GetOptions

func (peer *DefaultIPCPPeerRule) GetOptions() []Option

GetOptions always returns nil

func (*DefaultIPCPPeerRule) HandlerConfReq

func (peer *DefaultIPCPPeerRule) HandlerConfReq(received []Option) (nak, reject []Option)

HandlerConfReq will reject any options other than OpIPAddress, and ACK any OpIPAddress value;

type DefaultOwnOptionRule

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

DefaultOwnOptionRule is the default OwnOptionRule implementation

func NewDefaultOwnOptionRule

func NewDefaultOwnOptionRule() *DefaultOwnOptionRule

NewDefaultOwnOptionRule returns a new DefaultOwnOptionRule

func (*DefaultOwnOptionRule) GetOption

func (own *DefaultOwnOptionRule) GetOption(o uint8) Option

func (*DefaultOwnOptionRule) GetOptions

func (own *DefaultOwnOptionRule) GetOptions() []Option

func (*DefaultOwnOptionRule) HandlerConfNAK

func (own *DefaultOwnOptionRule) HandlerConfNAK(received []Option) error

HandlerConfNAK accepts all options listed in conf-nak

func (*DefaultOwnOptionRule) HandlerConfRej

func (own *DefaultOwnOptionRule) HandlerConfRej(received []Option)

HandlerConfRej removes all options listed in conf-rej

type DefaultPeerOptionRule

type DefaultPeerOptionRule struct {
	// AuthOp is the required Auth Protocol Option (PAP or CHAP)
	AuthOp *OpAuthProto
	// contains filtered or unexported fields
}

DefaultPeerOptionRule is the default PeerOptionRule implementation.

func NewDefaultPeerOptionRule

func NewDefaultPeerOptionRule(authProto ppp.ProtocolNumber) (*DefaultPeerOptionRule, error)

NewDefaultPeerOptionRule create a new DefaultPeerOptionRule instance with specified auth protocol

func (*DefaultPeerOptionRule) GetOptions

func (rule *DefaultPeerOptionRule) GetOptions() []Option

func (*DefaultPeerOptionRule) HandlerConfReq

func (rule *DefaultPeerOptionRule) HandlerConfReq(received []Option) (nak, reject []Option)

HandlerConfReq implements PeerOptionRule, if config-request include an auth-proto option that is different from required one, it will be NAKed; Option in conf-req other than auth-proto, magic number and MRU will be rejected.

type GenericOption

type GenericOption struct {
	Code    uint8
	Proto   ppp.ProtocolNumber
	Payload []byte
}

GenericOption is a general LCP/IPCP/IPv6CP option that doesn't have any explicit mention in PPP protocol documentation.

func (*GenericOption) Equal

func (gop *GenericOption) Equal(b Option) bool

func (*GenericOption) GetPayload

func (gop *GenericOption) GetPayload() []byte

func (*GenericOption) Parse

func (gop *GenericOption) Parse(buf []byte) (int, error)

func (*GenericOption) Serialize

func (gop *GenericOption) Serialize() ([]byte, error)

func (*GenericOption) String

func (gop *GenericOption) String() string

func (*GenericOption) Type

func (gop *GenericOption) Type() uint8

type IPCP6OptionType

type IPCP6OptionType uint8
const (
	IP6CPOpInterfaceIdentifier     IPCP6OptionType = 0x01
	IP6CPOpIPv6CompressionProtocol IPCP6OptionType = 0x02
)

List of IPv6CP option types

func (IPCP6OptionType) String

func (code IPCP6OptionType) String() string

type IPCPOptionType

type IPCPOptionType uint8
const (
	OpIPAddresses                IPCPOptionType = 0x01
	OpIPCompressionProtocol      IPCPOptionType = 0x02
	OpIPAddress                  IPCPOptionType = 0x03
	OpMobileIPv4                 IPCPOptionType = 0x04
	OpPrimaryDNSServerAddress    IPCPOptionType = 0x81
	OpPrimaryNBNSServerAddress   IPCPOptionType = 0x82
	OpSecondaryDNSServerAddress  IPCPOptionType = 0x83
	OpSecondaryNBNSServerAddress IPCPOptionType = 0x84
)

List of IPCP option types

func (IPCPOptionType) String

func (o IPCPOptionType) String() string

type IPv4AddrOption

type IPv4AddrOption struct {
	AddrType IPCPOptionType
	Addr     net.IP
}

IPv4AddrOption represents IPCP option contains a single IPv4 address

func (*IPv4AddrOption) Equal

func (addr *IPv4AddrOption) Equal(b Option) bool

func (*IPv4AddrOption) GetPayload

func (addr *IPv4AddrOption) GetPayload() []byte

func (*IPv4AddrOption) Parse

func (addr *IPv4AddrOption) Parse(buf []byte) (int, error)

func (*IPv4AddrOption) Serialize

func (addr *IPv4AddrOption) Serialize() ([]byte, error)

func (*IPv4AddrOption) String

func (addr *IPv4AddrOption) String() string

func (*IPv4AddrOption) Type

func (addr *IPv4AddrOption) Type() uint8

type InterfaceIDOption

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

InterfaceIDOption is the IPv6CP interface ID option

func (*InterfaceIDOption) Equal

func (opt *InterfaceIDOption) Equal(b Option) bool

func (*InterfaceIDOption) GetPayload

func (opt *InterfaceIDOption) GetPayload() []byte

func (*InterfaceIDOption) Parse

func (opt *InterfaceIDOption) Parse(buf []byte) (int, error)

func (*InterfaceIDOption) Serialize

func (opt *InterfaceIDOption) Serialize() ([]byte, error)

func (*InterfaceIDOption) String

func (opt *InterfaceIDOption) String() string

func (*InterfaceIDOption) Type

func (opt *InterfaceIDOption) Type() uint8

type LCP

type LCP struct {
	OwnRule  OwnOptionRule  // Handle own options
	PeerRule PeerOptionRule // Handle peer's options
	// contains filtered or unexported fields
}

LCP is the implementation for LCP/IPCP/IPv6CP

func NewLCP

func NewLCP(proto ppp.ProtocolNumber, pppProto *ppp.PPP, h LayerNotifyHandler, peerRule PeerOptionRule, optionRule OwnOptionRule) *LCP

NewLCP creates a new LCP/IPCP/IPv6CP according to the specific proto, runs over specified pppProto, calls h whenever there is layer event. optionly, LCPModifier(s) could be specified to change default config

func (*LCP) Close

func (lcp *LCP) Close() error

func (*LCP) CloseEvent

func (lcp *LCP) CloseEvent() error

CloseEvent is admin Close event, as defined in RFC1661

func (*LCP) DownEvent

func (lcp *LCP) DownEvent() error

DownEvent is lower layer down event, as defined in RFC1661

func (*LCP) OpenEvent

func (lcp *LCP) OpenEvent() error

OpenEvent is admin Open event, as defined in RFC1661

func (*LCP) Start

func (lcp *LCP) Start(ctx context.Context)

func (*LCP) UpEvent

func (lcp *LCP) UpEvent() error

UpEvent is lower layer up event, as defined in RFC1661

type LayerNotifyEvent

type LayerNotifyEvent uint8

LayerNotifyEvent is the tlu/tld/tls/tlf event (as defined in RFC1661)

const (
	LayerNotifyUp LayerNotifyEvent = iota
	LayerNotifyDown
	LayerNotifyStarted
	LayerNotifyFinished
)

List of LayerNotifyEvent statuses

func (LayerNotifyEvent) String

func (n LayerNotifyEvent) String() string

type LayerNotifyHandler

type LayerNotifyHandler func(evt LayerNotifyEvent)

LayerNotifyHandler is the handler function to handle Layer event (tlu/tld/tls/tlf as defined in RFC1661)

type MsgCode

type MsgCode uint8
const (
	CodeConfigureRequest MsgCode = 0x01
	CodeConfigureAck     MsgCode = 0x02
	CodeConfigureNak     MsgCode = 0x03
	CodeConfigureReject  MsgCode = 0x04
	CodeTerminateRequest MsgCode = 0x05
	CodeTerminateAck     MsgCode = 0x06
	CodeCodeReject       MsgCode = 0x07
	CodeProtocolReject   MsgCode = 0x08
	CodeEchoRequest      MsgCode = 0x09
	CodeEchoReply        MsgCode = 0x0A
	CodeDiscardRequest   MsgCode = 0x0B
)

List of LCP message codes

func (MsgCode) String

func (code MsgCode) String() string

type OpAuthProto

type OpAuthProto struct {
	Proto   ppp.ProtocolNumber
	CHAPAlg CHAPAuthAlg
	Payload []byte
}

OpAuthProto is the LCP auth protocol option

func NewCHAPAuthOp

func NewCHAPAuthOp() *OpAuthProto

NewCHAPAuthOp returns a new CHAP OpAuthProto with MD5

func NewPAPAuthOp

func NewPAPAuthOp() *OpAuthProto

NewPAPAuthOp returns a new PAP OpAuthProto

func (*OpAuthProto) Equal

func (auth *OpAuthProto) Equal(b Option) bool

func (*OpAuthProto) GetPayload

func (auth *OpAuthProto) GetPayload() []byte

func (*OpAuthProto) Parse

func (auth *OpAuthProto) Parse(buf []byte) (int, error)

func (*OpAuthProto) Serialize

func (auth *OpAuthProto) Serialize() ([]byte, error)

func (*OpAuthProto) String

func (auth *OpAuthProto) String() string

func (*OpAuthProto) Type

func (auth *OpAuthProto) Type() uint8

type OpMRU

type OpMRU uint16

OpMRU is the LCP MRU option

func (*OpMRU) Equal

func (mru *OpMRU) Equal(b Option) bool

func (*OpMRU) GetPayload

func (mru *OpMRU) GetPayload() []byte

func (*OpMRU) Parse

func (mru *OpMRU) Parse(buf []byte) (int, error)

func (*OpMRU) Serialize

func (mru *OpMRU) Serialize() ([]byte, error)

func (*OpMRU) String

func (mru *OpMRU) String() string

func (*OpMRU) Type

func (mru *OpMRU) Type() uint8

type OpMagicNum

type OpMagicNum uint32

OpMagicNum is the LCP magic number option

func (*OpMagicNum) Equal

func (mn *OpMagicNum) Equal(b Option) bool

func (*OpMagicNum) GetPayload

func (mn *OpMagicNum) GetPayload() []byte

func (*OpMagicNum) Parse

func (mn *OpMagicNum) Parse(buf []byte) (int, error)

func (*OpMagicNum) Serialize

func (mn *OpMagicNum) Serialize() ([]byte, error)

func (*OpMagicNum) String

func (mn *OpMagicNum) String() string

func (*OpMagicNum) Type

func (mn *OpMagicNum) Type() uint8

type Option

type Option interface {
	// Type returns option type as uint8
	Type() uint8
	// Serialize option into bytes
	Serialize() ([]byte, error)
	// Parse buf into the option, return length of used bytes
	Parse(buf []byte) (int, error)
	// GetPayload returns payload bytes
	GetPayload() []byte
	// String returns a string representation of the option
	String() string
	// Equal returns true if b has same value and type
	Equal(b Option) bool
}

Option is the LCP/IPCP/IPv6 option interface

type OptionType

type OptionType uint8
const (
	OpTypeMaximumReceiveUnit                OptionType = 0x01
	OpTypeAuthenticationProtocol            OptionType = 0x03
	OpTypeQualityProtocol                   OptionType = 0x04
	OpTypeMagicNumber                       OptionType = 0x05
	OpTypeProtocolFieldCompression          OptionType = 0x07
	OpTypeAddressandControlFieldCompression OptionType = 0x08
)

List of LCP option types

func (OptionType) String

func (op OptionType) String() string

type OwnOptionRule

type OwnOptionRule interface {
	// HandlerConfRej is the handler function to handle received Conf-Reject
	HandlerConfRej(received []Option)
	// HandlerConfNAK is the handler function to handle received Conf-Nak
	HandlerConfNAK(received []Option) error
	// GetOptions returns current own options
	GetOptions() []Option
	// GetOption returns current option with type o
	GetOption(o byte) Option
}

OwnOptionRule is rule that used to handle own LCP options, user could provide implementation of this interface to get custom behavior

type Packet

type Packet struct {
	// Proto is one of ProtoLCP, ProtoIPCP, ProtoIPv6CP
	Proto ppp.ProtocolNumber
	// Msg code
	Code MsgCode
	// Msg Id
	ID uint8
	// Msg length
	Len uint16
	// Magic Number if exists
	MagicNum uint32
	// Rejected protocol number, if exists
	RejectedProto ppp.ProtocolNumber
	// LCP allows multiple elements with the same type of option,
	// in the same order between request and response (requirement)
	Options []Option
	// Payload
	Payload []byte
}

Packet represents a LCP/IPCP/IPv6CP packet. It will be sent over PPP.

func NewPacket

func NewPacket(p ppp.ProtocolNumber) *Packet

func (*Packet) GetOption

func (p *Packet) GetOption(optType OptionType) (r []Option)

GetOption return a slice of options where the type is the same of optType.

func (*Packet) Parse

func (p *Packet) Parse(buf []byte) error

func (*Packet) Serialize

func (p *Packet) Serialize() ([]byte, error)

func (*Packet) String

func (p *Packet) String() string

type PeerOptionRule

type PeerOptionRule interface {
	// HandlerConfReq is the handler function to handle received Conf-Request.
	// if a received option needs to be naked or rejected, include it in returned nak/reject LCPOptions
	HandlerConfReq(received []Option) (nak, reject []Option)
	// GetOptions return current peer's options
	GetOptions() []Option
}

PeerOptionRule is rule that use for handle received config-req from peer

type State

type State uint32

State is the current LCP protocol state

const (
	StateInitial State = iota
	StateStarting
	StateClosed
	StateStopped
	StateClosing
	StateStopping
	StateReqSent
	StateAckRcvd
	StateAckSent
	StateOpened
	StateEchoReqSent
)

LCP protocol state (as defined in RFC1661)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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