shared, bpf: add bpf link serialization
core: serialize socket_bind bpf links
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
|
||||
#include "bpf-link.h"
|
||||
#include "serialize.h"
|
||||
|
||||
bool can_link_bpf_program(struct bpf_program *prog) {
|
||||
_cleanup_(bpf_link_freep) struct bpf_link *link = NULL;
|
||||
@@ -14,6 +15,21 @@ bool can_link_bpf_program(struct bpf_program *prog) {
|
||||
return libbpf_get_error(link) == -EBADF;
|
||||
}
|
||||
|
||||
int serialize_bpf_link(FILE *f, FDSet *fds, const char *key, struct bpf_link *link) {
|
||||
int fd;
|
||||
|
||||
assert(key);
|
||||
|
||||
if (!link)
|
||||
return -ENOENT;
|
||||
|
||||
if (libbpf_get_error(link) != 0)
|
||||
return -EINVAL;
|
||||
|
||||
fd = bpf_link__fd(link);
|
||||
return serialize_fd(f, fds, key, fd);
|
||||
}
|
||||
|
||||
struct bpf_link *bpf_link_free(struct bpf_link *link) {
|
||||
/* bpf_link__destroy handles link == NULL case */
|
||||
(void) bpf_link__destroy(link);
|
||||
|
||||
@@ -3,10 +3,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <bpf/libbpf.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fdset.h"
|
||||
#include "macro.h"
|
||||
|
||||
bool can_link_bpf_program(struct bpf_program *prog);
|
||||
|
||||
int serialize_bpf_link(FILE *f, FDSet *fds, const char *key, struct bpf_link *link);
|
||||
|
||||
struct bpf_link *bpf_link_free(struct bpf_link *p);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(struct bpf_link *, bpf_link_free);
|
||||
|
||||
Reference in New Issue
Block a user