#include <sys/socket.h>
#include <netinet/in.h>
-#ifdef __APPLE__
-#include <System/net/pfkeyv2.h>
-#else
#include <net/pfkeyv2.h>
-#endif
#ifdef HAVE_NETINET6_IPSEC
# include <netinet6/ipsec.h>
#else
#include <errno.h>
#include <stdlib.h>
+#include "var.h"
#include "libpfkey.h"
#include "vchar.h"
#include "extern.h"
static int p_aiflags = 0, p_aifamily = PF_UNSPEC;
-static struct addrinfo *parse_addr __P((char *, char *));
-static int fix_portstr __P((vchar_t *, vchar_t *, vchar_t *));
-static int setvarbuf __P((char *, int *, struct sadb_ext *, int,
- const void *, int));
-void parse_init __P((void));
-void free_buffer __P((void));
-
-int setkeymsg0 __P((struct sadb_msg *, unsigned int, unsigned int, size_t));
-static int setkeymsg_spdaddr __P((unsigned int, unsigned int, vchar_t *,
- struct addrinfo *, int, struct addrinfo *, int));
-static int setkeymsg_spdaddr_tag __P((unsigned int, char *, vchar_t *));
-static int setkeymsg_addr __P((unsigned int, unsigned int,
- struct addrinfo *, struct addrinfo *, int));
-static int setkeymsg_add __P((unsigned int, unsigned int,
- struct addrinfo *, struct addrinfo *));
+static struct addrinfo *parse_addr(char *, char *);
+static int fix_portstr(vchar_t *, vchar_t *, vchar_t *);
+static int setvarbuf(char *, int *, struct sadb_ext *, int, const void *, int);
+void parse_init(void);
+void free_buffer(void);
+
+int setkeymsg0(struct sadb_msg *, unsigned int, unsigned int, size_t);
+static int setkeymsg_spdaddr(unsigned int, unsigned int, vchar_t *,
+ struct addrinfo *, int, struct addrinfo *, int);
+static int setkeymsg_spdaddr_tag(unsigned int, char *, vchar_t *);
+static int setkeymsg_addr(unsigned int, unsigned int,
+ struct addrinfo *, struct addrinfo *, int);
+static int setkeymsg_add(unsigned int, unsigned int,
+ struct addrinfo *, struct addrinfo *);
%}
%union {
int dplen;
{
struct sadb_msg *msg;
- char buf[BUFSIZ];
+ union { // Wcast-align fix - force alignment
+ u_int64_t force_align;
+ char buf[BUFSIZ];
+ } u_buf;
int l, l0;
struct sadb_address m_addr;
struct addrinfo *s, *d;
int saved_level, saved_id = 0;
#endif
- msg = (struct sadb_msg *)buf;
+ msg = (struct sadb_msg *)&u_buf;
if (!srcs || !dsts)
return -1;
setkeymsg0(msg, type, SADB_SATYPE_UNSPEC, 0);
l = sizeof(struct sadb_msg);
- sp = (struct sadb_x_policy*) (buf + l);
- memcpy(buf + l, policy->buf, policy->len);
+ sp = ALIGNED_CAST(struct sadb_x_policy*)(u_buf.buf + l);
+ memcpy(u_buf.buf + l, policy->buf, policy->len);
l += policy->len;
l0 = l;
(splen >= 0 ? splen : plen);
m_addr.sadb_address_reserved = 0;
- setvarbuf(buf, &l, (struct sadb_ext *)&m_addr,
+ setvarbuf(u_buf.buf, &l, (struct sadb_ext *)&m_addr,
sizeof(m_addr), (caddr_t)sa, salen);
/* set dst */
(dplen >= 0 ? dplen : plen);
m_addr.sadb_address_reserved = 0;
- setvarbuf(buf, &l, (struct sadb_ext *)&m_addr,
+ setvarbuf(u_buf.buf, &l, (struct sadb_ext *)&m_addr,
sizeof(m_addr), sa, salen);
msg->sadb_msg_len = PFKEY_UNIT64(l);
- sendkeymsg(buf, l);
+ sendkeymsg(u_buf.buf, l);
#ifdef HAVE_POLICY_FWD
/* create extra call for FWD policy */
vchar_t *policy;
{
struct sadb_msg *msg;
- char buf[BUFSIZ];
+ union { // Wcast-align fix - force alignment
+ u_int64_t force_align;
+ char buf[BUFSIZ];
+ } u_buf;
int l, l0;
#ifdef SADB_X_EXT_TAG
struct sadb_x_tag m_tag;
#endif
int n;
- msg = (struct sadb_msg *)buf;
+ msg = (struct sadb_msg *)&u_buf;
/* fix up length afterwards */
setkeymsg0(msg, type, SADB_SATYPE_UNSPEC, 0);
l = sizeof(struct sadb_msg);
- memcpy(buf + l, policy->buf, policy->len);
+ memcpy(u_buf.buf + l, policy->buf, policy->len);
l += policy->len;
l0 = l;
msg->sadb_msg_len = PFKEY_UNIT64(l);
- sendkeymsg(buf, l);
+ sendkeymsg(u_buf.buf, l);
return 0;
}
int no_spi;
{
struct sadb_msg *msg;
- char buf[BUFSIZ];
+ union { // Wcast-align fix - force alignment
+ u_int64_t force_align;
+ char buf[BUFSIZ];
+ } u_buf;
int l, l0, len;
struct sadb_sa m_sa;
struct sadb_x_sa2 m_sa2;
struct sockaddr *sa;
int salen;
- msg = (struct sadb_msg *)buf;
+ msg = (struct sadb_msg *)&u_buf;
if (!srcs || !dsts)
return -1;
m_sa.sadb_sa_encrypt = p_alg_enc;
m_sa.sadb_sa_flags = p_ext;
- memcpy(buf + l, &m_sa, len);
+ memcpy(u_buf.buf + l, &m_sa, len);
l += len;
len = sizeof(struct sadb_x_sa2);
m_sa2.sadb_x_sa2_mode = p_mode;
m_sa2.sadb_x_sa2_reqid = p_reqid;
- memcpy(buf + l, &m_sa2, len);
+ memcpy(u_buf.buf + l, &m_sa2, len);
l += len;
}
m_addr.sadb_address_prefixlen = plen;
m_addr.sadb_address_reserved = 0;
- setvarbuf(buf, &l, (struct sadb_ext *)&m_addr,
+ setvarbuf(u_buf.buf, &l, (struct sadb_ext *)&m_addr,
sizeof(m_addr), sa, salen);
/* set dst */
m_addr.sadb_address_prefixlen = plen;
m_addr.sadb_address_reserved = 0;
- setvarbuf(buf, &l, (struct sadb_ext *)&m_addr,
+ setvarbuf(u_buf.buf, &l, (struct sadb_ext *)&m_addr,
sizeof(m_addr), sa, salen);
msg->sadb_msg_len = PFKEY_UNIT64(l);
- sendkeymsg(buf, l);
+ sendkeymsg(u_buf.buf, l);
n++;
}
#ifdef SADB_X_EXT_NAT_T_TYPE
static u_int16_t get_port (struct addrinfo *addr)
{
- struct sockaddr *s = addr->ai_addr;
+ struct sockaddr_storage *s = addr->ai_addr;
u_int16_t port = 0;
switch (s->sa_family) {
struct addrinfo *dsts;
{
struct sadb_msg *msg;
- char buf[BUFSIZ];
+ union { // Wcast-align fix - force alignment
+ u_int64_t force_align;
+ char buf[BUFSIZ];
+ } u_buf;
int l, l0, len;
struct sadb_sa m_sa;
struct sadb_x_sa2 m_sa2;
struct sockaddr *sa;
int salen;
- msg = (struct sadb_msg *)buf;
+ msg = (struct sadb_msg *)&u_buf;
if (!srcs || !dsts)
return -1;
m.key.sadb_key_bits = p_key_enc_len * 8;
m.key.sadb_key_reserved = 0;
- setvarbuf(buf, &l, &m.ext, sizeof(m.key),
+ setvarbuf(u_buf.buf, &l, &m.ext, sizeof(m.key),
p_key_enc, p_key_enc_len);
}
m.key.sadb_key_bits = p_key_auth_len * 8;
m.key.sadb_key_reserved = 0;
- setvarbuf(buf, &l, &m.ext, sizeof(m.key),
+ setvarbuf(u_buf.buf, &l, &m.ext, sizeof(m.key),
p_key_auth, p_key_auth_len);
}
m_lt.sadb_lifetime_addtime = p_lt_hard;
m_lt.sadb_lifetime_usetime = 0;
- memcpy(buf + l, &m_lt, slen);
+ memcpy(u_buf.buf + l, &m_lt, slen);
l += slen;
}
m_lt.sadb_lifetime_addtime = p_lt_soft;
m_lt.sadb_lifetime_usetime = 0;
- memcpy(buf + l, &m_lt, slen);
+ memcpy(u_buf.buf + l, &m_lt, slen);
l += slen;
}
m_sa.sadb_sa_encrypt = p_alg_enc;
m_sa.sadb_sa_flags = p_ext;
- memcpy(buf + l, &m_sa, len);
+ memcpy(u_buf.buf + l, &m_sa, len);
l += len;
len = sizeof(struct sadb_x_sa2);
m_sa2.sadb_x_sa2_mode = p_mode;
m_sa2.sadb_x_sa2_reqid = p_reqid;
- memcpy(buf + l, &m_sa2, len);
+ memcpy(u_buf.buf + l, &m_sa2, len);
l += len;
#ifdef SADB_X_EXT_NAT_T_TYPE
m_addr.sadb_address_prefixlen = plen;
m_addr.sadb_address_reserved = 0;
- setvarbuf(buf, &l, (struct sadb_ext *)&m_addr,
+ setvarbuf(u_buf.buf, &l, (struct sadb_ext *)&m_addr,
sizeof(m_addr), sa, salen);
/* set dst */
m_addr.sadb_address_prefixlen = plen;
m_addr.sadb_address_reserved = 0;
- setvarbuf(buf, &l, (struct sadb_ext *)&m_addr,
+ setvarbuf(u_buf.buf, &l, (struct sadb_ext *)&m_addr,
sizeof(m_addr), sa, salen);
#ifdef SADB_X_EXT_NAT_T_TYPE
#endif
msg->sadb_msg_len = PFKEY_UNIT64(l);
- sendkeymsg(buf, l);
+ sendkeymsg(u_buf.buf, l);
n++;
}