+static inline int
+ipsec_ev_route_pkts(struct rte_event_vector *vec, struct route_table *rt,
+ struct ipsec_traffic *t, struct sa_ctx *sa_ctx)
+{
+ struct rte_ipsec_session *sess;
+ uint32_t sa_idx, i, j = 0;
+ uint16_t port_id = 0;
+ struct rte_mbuf *pkt;
+ struct ipsec_sa *sa;
+
+ /* Route IPv4 packets */
+ for (i = 0; i < t->ip4.num; i++) {
+ pkt = t->ip4.pkts[i];
+ port_id = route4_pkt(pkt, rt->rt4_ctx);
+ if (port_id != RTE_MAX_ETHPORTS) {
+ /* Update mac addresses */
+ update_mac_addrs(pkt, port_id);
+ /* Update the event with the dest port */
+ ipsec_event_pre_forward(pkt, port_id);
+ ev_vector_attr_update(vec, pkt);
+ vec->mbufs[j++] = pkt;
+ } else
+ free_pkts(&pkt, 1);
+ }
+
+ /* Route IPv6 packets */
+ for (i = 0; i < t->ip6.num; i++) {
+ pkt = t->ip6.pkts[i];
+ port_id = route6_pkt(pkt, rt->rt6_ctx);
+ if (port_id != RTE_MAX_ETHPORTS) {
+ /* Update mac addresses */
+ update_mac_addrs(pkt, port_id);
+ /* Update the event with the dest port */
+ ipsec_event_pre_forward(pkt, port_id);
+ ev_vector_attr_update(vec, pkt);
+ vec->mbufs[j++] = pkt;
+ } else
+ free_pkts(&pkt, 1);
+ }
+
+ /* Route ESP packets */
+ for (i = 0; i < t->ipsec.num; i++) {
+ /* Validate sa_idx */
+ sa_idx = t->ipsec.res[i];
+ pkt = t->ipsec.pkts[i];
+ if (unlikely(sa_idx >= sa_ctx->nb_sa))
+ free_pkts(&pkt, 1);
+ else {
+ /* Else the packet has to be protected */
+ sa = &(sa_ctx->sa[sa_idx]);
+ /* Get IPsec session */
+ sess = ipsec_get_primary_session(sa);
+ /* Allow only inline protocol for now */
+ if (unlikely(sess->type !=
+ RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)) {
+ RTE_LOG(ERR, IPSEC, "SA type not supported\n");
+ free_pkts(&pkt, 1);
+ continue;
+ }
+ rte_security_set_pkt_metadata(sess->security.ctx,
+ sess->security.ses, pkt, NULL);
+
+ pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+ port_id = sa->portid;
+ update_mac_addrs(pkt, port_id);
+ ipsec_event_pre_forward(pkt, port_id);
+ ev_vector_attr_update(vec, pkt);
+ vec->mbufs[j++] = pkt;
+ }
+ }
+
+ return j;
+}
+
+static inline void
+classify_pkt(struct rte_mbuf *pkt, struct ipsec_traffic *t)
+{
+ enum pkt_type type;
+ uint8_t *nlp;
+
+ /* Check the packet type */
+ type = process_ipsec_get_pkt_type(pkt, &nlp);
+
+ switch (type) {
+ case PKT_TYPE_PLAIN_IPV4:
+ t->ip4.data[t->ip4.num] = nlp;
+ t->ip4.pkts[(t->ip4.num)++] = pkt;
+ break;
+ case PKT_TYPE_PLAIN_IPV6:
+ t->ip6.data[t->ip6.num] = nlp;
+ t->ip6.pkts[(t->ip6.num)++] = pkt;
+ break;
+ default:
+ RTE_LOG_DP(DEBUG, IPSEC_ESP, "Unsupported packet type = %d\n",
+ type);
+ free_pkts(&pkt, 1);
+ break;
+ }
+}
+
+static inline int
+process_ipsec_ev_inbound_vector(struct ipsec_ctx *ctx, struct route_table *rt,
+ struct rte_event_vector *vec)
+{
+ struct ipsec_traffic t;
+ struct rte_mbuf *pkt;
+ int i;
+
+ t.ip4.num = 0;
+ t.ip6.num = 0;
+ t.ipsec.num = 0;
+
+ for (i = 0; i < vec->nb_elem; i++) {
+ /* Get pkt from event */
+ pkt = vec->mbufs[i];
+
+ if (pkt->ol_flags & RTE_MBUF_F_RX_SEC_OFFLOAD) {
+ if (unlikely(pkt->ol_flags &
+ RTE_MBUF_F_RX_SEC_OFFLOAD_FAILED)) {
+ RTE_LOG(ERR, IPSEC,
+ "Inbound security offload failed\n");
+ free_pkts(&pkt, 1);
+ continue;
+ }
+ }
+
+ classify_pkt(pkt, &t);
+ }
+
+ check_sp_sa_bulk(ctx->sp4_ctx, ctx->sa_ctx, &t.ip4);
+ check_sp_sa_bulk(ctx->sp6_ctx, ctx->sa_ctx, &t.ip6);
+
+ return ipsec_ev_route_pkts(vec, rt, &t, ctx->sa_ctx);
+}
+
+static inline int
+process_ipsec_ev_outbound_vector(struct ipsec_ctx *ctx, struct route_table *rt,
+ struct rte_event_vector *vec)
+{
+ struct ipsec_traffic t;
+ struct rte_mbuf *pkt;
+ uint32_t i;
+
+ t.ip4.num = 0;
+ t.ip6.num = 0;
+ t.ipsec.num = 0;
+
+ for (i = 0; i < vec->nb_elem; i++) {
+ /* Get pkt from event */
+ pkt = vec->mbufs[i];
+
+ classify_pkt(pkt, &t);
+
+ /* Provide L2 len for Outbound processing */
+ pkt->l2_len = RTE_ETHER_HDR_LEN;
+ }
+
+ check_sp_bulk(ctx->sp4_ctx, &t.ip4, &t.ipsec);
+ check_sp_bulk(ctx->sp6_ctx, &t.ip6, &t.ipsec);
+
+ return ipsec_ev_route_pkts(vec, rt, &t, ctx->sa_ctx);
+}
+
+static inline int
+process_ipsec_ev_drv_mode_outbound_vector(struct rte_event_vector *vec,
+ struct port_drv_mode_data *data)
+{
+ struct rte_mbuf *pkt;
+ int16_t port_id;
+ uint32_t i;
+ int j = 0;
+
+ for (i = 0; i < vec->nb_elem; i++) {
+ pkt = vec->mbufs[i];
+ port_id = pkt->port;
+
+ if (unlikely(!data[port_id].sess)) {
+ free_pkts(&pkt, 1);
+ continue;
+ }
+ ipsec_event_pre_forward(pkt, port_id);
+ /* Save security session */
+ rte_security_set_pkt_metadata(data[port_id].ctx,
+ data[port_id].sess, pkt,
+ NULL);
+
+ /* Mark the packet for Tx security offload */
+ pkt->ol_flags |= RTE_MBUF_F_TX_SEC_OFFLOAD;
+
+ /* Provide L2 len for Outbound processing */
+ pkt->l2_len = RTE_ETHER_HDR_LEN;
+
+ vec->mbufs[j++] = pkt;
+ }
+
+ return j;
+}
+
+static inline void
+ipsec_ev_vector_process(struct lcore_conf_ev_tx_int_port_wrkr *lconf,
+ struct eh_event_link_info *links,
+ struct rte_event *ev)
+{
+ struct rte_event_vector *vec = ev->vec;
+ struct rte_mbuf *pkt;
+ int ret;
+
+ pkt = vec->mbufs[0];
+
+ ev_vector_attr_init(vec);
+ if (is_unprotected_port(pkt->port))
+ ret = process_ipsec_ev_inbound_vector(&lconf->inbound,
+ &lconf->rt, vec);
+ else
+ ret = process_ipsec_ev_outbound_vector(&lconf->outbound,
+ &lconf->rt, vec);
+
+ if (likely(ret > 0)) {
+ vec->nb_elem = ret;
+ rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
+ links[0].event_port_id,
+ ev, 1, 0);
+ } else {
+ rte_mempool_put(rte_mempool_from_obj(vec), vec);
+ }
+}
+
+static inline void
+ipsec_ev_vector_drv_mode_process(struct eh_event_link_info *links,
+ struct rte_event *ev,
+ struct port_drv_mode_data *data)
+{
+ struct rte_event_vector *vec = ev->vec;
+ struct rte_mbuf *pkt;
+
+ pkt = vec->mbufs[0];
+
+ if (!is_unprotected_port(pkt->port))
+ vec->nb_elem = process_ipsec_ev_drv_mode_outbound_vector(vec,
+ data);
+ if (vec->nb_elem > 0)
+ rte_event_eth_tx_adapter_enqueue(links[0].eventdev_id,
+ links[0].event_port_id,
+ ev, 1, 0);
+ else
+ rte_mempool_put(rte_mempool_from_obj(vec), vec);
+}
+