avc_netlink_loop(3)
π avc_netlink_loop β SELinux netlink processing π
okay bestie, welcome to the avc_netlink_loop(3) page from the SELinux API documentation β this is the one that's all about listening for SELinux gossip straight from the kernel. π¦
β¨ NAME β¨
avc_netlink_open, avc_netlink_close, avc_netlink_acquire_fd, avc_netlink_release_fd, avc_netlink_check_nb, avc_netlink_loop β SELinux netlink processing, aka the whole friend group of functions that handle your notification vibes π
πΈ SYNOPSIS πΈ
#include <selinux/selinux.h>
#include <selinux/avc.h>
int avc_netlink_open(int blocking);
void avc_netlink_close(void);
int avc_netlink_acquire_fd(void);
void avc_netlink_release_fd(void);
void avc_netlink_loop(void);
int avc_netlink_check_nb(void);
π DESCRIPTION π
so here's the tea π β these functions let your app handle notification of SELinux events via netlink. like, the kernel is texting, and this is how you read the messages.
normally the userspace AVC is the one doing the checking β it peeks at netlink messages on every single call to avc_has_perm(3). but maybe you're a main character who wants to override that behavior and check for notifications on your own terms, for example inside a select(2) loop. very valid. π
and not only that β these functions also let you do netlink monitoring without even needing a call to avc_open(3). no cap.
avc_netlink_open()β opens a netlink socket to receive SELinux notifications. the socket descriptor is stored internally, so if you want to actually own it in your app code, useavc_netlink_acquire_fd(3). theblockingargument controls whether theO_NONBLOCKflag gets set on the socket descriptor. also fun fact:avc_open(3)calls this function internally, and it specifies non-blocking behavior when it does. π«Άavc_netlink_close()β closes the netlink socket. and guess what, you don't even have to remember to call it, becauseavc_destroy(3)calls it automatically for you. iconic teamwork. β¨avc_netlink_acquire_fd()β returns the netlink socket descriptor number and informs the userspace AVC that it should not check the socket descriptor automatically on calls toavc_has_perm(3)anymore. and if no such socket descriptor exists yet? no stress βavc_netlink_acquire_fd(3)will first callavc_netlink_open(3)and then return the resulting fd. πavc_netlink_release_fd()β gives control of the netlink socket back to the userspace AVC, which re-enables automatic processing of notifications. it's giving "here, you take it back bestie." πavc_netlink_check_nb()β checks the netlink socket for pending messages and processes them. callbacks for policyload and enforcing changes will get called; go seeselinux_set_callback(3). and important: this function does not block. it's the "quick vibe check, no waiting" one. πavc_netlink_loop()β enters a loop, blocking on the netlink socket and processing messages as they are received.
β οΈ okay so listen: this function will not return unless an error occurs on the socket. and if an error does occur, the socket gets closed. so this is a "you live here now" function. commit to it. π
β RETURN VALUE β
avc_netlink_acquire_fd() returns a non-negative file descriptor number on success. the other functions that have a return value return zero on success. and on error? -1 is returned and errno is set appropriately. classic. π
π AUTHOR π
Originally KaiGai Kohei. Updated by Mike Palmiotto <mike.palmiotto@crunchydata.com>
π₯ SEE ALSO π₯
avc_open(3), selinux_set_callback(3), selinux(8)
and that's the whole page, bestie β slay β¨ this was avc_netlink_loop(3) from the SELinux API documentation, dated 30 Mar 2009. go forth and loop responsibly ππ¦π
π¦ where this page comes from
- alpine 3.24: libselinux-doc 3.10-r1 Β· Public-Domain
- centos-stream 10: libselinux-devel 3.11-3.el10 Β· LicenseRef-Fedora-Public-Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- centos-stream 9: libselinux-devel 3.6-5.el9 Β· Public Domain
- debian bookworm: libselinux1-dev 3.4-1+b6
- debian trixie: libselinux1-dev 3.8.1-1 Β· LicenseRef-public-domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 43: libselinux-devel 3.9-5.fc43 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.10-1.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- fedora 44: libselinux-devel 3.11-2.fc44 Β· LicenseRef-Fedora-Public-Domain
- nixos 26.05: libselinux 3.10
- nixpkgs unstable: libselinux 3.11
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- opensuse-leap 16.0: libselinux-devel 3.8.1-160000.4.1 Β· SUSE-Public-Domain
- ubuntu jammy: libselinux1-dev 3.3-1build2
- ubuntu noble: libselinux1-dev 3.5-2ubuntu2 Β· LicenseRef-public-domain
- ubuntu noble: libselinux1-dev 3.5-2ubuntu2.1 Β· LicenseRef-public-domain
- ubuntu questing: libselinux1-dev 3.8.1-1build1
- ubuntu resolute: libselinux-dev 3.9-4build1 Β· LicenseRef-public-domain
- ubuntu stonking: libselinux-dev 3.11-2.1 Β· LicenseRef-public-domain
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms