-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
63 lines (52 loc) · 1.71 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package lldpd
import (
"net"
)
// InterfaceFilterFn is the function used to filter interface
// This function is called once for every interface the daemon
// can potentially listen on. It should return true if the
// daemon should listen on the interface.
type InterfaceFilterFn func(*net.Interface) bool
var defaultInterfaceFilterFn InterfaceFilterFn = func(_ *net.Interface) bool { return true }
// InterfaceFilter allows a user to filter interfaces
func InterfaceFilter(fn InterfaceFilterFn) Option {
return func(l *LLDPD) error {
l.filterFn = fn
return nil
}
}
// ReplyUnicast instructs the daemon to send lldp PDU's to the
// src mac address, instead of the lldp broadcast address
func ReplyUnicast() Option {
return func(l *LLDPD) error {
l.replyUnicast = true
return nil
}
}
// SourceAddress sets the ethernet source address to use
// for LLDP PDU's
func SourceAddress(addr net.HardwareAddr) Option {
return func(l *LLDPD) error {
l.sourceAddress = addr
return nil
}
}
// PortLookupFn is the function used to respond with a different
// port description. This function is called once, on first receive
// of an LLDP PDU on a port and the reply is cached untill restart.
type PortLookupFn func(*net.Interface) string
var defaultPortLookupFn PortLookupFn = func(ifi *net.Interface) string { return ifi.Name }
// PortLookup allows a user to use a different port description
// lookup mechanism
func PortLookup(fn PortLookupFn) Option {
return func(l *LLDPD) error {
l.portLookupFn = fn
return nil
}
}
// Option is a functional option handler for LLDPD.
type Option func(*LLDPD) error
// SetOption runs a functional option against LLDPD.
func (p *LLDPD) SetOption(option Option) error {
return option(p)
}