1seccomp_export_bpf(3)      libseccomp Documentation      seccomp_export_bpf(3)
2
3
4

NAME

6       seccomp_export_bpf, seccomp_export_pfc - Export the seccomp filter
7

SYNOPSIS

9       #include <seccomp.h>
10
11       typedef void * scmp_filter_ctx;
12
13       int seccomp_export_bpf(const scmp_filter_ctx ctx, int fd);
14       int seccomp_export_pfc(const scmp_filter_ctx ctx, int fd);
15
16       Link with -lseccomp.
17

DESCRIPTION

19       The  seccomp_export_bpf()  and  seccomp_export_pfc() functions generate
20       and output the current seccomp filter in  either  BPF  (Berkley  Packet
21       Filter)   or   PFC   (Pseudo   Filter   Code).    The  output  of  sec‐
22       comp_export_bpf() is suitable for loading into the  kernel,  while  the
23       output  of  seccomp_export_pfc() is human readable and is intended pri‐
24       marily as a debugging tool for developers using libseccomp.  Both func‐
25       tions write the filter to the fd file descriptor.
26
27       The  filter  context  ctx  is  the  value  returned by the call to sec‐
28       comp_init(3).
29
30       While the two output formats are guaranteed to be functionally  equiva‐
31       lent  for  the  given seccomp filter configuration, the filter instruc‐
32       tions, and their ordering, are not guaranteed to be the  same  in  both
33       the BPF and PFC formats.
34

RETURN VALUE

36       Returns zero on success, negative errno values on failure.
37

EXAMPLES

39       #include <seccomp.h>
40
41       int main(int argc, char *argv[])
42       {
43            int rc = -1;
44            scmp_filter_ctx ctx;
45            int filter_fd;
46
47            ctx = seccomp_init(SCMP_ACT_KILL);
48            if (ctx == NULL)
49                 goto out;
50
51            /* ... */
52
53            filter_fd = open("/tmp/seccomp_filter.bpf", O_WRONLY);
54            if (filter_fd == -1) {
55                 rc = -errno;
56                 goto out;
57            }
58
59            rc = seccomp_export_bpf(ctx, filter_fd);
60            if (rc < 0) {
61                 close(filter_fd);
62                 goto out;
63            }
64            close(filter_fd);
65
66            /* ... */
67
68       out:
69            seccomp_release(ctx);
70            return -rc;
71       }
72

NOTES

74       While  the  seccomp  filter can be generated independent of the kernel,
75       kernel support is required to load and enforce the seccomp filter  gen‐
76       erated by libseccomp.
77
78       The  libseccomp project site, with more information and the source code
79       repository,  can  be  found  at  https://github.com/seccomp/libseccomp.
80       This tool, as well as the libseccomp library, is currently under devel‐
81       opment, please report any bugs at the project site or directly  to  the
82       author.
83

AUTHOR

85       Paul Moore <paul@paul-moore.com>
86

SEE ALSO

88       seccomp_init(3), seccomp_release(3)
89
90
91
92
93paul@paul-moore.com              25 July 2012            seccomp_export_bpf(3)
Impressum