| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package nested |
| 18 |
|
| 19 |
import ( |
| 20 |
"inet.af/netstack/sync" |
| 21 |
"inet.af/netstack/tcpip" |
| 22 |
"inet.af/netstack/tcpip/header" |
| 23 |
"inet.af/netstack/tcpip/stack" |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
type Endpoint struct { |
| 32 |
child stack.LinkEndpoint |
| 33 |
embedder stack.NetworkDispatcher |
| 34 |
|
| 35 |
|
| 36 |
mu sync.RWMutex |
| 37 |
dispatcher stack.NetworkDispatcher |
| 38 |
} |
| 39 |
|
| 40 |
var _ stack.GSOEndpoint = (*Endpoint)(nil) |
| 41 |
var _ stack.LinkEndpoint = (*Endpoint)(nil) |
| 42 |
var _ stack.NetworkDispatcher = (*Endpoint)(nil) |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
func (e *Endpoint) Init(child stack.LinkEndpoint, embedder stack.NetworkDispatcher) { |
| 49 |
e.child = child |
| 50 |
e.embedder = embedder |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
func (e *Endpoint) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) { |
| 55 |
e.mu.RLock() |
| 56 |
d := e.dispatcher |
| 57 |
e.mu.RUnlock() |
| 58 |
if d != nil { |
| 59 |
d.DeliverNetworkPacket(remote, local, protocol, pkt) |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
func (e *Endpoint) Attach(dispatcher stack.NetworkDispatcher) { |
| 65 |
e.mu.Lock() |
| 66 |
e.dispatcher = dispatcher |
| 67 |
e.mu.Unlock() |
| 68 |
|
| 69 |
|
| 70 |
var pass stack.NetworkDispatcher |
| 71 |
if dispatcher != nil { |
| 72 |
pass = e.embedder |
| 73 |
} |
| 74 |
e.child.Attach(pass) |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
func (e *Endpoint) IsAttached() bool { |
| 79 |
e.mu.RLock() |
| 80 |
isAttached := e.dispatcher != nil |
| 81 |
e.mu.RUnlock() |
| 82 |
return isAttached |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
func (e *Endpoint) MTU() uint32 { |
| 87 |
return e.child.MTU() |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
func (e *Endpoint) Capabilities() stack.LinkEndpointCapabilities { |
| 92 |
return e.child.Capabilities() |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
func (e *Endpoint) MaxHeaderLength() uint16 { |
| 97 |
return e.child.MaxHeaderLength() |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
func (e *Endpoint) LinkAddress() tcpip.LinkAddress { |
| 102 |
return e.child.LinkAddress() |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
func (e *Endpoint) WritePacket(r stack.RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error { |
| 107 |
return e.child.WritePacket(r, protocol, pkt) |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
func (e *Endpoint) WritePackets(r stack.RouteInfo, pkts stack.PacketBufferList, protocol tcpip.NetworkProtocolNumber) (int, tcpip.Error) { |
| 112 |
return e.child.WritePackets(r, pkts, protocol) |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
func (e *Endpoint) Wait() { |
| 117 |
e.child.Wait() |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
func (e *Endpoint) GSOMaxSize() uint32 { |
| 122 |
if e, ok := e.child.(stack.GSOEndpoint); ok { |
| 123 |
return e.GSOMaxSize() |
| 124 |
} |
| 125 |
return 0 |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
func (e *Endpoint) SupportedGSO() stack.SupportedGSO { |
| 130 |
if e, ok := e.child.(stack.GSOEndpoint); ok { |
| 131 |
return e.SupportedGSO() |
| 132 |
} |
| 133 |
return stack.GSONotSupported |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
func (e *Endpoint) ARPHardwareType() header.ARPHardwareType { |
| 138 |
return e.child.ARPHardwareType() |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
func (e *Endpoint) AddHeader(local, remote tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) { |
| 143 |
e.child.AddHeader(local, remote, protocol, pkt) |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
func (e *Endpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error { |
| 148 |
return e.child.WriteRawPacket(pkt) |
| 149 |
} |