Style and simplify.

This commit is contained in:
maxv 2018-02-15 13:51:32 +00:00
parent 2ebc96e2af
commit 30a9923153
1 changed files with 37 additions and 38 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: xform_ipcomp.c,v 1.56 2018/02/15 04:24:32 ozaki-r Exp $ */
/* $NetBSD: xform_ipcomp.c,v 1.57 2018/02/15 13:51:32 maxv Exp $ */
/* $FreeBSD: src/sys/netipsec/xform_ipcomp.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */
/* $OpenBSD: ip_ipcomp.c,v 1.1 2001/07/05 12:08:52 jjbg Exp $ */
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: xform_ipcomp.c,v 1.56 2018/02/15 04:24:32 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: xform_ipcomp.c,v 1.57 2018/02/15 13:51:32 maxv Exp $");
/* IP payload compression protocol (IPComp), see RFC 2393 */
#if defined(_KERNEL_OPT)
@ -74,7 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: xform_ipcomp.c,v 1.56 2018/02/15 04:24:32 ozaki-r Ex
percpu_t *ipcompstat_percpu;
int ipcomp_enable = 1;
int ipcomp_enable = 1;
#ifdef __FreeBSD__
SYSCTL_DECL(_net_inet_ipcomp);
@ -258,7 +258,7 @@ ipcomp_input_cb(struct cryptop *crp)
struct secasindex *saidx __diagused;
int hlen = IPCOMP_HLENGTH, error, clen;
uint8_t nproto;
void *addr;
struct ipcomp *ipc;
uint16_t dport;
uint16_t sport;
IPSEC_DECLARE_LOCK_VARIABLE;
@ -303,27 +303,28 @@ ipcomp_input_cb(struct cryptop *crp)
/* Update the counters */
IPCOMP_STATADD(IPCOMP_STAT_IBYTES, m->m_pkthdr.len - skip - hlen);
clen = crp->crp_olen; /* Length of data after processing */
/* Length of data after processing */
clen = crp->crp_olen;
/* Release the crypto descriptors */
pool_cache_put(ipcomp_tdb_crypto_pool_cache, tc);
tc = NULL;
crypto_freereq(crp), crp = NULL;
crypto_freereq(crp);
crp = NULL;
/* In case it's not done already, adjust the size of the mbuf chain */
m->m_pkthdr.len = clen + hlen + skip;
if (m->m_len < skip + hlen && (m = m_pullup(m, skip + hlen)) == 0) {
IPCOMP_STATINC(IPCOMP_STAT_HDROPS); /*XXX*/
IPCOMP_STATINC(IPCOMP_STAT_HDROPS);
DPRINTF(("%s: m_pullup failed\n", __func__));
error = EINVAL; /*XXX*/
error = EINVAL;
goto bad;
}
/* Keep the next protocol field */
addr = (uint8_t*) mtod(m, struct ip *) + skip;
nproto = ((struct ipcomp *) addr)->comp_nxt;
ipc = (struct ipcomp *)(mtod(m, uint8_t *) + skip);
nproto = ipc->comp_nxt;
switch (nproto) {
case IPPROTO_IPCOMP:
case IPPROTO_AH:
@ -349,13 +350,14 @@ ipcomp_input_cb(struct cryptop *crp)
}
/* Restore the Next Protocol field */
m_copyback(m, protoff, sizeof(uint8_t), (uint8_t *) &nproto);
m_copyback(m, protoff, sizeof(uint8_t), (uint8_t *)&nproto);
IPSEC_COMMON_INPUT_CB(m, sav, skip, protoff);
KEY_SA_UNREF(&sav);
IPSEC_RELEASE_GLOBAL_LOCKS();
return error;
bad:
if (sav)
KEY_SA_UNREF(&sav);
@ -373,14 +375,8 @@ bad:
* IPComp output routine, called by ipsec[46]_process_packet()
*/
static int
ipcomp_output(
struct mbuf *m,
const struct ipsecrequest *isr,
struct secasvar *sav,
struct mbuf **mp,
int skip,
int protoff
)
ipcomp_output(struct mbuf *m, const struct ipsecrequest *isr,
struct secasvar *sav, struct mbuf **mp, int skip, int protoff)
{
char buf[IPSEC_ADDRSTRLEN];
const struct comp_algo *ipcompx;
@ -394,9 +390,10 @@ ipcomp_output(
KASSERT(sav->tdb_compalgxform != NULL);
ipcompx = sav->tdb_compalgxform;
ralen = m->m_pkthdr.len - skip; /* Raw payload length before comp. */
/* Don't process the packet if it is too short */
/* Raw payload length before comp. */
ralen = m->m_pkthdr.len - skip;
/* Don't process the packet if it is too short */
if (ralen < ipcompx->minlen) {
IPCOMP_STATINC(IPCOMP_STAT_MINLEN);
return ipsec_process_done(m, isr, sav);
@ -410,14 +407,14 @@ ipcomp_output(
switch (sav->sah->saidx.dst.sa.sa_family) {
#ifdef INET
case AF_INET:
maxpacketsize = IP_MAXPACKET;
maxpacketsize = IP_MAXPACKET;
break;
#endif /* INET */
#endif
#ifdef INET6
case AF_INET6:
maxpacketsize = IPV6_MAXPACKET;
maxpacketsize = IPV6_MAXPACKET;
break;
#endif /* INET6 */
#endif
default:
IPCOMP_STATINC(IPCOMP_STAT_NOPF);
DPRINTF(("%s: unknown/unsupported protocol family %d"
@ -522,10 +519,11 @@ ipcomp_output(
crp->crp_sid = sav->tdb_cryptoid;
return crypto_dispatch(crp);
bad:
if (m)
m_freem(m);
return (error);
return error;
}
/*
@ -594,18 +592,18 @@ ipcomp_output_cb(struct cryptop *crp)
#ifdef INET
case AF_INET:
ipcomp->comp_nxt = mtod(m, struct ip *)->ip_p;
break;
#endif /* INET */
break;
#endif
#ifdef INET6
case AF_INET6:
ipcomp->comp_nxt = mtod(m, struct ip6_hdr *)->ip6_nxt;
break;
break;
#endif
}
ipcomp->comp_flags = 0;
if ((sav->flags & SADB_X_EXT_RAWCPI) == 0)
cpi = sav->alg_enc;
cpi = sav->alg_enc;
else
cpi = ntohl(sav->spi) & 0xffff;
ipcomp->comp_cpi = htons(cpi);
@ -620,13 +618,13 @@ ipcomp_output_cb(struct cryptop *crp)
case AF_INET:
mtod(m, struct ip *)->ip_len = htons(m->m_pkthdr.len);
break;
#endif /* INET */
#endif
#ifdef INET6
case AF_INET6:
mtod(m, struct ip6_hdr *)->ip6_plen =
htons(m->m_pkthdr.len) - sizeof(struct ip6_hdr);
htons(m->m_pkthdr.len) - sizeof(struct ip6_hdr);
break;
#endif /* INET6 */
#endif
default:
IPCOMP_STATINC(IPCOMP_STAT_NOPF);
DPRINTF(("ipcomp_output: unknown/unsupported protocol "
@ -640,11 +638,11 @@ ipcomp_output_cb(struct cryptop *crp)
} else {
/* compression was useless, we have lost time */
IPCOMP_STATINC(IPCOMP_STAT_USELESS);
DPRINTF(("ipcomp_output_cb: compression was useless : initial size was %d"
"and compressed size is %d\n", rlen, crp->crp_olen));
DPRINTF(("ipcomp_output_cb: compression was useless: initial"
"size was %d and compressed size is %d\n", rlen,
crp->crp_olen));
}
/* Release the crypto descriptor */
pool_cache_put(ipcomp_tdb_crypto_pool_cache, tc);
crypto_freereq(crp);
@ -655,6 +653,7 @@ ipcomp_output_cb(struct cryptop *crp)
KEY_SP_UNREF(&isr->sp);
IPSEC_RELEASE_GLOBAL_LOCKS();
return error;
bad:
if (sav)
KEY_SA_UNREF(&sav);