X-Git-Url: https://git.saurik.com/apple/ipsec.git/blobdiff_plain/e8d9021d008d9729f3dfcdc16bb03a990513b007..4aae5213ac6b23efbfc7eda20872343e43247100:/ipsec-tools/setkey/parse.y diff --git a/ipsec-tools/setkey/parse.y b/ipsec-tools/setkey/parse.y index 6578a54..42762a0 100644 --- a/ipsec-tools/setkey/parse.y +++ b/ipsec-tools/setkey/parse.y @@ -40,7 +40,7 @@ #include #include -#include +#include #ifdef HAVE_NETINET6_IPSEC # include #else @@ -56,6 +56,7 @@ #include #include +#include "var.h" #include "libpfkey.h" #include "vchar.h" #include "extern.h" @@ -84,21 +85,20 @@ static struct addrinfo * p_natt_oa = NULL; 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 { @@ -862,7 +862,10 @@ setkeymsg_spdaddr(type, upper, policy, srcs, splen, dsts, dplen) 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; @@ -876,7 +879,7 @@ setkeymsg_spdaddr(type, upper, policy, srcs, splen, dsts, dplen) int saved_level, saved_id = 0; #endif - msg = (struct sadb_msg *)buf; + msg = (struct sadb_msg *)&u_buf; if (!srcs || !dsts) return -1; @@ -885,8 +888,8 @@ setkeymsg_spdaddr(type, upper, policy, srcs, splen, dsts, dplen) 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; @@ -924,7 +927,7 @@ setkeymsg_spdaddr(type, upper, policy, srcs, splen, dsts, dplen) (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 */ @@ -938,12 +941,12 @@ setkeymsg_spdaddr(type, upper, policy, srcs, splen, dsts, dplen) (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 */ @@ -989,20 +992,23 @@ setkeymsg_spdaddr_tag(type, tag, 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; @@ -1021,7 +1027,7 @@ setkeymsg_spdaddr_tag(type, tag, policy) msg->sadb_msg_len = PFKEY_UNIT64(l); - sendkeymsg(buf, l); + sendkeymsg(u_buf.buf, l); return 0; } @@ -1036,7 +1042,10 @@ setkeymsg_addr(type, satype, srcs, dsts, no_spi) 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; @@ -1047,7 +1056,7 @@ setkeymsg_addr(type, satype, srcs, dsts, no_spi) struct sockaddr *sa; int salen; - msg = (struct sadb_msg *)buf; + msg = (struct sadb_msg *)&u_buf; if (!srcs || !dsts) return -1; @@ -1067,7 +1076,7 @@ setkeymsg_addr(type, satype, srcs, dsts, no_spi) 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); @@ -1076,7 +1085,7 @@ setkeymsg_addr(type, satype, srcs, dsts, no_spi) 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; } @@ -1114,7 +1123,7 @@ setkeymsg_addr(type, satype, srcs, dsts, no_spi) 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 */ @@ -1127,12 +1136,12 @@ setkeymsg_addr(type, satype, srcs, dsts, no_spi) 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++; } @@ -1147,7 +1156,7 @@ setkeymsg_addr(type, satype, srcs, dsts, no_spi) #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) { @@ -1181,7 +1190,10 @@ setkeymsg_add(type, satype, srcs, dsts) 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; @@ -1192,7 +1204,7 @@ setkeymsg_add(type, satype, srcs, dsts) struct sockaddr *sa; int salen; - msg = (struct sadb_msg *)buf; + msg = (struct sadb_msg *)&u_buf; if (!srcs || !dsts) return -1; @@ -1215,7 +1227,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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); } @@ -1233,7 +1245,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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); } @@ -1249,7 +1261,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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; } @@ -1265,7 +1277,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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; } @@ -1279,7 +1291,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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); @@ -1288,7 +1300,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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 @@ -1366,7 +1378,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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 */ @@ -1379,7 +1391,7 @@ setkeymsg_add(type, satype, srcs, dsts) 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 @@ -1408,7 +1420,7 @@ setkeymsg_add(type, satype, srcs, dsts) #endif msg->sadb_msg_len = PFKEY_UNIT64(l); - sendkeymsg(buf, l); + sendkeymsg(u_buf.buf, l); n++; }