1*d3bec013SDavid Verbeiren // SPDX-License-Identifier: GPL-2.0 2*d3bec013SDavid Verbeiren /* Copyright (c) 2020 Tessares SA <http://www.tessares.net> */ 3*d3bec013SDavid Verbeiren 4*d3bec013SDavid Verbeiren #include "vmlinux.h" 5*d3bec013SDavid Verbeiren #include <bpf/bpf_helpers.h> 6*d3bec013SDavid Verbeiren 7*d3bec013SDavid Verbeiren __u64 inKey = 0; 8*d3bec013SDavid Verbeiren __u64 inValue = 0; 9*d3bec013SDavid Verbeiren __u32 inPid = 0; 10*d3bec013SDavid Verbeiren 11*d3bec013SDavid Verbeiren struct { 12*d3bec013SDavid Verbeiren __uint(type, BPF_MAP_TYPE_PERCPU_HASH); 13*d3bec013SDavid Verbeiren __uint(max_entries, 2); 14*d3bec013SDavid Verbeiren __type(key, __u64); 15*d3bec013SDavid Verbeiren __type(value, __u64); 16*d3bec013SDavid Verbeiren } hashmap1 SEC(".maps"); 17*d3bec013SDavid Verbeiren 18*d3bec013SDavid Verbeiren 19*d3bec013SDavid Verbeiren SEC("tp/syscalls/sys_enter_getpgid") sysenter_getpgid(const void * ctx)20*d3bec013SDavid Verbeirenint sysenter_getpgid(const void *ctx) 21*d3bec013SDavid Verbeiren { 22*d3bec013SDavid Verbeiren /* Just do it for once, when called from our own test prog. This 23*d3bec013SDavid Verbeiren * ensures the map value is only updated for a single CPU. 24*d3bec013SDavid Verbeiren */ 25*d3bec013SDavid Verbeiren int cur_pid = bpf_get_current_pid_tgid() >> 32; 26*d3bec013SDavid Verbeiren 27*d3bec013SDavid Verbeiren if (cur_pid == inPid) 28*d3bec013SDavid Verbeiren bpf_map_update_elem(&hashmap1, &inKey, &inValue, BPF_NOEXIST); 29*d3bec013SDavid Verbeiren 30*d3bec013SDavid Verbeiren return 0; 31*d3bec013SDavid Verbeiren } 32*d3bec013SDavid Verbeiren 33*d3bec013SDavid Verbeiren char _license[] SEC("license") = "GPL"; 34