github.com/vishvananda/netlink@v1.3.0/xfrm_linux.go (about)

     1  package netlink
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"golang.org/x/sys/unix"
     7  )
     8  
     9  // Proto is an enum representing an ipsec protocol.
    10  type Proto uint8
    11  
    12  const (
    13  	XFRM_PROTO_ROUTE2    Proto = unix.IPPROTO_ROUTING
    14  	XFRM_PROTO_ESP       Proto = unix.IPPROTO_ESP
    15  	XFRM_PROTO_AH        Proto = unix.IPPROTO_AH
    16  	XFRM_PROTO_HAO       Proto = unix.IPPROTO_DSTOPTS
    17  	XFRM_PROTO_COMP      Proto = unix.IPPROTO_COMP
    18  	XFRM_PROTO_IPSEC_ANY Proto = unix.IPPROTO_RAW
    19  )
    20  
    21  func (p Proto) String() string {
    22  	switch p {
    23  	case XFRM_PROTO_ROUTE2:
    24  		return "route2"
    25  	case XFRM_PROTO_ESP:
    26  		return "esp"
    27  	case XFRM_PROTO_AH:
    28  		return "ah"
    29  	case XFRM_PROTO_HAO:
    30  		return "hao"
    31  	case XFRM_PROTO_COMP:
    32  		return "comp"
    33  	case XFRM_PROTO_IPSEC_ANY:
    34  		return "ipsec-any"
    35  	}
    36  	return fmt.Sprintf("%d", p)
    37  }
    38  
    39  // Mode is an enum representing an ipsec transport.
    40  type Mode uint8
    41  
    42  const (
    43  	XFRM_MODE_TRANSPORT Mode = iota
    44  	XFRM_MODE_TUNNEL
    45  	XFRM_MODE_ROUTEOPTIMIZATION
    46  	XFRM_MODE_IN_TRIGGER
    47  	XFRM_MODE_BEET
    48  	XFRM_MODE_MAX
    49  )
    50  
    51  func (m Mode) String() string {
    52  	switch m {
    53  	case XFRM_MODE_TRANSPORT:
    54  		return "transport"
    55  	case XFRM_MODE_TUNNEL:
    56  		return "tunnel"
    57  	case XFRM_MODE_ROUTEOPTIMIZATION:
    58  		return "ro"
    59  	case XFRM_MODE_IN_TRIGGER:
    60  		return "in_trigger"
    61  	case XFRM_MODE_BEET:
    62  		return "beet"
    63  	}
    64  	return fmt.Sprintf("%d", m)
    65  }
    66  
    67  // XfrmMark represents the mark associated to the state or policy
    68  type XfrmMark struct {
    69  	Value uint32
    70  	Mask  uint32
    71  }
    72  
    73  func (m *XfrmMark) String() string {
    74  	return fmt.Sprintf("(0x%x,0x%x)", m.Value, m.Mask)
    75  }