---
name: "avc_netlink_open"
section: "3"
platform: "linux"
package: "libselinux1-dev"
version: "3.8.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/avc_netlink_loop"
---

# avc\_netlink\_open(3)

SELinux netlink processing

Part of [avc\_netlink\_loop(3)](/avc_netlink_loop/3.md).

## 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

## 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

These functions enable applications to handle notification of SELinux events via netlink.  The userspace AVC normally checks for netlink messages on each call to [**avc\_has\_perm**(3)](/avc_has_perm/3.md). Applications may wish to override this behavior and check for notification separately, for example in a [**select**(2)](/select/2.md) loop.  These functions also permit netlink monitoring without requiring a call to [**avc\_open**(3)](/avc_open/3.md).

**avc\_netlink\_open**() opens a netlink socket to receive SELinux notifications.  The socket descriptor is stored internally; use [**avc\_netlink\_acquire\_fd**(3)](/avc_netlink_acquire_fd/3.md) to take ownership of it in application code.  The *blocking* argument controls whether the O\_NONBLOCK flag is set on the socket descriptor. [**avc\_open**(3)](/avc_open/3.md) calls this function internally, specifying non-blocking behavior.

**avc\_netlink\_close**() closes the netlink socket.  This function is called automatically by [**avc\_destroy**(3)](/avc_destroy/3.md).

**avc\_netlink\_acquire\_fd**() returns the netlink socket descriptor number and informs the userspace AVC not to check the socket descriptor automatically on calls to [**avc\_has\_perm**(3)](/avc_has_perm/3.md). If no such socket descriptor exists, [**avc\_netlink\_acquire\_fd**(3)](/avc_netlink_acquire_fd/3.md) will first call [**avc\_netlink\_open**(3)](/avc_netlink_open/3.md) and then return the resulting fd.

**avc\_netlink\_release\_fd**() returns control of the netlink socket to the userspace AVC, re-enabling automatic processing of notifications.

**avc\_netlink\_check\_nb**() checks the netlink socket for pending messages and processes them. Callbacks for policyload and enforcing changes will be called; see [**selinux\_set\_callback**(3)](/selinux_set_callback/3.md). This function does not block.

**avc\_netlink\_loop**() enters a loop blocking on the netlink socket and processing messages as they are received.  This function will not return unless an error occurs on the socket, in which case the socket is closed.

## RETURN VALUE

**avc\_netlink\_acquire\_fd**() returns a non-negative file descriptor number on success.  Other functions with a return value return zero on success.  On error, -1 is returned and *errno* is set appropriately.

## AUTHOR

Originally KaiGai Kohei. Updated by Mike Palmiotto \<mike.palmiotto@crunchydata.com\>

## SEE ALSO

[**avc\_open**(3)](/avc_open/3.md), [**selinux\_set\_callback**(3)](/selinux_set_callback/3.md), [**selinux**(8)](/selinux/8.md)
