History

bpf: Added new helper bpf_get_ns_current_pid_tgid

New bpf helper bpf_get_ns_current_pid_tgid, This helper will return pid and tgid from current task which namespace matches dev_t and inode number provided, this will allows us to instrument a process inside a container.

Carlos Neira committed 6 years ago

Commit b4490c51 parent 1e2328e7 files · +88 −2Browse files

Showing the changes to include/uapi/linux (1 of 7 files). Show all

Unified · Split

include/uapi/linux/bpf.h+19−1
@@ -2914,6 +2914,19 @@ union bpf_attr { · 2913 unmodified lines
29142914 * of sizeof(struct perf_branch_entry).
29152915 *
29162916 * **-ENOENT** if architecture does not support branch records.
2917+ *
2918+ * int bpf_get_ns_current_pid_tgid(u64 dev, u64 ino, struct bpf_pidns_info *nsdata, u32 size)
2919+ * Description
2920+ * Returns 0 on success, values for *pid* and *tgid* as seen from the current
2921+ * *namespace* will be returned in *nsdata*.
2922+ *
2923+ * On failure, the returned value is one of the following:
2924+ *
2925+ * **-EINVAL** if dev and inum supplied don't match dev_t and inode number
2926+ * with nsfs of current task, or if dev conversion to dev_t lost high bits.
2927+ *
2928+ * **-ENOENT** if pidns does not exists for the current task.
2929+ *
29172930 */
29182931 #define __BPF_FUNC_MAPPER(FN) \
29192932 FN(unspec), \
@@ -3035,7 +3048,8 @@ union bpf_attr { · 115 unmodified lines
30353048 FN(tcp_send_ack), \
30363049 FN(send_signal_thread), \
30373050 FN(jiffies64), \
3038− FN(read_branch_records),
3051+ FN(read_branch_records), \
3052+ FN(get_ns_current_pid_tgid),
30393053
30403054 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
30413055 * function eBPF program intends to call
@@ -3829,4 +3843,8 @@ struct bpf_sockopt { · 787 unmodified lines
38293843 __s32 retval;
38303844 };
38313845
3846+struct bpf_pidns_info {
3847+ __u32 pid;
3848+ __u32 tgid;
3849+};
38323850 #endif /* _UAPI__LINUX_BPF_H__ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t