2022-02-07 06:35:29 +05:30
|
|
|
// Copyright 2011-2018 Nicholas J. Kain <njkain at gmail dot com>
|
|
|
|
// SPDX-License-Identifier: MIT
|
2011-07-04 03:00:55 +05:30
|
|
|
#ifndef NK_NL_H_
|
|
|
|
#define NK_NL_H_
|
|
|
|
|
|
|
|
// Limited netlink code. The horrors...
|
|
|
|
|
|
|
|
#include <linux/netlink.h>
|
2014-03-15 12:14:43 +05:30
|
|
|
#include <linux/rtnetlink.h>
|
2011-07-04 03:00:55 +05:30
|
|
|
|
|
|
|
static inline int nlmsg_get_error(const struct nlmsghdr *nlh)
|
|
|
|
{
|
2014-03-24 19:25:55 +05:30
|
|
|
const struct nlmsgerr *err = (const struct nlmsgerr *)NLMSG_DATA(nlh);
|
2011-07-04 03:00:55 +05:30
|
|
|
if (nlh->nlmsg_len < sizeof(struct nlmsgerr) + NLMSG_HDRLEN)
|
|
|
|
return EBADMSG;
|
2014-06-14 08:05:57 +05:30
|
|
|
return -err->error;
|
2011-07-04 03:00:55 +05:30
|
|
|
}
|
|
|
|
|
2014-03-18 07:40:58 +05:30
|
|
|
int rtattr_assign(struct rtattr *attr, int type, void *data);
|
|
|
|
int nl_add_rtattr(struct nlmsghdr *n, size_t max_length, int type,
|
|
|
|
const void *data, size_t data_length);
|
2014-03-15 12:14:43 +05:30
|
|
|
typedef int (*nl_rtattr_parse_fn)(struct rtattr *attr, int type, void *data);
|
2014-03-18 07:40:58 +05:30
|
|
|
void nl_rtattr_parse(const struct nlmsghdr *nlh, size_t offset,
|
|
|
|
nl_rtattr_parse_fn workfn, void *data);
|
2011-07-04 03:00:55 +05:30
|
|
|
|
2015-05-27 21:53:50 +05:30
|
|
|
ssize_t nl_recv_buf(int fd, char *buf, size_t blen);
|
2011-07-04 03:00:55 +05:30
|
|
|
|
2014-03-15 12:14:43 +05:30
|
|
|
typedef void (*nlmsg_foreach_fn)(const struct nlmsghdr *, void *);
|
2015-05-27 21:53:50 +05:30
|
|
|
int nl_foreach_nlmsg(char *buf, size_t blen, uint32_t seq,
|
2014-03-18 07:40:58 +05:30
|
|
|
uint32_t portid,
|
|
|
|
nlmsg_foreach_fn pfn, void *fnarg);
|
2018-02-09 13:09:46 +05:30
|
|
|
int nl_sendgetlinks(int fd, uint32_t seq);
|
|
|
|
int nl_sendgetlink(int fd, uint32_t seq, int ifindex);
|
|
|
|
int nl_sendgetaddr(int fd, uint32_t seq, uint32_t ifindex);
|
|
|
|
int nl_sendgetaddr4(int fd, uint32_t seq, uint32_t ifindex);
|
|
|
|
int nl_sendgetaddr6(int fd, uint32_t seq, uint32_t ifindex);
|
|
|
|
int nl_sendgetaddrs(int fd, uint32_t seq);
|
|
|
|
int nl_sendgetaddrs4(int fd, uint32_t seq);
|
|
|
|
int nl_sendgetaddrs6(int fd, uint32_t seq);
|
2014-03-18 07:40:58 +05:30
|
|
|
|
2018-02-09 13:09:46 +05:30
|
|
|
int nl_open(int nltype, unsigned nlgroup, uint32_t *nlportid);
|
2011-07-04 03:00:55 +05:30
|
|
|
|
2022-02-07 06:35:29 +05:30
|
|
|
#endif
|
|
|
|
|