> + if (unlikely(!ns_task))
> + return -EINVAL;
> +
> + ((struct bpf_current_pidns_info*)buf)->
tgid = ns_task->tgid;
> + ((struct bpf_current_pidns_info*)buf)->
pid = ns_task->pid;
> +
> + return 0;
> +}
> +
> +
> +const struct bpf_func_proto bpf_get_current_pidns_info_
proto = {
> + .func = bpf_get_current_pidns_info,
> + .gpl_only = false,
> + .ret_type = RET_INTEGER,
> + .arg1_type = ARG_PTR_TO_UNINIT_MEM,
> + .arg2_type = ARG_CONST_SIZE,
> +};
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index dc498b6..06297e7 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -487,6 +487,8 @@ static const struct bpf_func_proto
> *tracing_func_proto(enum bpf_func_id func_id)
> return &bpf_get_prandom_u32_proto;
> case BPF_FUNC_probe_read_str:
> return &bpf_probe_read_str_proto;
> + case BPF_FUNC_get_current_pidns_
info:
> + return &bpf_get_current_pidns_info_
proto;
> default:
> return NULL;
> }
> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
> index 87246be..0af924f 100644
> --- a/samples/bpf/Makefile
> +++ b/samples/bpf/Makefile
> @@ -37,6 +37,7 @@ hostprogs-y += xdp_tx_iptunnel
> hostprogs-y += test_map_in_map
> hostprogs-y += per_socket_stats_example
> hostprogs-y += load_sock_ops
> +hostprogs-y += trace_ns_info
>
> # Libbpf dependencies
> LIBBPF := ../../tools/lib/bpf/bpf.o
> @@ -78,7 +79,7 @@ lwt_len_hist-objs := bpf_load.o $(LIBBPF)
> lwt_len_hist_user.o
> xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
> test_map_in_map-objs := bpf_load.o $(LIBBPF) test_map_in_map_user.o
> per_socket_stats_example-objs := $(LIBBPF) cookie_uid_helper_example.o
> -
> +trace_ns_info-objs := bpf_load.o $(LIBBPF) trace_ns_info_user.o
> # Tell kbuild to always build the programs
> always := $(hostprogs-y)
> always += sockex1_kern.o
> @@ -119,6 +120,7 @@ always += tcp_bufs_kern.o
> always += tcp_cong_kern.o
> always += tcp_iw_kern.o
> always += tcp_clamp_kern.o
> +always += trace_ns_info_user_kern.o
>
> HOSTCFLAGS += -I$(objtree)/usr/include
> HOSTCFLAGS += -I$(srctree)/tools/lib/
> @@ -155,6 +157,7 @@ HOSTLOADLIBES_tc_l2_redirect += -l elf
> HOSTLOADLIBES_lwt_len_hist += -l elf
> HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
> HOSTLOADLIBES_test_map_in_map += -lelf
> +HOSTLOADLIBES_trace_ns_info += -lelf
>
> # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on
> cmdline:
> # make samples/bpf/ LLC=~/git/llvm/build/bin/llc
> CLANG=~/git/llvm/build/bin/
clang
> diff --git a/samples/bpf/trace_ns_info_
user.c
> b/samples/bpf/trace_ns_info_
user.c
> new file mode 100644
> index 0000000..0dce083
> --- /dev/null
> +++ b/samples/bpf/trace_ns_info_
user.c
> @@ -0,0 +1,32 @@
> +/* Copyright (c) 2017
cneirabustos@...
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + */
> +
> +#include <stdio.h>
> +#include <linux/bpf.h>
> +#include <unistd.h>
> +#include "libbpf.h"
> +#include "bpf_load.h"
> +
> +int main(int ac, char **argv)
> +{
> + FILE *f;
> + char filename[256];
> +
> + snprintf(filename, sizeof(filename), "%s_user_kern.o", argv[0]);
> + printf("loading %s\n",filename);
> +
> +
> + if (load_bpf_file(filename)) {
> + printf("%s", bpf_log_buf);
> + return 1;
> + }
> +
> + f = popen("taskset 1 ping localhost", "r");
> + (void) f;
> + read_trace_pipe();