github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/tcpip/transport/packet/endpoint_state.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package packet 16 17 import ( 18 "fmt" 19 "time" 20 21 "github.com/ttpreport/gvisor-ligolo/pkg/tcpip" 22 "github.com/ttpreport/gvisor-ligolo/pkg/tcpip/stack" 23 ) 24 25 // saveReceivedAt is invoked by stateify. 26 func (p *packet) saveReceivedAt() int64 { 27 return p.receivedAt.UnixNano() 28 } 29 30 // loadReceivedAt is invoked by stateify. 31 func (p *packet) loadReceivedAt(nsec int64) { 32 p.receivedAt = time.Unix(0, nsec) 33 } 34 35 // beforeSave is invoked by stateify. 36 func (ep *endpoint) beforeSave() { 37 ep.rcvMu.Lock() 38 defer ep.rcvMu.Unlock() 39 ep.rcvDisabled = true 40 } 41 42 // afterLoad is invoked by stateify. 43 func (ep *endpoint) afterLoad() { 44 ep.mu.Lock() 45 defer ep.mu.Unlock() 46 47 ep.stack = stack.StackFromEnv 48 ep.ops.InitHandler(ep, ep.stack, tcpip.GetStackSendBufferLimits, tcpip.GetStackReceiveBufferLimits) 49 50 if err := ep.stack.RegisterPacketEndpoint(ep.boundNIC, ep.boundNetProto, ep); err != nil { 51 panic(fmt.Sprintf("RegisterPacketEndpoint(%d, %d, _): %s", ep.boundNIC, ep.boundNetProto, err)) 52 } 53 54 ep.rcvMu.Lock() 55 ep.rcvDisabled = false 56 ep.rcvMu.Unlock() 57 }