add support for linux network namespace
This commit is contained in:
@ -38,6 +38,7 @@ func (*route) Dial(ctx context.Context, network, address string, opts ...DialOpt
|
||||
netd := dialer.NetDialer{
|
||||
Timeout: options.Timeout,
|
||||
Interface: options.Interface,
|
||||
Netns: options.Netns,
|
||||
Logger: options.Logger,
|
||||
}
|
||||
if options.SockOpts != nil {
|
||||
@ -95,6 +96,7 @@ func (r *route) Nodes() []*Node {
|
||||
type DialOptions struct {
|
||||
Timeout time.Duration
|
||||
Interface string
|
||||
Netns string
|
||||
SockOpts *SockOpts
|
||||
Logger logger.Logger
|
||||
}
|
||||
@ -113,6 +115,12 @@ func InterfaceDialOption(ifName string) DialOption {
|
||||
}
|
||||
}
|
||||
|
||||
func NetnsDialOption(netns string) DialOption {
|
||||
return func(opts *DialOptions) {
|
||||
opts.Netns = netns
|
||||
}
|
||||
}
|
||||
|
||||
func SockOptsDialOption(so *SockOpts) DialOption {
|
||||
return func(opts *DialOptions) {
|
||||
opts.SockOpts = so
|
||||
|
@ -21,6 +21,7 @@ type RouterOptions struct {
|
||||
Retries int
|
||||
Timeout time.Duration
|
||||
IfceName string
|
||||
Netns string
|
||||
SockOpts *SockOpts
|
||||
Chain Chainer
|
||||
Resolver resolver.Resolver
|
||||
@ -37,6 +38,12 @@ func InterfaceRouterOption(ifceName string) RouterOption {
|
||||
}
|
||||
}
|
||||
|
||||
func NetnsRouterOption(netns string) RouterOption {
|
||||
return func(o *RouterOptions) {
|
||||
o.Netns = netns
|
||||
}
|
||||
}
|
||||
|
||||
func SockOptsRouterOption(so *SockOpts) RouterOption {
|
||||
return func(o *RouterOptions) {
|
||||
o.SockOpts = so
|
||||
@ -181,6 +188,7 @@ func (r *Router) dial(ctx context.Context, network, address string) (conn net.Co
|
||||
}
|
||||
conn, err = route.Dial(ctx, network, ipAddr,
|
||||
InterfaceDialOption(r.options.IfceName),
|
||||
NetnsDialOption(r.options.Netns),
|
||||
SockOptsDialOption(r.options.SockOpts),
|
||||
LoggerDialOption(r.options.Logger),
|
||||
TimeoutDialOption(r.options.Timeout),
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
type TransportOptions struct {
|
||||
Addr string
|
||||
IfceName string
|
||||
Netns string
|
||||
SockOpts *SockOpts
|
||||
Route Route
|
||||
Timeout time.Duration
|
||||
@ -32,6 +33,12 @@ func InterfaceTransportOption(ifceName string) TransportOption {
|
||||
}
|
||||
}
|
||||
|
||||
func NetnsTransportOption(netns string) TransportOption {
|
||||
return func(o *TransportOptions) {
|
||||
o.Netns = netns
|
||||
}
|
||||
}
|
||||
|
||||
func SockOptsTransportOption(so *SockOpts) TransportOption {
|
||||
return func(o *TransportOptions) {
|
||||
o.SockOpts = so
|
||||
@ -73,6 +80,7 @@ func NewTransport(d dialer.Dialer, c connector.Connector, opts ...TransportOptio
|
||||
func (tr *Transport) Dial(ctx context.Context, addr string) (net.Conn, error) {
|
||||
netd := &net_dialer.NetDialer{
|
||||
Interface: tr.options.IfceName,
|
||||
Netns: tr.options.Netns,
|
||||
Timeout: tr.options.Timeout,
|
||||
}
|
||||
if tr.options.SockOpts != nil {
|
||||
@ -108,6 +116,7 @@ func (tr *Transport) Handshake(ctx context.Context, conn net.Conn) (net.Conn, er
|
||||
func (tr *Transport) Connect(ctx context.Context, conn net.Conn, network, address string) (net.Conn, error) {
|
||||
netd := &net_dialer.NetDialer{
|
||||
Interface: tr.options.IfceName,
|
||||
Netns: tr.options.Netns,
|
||||
Timeout: tr.options.Timeout,
|
||||
}
|
||||
if tr.options.SockOpts != nil {
|
||||
|
Reference in New Issue
Block a user