Moving charon to libcharon.
[strongswan.git] / src / libcharon / plugins / kernel_netlink / kernel_netlink_shared.h
1 /*
2 * Copyright (C) 2008 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #ifndef KERNEL_NETLINK_SHARED_H_
17 #define KERNEL_NETLINK_SHARED_H_
18
19 #include <library.h>
20
21 #include <linux/rtnetlink.h>
22
23 /**
24 * General purpose netlink buffer.
25 *
26 * 1024 byte is currently sufficient for all operations. Some platform
27 * require an enforced aligment to four bytes (e.g. ARM).
28 */
29 typedef u_char netlink_buf_t[1024] __attribute__((aligned(RTA_ALIGNTO)));
30
31 typedef struct netlink_socket_t netlink_socket_t;
32
33 /**
34 * Wrapper around a netlink socket.
35 */
36 struct netlink_socket_t {
37
38 /**
39 * Send a netlink message and wait for a reply.
40 *
41 * @param in netlink message to send
42 * @param out received netlink message
43 * @param out_len length of the received message
44 */
45 status_t (*send)(netlink_socket_t *this, struct nlmsghdr *in, struct nlmsghdr **out, size_t *out_len);
46
47 /**
48 * Send a netlink message and wait for its acknowledge.
49 *
50 * @param in netlink message to send
51 */
52 status_t (*send_ack)(netlink_socket_t *this, struct nlmsghdr *in);
53
54 /**
55 * Destroy the socket.
56 */
57 void (*destroy)(netlink_socket_t *this);
58 };
59
60 /**
61 * Create a netlink_socket_t object.
62 *
63 * @param protocol protocol type (e.g. NETLINK_XFRM or NETLINK_ROUTE)
64 */
65 netlink_socket_t *netlink_socket_create(int protocol);
66
67 /**
68 * Creates an rtattr and adds it to the given netlink message.
69 *
70 * @param hdr netlink message
71 * @param rta_type type of the rtattr
72 * @param data data to add to the rtattr
73 * @param buflen length of the netlink message buffer
74 */
75 void netlink_add_attribute(struct nlmsghdr *hdr, int rta_type, chunk_t data, size_t buflen);
76
77 #endif /* KERNEL_NETLINK_SHARED_H_ */