2011-07-25 12:00:57 +05:30
|
|
|
/* nl.h - low level netlink protocol functions
|
|
|
|
*
|
2014-03-13 00:55:07 +05:30
|
|
|
* Copyright (c) 2011-2014 Nicholas J. Kain <njkain at gmail dot com>
|
2011-07-25 12:00:57 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
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
|
|
|
|
2014-03-18 07:40:58 +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 *);
|
2014-03-18 07:40:58 +05:30
|
|
|
int nl_foreach_nlmsg(char *buf, size_t blen, uint32_t seq,
|
|
|
|
uint32_t portid,
|
|
|
|
nlmsg_foreach_fn pfn, void *fnarg);
|
|
|
|
int nl_sendgetlinks(int fd, int seq);
|
|
|
|
int nl_sendgetlink(int fd, int seq, int ifindex);
|
2014-03-28 09:39:53 +05:30
|
|
|
int nl_sendgetaddr4(int fd, int seq, int ifindex);
|
|
|
|
int nl_sendgetaddr6(int fd, int seq, int ifindex);
|
|
|
|
int nl_sendgetaddrs(int fd, int seq);
|
|
|
|
int nl_sendgetaddrs4(int fd, int seq);
|
|
|
|
int nl_sendgetaddrs6(int fd, int seq);
|
2014-03-18 07:40:58 +05:30
|
|
|
|
|
|
|
int nl_open(int nltype, int nlgroup, int *nlportid);
|
2011-07-04 03:00:55 +05:30
|
|
|
|
|
|
|
#endif /* NK_NL_H_ */
|