/** * ixgbevf_ipsec_set_pf_sa - ask the PF to set up an SA * @adapter: board private structure * @xs: xfrm info to be sent to the PF * * Returns: positive offload handle from the PF, or negative error code
**/ staticint ixgbevf_ipsec_set_pf_sa(struct ixgbevf_adapter *adapter, struct xfrm_state *xs)
{
u32 msgbuf[IXGBE_VFMAILBOX_SIZE] = { 0 }; struct ixgbe_hw *hw = &adapter->hw; struct sa_mbx_msg *sam; int ret;
/* send the important bits to the PF */
sam = (struct sa_mbx_msg *)(&msgbuf[1]);
sam->dir = xs->xso.dir;
sam->spi = xs->id.spi;
sam->proto = xs->id.proto;
sam->family = xs->props.family;
ret = ixgbevf_write_mbx(hw, msgbuf, IXGBE_VFMAILBOX_SIZE); if (ret) goto out;
ret = ixgbevf_poll_mbx(hw, msgbuf, 2); if (ret) goto out;
ret = (int)msgbuf[1]; if (msgbuf[0] & IXGBE_VT_MSGTYPE_FAILURE && ret >= 0)
ret = -1;
out:
spin_unlock_bh(&adapter->mbx_lock);
return ret;
}
/** * ixgbevf_ipsec_del_pf_sa - ask the PF to delete an SA * @adapter: board private structure * @pfsa: sa index returned from PF when created, -1 for all * * Returns: 0 on success, or negative error code
**/ staticint ixgbevf_ipsec_del_pf_sa(struct ixgbevf_adapter *adapter, int pfsa)
{ struct ixgbe_hw *hw = &adapter->hw;
u32 msgbuf[2]; int err;
/** * ixgbevf_ipsec_restore - restore the IPsec HW settings after a reset * @adapter: board private structure * * Reload the HW tables from the SW tables after they've been bashed * by a chip reset. While we're here, make sure any stale VF data is * removed, since we go through reset when num_vfs changes.
**/ void ixgbevf_ipsec_restore(struct ixgbevf_adapter *adapter)
{ struct ixgbevf_ipsec *ipsec = adapter->ipsec; struct net_device *netdev = adapter->netdev; int i;
if (!(adapter->netdev->features & NETIF_F_HW_ESP)) return;
/* reload the Rx and Tx keys */ for (i = 0; i < IXGBE_IPSEC_MAX_SA_COUNT; i++) { struct rx_sa *r = &ipsec->rx_tbl[i]; struct tx_sa *t = &ipsec->tx_tbl[i]; int ret;
if (r->used) {
ret = ixgbevf_ipsec_set_pf_sa(adapter, r->xs); if (ret < 0)
netdev_err(netdev, "reload rx_tbl[%d] failed = %d\n",
i, ret);
}
if (t->used) {
ret = ixgbevf_ipsec_set_pf_sa(adapter, t->xs); if (ret < 0)
netdev_err(netdev, "reload tx_tbl[%d] failed = %d\n",
i, ret);
}
}
}
/** * ixgbevf_ipsec_find_empty_idx - find the first unused security parameter index * @ipsec: pointer to IPsec struct * @rxtable: true if we need to look in the Rx table * * Returns the first unused index in either the Rx or Tx SA table
**/ static int ixgbevf_ipsec_find_empty_idx(struct ixgbevf_ipsec *ipsec, bool rxtable)
{
u32 i;
if (rxtable) { if (ipsec->num_rx_sa == IXGBE_IPSEC_MAX_SA_COUNT) return -ENOSPC;
/* search rx sa table */ for (i = 0; i < IXGBE_IPSEC_MAX_SA_COUNT; i++) { if (!ipsec->rx_tbl[i].used) return i;
}
} else { if (ipsec->num_tx_sa == IXGBE_IPSEC_MAX_SA_COUNT) return -ENOSPC;
/* search tx sa table */ for (i = 0; i < IXGBE_IPSEC_MAX_SA_COUNT; i++) { if (!ipsec->tx_tbl[i].used) return i;
}
}
return -ENOSPC;
}
/** * ixgbevf_ipsec_find_rx_state - find the state that matches * @ipsec: pointer to IPsec struct * @daddr: inbound address to match * @proto: protocol to match * @spi: SPI to match * @ip4: true if using an IPv4 address * * Returns a pointer to the matching SA state information
**/ static struct xfrm_state *ixgbevf_ipsec_find_rx_state(struct ixgbevf_ipsec *ipsec,
__be32 *daddr, u8 proto,
__be32 spi, bool ip4)
{ struct xfrm_state *ret = NULL; struct rx_sa *rsa;
/** * ixgbevf_ipsec_parse_proto_keys - find the key and salt based on the protocol * @dev: pointer to net device to program * @xs: pointer to xfrm_state struct * @mykey: pointer to key array to populate * @mysalt: pointer to salt value to populate * * This copies the protocol keys and salt to our own data tables. The * 82599 family only supports the one algorithm.
**/ staticint ixgbevf_ipsec_parse_proto_keys(struct net_device *dev, struct xfrm_state *xs,
u32 *mykey, u32 *mysalt)
{ unsignedchar *key_data; char *alg_name = NULL; int key_len;
if (!xs->aead) {
netdev_err(dev, "Unsupported IPsec algorithm\n"); return -EINVAL;
}
if (xs->aead->alg_icv_len != IXGBE_IPSEC_AUTH_BITS) {
netdev_err(dev, "IPsec offload requires %d bit authentication\n",
IXGBE_IPSEC_AUTH_BITS); return -EINVAL;
}
if (strcmp(alg_name, aes_gcm_name)) {
netdev_err(dev, "Unsupported IPsec algorithm - please use %s\n",
aes_gcm_name); return -EINVAL;
}
/* The key bytes come down in a big endian array of bytes, so * we don't need to do any byte swapping. * 160 accounts for 16 byte key and 4 byte salt
*/ if (key_len > IXGBE_IPSEC_KEY_BITS) {
*mysalt = ((u32 *)key_data)[4];
} elseif (key_len == IXGBE_IPSEC_KEY_BITS) {
*mysalt = 0;
} else {
netdev_err(dev, "IPsec hw offload only supports keys up to 128 bits with a 32 bit salt\n"); return -EINVAL;
}
memcpy(mykey, key_data, 16);
return 0;
}
/** * ixgbevf_ipsec_add_sa - program device with a security association * @dev: pointer to net device to program * @xs: pointer to transformer state struct * @extack: extack point to fill failure reason
**/ staticint ixgbevf_ipsec_add_sa(struct net_device *dev, struct xfrm_state *xs, struct netlink_ext_ack *extack)
{ struct ixgbevf_adapter *adapter; struct ixgbevf_ipsec *ipsec;
u16 sa_idx; int ret;
if (xs->xso.dir == XFRM_DEV_OFFLOAD_IN) { struct rx_sa rsa;
if (xs->calg) {
NL_SET_ERR_MSG_MOD(extack, "Compression offload not supported"); return -EINVAL;
}
/* find the first unused index */
ret = ixgbevf_ipsec_find_empty_idx(ipsec, true); if (ret < 0) {
NL_SET_ERR_MSG_MOD(extack, "No space for SA in Rx table!"); return ret;
}
sa_idx = (u16)ret;
if (rsa.xs->id.proto & IPPROTO_ESP)
rsa.decrypt = xs->ealg || xs->aead;
/* get the key and salt */
ret = ixgbevf_ipsec_parse_proto_keys(dev, xs, rsa.key,
&rsa.salt); if (ret) {
NL_SET_ERR_MSG_MOD(extack, "Failed to get key data for Rx SA table"); return ret;
}
/* get ip for rx sa table */ if (xs->props.family == AF_INET6)
memcpy(rsa.ipaddr, &xs->id.daddr.a6, 16); else
memcpy(&rsa.ipaddr[3], &xs->id.daddr.a4, 4);
rsa.mode = IXGBE_RXMOD_VALID; if (rsa.xs->id.proto & IPPROTO_ESP)
rsa.mode |= IXGBE_RXMOD_PROTO_ESP; if (rsa.decrypt)
rsa.mode |= IXGBE_RXMOD_DECRYPT; if (rsa.xs->props.family == AF_INET6)
rsa.mode |= IXGBE_RXMOD_IPV6;
ret = ixgbevf_ipsec_set_pf_sa(adapter, xs); if (ret < 0) return ret;
rsa.pfsa = ret;
/* the preparations worked, so save the info */
memcpy(&ipsec->rx_tbl[sa_idx], &rsa, sizeof(rsa));
/* hash the new entry for faster search in Rx path */
hash_add_rcu(ipsec->rx_sa_list, &ipsec->rx_tbl[sa_idx].hlist,
(__force u32)rsa.xs->id.spi);
} else { struct tx_sa tsa;
/* find the first unused index */
ret = ixgbevf_ipsec_find_empty_idx(ipsec, false); if (ret < 0) {
NL_SET_ERR_MSG_MOD(extack, "No space for SA in Tx table"); return ret;
}
sa_idx = (u16)ret;
if (xs->id.proto & IPPROTO_ESP)
tsa.encrypt = xs->ealg || xs->aead;
ret = ixgbevf_ipsec_parse_proto_keys(dev, xs, tsa.key,
&tsa.salt); if (ret) {
NL_SET_ERR_MSG_MOD(extack, "Failed to get key data for Tx SA table");
memset(&tsa, 0, sizeof(tsa)); return ret;
}
ret = ixgbevf_ipsec_set_pf_sa(adapter, xs); if (ret < 0) return ret;
tsa.pfsa = ret;
/* the preparations worked, so save the info */
memcpy(&ipsec->tx_tbl[sa_idx], &tsa, sizeof(tsa));
/** * ixgbevf_ipsec_del_sa - clear out this specific SA * @dev: pointer to net device to program * @xs: pointer to transformer state struct
**/ staticvoid ixgbevf_ipsec_del_sa(struct net_device *dev, struct xfrm_state *xs)
{ struct ixgbevf_adapter *adapter; struct ixgbevf_ipsec *ipsec;
u16 sa_idx;
if (xs->id.proto == IPPROTO_ESP) {
itd->flags |= IXGBE_ADVTXD_TUCMD_IPSEC_TYPE_ESP |
IXGBE_ADVTXD_TUCMD_L4T_TCP; if (first->protocol == htons(ETH_P_IP))
itd->flags |= IXGBE_ADVTXD_TUCMD_IPV4;
/* The actual trailer length is authlen (16 bytes) plus * 2 bytes for the proto and the padlen values, plus * padlen bytes of padding. This ends up not the same * as the static value found in xs->props.trailer_len (21). * * ... but if we're doing GSO, don't bother as the stack * doesn't add a trailer for those.
*/ if (!skb_is_gso(first->skb)) { /* The "correct" way to get the auth length would be * to use * authlen = crypto_aead_authsize(xs->data); * but since we know we only have one size to worry * about * we can let the compiler use the constant * and save us a few CPU cycles.
*/ constint authlen = IXGBE_IPSEC_AUTH_BITS / 8; struct sk_buff *skb = first->skb;
u8 padlen; int ret;
ret = skb_copy_bits(skb, skb->len - (authlen + 2),
&padlen, 1); if (unlikely(ret)) return 0;
itd->trailer_len = authlen + 2 + padlen;
}
} if (tsa->encrypt)
itd->flags |= IXGBE_ADVTXD_TUCMD_IPSEC_ENCRYPT_EN;
return 1;
}
/** * ixgbevf_ipsec_rx - decode IPsec bits from Rx descriptor * @rx_ring: receiving ring * @rx_desc: receive data descriptor * @skb: current data packet * * Determine if there was an IPsec encapsulation noticed, and if so set up * the resulting status for later in the receive stack.
**/ void ixgbevf_ipsec_rx(struct ixgbevf_ring *rx_ring, union ixgbe_adv_rx_desc *rx_desc, struct sk_buff *skb)
{ struct ixgbevf_adapter *adapter = netdev_priv(rx_ring->netdev);
__le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
__le16 ipsec_pkt_types = cpu_to_le16(IXGBE_RXDADV_PKTTYPE_IPSEC_AH |
IXGBE_RXDADV_PKTTYPE_IPSEC_ESP); struct ixgbevf_ipsec *ipsec = adapter->ipsec; struct xfrm_offload *xo = NULL; struct xfrm_state *xs = NULL; struct ipv6hdr *ip6 = NULL; struct iphdr *ip4 = NULL; struct sec_path *sp; void *daddr;
__be32 spi;
u8 *c_hdr;
u8 proto;
/* Find the IP and crypto headers in the data. * We can assume no VLAN header in the way, b/c the * hw won't recognize the IPsec packet and anyway the * currently VLAN device doesn't support xfrm offload.
*/ if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_IPV4)) {
ip4 = (struct iphdr *)(skb->data + ETH_HLEN);
daddr = &ip4->daddr;
c_hdr = (u8 *)ip4 + ip4->ihl * 4;
} elseif (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_IPV6)) {
ip6 = (struct ipv6hdr *)(skb->data + ETH_HLEN);
daddr = &ip6->daddr;
c_hdr = (u8 *)ip6 + sizeof(struct ipv6hdr);
} else { return;
}
switch (pkt_info & ipsec_pkt_types) { case cpu_to_le16(IXGBE_RXDADV_PKTTYPE_IPSEC_AH):
spi = ((struct ip_auth_hdr *)c_hdr)->spi;
proto = IPPROTO_AH; break; case cpu_to_le16(IXGBE_RXDADV_PKTTYPE_IPSEC_ESP):
spi = ((struct ip_esp_hdr *)c_hdr)->spi;
proto = IPPROTO_ESP; break; default: return;
}
xs = ixgbevf_ipsec_find_rx_state(ipsec, daddr, proto, spi, !!ip4); if (unlikely(!xs)) return;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.