// automatically generated by stateify.

package tun

import (
	"context"

	"github.com/sagernet/gvisor/pkg/state"
)

func (d *Device) StateTypeName() string {
	return "pkg/tcpip/link/tun.Device"
}

func (d *Device) StateFields() []string {
	return []string{
		"Queue",
		"endpoint",
		"notifyHandle",
		"flags",
	}
}

// +checklocksignore
func (d *Device) StateSave(stateSinkObject state.Sink) {
	d.beforeSave()
	stateSinkObject.Save(0, &d.Queue)
	stateSinkObject.Save(1, &d.endpoint)
	stateSinkObject.Save(2, &d.notifyHandle)
	stateSinkObject.Save(3, &d.flags)
}

func (d *Device) afterLoad(context.Context) {}

// +checklocksignore
func (d *Device) StateLoad(ctx context.Context, stateSourceObject state.Source) {
	stateSourceObject.Load(0, &d.Queue)
	stateSourceObject.Load(1, &d.endpoint)
	stateSourceObject.Load(2, &d.notifyHandle)
	stateSourceObject.Load(3, &d.flags)
}

func (f *Flags) StateTypeName() string {
	return "pkg/tcpip/link/tun.Flags"
}

func (f *Flags) StateFields() []string {
	return []string{
		"TUN",
		"TAP",
		"NoPacketInfo",
		"Exclusive",
	}
}

func (f *Flags) beforeSave() {}

// +checklocksignore
func (f *Flags) StateSave(stateSinkObject state.Sink) {
	f.beforeSave()
	stateSinkObject.Save(0, &f.TUN)
	stateSinkObject.Save(1, &f.TAP)
	stateSinkObject.Save(2, &f.NoPacketInfo)
	stateSinkObject.Save(3, &f.Exclusive)
}

func (f *Flags) afterLoad(context.Context) {}

// +checklocksignore
func (f *Flags) StateLoad(ctx context.Context, stateSourceObject state.Source) {
	stateSourceObject.Load(0, &f.TUN)
	stateSourceObject.Load(1, &f.TAP)
	stateSourceObject.Load(2, &f.NoPacketInfo)
	stateSourceObject.Load(3, &f.Exclusive)
}

func (e *tunEndpoint) StateTypeName() string {
	return "pkg/tcpip/link/tun.tunEndpoint"
}

func (e *tunEndpoint) StateFields() []string {
	return []string{
		"tunEndpointRefs",
		"Endpoint",
		"stack",
		"nicID",
		"name",
		"isTap",
		"persistent",
		"closed",
	}
}

func (e *tunEndpoint) beforeSave() {}

// +checklocksignore
func (e *tunEndpoint) StateSave(stateSinkObject state.Sink) {
	e.beforeSave()
	stateSinkObject.Save(0, &e.tunEndpointRefs)
	stateSinkObject.Save(1, &e.Endpoint)
	stateSinkObject.Save(2, &e.stack)
	stateSinkObject.Save(3, &e.nicID)
	stateSinkObject.Save(4, &e.name)
	stateSinkObject.Save(5, &e.isTap)
	stateSinkObject.Save(6, &e.persistent)
	stateSinkObject.Save(7, &e.closed)
}

func (e *tunEndpoint) afterLoad(context.Context) {}

// +checklocksignore
func (e *tunEndpoint) StateLoad(ctx context.Context, stateSourceObject state.Source) {
	stateSourceObject.Load(0, &e.tunEndpointRefs)
	stateSourceObject.Load(1, &e.Endpoint)
	stateSourceObject.Load(2, &e.stack)
	stateSourceObject.Load(3, &e.nicID)
	stateSourceObject.Load(4, &e.name)
	stateSourceObject.Load(5, &e.isTap)
	stateSourceObject.Load(6, &e.persistent)
	stateSourceObject.Load(7, &e.closed)
}

func (r *tunEndpointRefs) StateTypeName() string {
	return "pkg/tcpip/link/tun.tunEndpointRefs"
}

func (r *tunEndpointRefs) StateFields() []string {
	return []string{
		"refCount",
	}
}

func (r *tunEndpointRefs) beforeSave() {}

// +checklocksignore
func (r *tunEndpointRefs) StateSave(stateSinkObject state.Sink) {
	r.beforeSave()
	stateSinkObject.Save(0, &r.refCount)
}

// +checklocksignore
func (r *tunEndpointRefs) StateLoad(ctx context.Context, stateSourceObject state.Source) {
	stateSourceObject.Load(0, &r.refCount)
	stateSourceObject.AfterLoad(func() { r.afterLoad(ctx) })
}

func init() {
	state.Register((*Device)(nil))
	state.Register((*Flags)(nil))
	state.Register((*tunEndpoint)(nil))
	state.Register((*tunEndpointRefs)(nil))
}
