|
Packit Service |
87a54e |
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2018 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#ifndef __NM_NETLINK_H__
|
|
Packit |
5756e2 |
#define __NM_NETLINK_H__
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include <linux/netlink.h>
|
|
Packit |
5756e2 |
#include <linux/rtnetlink.h>
|
|
Packit |
5756e2 |
#include <linux/genetlink.h>
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-std-aux/unaligned.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLMSGERR_ATTR_UNUSED 0
|
|
Packit Service |
a1bd4f |
#define NLMSGERR_ATTR_MSG 1
|
|
Packit Service |
a1bd4f |
#define NLMSGERR_ATTR_OFFS 2
|
|
Packit Service |
a1bd4f |
#define NLMSGERR_ATTR_COOKIE 3
|
|
Packit Service |
a1bd4f |
#define NLMSGERR_ATTR_MAX 3
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#ifndef NLM_F_ACK_TLVS
|
|
Packit Service |
a1bd4f |
#define NLM_F_ACK_TLVS 0x200
|
|
Packit |
5756e2 |
#endif
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/* Basic attribute data types */
|
|
Packit |
5756e2 |
enum {
|
|
Packit Service |
a1bd4f |
NLA_UNSPEC, /* Unspecified type, binary data chunk */
|
|
Packit Service |
a1bd4f |
NLA_U8, /* 8 bit integer */
|
|
Packit Service |
a1bd4f |
NLA_U16, /* 16 bit integer */
|
|
Packit Service |
a1bd4f |
NLA_U32, /* 32 bit integer */
|
|
Packit Service |
a1bd4f |
NLA_U64, /* 64 bit integer */
|
|
Packit Service |
a1bd4f |
NLA_STRING, /* NUL terminated character string */
|
|
Packit Service |
a1bd4f |
NLA_FLAG, /* Flag */
|
|
Packit Service |
a1bd4f |
NLA_MSECS, /* Micro seconds (64bit) */
|
|
Packit Service |
a1bd4f |
NLA_NESTED, /* Nested attributes */
|
|
Packit Service |
a1bd4f |
NLA_NESTED_COMPAT,
|
|
Packit Service |
a1bd4f |
NLA_NUL_STRING,
|
|
Packit Service |
a1bd4f |
NLA_BINARY,
|
|
Packit Service |
a1bd4f |
NLA_S8,
|
|
Packit Service |
a1bd4f |
NLA_S16,
|
|
Packit Service |
a1bd4f |
NLA_S32,
|
|
Packit Service |
a1bd4f |
NLA_S64,
|
|
Packit Service |
a1bd4f |
__NLA_TYPE_MAX,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#define NLA_TYPE_MAX (__NLA_TYPE_MAX - 1)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct nl_msg;
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const char *nl_nlmsgtype2str(int type, char *buf, size_t size);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const char *nl_nlmsg_flags2str(int flags, char *buf, size_t len);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
const char *nl_nlmsghdr_to_str(const struct nlmsghdr *hdr, char *buf, gsize len);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct nla_policy {
|
|
Packit Service |
a1bd4f |
/* Type of attribute or NLA_UNSPEC */
|
|
Packit Service |
a1bd4f |
uint16_t type;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Minimal length of payload required */
|
|
Packit Service |
a1bd4f |
uint16_t minlen;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Maximal length of payload allowed */
|
|
Packit Service |
a1bd4f |
uint16_t maxlen;
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/* static asserts that @tb and @policy are suitable arguments to nla_parse(). */
|
|
Packit Service |
a1bd4f |
#define _nl_static_assert_tb(tb, policy) \
|
|
Packit Service |
a1bd4f |
G_STMT_START \
|
|
Packit Service |
a1bd4f |
{ \
|
|
Packit Service |
a1bd4f |
G_STATIC_ASSERT_EXPR(G_N_ELEMENTS(tb) > 0); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
/* We allow @policy to be either a C array or NULL. The sizeof()
|
|
Packit Service |
a1bd4f |
* must either match the expected array size or the sizeof(NULL),
|
|
Packit Service |
a1bd4f |
* but not both. */ \
|
|
Packit Service |
a1bd4f |
G_STATIC_ASSERT_EXPR((sizeof(policy) == G_N_ELEMENTS(tb) * sizeof(struct nla_policy)) \
|
|
Packit Service |
a1bd4f |
^ (sizeof(policy) == sizeof(NULL))); \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
G_STMT_END
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_attr_size(int payload)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(payload >= 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return NLA_HDRLEN + payload;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_total_size(int payload)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return NLA_ALIGN(nla_attr_size(payload));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_padlen(int payload)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nla_total_size(payload) - nla_attr_size(payload);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int attrlen);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_len(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla);
|
|
Packit Service |
a1bd4f |
nm_assert(nla->nla_len >= NLA_HDRLEN);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return ((int) nla->nla_len) - NLA_HDRLEN;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_type(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return nla->nla_type & NLA_TYPE_MASK;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline void *
|
|
Packit Service |
a1bd4f |
nla_data(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return &(((char *) nla)[NLA_HDRLEN]);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nla_data_as(type, nla) \
|
|
Packit Service |
a1bd4f |
({ \
|
|
Packit Service |
a1bd4f |
const struct nlattr *_nla = (nla); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(_nla) >= sizeof(type)); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
/* note that casting the pointer is undefined behavior in C, if
|
|
Packit Service |
a1bd4f |
* the data has wrong alignment. Netlink data is aligned to 4 bytes,
|
|
Packit Service |
a1bd4f |
* that means, if the alignment is larger than 4, this is invalid. */ \
|
|
Packit Service |
a1bd4f |
G_STATIC_ASSERT_EXPR(_nm_alignof(type) <= NLA_ALIGNTO); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
(type *) nla_data(_nla); \
|
|
Packit Service |
a1bd4f |
})
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline uint8_t
|
|
Packit Service |
a1bd4f |
nla_get_u8(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= sizeof(uint8_t));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return *((const uint8_t *) nla_data(nla));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int8_t
|
|
Packit Service |
a1bd4f |
nla_get_s8(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= sizeof(int8_t));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return *((const int8_t *) nla_data(nla));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline uint8_t
|
|
Packit Service |
a1bd4f |
nla_get_u8_cond(/*const*/ struct nlattr *const *tb, int attr, uint8_t default_val)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(tb);
|
|
Packit Service |
a1bd4f |
nm_assert(attr >= 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return tb[attr] ? nla_get_u8(tb[attr]) : default_val;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline uint16_t
|
|
Packit Service |
a1bd4f |
nla_get_u16(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= sizeof(uint16_t));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return *((const uint16_t *) nla_data(nla));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline uint32_t
|
|
Packit Service |
a1bd4f |
nla_get_u32(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= sizeof(uint32_t));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return *((const uint32_t *) nla_data(nla));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int32_t
|
|
Packit Service |
a1bd4f |
nla_get_s32(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= sizeof(int32_t));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return *((const int32_t *) nla_data(nla));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline uint64_t
|
|
Packit Service |
a1bd4f |
nla_get_u64(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= sizeof(uint64_t));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return unaligned_read_ne64(nla_data(nla));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline uint64_t
|
|
Packit Service |
a1bd4f |
nla_get_be64(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= sizeof(uint64_t));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return unaligned_read_be64(nla_data(nla));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline char *
|
|
Packit Service |
a1bd4f |
nla_get_string(const struct nlattr *nla)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(nla_len(nla) >= 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return (char *) nla_data(nla);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
size_t nla_memcpy(void *dst, const struct nlattr *nla, size_t dstsize);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nla_memcpy_checked_size(dst, nla, dstsize) \
|
|
Packit Service |
a1bd4f |
G_STMT_START \
|
|
Packit Service |
a1bd4f |
{ \
|
|
Packit Service |
a1bd4f |
void *const _dst = (dst); \
|
|
Packit Service |
a1bd4f |
const struct nlattr *const _nla = (nla); \
|
|
Packit Service |
a1bd4f |
const size_t _dstsize = (dstsize); \
|
|
Packit Service |
a1bd4f |
size_t _srcsize; \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
/* assert that, if @nla is given, that it has the exact expected
|
|
Packit Service |
a1bd4f |
* size. This implies that the caller previously verified the length
|
|
Packit Service |
a1bd4f |
* of the attribute (via minlen/maxlen at nla_parse()). */ \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
if (_nla) { \
|
|
Packit Service |
a1bd4f |
_srcsize = nla_memcpy(_dst, _nla, _dstsize); \
|
|
Packit Service |
a1bd4f |
nm_assert(_srcsize == _dstsize); \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
G_STMT_END
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_put_string(struct nl_msg *msg, int attrtype, const char *str)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(str);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return nla_put(msg, attrtype, strlen(str) + 1, str);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_put_uint8(struct nl_msg *msg, int attrtype, uint8_t val)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nla_put(msg, attrtype, sizeof(val), &val;;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_put_uint16(struct nl_msg *msg, int attrtype, uint16_t val)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nla_put(msg, attrtype, sizeof(val), &val;;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_put_uint32(struct nl_msg *msg, int attrtype, uint32_t val)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nla_put(msg, attrtype, sizeof(val), &val;;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT(msg, attrtype, attrlen, data) \
|
|
Packit Service |
a1bd4f |
G_STMT_START \
|
|
Packit Service |
a1bd4f |
{ \
|
|
Packit Service |
a1bd4f |
if (nla_put(msg, attrtype, attrlen, data) < 0) \
|
|
Packit Service |
a1bd4f |
goto nla_put_failure; \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
G_STMT_END
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_TYPE(msg, type, attrtype, value) \
|
|
Packit Service |
a1bd4f |
G_STMT_START \
|
|
Packit Service |
a1bd4f |
{ \
|
|
Packit Service |
a1bd4f |
type __nla_tmp = value; \
|
|
Packit Service |
a1bd4f |
NLA_PUT(msg, attrtype, sizeof(type), &__nla_tmp); \
|
|
Packit Service |
a1bd4f |
} \
|
|
Packit Service |
a1bd4f |
G_STMT_END
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_U8(msg, attrtype, value) NLA_PUT_TYPE(msg, uint8_t, attrtype, value)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_S8(msg, attrtype, value) NLA_PUT_TYPE(msg, int8_t, attrtype, value)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_U16(msg, attrtype, value) NLA_PUT_TYPE(msg, uint16_t, attrtype, value)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_U32(msg, attrtype, value) NLA_PUT_TYPE(msg, uint32_t, attrtype, value)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_S32(msg, attrtype, value) NLA_PUT_TYPE(msg, int32_t, attrtype, value)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_U64(msg, attrtype, value) NLA_PUT_TYPE(msg, uint64_t, attrtype, value)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_STRING(msg, attrtype, value) NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define NLA_PUT_FLAG(msg, attrtype) NLA_PUT(msg, attrtype, 0, NULL)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_ok(const struct nlattr *nla, int remaining)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return remaining >= (int) sizeof(*nla) && nla->nla_len >= sizeof(*nla)
|
|
Packit Service |
a1bd4f |
&& nla->nla_len <= remaining;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline struct nlattr *
|
|
Packit Service |
a1bd4f |
nla_next(const struct nlattr *nla, int *remaining)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
int totlen = NLA_ALIGN(nla->nla_len);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
*remaining -= totlen;
|
|
Packit Service |
a1bd4f |
return (struct nlattr *) ((char *) nla + totlen);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#define nla_for_each_attr(pos, head, len, rem) \
|
|
Packit Service |
a1bd4f |
for (pos = head, rem = len; nla_ok(pos, rem); pos = nla_next(pos, &(rem)))
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
#define nla_for_each_nested(pos, nla, rem) \
|
|
Packit Service |
a1bd4f |
for (pos = (struct nlattr *) nla_data(nla), rem = nla_len(nla); nla_ok(pos, rem); \
|
|
Packit Service |
a1bd4f |
pos = nla_next(pos, &(rem)))
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr);
|
|
Packit Service |
a1bd4f |
struct nlattr *nla_nest_start(struct nl_msg *msg, int attrtype);
|
|
Packit Service |
a1bd4f |
int nla_nest_end(struct nl_msg *msg, struct nlattr *start);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
int nla_parse(struct nlattr * tb[],
|
|
Packit Service |
a1bd4f |
int maxtype,
|
|
Packit Service |
a1bd4f |
struct nlattr * head,
|
|
Packit Service |
a1bd4f |
int len,
|
|
Packit Service |
a1bd4f |
const struct nla_policy *policy);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
#define nla_parse_arr(tb, head, len, policy) \
|
|
Packit Service |
a1bd4f |
({ \
|
|
Packit Service |
a1bd4f |
_nl_static_assert_tb((tb), (policy)); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
nla_parse((tb), G_N_ELEMENTS(tb) - 1, (head), (len), (policy)); \
|
|
Packit Service |
a1bd4f |
})
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nla_parse_nested(struct nlattr * tb[],
|
|
Packit Service |
a1bd4f |
int maxtype,
|
|
Packit Service |
a1bd4f |
struct nlattr * nla,
|
|
Packit Service |
a1bd4f |
const struct nla_policy *policy)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nla_parse(tb, maxtype, nla_data(nla), nla_len(nla), policy);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nla_parse_nested_arr(tb, nla, policy) \
|
|
Packit Service |
a1bd4f |
({ \
|
|
Packit Service |
a1bd4f |
_nl_static_assert_tb((tb), (policy)); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
nla_parse_nested((tb), G_N_ELEMENTS(tb) - 1, (nla), (policy)); \
|
|
Packit Service |
a1bd4f |
})
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nl_msg *nlmsg_alloc(void);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nl_msg *nlmsg_alloc_size(size_t max);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nl_msg *nlmsg_alloc_convert(struct nlmsghdr *hdr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nl_msg *nlmsg_alloc_simple(int nlmsgtype, int flags);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void *nlmsg_reserve(struct nl_msg *n, size_t len, int pad);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nlmsg_append(struct nl_msg *n, const void *data, size_t len, int pad);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nlmsg_append_struct(n, data) nlmsg_append(n, (data), sizeof(*(data)), NLMSG_ALIGNTO)
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nlmsg_free(struct nl_msg *msg);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nlmsg_size(int payload)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(payload >= 0 && payload < G_MAXINT - NLMSG_HDRLEN - 4);
|
|
Packit Service |
a1bd4f |
return NLMSG_HDRLEN + payload;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nlmsg_total_size(int payload)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return NLMSG_ALIGN(nlmsg_size(payload));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nlmsg_ok(const struct nlmsghdr *nlh, int remaining)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return (remaining >= (int) sizeof(struct nlmsghdr) && nlh->nlmsg_len >= sizeof(struct nlmsghdr)
|
|
Packit Service |
a1bd4f |
&& nlh->nlmsg_len <= remaining);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline struct nlmsghdr *
|
|
Packit Service |
a1bd4f |
nlmsg_next(struct nlmsghdr *nlh, int *remaining)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
int totlen = NLMSG_ALIGN(nlh->nlmsg_len);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
*remaining -= totlen;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return (struct nlmsghdr *) ((unsigned char *) nlh + totlen);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nlmsg_get_proto(struct nl_msg *msg);
|
|
Packit Service |
a1bd4f |
void nlmsg_set_proto(struct nl_msg *msg, int protocol);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nlmsg_set_src(struct nl_msg *msg, struct sockaddr_nl *addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct ucred *nlmsg_get_creds(struct nl_msg *msg);
|
|
Packit Service |
a1bd4f |
void nlmsg_set_creds(struct nl_msg *msg, struct ucred *creds);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline void
|
|
Packit Service |
a1bd4f |
_nm_auto_nl_msg_cleanup(struct nl_msg **ptr)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nlmsg_free(*ptr);
|
|
Packit |
5756e2 |
}
|
|
Packit Service |
a1bd4f |
#define nm_auto_nlmsg nm_auto(_nm_auto_nl_msg_cleanup)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline void *
|
|
Packit Service |
a1bd4f |
nlmsg_data(const struct nlmsghdr *nlh)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return (unsigned char *) nlh + NLMSG_HDRLEN;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline void *
|
|
Packit Service |
a1bd4f |
nlmsg_tail(const struct nlmsghdr *nlh)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return (unsigned char *) nlh + NLMSG_ALIGN(nlh->nlmsg_len);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nlmsghdr *nlmsg_hdr(struct nl_msg *n);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nlmsg_valid_hdr(const struct nlmsghdr *nlh, int hdrlen)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
if (nlh->nlmsg_len < nlmsg_size(hdrlen))
|
|
Packit Service |
a1bd4f |
return 0;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return 1;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nlmsg_datalen(const struct nlmsghdr *nlh)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nlh->nlmsg_len - NLMSG_HDRLEN;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline int
|
|
Packit Service |
a1bd4f |
nlmsg_attrlen(const struct nlmsghdr *nlh, int hdrlen)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return NM_MAX((int) (nlmsg_datalen(nlh) - NLMSG_ALIGN(hdrlen)), 0);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline struct nlattr *
|
|
Packit Service |
a1bd4f |
nlmsg_attrdata(const struct nlmsghdr *nlh, int hdrlen)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
unsigned char *data = nlmsg_data(nlh);
|
|
Packit Service |
a1bd4f |
return (struct nlattr *) (data + NLMSG_ALIGN(hdrlen));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline struct nlattr *
|
|
Packit Service |
a1bd4f |
nlmsg_find_attr(struct nlmsghdr *nlh, int hdrlen, int attrtype)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return nla_find(nlmsg_attrdata(nlh, hdrlen), nlmsg_attrlen(nlh, hdrlen), attrtype);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nlmsg_parse(struct nlmsghdr * nlh,
|
|
Packit Service |
a1bd4f |
int hdrlen,
|
|
Packit Service |
a1bd4f |
struct nlattr * tb[],
|
|
Packit Service |
a1bd4f |
int maxtype,
|
|
Packit Service |
a1bd4f |
const struct nla_policy *policy);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nlmsg_parse_arr(nlh, hdrlen, tb, policy) \
|
|
Packit Service |
a1bd4f |
({ \
|
|
Packit Service |
a1bd4f |
_nl_static_assert_tb((tb), (policy)); \
|
|
Packit Service |
a1bd4f |
G_STATIC_ASSERT_EXPR((hdrlen) >= 0); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
nlmsg_parse((nlh), (hdrlen), (tb), G_N_ELEMENTS(tb) - 1, (policy)); \
|
|
Packit Service |
a1bd4f |
})
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nlmsghdr *
|
|
Packit Service |
a1bd4f |
nlmsg_put(struct nl_msg *n, uint32_t pid, uint32_t seq, int type, int payload, int flags);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#define NL_AUTO_PORT 0
|
|
Packit |
5756e2 |
#define NL_AUTO_SEQ 0
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct nl_sock;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct nl_sock *nl_socket_alloc(void);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nl_socket_free(struct nl_sock *sk);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_socket_get_fd(const struct nl_sock *sk);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
struct sockaddr_nl *nlmsg_get_dst(struct nl_msg *msg);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
size_t nl_socket_get_msg_buf_size(struct nl_sock *sk);
|
|
Packit Service |
a1bd4f |
int nl_socket_set_msg_buf_size(struct nl_sock *sk, size_t bufsize);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_socket_set_buffer_size(struct nl_sock *sk, int rxbuf, int txbuf);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_socket_set_passcred(struct nl_sock *sk, int state);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_socket_set_nonblocking(const struct nl_sock *sk);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nl_socket_disable_msg_peek(struct nl_sock *sk);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
uint32_t nl_socket_get_local_port(const struct nl_sock *sk);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_socket_add_memberships(struct nl_sock *sk, int group, ...);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_connect(struct nl_sock *sk, int protocol);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_recv(struct nl_sock * sk,
|
|
Packit Service |
a1bd4f |
struct sockaddr_nl *nla,
|
|
Packit Service |
a1bd4f |
unsigned char ** buf,
|
|
Packit Service |
a1bd4f |
struct ucred * out_creds,
|
|
Packit Service |
a1bd4f |
gboolean * out_creds_has);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_send(struct nl_sock *sk, struct nl_msg *msg);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_send_auto(struct nl_sock *sk, struct nl_msg *msg);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
enum nl_cb_action {
|
|
Packit Service |
a1bd4f |
/* Proceed with wathever would come next */
|
|
Packit Service |
a1bd4f |
NL_OK,
|
|
Packit Service |
a1bd4f |
/* Skip this message */
|
|
Packit Service |
a1bd4f |
NL_SKIP,
|
|
Packit Service |
a1bd4f |
/* Stop parsing altogether and discard remaining messages */
|
|
Packit Service |
a1bd4f |
NL_STOP,
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
typedef int (*nl_recvmsg_msg_cb_t)(struct nl_msg *msg, void *arg);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
typedef int (*nl_recvmsg_err_cb_t)(struct sockaddr_nl *nla, struct nlmsgerr *nlerr, void *arg);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
struct nl_cb {
|
|
Packit Service |
a1bd4f |
nl_recvmsg_msg_cb_t valid_cb;
|
|
Packit Service |
a1bd4f |
void * valid_arg;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nl_recvmsg_msg_cb_t finish_cb;
|
|
Packit Service |
a1bd4f |
void * finish_arg;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nl_recvmsg_msg_cb_t ack_cb;
|
|
Packit Service |
a1bd4f |
void * ack_arg;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nl_recvmsg_err_cb_t err_cb;
|
|
Packit Service |
a1bd4f |
void * err_arg;
|
|
Packit |
5756e2 |
};
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_send_iovec(struct nl_sock *sk, struct nl_msg *msg, struct iovec *iov, unsigned iovlen);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nl_complete_msg(struct nl_sock *sk, struct nl_msg *msg);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_recvmsgs(struct nl_sock *sk, const struct nl_cb *cb);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_wait_for_ack(struct nl_sock *sk, const struct nl_cb *cb);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
int nl_socket_set_ext_ack(struct nl_sock *sk, gboolean enable);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void * genlmsg_put(struct nl_msg *msg,
|
|
Packit Service |
a1bd4f |
uint32_t port,
|
|
Packit Service |
a1bd4f |
uint32_t seq,
|
|
Packit Service |
a1bd4f |
int family,
|
|
Packit Service |
a1bd4f |
int hdrlen,
|
|
Packit Service |
a1bd4f |
int flags,
|
|
Packit Service |
a1bd4f |
uint8_t cmd,
|
|
Packit Service |
a1bd4f |
uint8_t version);
|
|
Packit Service |
a1bd4f |
void * genlmsg_data(const struct genlmsghdr *gnlh);
|
|
Packit Service |
a1bd4f |
void * genlmsg_user_hdr(const struct genlmsghdr *gnlh);
|
|
Packit Service |
a1bd4f |
struct genlmsghdr *genlmsg_hdr(struct nlmsghdr *nlh);
|
|
Packit Service |
a1bd4f |
void * genlmsg_user_data(const struct genlmsghdr *gnlh, const int hdrlen);
|
|
Packit Service |
a1bd4f |
struct nlattr * genlmsg_attrdata(const struct genlmsghdr *gnlh, int hdrlen);
|
|
Packit Service |
a1bd4f |
int genlmsg_len(const struct genlmsghdr *gnlh);
|
|
Packit Service |
a1bd4f |
int genlmsg_attrlen(const struct genlmsghdr *gnlh, int hdrlen);
|
|
Packit Service |
a1bd4f |
int genlmsg_valid_hdr(struct nlmsghdr *nlh, int hdrlen);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
int genlmsg_parse(struct nlmsghdr * nlh,
|
|
Packit Service |
a1bd4f |
int hdrlen,
|
|
Packit Service |
a1bd4f |
struct nlattr * tb[],
|
|
Packit Service |
a1bd4f |
int maxtype,
|
|
Packit Service |
a1bd4f |
const struct nla_policy *policy);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
#define genlmsg_parse_arr(nlh, hdrlen, tb, policy) \
|
|
Packit Service |
a1bd4f |
({ \
|
|
Packit Service |
a1bd4f |
_nl_static_assert_tb((tb), (policy)); \
|
|
Packit Service |
a1bd4f |
G_STATIC_ASSERT_EXPR((hdrlen) >= 0); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
genlmsg_parse((nlh), (hdrlen), (tb), G_N_ELEMENTS(tb) - 1, (policy)); \
|
|
Packit Service |
a1bd4f |
})
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
int genl_ctrl_resolve(struct nl_sock *sk, const char *name);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#endif /* __NM_NETLINK_H__ */
|