0001
0002
0003 #include "bpf_iter.h"
0004 #include "bpf_tracing_net.h"
0005 #include <bpf/bpf_helpers.h>
0006 #include <limits.h>
0007
0008 #define AUTOBIND_LEN 6
0009 char sun_path[AUTOBIND_LEN];
0010
0011 #define NR_CASES 5
0012 int sndbuf_setsockopt[NR_CASES] = {-1, 0, 8192, INT_MAX / 2, INT_MAX};
0013 int sndbuf_getsockopt[NR_CASES] = {-1, -1, -1, -1, -1};
0014 int sndbuf_getsockopt_expected[NR_CASES];
0015
0016 static inline int cmpname(struct unix_sock *unix_sk)
0017 {
0018 int i;
0019
0020 for (i = 0; i < AUTOBIND_LEN; i++) {
0021 if (unix_sk->addr->name->sun_path[i] != sun_path[i])
0022 return -1;
0023 }
0024
0025 return 0;
0026 }
0027
0028 SEC("iter/unix")
0029 int change_sndbuf(struct bpf_iter__unix *ctx)
0030 {
0031 struct unix_sock *unix_sk = ctx->unix_sk;
0032 int i, err;
0033
0034 if (!unix_sk || !unix_sk->addr)
0035 return 0;
0036
0037 if (unix_sk->addr->name->sun_path[0])
0038 return 0;
0039
0040 if (cmpname(unix_sk))
0041 return 0;
0042
0043 for (i = 0; i < NR_CASES; i++) {
0044 err = bpf_setsockopt(unix_sk, SOL_SOCKET, SO_SNDBUF,
0045 &sndbuf_setsockopt[i],
0046 sizeof(sndbuf_setsockopt[i]));
0047 if (err)
0048 break;
0049
0050 err = bpf_getsockopt(unix_sk, SOL_SOCKET, SO_SNDBUF,
0051 &sndbuf_getsockopt[i],
0052 sizeof(sndbuf_getsockopt[i]));
0053 if (err)
0054 break;
0055 }
0056
0057 return 0;
0058 }
0059
0060 char _license[] SEC("license") = "GPL";