github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/ebpf/end.go (about)

     1  package ebpf
     2  
     3  import "fmt"
     4  
     5  var _ Instruction = (*End16ToLE)(nil)
     6  
     7  type End16ToLE struct {
     8  	Dest Register
     9  }
    10  
    11  func (a *End16ToLE) Raw() ([]RawInstruction, error) {
    12  	return []RawInstruction{
    13  		{Op: BPF_ALU | BPF_END | BPF_TO_LE, Reg: NewReg(0, a.Dest), Imm: 16},
    14  	}, nil
    15  }
    16  
    17  func (a *End16ToLE) String() string {
    18  	return fmt.Sprintf("r%s = le16 r%s", a.Dest, a.Dest)
    19  }
    20  
    21  var _ Instruction = (*End32ToLE)(nil)
    22  
    23  type End32ToLE struct {
    24  	Dest Register
    25  }
    26  
    27  func (a *End32ToLE) Raw() ([]RawInstruction, error) {
    28  	return []RawInstruction{
    29  		{Op: BPF_ALU | BPF_END | BPF_TO_LE, Reg: NewReg(0, a.Dest), Imm: 32},
    30  	}, nil
    31  }
    32  
    33  func (a *End32ToLE) String() string {
    34  	return fmt.Sprintf("r%s = le32 r%s", a.Dest, a.Dest)
    35  }
    36  
    37  var _ Instruction = (*End64ToLE)(nil)
    38  
    39  type End64ToLE struct {
    40  	Dest Register
    41  }
    42  
    43  func (a *End64ToLE) Raw() ([]RawInstruction, error) {
    44  	return []RawInstruction{
    45  		{Op: BPF_ALU | BPF_END | BPF_TO_LE, Reg: NewReg(0, a.Dest), Imm: 64},
    46  	}, nil
    47  }
    48  
    49  func (a *End64ToLE) String() string {
    50  	return fmt.Sprintf("r%s = le64 r%s", a.Dest, a.Dest)
    51  }
    52  
    53  var _ Instruction = (*End16ToBE)(nil)
    54  
    55  type End16ToBE struct {
    56  	Dest Register
    57  }
    58  
    59  func (a *End16ToBE) Raw() ([]RawInstruction, error) {
    60  	return []RawInstruction{
    61  		{Op: BPF_ALU | BPF_END | BPF_TO_BE, Reg: NewReg(0, a.Dest), Imm: 16},
    62  	}, nil
    63  }
    64  
    65  func (a *End16ToBE) String() string {
    66  	return fmt.Sprintf("r%s = be16 r%s", a.Dest, a.Dest)
    67  }
    68  
    69  var _ Instruction = (*End32ToBE)(nil)
    70  
    71  type End32ToBE struct {
    72  	Dest Register
    73  }
    74  
    75  func (a *End32ToBE) Raw() ([]RawInstruction, error) {
    76  	return []RawInstruction{
    77  		{Op: BPF_ALU | BPF_END | BPF_TO_BE, Reg: NewReg(0, a.Dest), Imm: 32},
    78  	}, nil
    79  }
    80  
    81  func (a *End32ToBE) String() string {
    82  	return fmt.Sprintf("r%s = be32 r%s", a.Dest, a.Dest)
    83  }
    84  
    85  var _ Instruction = (*End64ToBE)(nil)
    86  
    87  type End64ToBE struct {
    88  	Dest Register
    89  }
    90  
    91  func (a *End64ToBE) Raw() ([]RawInstruction, error) {
    92  	return []RawInstruction{
    93  		{Op: BPF_ALU | BPF_END | BPF_TO_BE, Reg: NewReg(0, a.Dest), Imm: 64},
    94  	}, nil
    95  }
    96  
    97  func (a *End64ToBE) String() string {
    98  	return fmt.Sprintf("r%s = be64 r%s", a.Dest, a.Dest)
    99  }