Hi,
Is there any benefit for using SA_LEN() in the kernel? It is even
shorter without and only used in ipsec sources. No binary change.
ok?
bluhm
Index: net/pfkeyv2.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pfkeyv2.c,v
retrieving revision 1.153
diff -u -p -r1.153 pfkeyv2.c
--- net/pfkeyv2.c 28 Feb 2017 16:46:27 -0000 1.153
+++ net/pfkeyv2.c 4 May 2017 16:44:03 -0000
@@ -521,8 +521,8 @@ pfkeyv2_get(struct tdb *sa, void **heade
if (sa->tdb_last_used)
i += sizeof(struct sadb_lifetime);
- i += sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_src.sa));
- i += sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_dst.sa));
+ i += sizeof(struct sadb_address) + PADUP(sa->tdb_src.sa.sa_len);
+ i += sizeof(struct sadb_address) + PADUP(sa->tdb_dst.sa.sa_len);
if (sa->tdb_ids) {
i += sizeof(struct sadb_ident) +
PADUP(sa->tdb_ids->id_local->len);
@@ -559,7 +559,7 @@ pfkeyv2_get(struct tdb *sa, void **heade
if (sa->tdb_onext) {
i += sizeof(struct sadb_sa);
i += sizeof(struct sadb_address) +
- PADUP(SA_LEN(&sa->tdb_onext->tdb_dst.sa));
+ PADUP(sa->tdb_onext->tdb_dst.sa.sa_len);
i += sizeof(struct sadb_protocol);
}
@@ -1730,8 +1730,8 @@ pfkeyv2_acquire(struct ipsec_policy *ipo
/* How large a buffer do we need... XXX we only do one proposal for now
*/
i = sizeof(struct sadb_msg) +
(laddr == NULL ? 0 : sizeof(struct sadb_address) +
- PADUP(SA_LEN(&ipo->ipo_src.sa))) +
- sizeof(struct sadb_address) + PADUP(SA_LEN(&gw->sa)) +
+ PADUP(ipo->ipo_src.sa.sa_len)) +
+ sizeof(struct sadb_address) + PADUP(gw->sa.sa_len) +
sizeof(struct sadb_prop) + 1 * sizeof(struct sadb_comb);
if (ipo->ipo_ids) {
@@ -1767,22 +1767,22 @@ pfkeyv2_acquire(struct ipsec_policy *ipo
if (laddr) {
headers[SADB_EXT_ADDRESS_SRC] = p;
- p += sizeof(struct sadb_address) + PADUP(SA_LEN(&laddr->sa));
+ p += sizeof(struct sadb_address) + PADUP(laddr->sa.sa_len);
sadd = (struct sadb_address *) headers[SADB_EXT_ADDRESS_SRC];
sadd->sadb_address_len = (sizeof(struct sadb_address) +
- SA_LEN(&laddr->sa) + sizeof(uint64_t) - 1) /
+ laddr->sa.sa_len + sizeof(uint64_t) - 1) /
sizeof(uint64_t);
bcopy(laddr, headers[SADB_EXT_ADDRESS_SRC] +
- sizeof(struct sadb_address), SA_LEN(&laddr->sa));
+ sizeof(struct sadb_address), laddr->sa.sa_len);
}
headers[SADB_EXT_ADDRESS_DST] = p;
- p += sizeof(struct sadb_address) + PADUP(SA_LEN(&gw->sa));
+ p += sizeof(struct sadb_address) + PADUP(gw->sa.sa_len);
sadd = (struct sadb_address *) headers[SADB_EXT_ADDRESS_DST];
sadd->sadb_address_len = (sizeof(struct sadb_address) +
- SA_LEN(&gw->sa) + sizeof(uint64_t) - 1) / sizeof(uint64_t);
+ gw->sa.sa_len + sizeof(uint64_t) - 1) / sizeof(uint64_t);
bcopy(gw, headers[SADB_EXT_ADDRESS_DST] + sizeof(struct sadb_address),
- SA_LEN(&gw->sa));
+ gw->sa.sa_len);
if (ipo->ipo_ids)
export_identities(&p, ipo->ipo_ids, 0, headers);
@@ -1939,8 +1939,8 @@ pfkeyv2_expire(struct tdb *sa, u_int16_t
i = sizeof(struct sadb_msg) + sizeof(struct sadb_sa) +
2 * sizeof(struct sadb_lifetime) +
- sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_src.sa)) +
- sizeof(struct sadb_address) + PADUP(SA_LEN(&sa->tdb_dst.sa));
+ sizeof(struct sadb_address) + PADUP(sa->tdb_src.sa.sa_len) +
+ sizeof(struct sadb_address) + PADUP(sa->tdb_dst.sa.sa_len);
if (!(p = malloc(i, M_PFKEY, M_NOWAIT | M_ZERO))) {
rval = ENOMEM;
Index: net/pfkeyv2_convert.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/net/pfkeyv2_convert.c,v
retrieving revision 1.59
diff -u -p -r1.59 pfkeyv2_convert.c
--- net/pfkeyv2_convert.c 28 Feb 2017 16:46:27 -0000 1.59
+++ net/pfkeyv2_convert.c 4 May 2017 16:44:38 -0000
@@ -685,12 +685,12 @@ export_address(void **p, struct sockaddr
struct sadb_address *sadb_address = (struct sadb_address *) *p;
sadb_address->sadb_address_len = (sizeof(struct sadb_address) +
- PADUP(SA_LEN(sa))) / sizeof(uint64_t);
+ PADUP(sa->sa_len)) / sizeof(uint64_t);
*p += sizeof(struct sadb_address);
- bcopy(sa, *p, SA_LEN(sa));
+ bcopy(sa, *p, sa->sa_len);
((struct sockaddr *) *p)->sa_family = sa->sa_family;
- *p += PADUP(SA_LEN(sa));
+ *p += PADUP(sa->sa_len);
}
/*
Index: netinet/ip_ipsp.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_ipsp.c,v
retrieving revision 1.220
diff -u -p -r1.220 ip_ipsp.c
--- netinet/ip_ipsp.c 14 Feb 2017 09:51:46 -0000 1.220
+++ netinet/ip_ipsp.c 4 May 2017 16:45:23 -0000
@@ -160,7 +160,7 @@ tdb_hash(u_int rdomain, u_int32_t spi, u
SipHash24_Update(&ctx, &rdomain, sizeof(rdomain));
SipHash24_Update(&ctx, &spi, sizeof(spi));
SipHash24_Update(&ctx, &proto, sizeof(proto));
- SipHash24_Update(&ctx, dst, SA_LEN(&dst->sa));
+ SipHash24_Update(&ctx, dst, dst->sa.sa_len);
return (SipHash24_End(&ctx) & tdb_hashmask);
}
@@ -237,8 +237,8 @@ reserve_spi(u_int rdomain, u_int32_t ssp
tdbp->tdb_spi = spi;
- memcpy(&tdbp->tdb_dst.sa, &dst->sa, SA_LEN(&dst->sa));
- memcpy(&tdbp->tdb_src.sa, &src->sa, SA_LEN(&src->sa));
+ memcpy(&tdbp->tdb_dst.sa, &dst->sa, dst->sa.sa_len);
+ memcpy(&tdbp->tdb_src.sa, &src->sa, src->sa.sa_len);
tdbp->tdb_sproto = sproto;
tdbp->tdb_flags |= TDBF_INVALID; /* Mark SA invalid for now. */
tdbp->tdb_satype = SADB_SATYPE_UNSPEC;
@@ -283,7 +283,7 @@ gettdb(u_int rdomain, u_int32_t spi, uni
for (tdbp = tdbh[hashval]; tdbp != NULL; tdbp = tdbp->tdb_hnext)
if ((tdbp->tdb_spi == spi) && (tdbp->tdb_sproto == proto) &&
(tdbp->tdb_rdomain == rdomain) &&
- !memcmp(&tdbp->tdb_dst, dst, SA_LEN(&dst->sa)))
+ !memcmp(&tdbp->tdb_dst, dst, dst->sa.sa_len))
break;
return tdbp;
@@ -313,8 +313,8 @@ gettdbbysrcdst(u_int rdomain, u_int32_t
(tdbp->tdb_rdomain == rdomain) &&
((tdbp->tdb_flags & TDBF_INVALID) == 0) &&
(tdbp->tdb_dst.sa.sa_family == AF_UNSPEC ||
- !memcmp(&tdbp->tdb_dst, dst, SA_LEN(&dst->sa))) &&
- !memcmp(&tdbp->tdb_src, src, SA_LEN(&src->sa)))
+ !memcmp(&tdbp->tdb_dst, dst, dst->sa.sa_len)) &&
+ !memcmp(&tdbp->tdb_src, src, src->sa.sa_len))
break;
if (tdbp != NULL)
@@ -330,7 +330,7 @@ gettdbbysrcdst(u_int rdomain, u_int32_t
(tdbp->tdb_rdomain == rdomain) &&
((tdbp->tdb_flags & TDBF_INVALID) == 0) &&
(tdbp->tdb_dst.sa.sa_family == AF_UNSPEC ||
- !memcmp(&tdbp->tdb_dst, dst, SA_LEN(&dst->sa))) &&
+ !memcmp(&tdbp->tdb_dst, dst, dst->sa.sa_len)) &&
tdbp->tdb_src.sa.sa_family == AF_UNSPEC)
break;
@@ -395,7 +395,7 @@ gettdbbydst(u_int rdomain, union sockadd
if ((tdbp->tdb_sproto == sproto) &&
(tdbp->tdb_rdomain == rdomain) &&
((tdbp->tdb_flags & TDBF_INVALID) == 0) &&
- (!memcmp(&tdbp->tdb_dst, dst, SA_LEN(&dst->sa)))) {
+ (!memcmp(&tdbp->tdb_dst, dst, dst->sa.sa_len))) {
/* Do IDs match ? */
if (!ipsp_aux_match(tdbp, ids, filter, filtermask))
continue;
@@ -426,7 +426,7 @@ gettdbbysrc(u_int rdomain, union sockadd
if ((tdbp->tdb_sproto == sproto) &&
(tdbp->tdb_rdomain == rdomain) &&
((tdbp->tdb_flags & TDBF_INVALID) == 0) &&
- (!memcmp(&tdbp->tdb_src, src, SA_LEN(&src->sa)))) {
+ (!memcmp(&tdbp->tdb_src, src, src->sa.sa_len))) {
/* Check whether IDs match */
if (!ipsp_aux_match(tdbp, ids, filter,
filtermask))
Index: netinet/ipsec_input.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ipsec_input.c,v
retrieving revision 1.147
diff -u -p -r1.147 ipsec_input.c
--- netinet/ipsec_input.c 14 Apr 2017 20:46:31 -0000 1.147
+++ netinet/ipsec_input.c 4 May 2017 16:45:42 -0000
@@ -806,8 +806,8 @@ udpencap_ctlinput(int cmd, struct sockad
if (tdbp->tdb_sproto == IPPROTO_ESP &&
((tdbp->tdb_flags & (TDBF_INVALID|TDBF_UDPENCAP)) ==
TDBF_UDPENCAP) &&
- !memcmp(&tdbp->tdb_dst, &dst, SA_LEN(&su_dst->sa)) &&
- !memcmp(&tdbp->tdb_src, &src, SA_LEN(&su_src->sa))) {
+ !memcmp(&tdbp->tdb_dst, &dst, su_dst->sa.sa_len) &&
+ !memcmp(&tdbp->tdb_src, &src, su_src->sa.sa_len)) {
if ((adjust = ipsec_hdrsz(tdbp)) != -1) {
/* Store adjusted MTU in tdb */
tdbp->tdb_mtu = mtu - adjust;