diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-23 10:45:11 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-23 21:43:01 +0100 |
commit | dd357236f156b3be8cc8e4de2787e4ba08f3c68c (patch) | |
tree | ec6ef6458910064d4d9ddfae553d14cc084afd2d | |
parent | 9acc1a73ccb686afeaf02dec521311235745ad26 (diff) |
fix indent
-rw-r--r-- | pkg/tcpip/header/gre.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/link/channel/channel.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/link/gre/gre.go | 34 | ||||
-rw-r--r-- | pkg/tcpip/sample/tun_tcp_connect/main.go | 184 | ||||
-rw-r--r-- | pkg/tcpip/transport/gre/protocol.go | 10 |
5 files changed, 116 insertions, 116 deletions
diff --git a/pkg/tcpip/header/gre.go b/pkg/tcpip/header/gre.go index f5c52cd1b..6b85ecf6e 100644 --- a/pkg/tcpip/header/gre.go +++ b/pkg/tcpip/header/gre.go @@ -14,7 +14,7 @@ const ( type GRE []byte const ( - GREHeaderSize = 4 + GREHeaderSize = 4 // GREProtocolNumber is GRE's transport protocol number. GREProtocolNumber tcpip.TransportProtocolNumber = 47 diff --git a/pkg/tcpip/link/channel/channel.go b/pkg/tcpip/link/channel/channel.go index caf20e718..3f9d41887 100644 --- a/pkg/tcpip/link/channel/channel.go +++ b/pkg/tcpip/link/channel/channel.go @@ -131,7 +131,7 @@ type Endpoint struct { mtu uint32 linkAddr tcpip.LinkAddress LinkEPCapabilities stack.LinkEndpointCapabilities - NMaxHeaderLength uint16 + NMaxHeaderLength uint16 // Outbound packet queue. q *queue diff --git a/pkg/tcpip/link/gre/gre.go b/pkg/tcpip/link/gre/gre.go index 04f8f8da7..d177c3648 100644 --- a/pkg/tcpip/link/gre/gre.go +++ b/pkg/tcpip/link/gre/gre.go @@ -1,10 +1,10 @@ package gre import ( - "math" - "net" + "math" + "net" "log" - "os" + "os" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/header" @@ -33,11 +33,11 @@ func New(mtu uint32) *Endpoint{ } func (e *Endpoint) GetChannel() *channel.Endpoint { - return &e.Endpoint + return &e.Endpoint } func (e *Endpoint) Bind(s *stack.Stack, laddr tcpip.FullAddress) { - log.Println("Bind begin") + log.Println("Bind begin") // Create TCP endpoint. var wq waiter.Queue @@ -45,19 +45,19 @@ func (e *Endpoint) Bind(s *stack.Stack, laddr tcpip.FullAddress) { if err != nil { log.Fatal(err) } - log.Println("EP: %s", ep) + log.Println("EP: %s", ep) - raddr := tcpip.FullAddress{NIC: 1, Addr: tcpip.Address(net.ParseIP("10.0.0.1"))} - log.Println("Remote:", raddr.Addr, raddr) + raddr := tcpip.FullAddress{NIC: 1, Addr: tcpip.Address(net.ParseIP("10.0.0.1"))} + log.Println("Remote:", raddr.Addr, raddr) - if err := ep.Bind(tcpip.FullAddress{1, "", 0}); err != nil { - log.Fatal("Bind failed: ", err) - } + if err := ep.Bind(tcpip.FullAddress{1, "", 0}); err != nil { + log.Fatal("Bind failed: ", err) + } + + // if err := ep.Connect(raddr); err != nil { + // log.Fatal("Connect failed: ", err) + // } - // if err := ep.Connect(raddr); err != nil { - // log.Fatal("Connect failed: ", err) - // } - // Issue connect request and wait for it to complete. waitEntry, notifyCh := waiter.NewChannelEntry(nil) @@ -80,13 +80,13 @@ func (e *Endpoint) Bind(s *stack.Stack, laddr tcpip.FullAddress) { } } wq.EventUnregister(&waitEntry) - log.Println("Bind end") + log.Println("Bind end") } // Attach saves the stack network-layer dispatcher for use later when packets // are injected. func (e *Endpoint) Attach(dispatcher stack.NetworkDispatcher) { - log.Println("GRE: Attach") + log.Println("GRE: Attach") e.Endpoint.Attach(dispatcher) } diff --git a/pkg/tcpip/sample/tun_tcp_connect/main.go b/pkg/tcpip/sample/tun_tcp_connect/main.go index 06ee5110b..762c6dc29 100644 --- a/pkg/tcpip/sample/tun_tcp_connect/main.go +++ b/pkg/tcpip/sample/tun_tcp_connect/main.go @@ -41,7 +41,7 @@ package main import ( - "context" + "context" "bufio" "fmt" "log" @@ -99,71 +99,71 @@ func writer(ch chan struct{}, ep tcpip.Endpoint) { } type GrePacketInfo struct { - pi *channel.PacketInfo + pi *channel.PacketInfo } func (g GrePacketInfo) FullPayload() ([]byte, *tcpip.Error){ - log.Println("FullPayload") - pkt := g.pi.Pkt - size := pkt.Size() - vv := buffer.NewVectorisedView(size, pkt.Views()) - var buf = make([]byte, size, size) - pos := 0 - for { - copied, err := vv.Read(buf[pos:]) - log.Printf("VectorisedView Read: %d %d %d %v", size, pos, copied, err) - if err != nil { - return nil, tcpip.ErrBadBuffer - } - pos = pos + copied - if pos == size { - break - } - } - - log.Printf("FullPayload return: %d %v", len(buf), buf) - return buf, nil + log.Println("FullPayload") + pkt := g.pi.Pkt + size := pkt.Size() + vv := buffer.NewVectorisedView(size, pkt.Views()) + var buf = make([]byte, size, size) + pos := 0 + for { + copied, err := vv.Read(buf[pos:]) + log.Printf("VectorisedView Read: %d %d %d %v", size, pos, copied, err) + if err != nil { + return nil, tcpip.ErrBadBuffer + } + pos = pos + copied + if pos == size { + break + } + } + + log.Printf("FullPayload return: %d %v", len(buf), buf) + return buf, nil } func (g GrePacketInfo) Payload(size int) ([]byte, *tcpip.Error){ - log.Println("Payload") - return nil, tcpip.ErrNotSupported + log.Println("Payload") + return nil, tcpip.ErrNotSupported } type GreHandlerInfo struct { - ChEp *channel.Endpoint - Raw tcpip.Endpoint - Raddr tcpip.FullAddress + ChEp *channel.Endpoint + Raw tcpip.Endpoint + Raddr tcpip.FullAddress } func (info *GreHandlerInfo) greHandler(req *gre.ForwarderRequest) { - pkt := req.Pkt - log.Println("greHandler: ", req.Pkt.Size(), req.Pkt.Views()) - greHdr := header.GRE(pkt.TransportHeader().View()) - proto := greHdr.ProtocolType() - views := pkt.Data.Views() - size := pkt.Data.Size() - data := buffer.NewVectorisedView(size, views) + pkt := req.Pkt + log.Println("greHandler: ", req.Pkt.Size(), req.Pkt.Views()) + greHdr := header.GRE(pkt.TransportHeader().View()) + proto := greHdr.ProtocolType() + views := pkt.Data.Views() + size := pkt.Data.Size() + data := buffer.NewVectorisedView(size, views) newPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{ Data: data, }) - log.Printf("greHandler proto: %d cloned: %v", proto, newPkt.Views()) + log.Printf("greHandler proto: %d cloned: %v", proto, newPkt.Views()) - info.ChEp.InjectInbound(proto, newPkt) + info.ChEp.InjectInbound(proto, newPkt) } func (info *GreHandlerInfo) greRead(ep *channel.Endpoint) { - for { - pi, err := ep.ReadContext(context.Background()); - linkHdr := pi.Pkt.LinkHeader() - greHdr := header.GRE(linkHdr.Push(header.GREHeaderSize)) - greHdr.SetProtocolType(pi.Proto) - log.Printf("greRead %d %v %v %v", pi.Proto, pi, err, greHdr) - opts := tcpip.WriteOptions{ - //To: &info.Raddr - } - info.Raw.Write(GrePacketInfo{&pi}, opts) - } + for { + pi, err := ep.ReadContext(context.Background()); + linkHdr := pi.Pkt.LinkHeader() + greHdr := header.GRE(linkHdr.Push(header.GREHeaderSize)) + greHdr.SetProtocolType(pi.Proto) + log.Printf("greRead %d %v %v %v", pi.Proto, pi, err, greHdr) + opts := tcpip.WriteOptions{ + //To: &info.Raddr + } + info.Raw.Write(GrePacketInfo{&pi}, opts) + } } func main() { @@ -176,8 +176,8 @@ func main() { portName := os.Args[3] remoteAddrName := os.Args[4] remotePortName := os.Args[5] - greAddrName := os.Args[6] - greRemoteAddrName := os.Args[7] + greAddrName := os.Args[6] + greRemoteAddrName := os.Args[7] rand.Seed(time.Now().UnixNano()) @@ -189,7 +189,7 @@ func main() { Addr: tcpip.Address(net.ParseIP(remoteAddrName).To4()), } - log.Printf("local:%v remote:%v", addr, remote) + log.Printf("local:%v remote:%v", addr, remote) var localPort uint16 if v, err := strconv.Atoi(portName); err != nil { @@ -239,48 +239,48 @@ func main() { if tcperr != nil { log.Fatal(tcperr) } - log.Println("EP: %s", rawEp) - - raddr := greRemoteAddr - fraddr := tcpip.FullAddress{NIC: 1, Addr: raddr} - fgreAddr := tcpip.FullAddress{NIC: 1, Addr: greAddr} - tcperr = rawEp.Bind(fgreAddr) - if tcperr != nil { - log.Fatal(tcperr) - } - log.Printf("Remote: %v %v", raddr, fraddr) - - // Create GRE - greEP := grelink.New(mtu - 24) - chEP := greEP.GetChannel() - // TODO detect IPv4/IPv6 - greEP.NMaxHeaderLength = header.IPv6FixedHeaderSize + header.GREHeaderSize - - greInfo := GreHandlerInfo{ -// Ep: loEP, - ChEp: chEP, - Raw: rawEp, - Raddr: fraddr, - } - greFwd := gre.NewForwarder(s, greInfo.greHandler) - s.SetTransportProtocolHandler(header.GREProtocolNumber, greFwd.HandlePacket) - - go greInfo.greRead(chEP) - //greEP.Bind(s, greIP) + log.Println("EP: %s", rawEp) + + raddr := greRemoteAddr + fraddr := tcpip.FullAddress{NIC: 1, Addr: raddr} + fgreAddr := tcpip.FullAddress{NIC: 1, Addr: greAddr} + tcperr = rawEp.Bind(fgreAddr) + if tcperr != nil { + log.Fatal(tcperr) + } + log.Printf("Remote: %v %v", raddr, fraddr) + + // Create GRE + greEP := grelink.New(mtu - 24) + chEP := greEP.GetChannel() + // TODO detect IPv4/IPv6 + greEP.NMaxHeaderLength = header.IPv6FixedHeaderSize + header.GREHeaderSize + + greInfo := GreHandlerInfo{ +// Ep: loEP, + ChEp: chEP, + Raw: rawEp, + Raddr: fraddr, + } + greFwd := gre.NewForwarder(s, greInfo.greHandler) + s.SetTransportProtocolHandler(header.GREProtocolNumber, greFwd.HandlePacket) + + go greInfo.greRead(chEP) + //greEP.Bind(s, greIP) if err := s.CreateNIC(2, sniffer.New(greEP)); err != nil { log.Fatal(err) - } + } if err := s.AddAddress(2, ipv4.ProtocolNumber, addr); err != nil { log.Fatal(err) } // Add default route. - subnet, err := tcpip.NewSubnet( - tcpip.Address(net.ParseIP("10.0.0.0").To4()), - tcpip.AddressMask(net.ParseIP("255.255.255.0").To4())) - if err != nil { - panic(err) - } + subnet, err := tcpip.NewSubnet( + tcpip.Address(net.ParseIP("10.0.0.0").To4()), + tcpip.AddressMask(net.ParseIP("255.255.255.0").To4())) + if err != nil { + panic(err) + } s.SetRouteTable([]tcpip.Route{ { Destination: subnet, @@ -291,12 +291,12 @@ func main() { NIC: 2, }, }) - log.Printf("Nics enabled 1:%v 2:%v 3:%v", s.CheckNIC(1), s.CheckNIC(2), s.CheckNIC(3)) + log.Printf("Nics enabled 1:%v 2:%v 3:%v", s.CheckNIC(1), s.CheckNIC(2), s.CheckNIC(3)) - tcperr = rawEp.Connect(fraddr) - if tcperr != nil { - log.Fatal(tcperr) - } + tcperr = rawEp.Connect(fraddr) + if tcperr != nil { + log.Fatal(tcperr) + } // Create TCP endpoint. var wq waiter.Queue @@ -331,8 +331,8 @@ func main() { fmt.Println("Connected") - payload := tcpip.SlicePayload([]byte("GET / HTTP/1.0\r\nHost: www.m7n.se\r\n\r\n")) - ep.Write(payload, tcpip.WriteOptions{}) + payload := tcpip.SlicePayload([]byte("GET / HTTP/1.0\r\nHost: www.m7n.se\r\n\r\n")) + ep.Write(payload, tcpip.WriteOptions{}) // Start the writer in its own goroutine. writerCompletedCh := make(chan struct{}) diff --git a/pkg/tcpip/transport/gre/protocol.go b/pkg/tcpip/transport/gre/protocol.go index b98b5df93..087f61091 100644 --- a/pkg/tcpip/transport/gre/protocol.go +++ b/pkg/tcpip/transport/gre/protocol.go @@ -16,7 +16,7 @@ package gre import ( - "log" + "log" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/buffer" @@ -57,7 +57,7 @@ func (*protocol) Number() tcpip.TransportProtocolNumber { // NewEndpoint creates a new gre endpoint. func (p *protocol) NewEndpoint(netProto tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) { - // return newEndpoint(p.stack, netProto, waiterQueue), nil + // return newEndpoint(p.stack, netProto, waiterQueue), nil return nil, tcpip.ErrUnknownProtocolOption } @@ -69,7 +69,7 @@ func (p *protocol) NewRawEndpoint(netProto tcpip.NetworkProtocolNumber, waiterQu // MinimumPacketSize returns the minimum valid gre packet size. func (*protocol) MinimumPacketSize() int { - // TODO ? + // TODO ? return header.GREHeaderSize } @@ -78,13 +78,13 @@ func (*protocol) MinimumPacketSize() int { func (*protocol) ParsePorts(v buffer.View) (src, dst uint16, err *tcpip.Error) { // h := header.GRE(v) // return h.SourcePort(), h.DestinationPort(), nil - return 0, 0, nil + return 0, 0, nil } // HandleUnknownDestinationPacket handles packets that are targeted at this // protocol but don't match any existing endpoint. func (p *protocol) HandleUnknownDestinationPacket(id stack.TransportEndpointID, pkt *stack.PacketBuffer) stack.UnknownDestinationPacketDisposition { - log.Println("HandleUnknownDestinationPacket") + log.Println("HandleUnknownDestinationPacket") return stack.UnknownDestinationPacketHandled } |