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

     1  package ebpf
     2  
     3  import "fmt"
     4  
     5  var _ Instruction = (*CallHelper)(nil)
     6  
     7  type CallHelper struct {
     8  	Function int32
     9  }
    10  
    11  func (c *CallHelper) Raw() ([]RawInstruction, error) {
    12  	return []RawInstruction{
    13  		{Op: BPF_CALL | BPF_JMP, Reg: NewReg(0, 0), Imm: c.Function},
    14  	}, nil
    15  }
    16  
    17  func (c *CallHelper) String() string {
    18  	return fmt.Sprintf("call %d#%s", c.Function, BPFHelperFuncNumToStr[c.Function])
    19  }
    20  
    21  // CallHelperIndirect is illegal in the linux kernel, but we have it here to support non-kernel eBPF implementation.
    22  // This instruction is generated by clang when optimizations are disabled.
    23  type CallHelperIndirect struct {
    24  	Register Register
    25  }
    26  
    27  func (c *CallHelperIndirect) Raw() ([]RawInstruction, error) {
    28  	return []RawInstruction{
    29  		{Op: BPF_CALLX | BPF_JMP, Reg: NewReg(0, 0), Imm: int32(c.Register)},
    30  	}, nil
    31  }
    32  
    33  func (c *CallHelperIndirect) String() string {
    34  	return fmt.Sprintf("callx r%s", c.Register)
    35  }
    36  
    37  // BPFHelperFuncNumToStr is a translation tables from the helper function ids/numbers to their string form.
    38  // These are based on https://github.com/libbpf/libbpf/blob/master/src/bpf_helper_defs.h
    39  var BPFHelperFuncNumToStr = map[int32]string{
    40  	1:   "bpf_map_lookup_elem",
    41  	2:   "bpf_map_update_elem",
    42  	3:   "bpf_map_delete_elem",
    43  	4:   "bpf_probe_read",
    44  	5:   "bpf_ktime_get_ns",
    45  	6:   "bpf_trace_printk",
    46  	7:   "bpf_get_prandom_u32",
    47  	8:   "bpf_get_smp_processor_id",
    48  	9:   "bpf_skb_store_bytes",
    49  	10:  "bpf_l3_csum_replace",
    50  	11:  "bpf_l4_csum_replace",
    51  	12:  "bpf_tail_call",
    52  	13:  "bpf_clone_redirect",
    53  	14:  "bpf_get_current_pid_tgid",
    54  	15:  "bpf_get_current_uid_gid",
    55  	16:  "bpf_get_current_comm",
    56  	17:  "bpf_get_cgroup_classid",
    57  	18:  "bpf_skb_vlan_push",
    58  	19:  "bpf_skb_vlan_pop",
    59  	20:  "bpf_skb_get_tunnel_key",
    60  	21:  "bpf_skb_set_tunnel_key",
    61  	22:  "bpf_perf_event_read",
    62  	23:  "bpf_redirect",
    63  	24:  "bpf_get_route_realm",
    64  	25:  "bpf_perf_event_output",
    65  	26:  "bpf_skb_load_bytes",
    66  	27:  "bpf_get_stackid",
    67  	28:  "bpf_csum_diff",
    68  	29:  "bpf_skb_get_tunnel_opt",
    69  	30:  "bpf_skb_set_tunnel_opt",
    70  	31:  "bpf_skb_change_proto",
    71  	32:  "bpf_skb_change_type",
    72  	33:  "bpf_skb_under_cgroup",
    73  	34:  "bpf_get_hash_recalc",
    74  	35:  "bpf_get_current_task",
    75  	36:  "bpf_probe_write_user",
    76  	37:  "bpf_current_task_under_cgroup",
    77  	38:  "bpf_skb_change_tail",
    78  	39:  "bpf_skb_pull_data",
    79  	40:  "bpf_csum_update",
    80  	41:  "bpf_set_hash_invalid",
    81  	42:  "bpf_get_numa_node_id",
    82  	43:  "bpf_skb_change_head",
    83  	44:  "bpf_xdp_adjust_head",
    84  	45:  "bpf_probe_read_str",
    85  	46:  "bpf_get_socket_cookie",
    86  	47:  "bpf_get_socket_uid",
    87  	48:  "bpf_set_hash",
    88  	49:  "bpf_setsockopt",
    89  	50:  "bpf_skb_adjust_room",
    90  	51:  "bpf_redirect_map",
    91  	52:  "bpf_sk_redirect_map",
    92  	53:  "bpf_sock_map_update",
    93  	54:  "bpf_xdp_adjust_meta",
    94  	55:  "bpf_perf_event_read_value",
    95  	56:  "bpf_perf_prog_read_value",
    96  	57:  "bpf_getsockopt",
    97  	58:  "bpf_override_return",
    98  	59:  "bpf_sock_ops_cb_flags_set",
    99  	60:  "bpf_msg_redirect_map",
   100  	61:  "bpf_msg_apply_bytes",
   101  	62:  "bpf_msg_cork_bytes",
   102  	63:  "bpf_msg_pull_data",
   103  	64:  "bpf_bind",
   104  	65:  "bpf_xdp_adjust_tail",
   105  	66:  "bpf_skb_get_xfrm_state",
   106  	67:  "bpf_get_stack",
   107  	68:  "bpf_skb_load_bytes_relative",
   108  	69:  "bpf_fib_lookup",
   109  	70:  "bpf_sock_hash_update",
   110  	71:  "bpf_msg_redirect_hash",
   111  	72:  "bpf_sk_redirect_hash",
   112  	73:  "bpf_lwt_push_encap",
   113  	74:  "bpf_lwt_seg6_store_bytes",
   114  	75:  "bpf_lwt_seg6_adjust_srh",
   115  	76:  "bpf_lwt_seg6_action",
   116  	77:  "bpf_rc_repeat",
   117  	78:  "bpf_rc_keydown",
   118  	79:  "bpf_skb_cgroup_id",
   119  	80:  "bpf_get_current_cgroup_id",
   120  	81:  "bpf_get_local_storage",
   121  	82:  "bpf_sk_select_reuseport",
   122  	83:  "bpf_skb_ancestor_cgroup_id",
   123  	84:  "bpf_sk_lookup_tcp",
   124  	85:  "bpf_sk_lookup_udp",
   125  	86:  "bpf_sk_release",
   126  	87:  "bpf_map_push_elem",
   127  	88:  "bpf_map_pop_elem",
   128  	89:  "bpf_map_peek_elem",
   129  	90:  "bpf_msg_push_data",
   130  	91:  "bpf_msg_pop_data",
   131  	92:  "bpf_rc_pointer_rel",
   132  	93:  "bpf_spin_lock",
   133  	94:  "bpf_spin_unlock",
   134  	95:  "bpf_sk_fullsock",
   135  	96:  "bpf_tcp_sock",
   136  	97:  "bpf_skb_ecn_set_ce",
   137  	98:  "bpf_get_listener_sock",
   138  	99:  "bpf_skc_lookup_tcp",
   139  	100: "bpf_tcp_check_syncookie",
   140  	101: "bpf_sysctl_get_name",
   141  	102: "bpf_sysctl_get_current_value",
   142  	103: "bpf_sysctl_get_new_value",
   143  	104: "bpf_sysctl_set_new_value",
   144  	105: "bpf_strtol",
   145  	106: "bpf_strtoul",
   146  	107: "bpf_sk_storage_get",
   147  	108: "bpf_sk_storage_delete",
   148  	109: "bpf_send_signal",
   149  	110: "bpf_tcp_gen_syncookie",
   150  	111: "bpf_skb_output",
   151  	112: "bpf_probe_read_user",
   152  	113: "bpf_probe_read_kernel",
   153  	114: "bpf_probe_read_user_str",
   154  	115: "bpf_probe_read_kernel_str",
   155  	116: "bpf_tcp_send_ack",
   156  	117: "bpf_send_signal_thread",
   157  	118: "bpf_jiffies64",
   158  	119: "bpf_read_branch_records",
   159  	120: "bpf_get_ns_current_pid_tgid",
   160  	121: "bpf_xdp_output",
   161  	122: "bpf_get_netns_cookie",
   162  	123: "bpf_get_current_ancestor_cgroup_id",
   163  	124: "bpf_sk_assign",
   164  	125: "bpf_ktime_get_boot_ns",
   165  	126: "bpf_seq_printf",
   166  	127: "bpf_seq_write",
   167  	128: "bpf_sk_cgroup_id",
   168  	129: "bpf_sk_ancestor_cgroup_id",
   169  	130: "bpf_ringbuf_output",
   170  	131: "bpf_ringbuf_reserve",
   171  	132: "bpf_ringbuf_submit",
   172  	133: "bpf_ringbuf_discard",
   173  	134: "bpf_ringbuf_query",
   174  	135: "bpf_csum_level",
   175  	136: "bpf_skc_to_tcp6_sock",
   176  	137: "bpf_skc_to_tcp_sock",
   177  	138: "bpf_skc_to_tcp_timewait_sock",
   178  	139: "bpf_skc_to_tcp_request_sock",
   179  	140: "bpf_skc_to_udp6_sock",
   180  	141: "bpf_get_task_stack",
   181  	142: "bpf_load_hdr_opt",
   182  	143: "bpf_store_hdr_opt",
   183  	144: "bpf_reserve_hdr_opt",
   184  	145: "bpf_inode_storage_get",
   185  	146: "bpf_inode_storage_delete",
   186  	147: "bpf_d_path",
   187  	148: "bpf_copy_from_user",
   188  	149: "bpf_snprintf_btf",
   189  	150: "bpf_seq_printf_btf",
   190  	151: "bpf_skb_cgroup_classid",
   191  	152: "bpf_redirect_neigh",
   192  	153: "bpf_per_cpu_ptr",
   193  	154: "bpf_this_cpu_ptr",
   194  	155: "bpf_redirect_peer",
   195  	156: "bpf_task_storage_get",
   196  	157: "bpf_task_storage_delete",
   197  	158: "bpf_get_current_task_btf",
   198  	159: "bpf_bprm_opts_set",
   199  	160: "bpf_ktime_get_coarse_ns",
   200  	161: "bpf_ima_inode_hash",
   201  	162: "bpf_sock_from_file",
   202  	163: "bpf_check_mtu",
   203  	164: "bpf_for_each_map_elem",
   204  	165: "bpf_snprintf",
   205  	166: "bpf_sys_bpf",
   206  	167: "bpf_btf_find_by_name_kind",
   207  	168: "bpf_sys_close",
   208  	169: "bpf_timer_init",
   209  	170: "bpf_timer_set_callback",
   210  	171: "bpf_timer_start",
   211  	172: "bpf_timer_cancel",
   212  	173: "bpf_get_func_ip",
   213  	174: "bpf_get_attach_cookie",
   214  	175: "bpf_task_pt_regs",
   215  	176: "bpf_get_branch_snapshot",
   216  	177: "bpf_trace_vprintk",
   217  	178: "bpf_skc_to_unix_sock",
   218  	179: "bpf_kallsyms_lookup_name",
   219  	180: "bpf_find_vma",
   220  	181: "bpf_loop",
   221  	182: "bpf_strncmp",
   222  	183: "bpf_get_func_arg",
   223  	184: "bpf_get_func_ret",
   224  	185: "bpf_get_func_arg_cnt",
   225  }