Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies to latest #135

Merged
merged 2 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ require (
github.com/coreos/stream-metadata-go v0.3.0
github.com/dustin/go-humanize v1.0.0
github.com/google/gopacket v1.1.19
github.com/google/tcpproxy v0.0.0-20200125044825-b6bb9b5b8252
github.com/insomniacslk/dhcp v0.0.0-20210812084645-decc701b3665
github.com/linuxkit/virtsock v0.0.0-20201010232012-f8cee7dfc7a3
github.com/insomniacslk/dhcp v0.0.0-20220504074936-1ca156eafb9f
github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2
github.com/mdlayher/vsock v1.1.1
github.com/miekg/dns v1.1.50
github.com/onsi/ginkgo v1.16.5
Expand All @@ -22,10 +21,9 @@ require (
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
github.com/stretchr/testify v1.8.0
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gvisor.dev/gvisor v0.0.0-20220121190119-4f2d380c8b55
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f
gvisor.dev/gvisor v0.0.0-20220722234115-e3e6499abbba
inet.af/tcpproxy v0.0.0-20220326234310-be3ee21c9fa0
)
42 changes: 42 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/services/forwarder/ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import (

"github.com/containers/gvisor-tap-vsock/pkg/sshclient"
"github.com/containers/gvisor-tap-vsock/pkg/types"
"github.com/google/tcpproxy"
log "github.com/sirupsen/logrus"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"inet.af/tcpproxy"
)

type PortsForwarder struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/forwarder/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"net"
"sync"

"github.com/google/tcpproxy"
log "github.com/sirupsen/logrus"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/waiter"
"inet.af/tcpproxy"
)

const linkLocalSubnet = "169.254.0.0/16"
Expand Down
16 changes: 7 additions & 9 deletions pkg/tap/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/google/gopacket/layers"
log "github.com/sirupsen/logrus"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
)
Expand Down Expand Up @@ -57,11 +56,11 @@ func (e *LinkEndpoint) IsAttached() bool {
return e.dispatcher != nil
}

func (e *LinkEndpoint) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
e.dispatcher.DeliverNetworkPacket(remote, local, protocol, pkt)
func (e *LinkEndpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
e.dispatcher.DeliverNetworkPacket(protocol, pkt)
}

func (e *LinkEndpoint) AddHeader(local, remote tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *LinkEndpoint) AddHeader(pkt *stack.PacketBuffer) {
}

func (e *LinkEndpoint) Capabilities() stack.LinkEndpointCapabilities {
Expand All @@ -85,7 +84,7 @@ func (e *LinkEndpoint) Wait() {

func (e *LinkEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) {
n := 0
for p := pkts.Front(); p != nil; p = p.Next() {
for _, p := range pkts.AsSlice() {
if err := e.writePacket(p.EgressRoute, p.NetworkProtocolNumber, p); err != nil {
return n, err
}
Expand All @@ -107,7 +106,7 @@ func (e *LinkEndpoint) writePacket(r stack.RouteInfo, protocol tcpip.NetworkProt
DstAddr: r.RemoteLinkAddress,
})

h := header.ARP(pkt.NetworkHeader().View())
h := header.ARP(pkt.NetworkHeader().Slice())
if h.IsValid() &&
h.Op() == header.ARPReply {
ip := tcpip.Address(h.ProtocolAddressSender()).String()
Expand All @@ -119,12 +118,11 @@ func (e *LinkEndpoint) writePacket(r stack.RouteInfo, protocol tcpip.NetworkProt
}

if e.debug {
vv := buffer.NewVectorisedView(pkt.Size(), pkt.Views())
packet := gopacket.NewPacket(vv.ToView(), layers.LayerTypeEthernet, gopacket.Default)
packet := gopacket.NewPacket(pkt.ToView().AsSlice(), layers.LayerTypeEthernet, gopacket.Default)
log.Info(packet.String())
}

e.networkSwitch.DeliverNetworkPacket(r.RemoteLinkAddress, srcAddr, protocol, pkt)
e.networkSwitch.DeliverNetworkPacket(protocol, pkt)
return nil
}

Expand Down
84 changes: 32 additions & 52 deletions pkg/tap/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import (
"github.com/google/gopacket/layers"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"gvisor.dev/gvisor/pkg/bufferv2"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
)

type VirtualDevice interface {
DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer)
DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer)
LinkAddress() tcpip.LinkAddress
IP() string
}

type NetworkSwitch interface {
DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer)
DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer)
}

type Switch struct {
Expand Down Expand Up @@ -73,8 +73,8 @@ func (e *Switch) Connect(ep VirtualDevice) {
e.gateway = ep
}

func (e *Switch) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
if err := e.tx(local, remote, pkt); err != nil {
func (e *Switch) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
if err := e.tx(pkt); err != nil {
log.Error(err)
}
}
Expand Down Expand Up @@ -111,30 +111,35 @@ func (e *Switch) connect(conn net.Conn) (int, bool) {
return id, false
}

func (e *Switch) tx(src, dst tcpip.LinkAddress, pkt *stack.PacketBuffer) error {
func (e *Switch) tx(pkt *stack.PacketBuffer) error {
if e.protocol.Stream() {
return e.txStream(src, dst, pkt, e.protocol.(streamProtocol))
return e.txStream(pkt, e.protocol.(streamProtocol))
}
return e.txNonStream(src, dst, pkt)
return e.txNonStream(pkt)
}

func (e *Switch) txNonStream(src, dst tcpip.LinkAddress, pkt *stack.PacketBuffer) error {
return e.txBuf(src, dst, pkt, nil)
func (e *Switch) txNonStream(pkt *stack.PacketBuffer) error {
return e.txBuf(pkt, nil)
}

func (e *Switch) txStream(src, dst tcpip.LinkAddress, pkt *stack.PacketBuffer, sProtocol streamProtocol) error {
func (e *Switch) txStream(pkt *stack.PacketBuffer, sProtocol streamProtocol) error {
size := sProtocol.Buf()
sProtocol.Write(size, pkt.Size())
return e.txBuf(src, dst, pkt, size)
return e.txBuf(pkt, size)
}

func (e *Switch) txBuf(src, dst tcpip.LinkAddress, pkt *stack.PacketBuffer, size []byte) error {
func (e *Switch) txBuf(pkt *stack.PacketBuffer, size []byte) error {
e.writeLock.Lock()
defer e.writeLock.Unlock()

e.connLock.Lock()
defer e.connLock.Unlock()

buf := pkt.ToView().AsSlice()
eth := header.Ethernet(buf)
dst := eth.DestinationAddress()
src := eth.SourceAddress()

if dst == header.EthernetBroadcastAddress {
e.camLock.RLock()
srcID, ok := e.cam[src]
Expand All @@ -151,21 +156,10 @@ func (e *Switch) txBuf(src, dst tcpip.LinkAddress, pkt *stack.PacketBuffer, size
e.disconnect(id, conn)
return err
}
for _, view := range pkt.Views() {
if _, err := conn.Write(view); err != nil {
e.disconnect(id, conn)
return err
}
}
} else {
var b []byte
for _, view := range pkt.Views() {
b = append(b, []byte(view)...)
}
if _, err := conn.Write(b); err != nil {
e.disconnect(id, conn)
return err
}
}
if _, err := conn.Write(buf); err != nil {
e.disconnect(id, conn)
return err
}

atomic.AddUint64(&e.Sent, uint64(pkt.Size()))
Expand All @@ -184,21 +178,10 @@ func (e *Switch) txBuf(src, dst tcpip.LinkAddress, pkt *stack.PacketBuffer, size
e.disconnect(id, conn)
return err
}
for _, view := range pkt.Views() {
if _, err := conn.Write(view); err != nil {
e.disconnect(id, conn)
return err
}
}
} else {
var b []byte
for _, view := range pkt.Views() {
b = append(b, []byte(view)...)
}
if _, err := conn.Write(b); err != nil {
e.disconnect(id, conn)
return err
}
}
if _, err := conn.Write(buf); err != nil {
e.disconnect(id, conn)
return err
}
atomic.AddUint64(&e.Sent, uint64(pkt.Size()))
}
Expand Down Expand Up @@ -277,29 +260,26 @@ func (e *Switch) rxBuf(ctx context.Context, id int, buf []byte) {
log.Info(packet.String())
}

view := buffer.View(buf)
eth := header.Ethernet(view)
vv := buffer.NewVectorisedView(len(view), []buffer.View{view})
eth := header.Ethernet(buf)

e.camLock.Lock()
e.cam[eth.SourceAddress()] = id
e.camLock.Unlock()

if eth.DestinationAddress() != e.gateway.LinkAddress() {
if err := e.tx(eth.SourceAddress(), eth.DestinationAddress(), stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: vv,
if err := e.tx(stack.NewPacketBuffer(stack.PacketBufferOptions{
Payload: bufferv2.MakeWithData(buf),
})); err != nil {
log.Error(err)
}
}
if eth.DestinationAddress() == e.gateway.LinkAddress() || eth.DestinationAddress() == header.EthernetBroadcastAddress {
vv.TrimFront(header.EthernetMinimumSize)
data := bufferv2.MakeWithData(buf)
data.TrimFront(header.EthernetMinimumSize)
e.gateway.DeliverNetworkPacket(
eth.SourceAddress(),
eth.DestinationAddress(),
eth.Type(),
stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: vv,
Payload: data,
}),
)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/virtualnetwork/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"strconv"

"github.com/containers/gvisor-tap-vsock/pkg/types"
"github.com/google/tcpproxy"
log "github.com/sirupsen/logrus"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"inet.af/tcpproxy"
)

func (n *VirtualNetwork) Mux() *http.ServeMux {
Expand Down
2 changes: 0 additions & 2 deletions vendor/github.com/google/tcpproxy/.gitignore

This file was deleted.

15 changes: 3 additions & 12 deletions vendor/github.com/insomniacslk/dhcp/dhcpv4/dhcpv4.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading