-/* $OpenBSD: iked.h,v 1.80 2014/05/09 06:29:46 markus Exp $ */
+/* $OpenBSD: iked.h,v 1.81 2014/05/09 06:37:24 markus Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
u_int8_t flow_ipproto;
u_int8_t flow_type;
- struct iked_id *flow_srcid;
- struct iked_id *flow_dstid;
-
struct iked_addr *flow_local; /* outer source */
struct iked_addr *flow_peer; /* outer dest */
struct iked_sa *flow_ikesa; /* parent SA */
struct ibuf *csa_integrkey; /* auth key */
u_int16_t csa_integrid; /* auth xform id */
- struct iked_id *csa_srcid;
- struct iked_id *csa_dstid;
-
struct iked_addr *csa_local; /* outer source */
struct iked_addr *csa_peer; /* outer dest */
struct iked_sa *csa_ikesa; /* parent SA */
struct iked_id sa_rid; /* responder id */
struct iked_id sa_icert; /* initiator cert */
struct iked_id sa_rcert; /* responder cert */
+#define IKESA_SRCID(x) ((x)->sa_hdr.sh_initiator ? &(x)->sa_iid : &(x)->sa_rid)
+#define IKESA_DSTID(x) ((x)->sa_hdr.sh_initiator ? &(x)->sa_rid : &(x)->sa_iid)
char *sa_eapid; /* EAP identity */
struct iked_id sa_eap; /* EAP challenge */
-/* $OpenBSD: ikev2.c,v 1.111 2014/05/09 06:29:46 markus Exp $ */
+/* $OpenBSD: ikev2.c,v 1.112 2014/05/09 06:37:24 markus Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
struct iked_transform *xform, *encrxf = NULL, *integrxf = NULL;
struct iked_childsa *csa, *csb;
struct iked_flow *flow, *saflow, *flowa, *flowb;
- struct iked_id *peerid, *localid;
struct ibuf *keymat = NULL, *seed = NULL, *dhsecret = NULL;
struct group *group;
u_int32_t spi = 0;
if (!sa_stateok(sa, IKEV2_STATE_VALID))
return (-1);
- if (sa->sa_hdr.sh_initiator) {
- peerid = &sa->sa_rid;
- localid = &sa->sa_iid;
- } else {
- peerid = &sa->sa_iid;
- localid = &sa->sa_rid;
- }
-
- if (ikev2_sa_tag(sa, peerid) == -1)
+ if (ikev2_sa_tag(sa, IKESA_DSTID(sa)) == -1)
return (-1);
/* We need to determine the key material length first */
memcpy(flowa, flow, sizeof(*flow));
flowa->flow_dir = IPSP_DIRECTION_OUT;
flowa->flow_saproto = prop->prop_protoid;
- flowa->flow_srcid = localid;
- flowa->flow_dstid = peerid;
flowa->flow_local = &sa->sa_local;
flowa->flow_peer = &sa->sa_peer;
flowa->flow_ikesa = sa;
csa->csa_saproto = prop->prop_protoid;
csa->csa_ikesa = sa;
- csa->csa_srcid = localid;
- csa->csa_dstid = peerid;
csa->csa_spi.spi_protoid = prop->prop_protoid;
csa->csa_esn = esn;
/* install IPCOMP SAs */
csa->csa_ikesa = sa;
csa->csa_saproto = IKEV2_SAPROTO_IPCOMP;
- if (sa->sa_hdr.sh_initiator) {
- csa->csa_dstid = &sa->sa_rid;
- csa->csa_srcid = &sa->sa_iid;
- } else {
- csa->csa_dstid = &sa->sa_iid;
- csa->csa_srcid = &sa->sa_rid;
- }
csa->csa_spi.spi_size = 2;
csa->csa_spi.spi = sa->sa_cpi_out;
csa->csa_peerspi = sa->sa_cpi_in;
/* setup ESP flows for gateways */
flowa->flow_dir = IPSP_DIRECTION_OUT;
flowa->flow_saproto = IKEV2_SAPROTO_ESP;
- if (sa->sa_hdr.sh_initiator) {
- flowa->flow_dstid = &sa->sa_rid;
- flowa->flow_srcid = &sa->sa_iid;
- } else {
- flowa->flow_dstid = &sa->sa_iid;
- flowa->flow_srcid = &sa->sa_rid;
- }
flowa->flow_local = &sa->sa_local;
flowa->flow_peer = &sa->sa_peer;
memcpy(&flowa->flow_src, &sa->sa_local, sizeof(sa->sa_local));
-/* $OpenBSD: pfkey.c,v 1.36 2014/05/09 06:29:46 markus Exp $ */
+/* $OpenBSD: pfkey.c,v 1.37 2014/05/09 06:37:24 markus Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
(sizeof(sa_peer) + ROUNDUP(speer.ss_len)) / 8;
/* local id */
- sa_srcid = pfkey_id2ident(flow->flow_srcid,
+ sa_srcid = pfkey_id2ident(IKESA_SRCID(flow->flow_ikesa),
SADB_EXT_IDENTITY_SRC);
/* peer id */
- sa_dstid = pfkey_id2ident(flow->flow_dstid,
+ sa_dstid = pfkey_id2ident(IKESA_DSTID(flow->flow_ikesa),
SADB_EXT_IDENTITY_DST);
}
if (satype == SADB_X_SATYPE_IPCOMP)
sadb.sadb_sa_encrypt = SADB_X_CALG_DEFLATE;
- /* local id */
- sa_srcid = pfkey_id2ident(sa->csa_srcid, SADB_EXT_IDENTITY_SRC);
-
- /* peer id */
- sa_dstid = pfkey_id2ident(sa->csa_dstid, SADB_EXT_IDENTITY_DST);
+ /* Note that we need to swap the IDs for incoming SAs (SADB_UPDATE) */
+ if (action != SADB_UPDATE) {
+ sa_srcid = pfkey_id2ident(
+ IKESA_SRCID(sa->csa_ikesa), SADB_EXT_IDENTITY_SRC);
+ sa_dstid = pfkey_id2ident(
+ IKESA_DSTID(sa->csa_ikesa), SADB_EXT_IDENTITY_DST);
+ } else {
+ sa_srcid = pfkey_id2ident(
+ IKESA_DSTID(sa->csa_ikesa), SADB_EXT_IDENTITY_SRC);
+ sa_dstid = pfkey_id2ident(
+ IKESA_SRCID(sa->csa_ikesa), SADB_EXT_IDENTITY_DST);
+ }
tag = sa->csa_ikesa->sa_tag;
if (tag != NULL && *tag != '\0') {