github.com/rootless-containers/rootlesskit/v2@v2.3.4/pkg/port/port.go (about)

     1  package port
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  
     7  	"github.com/rootless-containers/rootlesskit/v2/pkg/api"
     8  )
     9  
    10  type Spec struct {
    11  	// Proto is one of ["tcp", "tcp4", "tcp6", "udp", "udp4", "udp6"].
    12  	// "tcp" may cause listening on both IPv4 and IPv6. (Corresponds to Go's net.Listen .)
    13  	Proto      string `json:"proto,omitempty"`
    14  	ParentIP   string `json:"parentIP,omitempty"` // IPv4 or IPv6 address. can be empty (0.0.0.0).
    15  	ParentPort int    `json:"parentPort,omitempty"`
    16  	ChildPort  int    `json:"childPort,omitempty"`
    17  	// ChildIP is an IPv4 or IPv6 address.
    18  	// Default values:
    19  	// - builtin     driver: 127.0.0.1
    20  	// - slirp4netns driver: slirp4netns's child IP, e.g., 10.0.2.100
    21  	ChildIP string `json:"childIP,omitempty"`
    22  }
    23  
    24  type Status struct {
    25  	ID   int  `json:"id"`
    26  	Spec Spec `json:"spec"`
    27  }
    28  
    29  // Manager MUST be thread-safe.
    30  type Manager interface {
    31  	AddPort(ctx context.Context, spec Spec) (*Status, error)
    32  	ListPorts(ctx context.Context) ([]Status, error)
    33  	RemovePort(ctx context.Context, id int) error
    34  }
    35  
    36  // ChildContext is used for RunParentDriver
    37  type ChildContext struct {
    38  	// IP of the tap device
    39  	IP net.IP
    40  }
    41  
    42  // ParentDriver is a driver for the parent process.
    43  type ParentDriver interface {
    44  	Manager
    45  	Info(ctx context.Context) (*api.PortDriverInfo, error)
    46  	// OpaqueForChild typically consists of socket path
    47  	// for controlling child from parent
    48  	OpaqueForChild() map[string]string
    49  	// RunParentDriver signals initComplete when ParentDriver is ready to
    50  	// serve as Manager.
    51  	// RunParentDriver blocks until quit is signaled.
    52  	//
    53  	// ChildContext is optional.
    54  	RunParentDriver(initComplete chan struct{}, quit <-chan struct{}, cctx *ChildContext) error
    55  }
    56  
    57  type ChildDriver interface {
    58  	// RunChildDriver is executed in the child's namespaces, excluding detached-netns.
    59  	RunChildDriver(opaque map[string]string, quit <-chan struct{}, detachedNetNSPath string) error
    60  }