add support for icmpv6
This commit is contained in:
@ -19,9 +19,11 @@ import (
|
||||
|
||||
func init() {
|
||||
registry.ListenerRegistry().Register("icmp", NewListener)
|
||||
registry.ListenerRegistry().Register("icmp6", NewListener6)
|
||||
}
|
||||
|
||||
type icmpListener struct {
|
||||
ip6 bool
|
||||
ln quic.EarlyListener
|
||||
cqueue chan net.Conn
|
||||
errChan chan error
|
||||
@ -41,6 +43,18 @@ func NewListener(opts ...listener.Option) listener.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
func NewListener6(opts ...listener.Option) listener.Listener {
|
||||
options := listener.Options{}
|
||||
for _, opt := range opts {
|
||||
opt(&options)
|
||||
}
|
||||
return &icmpListener{
|
||||
ip6: true,
|
||||
logger: options.Logger,
|
||||
options: options,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *icmpListener) Init(md md.Metadata) (err error) {
|
||||
if err = l.parseMetadata(md); err != nil {
|
||||
return
|
||||
@ -52,11 +66,15 @@ func (l *icmpListener) Init(md md.Metadata) (err error) {
|
||||
}
|
||||
|
||||
var conn net.PacketConn
|
||||
conn, err = icmp.ListenPacket("ip4:icmp", addr)
|
||||
if l.ip6 {
|
||||
conn, err = icmp.ListenPacket("ip6:ipv6-icmp", addr)
|
||||
} else {
|
||||
conn, err = icmp.ListenPacket("ip4:icmp", addr)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
conn = icmp_pkg.ServerConn(conn)
|
||||
conn = icmp_pkg.ServerConn(l.ip6, conn)
|
||||
conn = metrics.WrapPacketConn(l.options.Service, conn)
|
||||
conn = stats.WrapPacketConn(conn, l.options.Stats)
|
||||
conn = admission.WrapPacketConn(l.options.Admission, conn)
|
||||
|
@ -20,28 +20,19 @@ type metadata struct {
|
||||
}
|
||||
|
||||
func (l *icmpListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
keepAlive = "keepAlive"
|
||||
keepAlivePeriod = "ttl"
|
||||
handshakeTimeout = "handshakeTimeout"
|
||||
maxIdleTimeout = "maxIdleTimeout"
|
||||
|
||||
backlog = "backlog"
|
||||
)
|
||||
|
||||
l.md.backlog = mdutil.GetInt(md, backlog)
|
||||
l.md.backlog = mdutil.GetInt(md, "backlog")
|
||||
if l.md.backlog <= 0 {
|
||||
l.md.backlog = defaultBacklog
|
||||
}
|
||||
|
||||
if mdutil.GetBool(md, keepAlive) {
|
||||
l.md.keepAlivePeriod = mdutil.GetDuration(md, keepAlivePeriod)
|
||||
if mdutil.GetBool(md, "keepalive") {
|
||||
l.md.keepAlivePeriod = mdutil.GetDuration(md, "ttl")
|
||||
if l.md.keepAlivePeriod <= 0 {
|
||||
l.md.keepAlivePeriod = 10 * time.Second
|
||||
}
|
||||
}
|
||||
l.md.handshakeTimeout = mdutil.GetDuration(md, handshakeTimeout)
|
||||
l.md.maxIdleTimeout = mdutil.GetDuration(md, maxIdleTimeout)
|
||||
l.md.handshakeTimeout = mdutil.GetDuration(md, "handshakeTimeout")
|
||||
l.md.maxIdleTimeout = mdutil.GetDuration(md, "maxIdleTimeout")
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -11,10 +11,7 @@ type metadata struct {
|
||||
}
|
||||
|
||||
func (l *redirectListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
tproxy = "tproxy"
|
||||
)
|
||||
l.md.tproxy = mdutil.GetBool(md, tproxy)
|
||||
l.md.tproxy = mdutil.GetBool(md, "tproxy")
|
||||
l.md.mptcp = mdutil.GetBool(md, "mptcp")
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user