X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_ipsec%2Fesp_outb.c;h=55799a86710ae7dba548a884ef9c8b3608a619c6;hb=72d138ff0f58d2cf2c3ef58b0f5c32e186b82a15;hp=c798bc4c499d4b3255ec0d7280c00e93b63c36af;hpb=3affe1bbcc3e500fda8f6f91016c8b152cdf0d49;p=dpdk.git diff --git a/lib/librte_ipsec/esp_outb.c b/lib/librte_ipsec/esp_outb.c index c798bc4c49..55799a8671 100644 --- a/lib/librte_ipsec/esp_outb.c +++ b/lib/librte_ipsec/esp_outb.c @@ -104,11 +104,11 @@ outb_cop_prepare(struct rte_crypto_op *cop, static inline int32_t outb_tun_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc, const uint64_t ivp[IPSEC_MAX_IV_QWORD], struct rte_mbuf *mb, - union sym_op_data *icv) + union sym_op_data *icv, uint8_t sqh_len) { uint32_t clen, hlen, l2len, pdlen, pdofs, plen, tlen; struct rte_mbuf *ml; - struct esp_hdr *esph; + struct rte_esp_hdr *esph; struct esp_tail *espt; char *ph, *pt; uint64_t *iv; @@ -126,11 +126,11 @@ outb_tun_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc, /* pad length + esp tail */ pdlen = clen - plen; - tlen = pdlen + sa->icv_len; + tlen = pdlen + sa->icv_len + sqh_len; /* do append and prepend */ ml = rte_pktmbuf_lastseg(mb); - if (tlen + sa->sqh_len + sa->aad_len > rte_pktmbuf_tailroom(ml)) + if (tlen + sa->aad_len > rte_pktmbuf_tailroom(ml)) return -ENOSPC; /* prepend header */ @@ -152,11 +152,11 @@ outb_tun_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc, rte_memcpy(ph, sa->hdr, sa->hdr_len); /* update original and new ip header fields */ - update_tun_l3hdr(sa, ph + sa->hdr_l3_off, mb->pkt_len, sa->hdr_l3_off, - sqn_low16(sqc)); + update_tun_outb_l3hdr(sa, ph + sa->hdr_l3_off, ph + hlen, + mb->pkt_len - sqh_len, sa->hdr_l3_off, sqn_low16(sqc)); /* update spi, seqn and iv */ - esph = (struct esp_hdr *)(ph + sa->hdr_len); + esph = (struct rte_esp_hdr *)(ph + sa->hdr_len); iv = (uint64_t *)(esph + 1); copy_iv(iv, ivp, sa->iv_len); @@ -242,8 +242,8 @@ esp_outb_tun_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], gen_iv(iv, sqc); /* try to update the packet itself */ - rc = outb_tun_pkt_prepare(sa, sqc, iv, mb[i], &icv); - + rc = outb_tun_pkt_prepare(sa, sqc, iv, mb[i], &icv, + sa->sqh_len); /* success, setup crypto op */ if (rc >= 0) { outb_pkt_xprepare(sa, sqc, &icv); @@ -270,12 +270,13 @@ esp_outb_tun_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], static inline int32_t outb_trs_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc, const uint64_t ivp[IPSEC_MAX_IV_QWORD], struct rte_mbuf *mb, - uint32_t l2len, uint32_t l3len, union sym_op_data *icv) + uint32_t l2len, uint32_t l3len, union sym_op_data *icv, + uint8_t sqh_len) { uint8_t np; uint32_t clen, hlen, pdlen, pdofs, plen, tlen, uhlen; struct rte_mbuf *ml; - struct esp_hdr *esph; + struct rte_esp_hdr *esph; struct esp_tail *espt; char *ph, *pt; uint64_t *iv; @@ -292,11 +293,11 @@ outb_trs_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc, /* pad length + esp tail */ pdlen = clen - plen; - tlen = pdlen + sa->icv_len; + tlen = pdlen + sa->icv_len + sqh_len; /* do append and insert */ ml = rte_pktmbuf_lastseg(mb); - if (tlen + sa->sqh_len + sa->aad_len > rte_pktmbuf_tailroom(ml)) + if (tlen + sa->aad_len > rte_pktmbuf_tailroom(ml)) return -ENOSPC; /* prepend space for ESP header */ @@ -314,11 +315,11 @@ outb_trs_pkt_prepare(struct rte_ipsec_sa *sa, rte_be64_t sqc, insert_esph(ph, ph + hlen, uhlen); /* update ip header fields */ - np = update_trs_l3hdr(sa, ph + l2len, mb->pkt_len, l2len, l3len, - IPPROTO_ESP); + np = update_trs_l3hdr(sa, ph + l2len, mb->pkt_len - sqh_len, l2len, + l3len, IPPROTO_ESP); /* update spi, seqn and iv */ - esph = (struct esp_hdr *)(ph + uhlen); + esph = (struct rte_esp_hdr *)(ph + uhlen); iv = (uint64_t *)(esph + 1); copy_iv(iv, ivp, sa->iv_len); @@ -380,8 +381,8 @@ esp_outb_trs_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], gen_iv(iv, sqc); /* try to update the packet itself */ - rc = outb_trs_pkt_prepare(sa, sqc, iv, mb[i], l2, l3, &icv); - + rc = outb_trs_pkt_prepare(sa, sqc, iv, mb[i], l2, l3, &icv, + sa->sqh_len); /* success, setup crypto op */ if (rc >= 0) { outb_pkt_xprepare(sa, sqc, &icv); @@ -425,6 +426,9 @@ esp_outb_sqh_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], for (i = 0; i != num; i++) { if ((mb[i]->ol_flags & PKT_RX_SEC_OFFLOAD_FAILED) == 0) { ml = rte_pktmbuf_lastseg(mb[i]); + /* remove high-order 32 bits of esn from packet len */ + mb[i]->pkt_len -= sa->sqh_len; + ml->data_len -= sa->sqh_len; icv = rte_pktmbuf_mtod_offset(ml, void *, ml->data_len - icv_len); remove_sqh(icv, icv_len); @@ -494,7 +498,7 @@ inline_outb_tun_pkt_process(const struct rte_ipsec_session *ss, gen_iv(iv, sqc); /* try to update the packet itself */ - rc = outb_tun_pkt_prepare(sa, sqc, iv, mb[i], &icv); + rc = outb_tun_pkt_prepare(sa, sqc, iv, mb[i], &icv, 0); k += (rc >= 0); @@ -548,7 +552,7 @@ inline_outb_trs_pkt_process(const struct rte_ipsec_session *ss, /* try to update the packet itself */ rc = outb_trs_pkt_prepare(sa, sqc, iv, mb[i], - l2, l3, &icv); + l2, l3, &icv, 0); k += (rc >= 0);