pppoe

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: 11 Imported by: 0

Documentation

Overview

Package pppoe implements pppoe as defined in RFC2516

Index

Constants

View Source
const (
	// DefaultTimeout is default timeout for PPPoE
	DefaultTimeout = 3 * time.Second
	// DefaultRetry is the default retry for PPPoE
	DefaultRetry = 3
)
View Source
const (
	// EtherTypePPPoESession is the Ether type for PPPoE session pkt
	EtherTypePPPoESession = 0x8864
	// EtherTypePPPoEDiscovery is the Ether type for PPPoE discovery pkt
	EtherTypePPPoEDiscovery = 0x8863
)
View Source
const MaxTags = 32

MaxTags is the max tags allowed in a PPPoE pkt

Variables

This section is empty.

Functions

This section is empty.

Types

type BBFSubTagByteSlice

type BBFSubTagByteSlice struct {
	Value   []byte
	TagType BBFSubTagNum
}

BBFSubTagByteSlice is for all byte slice type BBF sub-tag

func (*BBFSubTagByteSlice) Parse

func (bslice *BBFSubTagByteSlice) Parse(buf []byte) (int, error)

Parse implements Tag interface

func (BBFSubTagByteSlice) Serialize

func (bslice BBFSubTagByteSlice) Serialize() ([]byte, error)

Serialize implements Tag interface

func (BBFSubTagByteSlice) String

func (bslice BBFSubTagByteSlice) String() string

String implements Tag interface

func (BBFSubTagByteSlice) Type

func (bslice BBFSubTagByteSlice) Type() uint16

Type implements Tag interface

type BBFSubTagNum

type BBFSubTagNum uint8

BBFSubTagNum is the BBF sub tag type

const (
	BBFSubTagNumCircuitID                      BBFSubTagNum = 1
	BBFSubTagNumRemoteID                       BBFSubTagNum = 2
	BBFSubTagActualDataRateUpstream            BBFSubTagNum = 0x81
	BBFSubTagActualDataRateDownstream          BBFSubTagNum = 0x82
	BBFSubTagMinimumDataRateUpstream           BBFSubTagNum = 0x83
	BBFSubTagMinimumDataRateDownstream         BBFSubTagNum = 0x84
	BBFSubTagAttainableDataRateUpstream        BBFSubTagNum = 0x85
	BBFSubTagAttainableDataRateDownstream      BBFSubTagNum = 0x86
	BBFSubTagMaximumDataRateUpstream           BBFSubTagNum = 0x87
	BBFSubTagMaximumDataRateDownstream         BBFSubTagNum = 0x88
	BBFSubTagMinDataRateUpstreaminlow          BBFSubTagNum = 0x89
	BBFSubTagMinimumDataRateDownstreaminlow    BBFSubTagNum = 0x8A
	BBFSubTagMaxInterleavingDelay              BBFSubTagNum = 0x8B
	BBFSubTagActualInterleavingUpstreamDelay   BBFSubTagNum = 0x8C
	BBFSubTagMaximumInterleavingDelay          BBFSubTagNum = 0x8D
	BBFSubTagActualInterleavingDownstreamDelay BBFSubTagNum = 0x8E
	BBFSubTagDataLinkEncap                     BBFSubTagNum = 0x90
	BBFSubTagIWFSessionFlag                    BBFSubTagNum = 0xFE
)

a list of BBF sub tag type

func (BBFSubTagNum) String

func (t BBFSubTagNum) String() string

String returns a string representation of t

type BBFSubTagString

type BBFSubTagString struct {
	TagType BBFSubTagNum
	Value   string
}

BBFSubTagString is for string type of BBF sub-tag

func (*BBFSubTagString) Parse

func (str *BBFSubTagString) Parse(buf []byte) (int, error)

Parse implements Tag interface

func (BBFSubTagString) Serialize

func (str BBFSubTagString) Serialize() ([]byte, error)

Serialize implements Tag interface

func (BBFSubTagString) String

func (str BBFSubTagString) String() string

String implements Tag interface

func (BBFSubTagString) Type

func (str BBFSubTagString) Type() uint16

Type implements Tag interface

type BBFSubTagUint32

type BBFSubTagUint32 struct {
	TagType BBFSubTagNum
	Value   uint32
}

BBFSubTagUint32 is for all numberic type of BBF sub-tag

func (*BBFSubTagUint32) Parse

func (num *BBFSubTagUint32) Parse(buf []byte) (int, error)

Parse implements Tag interface

func (BBFSubTagUint32) Serialize

func (num BBFSubTagUint32) Serialize() ([]byte, error)

Serialize implements Tag interface

func (BBFSubTagUint32) String

func (num BBFSubTagUint32) String() string

String implements Tag interface

func (BBFSubTagUint32) Type

func (num BBFSubTagUint32) Type() uint16

Type implements Tag interface

type BBFTag

type BBFTag []Tag

BBFTag represents a BBF PPPoE tag, which could include multiple sub-tag

func NewCircuitRemoteIDTag

func NewCircuitRemoteIDTag(cid, rid string) *BBFTag

NewCircuitRemoteIDTag return a BBF Tag with circuit-id and remote-id sub tag. if cid or rid is empty string, then it will not be included

func (*BBFTag) Parse

func (bbf *BBFTag) Parse(buf []byte) (int, error)

Parse implements Tag interface

func (BBFTag) Serialize

func (bbf BBFTag) Serialize() ([]byte, error)

Serialize implements Tag interface

func (BBFTag) String

func (bbf BBFTag) String() string

String implements Tag interface

func (BBFTag) Type

func (bbf BBFTag) Type() uint16

Type implements Tag interface

type Code

type Code uint8

Code is the PPPoE msg code

const (
	CodeSession Code = 0
	CodePADO    Code = 7
	CodePADI    Code = 9
	CodePADR    Code = 25
	CodePADS    Code = 101
	CodePADT    Code = 167
)

list of PPPoE msg code

func (Code) String

func (code Code) String() string

String return a string representation of code

type Endpoint

type Endpoint struct {
	// L2EP is the associated EtherConn's L2Endpoint
	L2EP *etherconn.L2Endpoint
	// SessionId is the PPPoE session ID
	SessionID uint16
}

Endpoint represents a PPPoE endpont

func (Endpoint) Network

func (pep Endpoint) Network() string

Network implenets net.Addr interface, always return "pppoe"

func (Endpoint) String

func (pep Endpoint) String() string

String implenets net.Addr interface, return "pppoe:<L2EP>:<SessionID>"

type Modifier

type Modifier func(pppoe *PPPoE)

Modifier is a function to provide custom configuration when creating new PPPoE instances

func WithDebug

func WithDebug(d bool) Modifier

WithDebug specifies if debug is enabled

func WithTags

func WithTags(t []Tag) Modifier

WithTags adds all tags in t in PPPoE request pkt

type PPPoE

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

PPPoE is the PPPoE protocol

func NewPPPoE

func NewPPPoE(conn *etherconn.EtherConn, logger *zap.Logger, options ...Modifier) *PPPoE

NewPPPoE return a new PPPoE struct; use conn as underlying transport, logger for logging; optionally Modifer could provide custom configurations;

func (*PPPoE) Close

func (pppoe *PPPoE) Close() error

Close implements net.PacketConn interface

func (*PPPoE) Dial

func (pppoe *PPPoE) Dial(ctx context.Context) error

Dial complets a full PPPoE discovery exchange (PADI/PADO/PADR/PADS)

func (*PPPoE) GetLogger

func (pppoe *PPPoE) GetLogger() *zap.Logger

GetLogger returns pppoe's logger

func (*PPPoE) LocalAddr

func (pppoe *PPPoE) LocalAddr() net.Addr

LocalAddr return local Endpoint, see doc of Endpoint

func (*PPPoE) ReadFrom

func (pppoe *PPPoE) ReadFrom(buf []byte) (int, net.Addr, error)

ReadFrom implments net.PacketConn interface; only works after pppoe session is open

func (*PPPoE) SetDeadline

func (pppoe *PPPoE) SetDeadline(t time.Time) error

SetDeadline implements net.PacketConn interface

func (*PPPoE) SetReadDeadline

func (pppoe *PPPoE) SetReadDeadline(t time.Time) error

SetReadDeadline implements net.PacketConn interface

func (*PPPoE) SetWriteDeadline

func (pppoe *PPPoE) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements net.PacketConn interface

func (*PPPoE) WriteTo

func (pppoe *PPPoE) WriteTo(p []byte, addr net.Addr) (n int, err error)

WriteTo implments net.PacketConn interface, addr is ignored, pkt is always sent to AC's MAC

type Pkt

type Pkt struct {
	Vertype   byte
	Code      Code
	SessionID uint16
	Len       uint16
	Payload   []byte
	Tags      []Tag
}

Pkt is the struct for PPPoE pkt

func (*Pkt) GetTag

func (pkt *Pkt) GetTag(t TagType) (r []Tag)

GetTag return a slice of tag with type t

func (*Pkt) Parse

func (pkt *Pkt) Parse(buf []byte) error

Parse buf into pkt

func (*Pkt) Serialize

func (pkt *Pkt) Serialize() ([]byte, error)

Serialize pkt into bytes, without copying, and no padding

func (Pkt) String

func (pkt Pkt) String() string

String returns a string representation of pkt

type Tag

type Tag interface {
	// Serialize Tag into byte slice
	Serialize() ([]byte, error)
	// Parse buf into Tag
	Parse(buf []byte) (int, error)
	// Type return PPPoE Tag type as uint16
	Type() uint16
	// String returns a string representation of Tag
	String() string
}

Tag is the interface for PPPoE Tag

type TagByteSlice

type TagByteSlice struct {
	Value   []byte
	TagType TagType
}

TagByteSlice is for all byte slice and unknown type of tag, e.g. ACuniq, ACCookie

func (*TagByteSlice) Parse

func (bslice *TagByteSlice) Parse(buf []byte) (int, error)

Parse implements Tag interface

func (TagByteSlice) Serialize

func (bslice TagByteSlice) Serialize() ([]byte, error)

Serialize implements Tag interface

func (TagByteSlice) String

func (bslice TagByteSlice) String() string

String implements Tag interface

func (TagByteSlice) Type

func (bslice TagByteSlice) Type() uint16

Type implements Tag interface

type TagEndofList

type TagEndofList struct{}

TagEndofList is the End-of-List tag

func (TagEndofList) Parse

func (eol TagEndofList) Parse(buf []byte) (int, error)

Parse implements Tag interface

func (TagEndofList) Serialize

func (eol TagEndofList) Serialize() ([]byte, error)

Serialize implements Tag interface

func (TagEndofList) String

func (eol TagEndofList) String() string

String implements Tag interface

func (TagEndofList) Type

func (eol TagEndofList) Type() uint16

Type implements Tag interface

type TagString

type TagString struct {
	Value   string
	TagType TagType
}

TagString is for all string type of tag, like ACName,SVCName

func NewSvcTag

func NewSvcTag(svc string) *TagString

NewSvcTag return a new Service-Name tag

func (*TagString) Parse

func (str *TagString) Parse(buf []byte) (int, error)

Parse implements Tag interface

func (TagString) Serialize

func (str TagString) Serialize() ([]byte, error)

Serialize implements Tag interface

func (TagString) String

func (str TagString) String() string

String implements Tag interface

func (TagString) Type

func (str TagString) Type() uint16

Type implements Tag interface

type TagType

type TagType uint16

TagType is the PPPoE tag type

const (
	TagTypeEndOfList         TagType = 0
	TagTypeServiceName       TagType = 257
	TagTypeACName            TagType = 258
	TagTypeHostUniq          TagType = 259
	TagTypeACCookie          TagType = 260
	TagTypeVendorSpecific    TagType = 261
	TagTypeCredits           TagType = 262
	TagTypeMetrics           TagType = 263
	TagTypeSequenceNumber    TagType = 264
	TagTypeCreditScaleFactor TagType = 265
	TagTypeRelaySessionID    TagType = 272
	TagTypeHURL              TagType = 273
	TagTypeMOTM              TagType = 274
	TagTypePPPMaxPayload     TagType = 288
	TagTypeIPRouteAdd        TagType = 289
	TagTypeServiceNameError  TagType = 513
	TagTypeACSystemError     TagType = 514
	TagTypeGenericError      TagType = 515
)

a list of PPPoE tag type

func (TagType) String

func (tag TagType) String() string

Jump to

Keyboard shortcuts

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