.max_entries = 1
};
+struct bpf_map_def SEC("maps") sock_cork_bytes = {
+ .type = BPF_MAP_TYPE_ARRAY,
+ .key_size = sizeof(int),
+ .value_size = sizeof(int),
+ .max_entries = 1
+};
+
SEC("sk_skb1")
int bpf_prog1(struct __sk_buff *skb)
{
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes)
bpf_msg_apply_bytes(msg, *bytes);
+ bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
+ if (bytes)
+ bpf_msg_cork_bytes(msg, *bytes);
return SK_PASS;
}
{
void *data_end = (void *)(long) msg->data_end;
void *data = (void *)(long) msg->data;
- int *bytes, err = 0, zero = 0;
+ int *bytes, err1 = -1, err2 = -1, zero = 0;
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes)
- err = bpf_msg_apply_bytes(msg, *bytes);
- bpf_printk("sk_msg2: data length %i err %i\n",
- (__u64)data_end - (__u64)data, err);
+ err1 = bpf_msg_apply_bytes(msg, *bytes);
+ bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
+ if (bytes)
+ err2 = bpf_msg_cork_bytes(msg, *bytes);
+ bpf_printk("sk_msg2: data length %i err1 %i err2 %i\n",
+ (__u64)data_end - (__u64)data, err1, err2);
return SK_PASS;
}
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes)
bpf_msg_apply_bytes(msg, *bytes);
+ bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
+ if (bytes)
+ bpf_msg_cork_bytes(msg, *bytes);
return bpf_msg_redirect_map(msg, &sock_map_redir, zero, 0);
}
{
void *data_end = (void *)(long) msg->data_end;
void *data = (void *)(long) msg->data;
- int *bytes, err = 0, zero = 0;
+ int *bytes, err1 = 0, err2 = 0, zero = 0;
bytes = bpf_map_lookup_elem(&sock_apply_bytes, &zero);
if (bytes)
- err = bpf_msg_apply_bytes(msg, *bytes);
- bpf_printk("sk_msg3: redirect(%iB) err=%i\n",
- (__u64)data_end - (__u64)data, err);
+ err1 = bpf_msg_apply_bytes(msg, *bytes);
+ bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
+ if (bytes)
+ err2 = bpf_msg_cork_bytes(msg, *bytes);
+
+ bpf_printk("sk_msg3: redirect(%iB) err1=%i err2=%i\n",
+ (__u64)data_end - (__u64)data, err1, err2);
return bpf_msg_redirect_map(msg, &sock_map_redir, zero, 0);
}
}
return SK_PASS;
}
+SEC("sk_msg6")
+int bpf_prog9(struct sk_msg_md *msg)
+{
+ void *data_end = (void *)(long) msg->data_end;
+ void *data = (void *)(long) msg->data;
+ int ret = 0, *bytes, zero = 0;
+
+ bytes = bpf_map_lookup_elem(&sock_cork_bytes, &zero);
+ if (bytes) {
+ if (((__u64)data_end - (__u64)data) >= *bytes)
+ return SK_PASS;
+ ret = bpf_msg_cork_bytes(msg, *bytes);
+ if (ret)
+ return SK_DROP;
+ }
+ return SK_PASS;
+}
char _license[] SEC("license") = "GPL";
int txmsg_redir;
int txmsg_redir_noisy;
int txmsg_apply;
+int txmsg_cork;
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h' },
{"txmsg_redir", no_argument, &txmsg_redir, 1 },
{"txmsg_redir_noisy", no_argument, &txmsg_redir_noisy, 1},
{"txmsg_apply", required_argument, NULL, 'a'},
+ {"txmsg_cork", required_argument, NULL, 'k'},
{0, 0, NULL, 0 }
};
case 'a':
txmsg_apply = atoi(optarg);
break;
+ case 'k':
+ txmsg_cork = atoi(optarg);
+ break;
case 'c':
cg_fd = open(optarg, O_DIRECTORY, O_RDONLY);
if (cg_fd < 0) {
tx_prog_fd = prog_fd[6];
else if (txmsg_apply)
tx_prog_fd = prog_fd[7];
+ else if (txmsg_cork)
+ tx_prog_fd = prog_fd[8];
else
tx_prog_fd = 0;
return err;
}
}
+
+ if (txmsg_cork) {
+ err = bpf_map_update_elem(map_fd[4],
+ &i, &txmsg_cork, BPF_ANY);
+ if (err) {
+ fprintf(stderr,
+ "ERROR: bpf_map_update_elem (cork_bytes): %d (%s\n",
+ err, strerror(errno));
+ return err;
+ }
+ }
+
}
if (test == PING_PONG)
err = forever_ping_pong(rate, &options);