using aligned buffers for netlink

This commit is contained in:
Martin Willi
2008-11-14 14:23:11 +00:00
parent 32ec3c1a8b
commit 21bf86f740
3 changed files with 23 additions and 14 deletions
@@ -735,7 +735,7 @@ static status_t get_spi_internal(private_kernel_netlink_ipsec_t *this,
host_t *src, host_t *dst, u_int8_t proto, u_int32_t min, u_int32_t max, host_t *src, host_t *dst, u_int8_t proto, u_int32_t min, u_int32_t max,
u_int32_t reqid, u_int32_t *spi) u_int32_t reqid, u_int32_t *spi)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr, *out; struct nlmsghdr *hdr, *out;
struct xfrm_userspi_info *userspi; struct xfrm_userspi_info *userspi;
u_int32_t received_spi = 0; u_int32_t received_spi = 0;
@@ -858,7 +858,7 @@ static status_t add_sa(private_kernel_netlink_ipsec_t *this,
ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi, ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
bool encap, bool inbound) bool encap, bool inbound)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
char *alg_name; char *alg_name;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
struct xfrm_usersa_info *sa; struct xfrm_usersa_info *sa;
@@ -1081,7 +1081,7 @@ static status_t get_replay_state(private_kernel_netlink_ipsec_t *this,
u_int32_t spi, protocol_id_t protocol, host_t *dst, u_int32_t spi, protocol_id_t protocol, host_t *dst,
struct xfrm_replay_state *replay) struct xfrm_replay_state *replay)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr, *out = NULL; struct nlmsghdr *hdr, *out = NULL;
struct xfrm_aevent_id *out_aevent = NULL, *aevent_id; struct xfrm_aevent_id *out_aevent = NULL, *aevent_id;
size_t len; size_t len;
@@ -1168,7 +1168,7 @@ static status_t get_replay_state(private_kernel_netlink_ipsec_t *this,
static status_t del_sa(private_kernel_netlink_ipsec_t *this, host_t *dst, static status_t del_sa(private_kernel_netlink_ipsec_t *this, host_t *dst,
u_int32_t spi, protocol_id_t protocol, u_int16_t cpi) u_int32_t spi, protocol_id_t protocol, u_int16_t cpi)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
struct xfrm_usersa_id *sa_id; struct xfrm_usersa_id *sa_id;
@@ -1211,7 +1211,8 @@ static status_t update_sa(private_kernel_netlink_ipsec_t *this,
host_t *new_src, host_t *new_dst, host_t *new_src, host_t *new_dst,
bool old_encap, bool new_encap) bool old_encap, bool new_encap)
{ {
unsigned char request[NETLINK_BUFFER_SIZE], *pos; netlink_buf_t request;
u_char *pos;
struct nlmsghdr *hdr, *out = NULL; struct nlmsghdr *hdr, *out = NULL;
struct xfrm_usersa_id *sa_id; struct xfrm_usersa_id *sa_id;
struct xfrm_usersa_info *out_sa = NULL, *sa; struct xfrm_usersa_info *out_sa = NULL, *sa;
@@ -1397,7 +1398,7 @@ static status_t add_policy(private_kernel_netlink_ipsec_t *this,
iterator_t *iterator; iterator_t *iterator;
policy_entry_t *current, *policy; policy_entry_t *current, *policy;
bool found = FALSE; bool found = FALSE;
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct xfrm_userpolicy_info *policy_info; struct xfrm_userpolicy_info *policy_info;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
@@ -1582,7 +1583,7 @@ static status_t query_policy(private_kernel_netlink_ipsec_t *this,
traffic_selector_t *dst_ts, traffic_selector_t *dst_ts,
policy_dir_t direction, u_int32_t *use_time) policy_dir_t direction, u_int32_t *use_time)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *out = NULL, *hdr; struct nlmsghdr *out = NULL, *hdr;
struct xfrm_userpolicy_id *policy_id; struct xfrm_userpolicy_id *policy_id;
struct xfrm_userpolicy_info *policy = NULL; struct xfrm_userpolicy_info *policy = NULL;
@@ -1654,7 +1655,7 @@ static status_t del_policy(private_kernel_netlink_ipsec_t *this,
{ {
policy_entry_t *current, policy, *to_delete = NULL; policy_entry_t *current, policy, *to_delete = NULL;
route_entry_t *route; route_entry_t *route;
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
struct xfrm_userpolicy_id *policy_id; struct xfrm_userpolicy_id *policy_id;
enumerator_t *enumerator; enumerator_t *enumerator;
@@ -761,7 +761,7 @@ static bool addr_in_subnet(chunk_t addr, chunk_t net, int net_len)
static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest, static host_t *get_route(private_kernel_netlink_net_t *this, host_t *dest,
bool nexthop, host_t *candidate) bool nexthop, host_t *candidate)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr, *out, *current; struct nlmsghdr *hdr, *out, *current;
struct rtmsg *msg; struct rtmsg *msg;
chunk_t chunk; chunk_t chunk;
@@ -948,7 +948,7 @@ static host_t* get_nexthop(private_kernel_netlink_net_t *this, host_t *dest)
static status_t manage_ipaddr(private_kernel_netlink_net_t *this, int nlmsg_type, static status_t manage_ipaddr(private_kernel_netlink_net_t *this, int nlmsg_type,
int flags, int if_index, host_t *ip) int flags, int if_index, host_t *ip)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
struct ifaddrmsg *msg; struct ifaddrmsg *msg;
chunk_t chunk; chunk_t chunk;
@@ -1116,7 +1116,7 @@ static status_t manage_srcroute(private_kernel_netlink_net_t *this, int nlmsg_ty
int flags, chunk_t dst_net, u_int8_t prefixlen, int flags, chunk_t dst_net, u_int8_t prefixlen,
host_t *gateway, host_t *src_ip, char *if_name) host_t *gateway, host_t *src_ip, char *if_name)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
struct rtmsg *msg; struct rtmsg *msg;
int ifindex; int ifindex;
@@ -1196,7 +1196,7 @@ status_t del_route(private_kernel_netlink_net_t *this, chunk_t dst_net,
*/ */
static status_t init_address_list(private_kernel_netlink_net_t *this) static status_t init_address_list(private_kernel_netlink_net_t *this)
{ {
char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *out, *current, *in; struct nlmsghdr *out, *current, *in;
struct rtgenmsg *msg; struct rtgenmsg *msg;
size_t len; size_t len;
@@ -1288,7 +1288,7 @@ static status_t init_address_list(private_kernel_netlink_net_t *this)
static status_t manage_rule(private_kernel_netlink_net_t *this, int nlmsg_type, static status_t manage_rule(private_kernel_netlink_net_t *this, int nlmsg_type,
u_int32_t table, u_int32_t prio) u_int32_t table, u_int32_t prio)
{ {
unsigned char request[NETLINK_BUFFER_SIZE]; netlink_buf_t request;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
struct rtmsg *msg; struct rtmsg *msg;
chunk_t chunk; chunk_t chunk;
@@ -20,7 +20,15 @@
#include <library.h> #include <library.h>
#define NETLINK_BUFFER_SIZE 1024 #include <linux/rtnetlink.h>
/**
* General purpose netlink buffer.
*
* 1024 byte is currently sufficient for all operations. Some platform
* require an enforced aligment to four bytes (e.g. ARM).
*/
typedef u_char netlink_buf_t[1024] __attribute__((aligned(RTA_ALIGNTO)));
typedef struct netlink_socket_t netlink_socket_t; typedef struct netlink_socket_t netlink_socket_t;