Lines Matching +full:xo +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * xfrm_device.c - IPsec device offloading code.
26 struct xfrm_offload *xo = xfrm_offload(skb); in __xfrm_transport_prep() local
29 if (xo->flags & XFRM_GSO_SEGMENT) in __xfrm_transport_prep()
30 skb->transport_header -= x->props.header_len; in __xfrm_transport_prep()
32 pskb_pull(skb, skb_transport_offset(skb) + x->props.header_len); in __xfrm_transport_prep()
39 struct xfrm_offload *xo = xfrm_offload(skb); in __xfrm_mode_tunnel_prep() local
41 if (xo->flags & XFRM_GSO_SEGMENT) in __xfrm_mode_tunnel_prep()
42 skb->transport_header = skb->network_header + hsize; in __xfrm_mode_tunnel_prep()
45 pskb_pull(skb, skb->mac_len + x->props.header_len); in __xfrm_mode_tunnel_prep()
51 struct xfrm_offload *xo = xfrm_offload(skb); in __xfrm_mode_beet_prep() local
54 if (xo->flags & XFRM_GSO_SEGMENT) in __xfrm_mode_beet_prep()
55 skb->transport_header = skb->network_header + hsize; in __xfrm_mode_beet_prep()
58 if (x->sel.family != AF_INET6) { in __xfrm_mode_beet_prep()
60 if (x->outer_mode.family == AF_INET6) in __xfrm_mode_beet_prep()
61 phlen += sizeof(struct ipv6hdr) - sizeof(struct iphdr); in __xfrm_mode_beet_prep()
64 pskb_pull(skb, skb->mac_len + hsize + (x->props.header_len - phlen)); in __xfrm_mode_beet_prep()
70 switch (x->outer_mode.encap) { in xfrm_outer_mode_prep()
72 if (x->outer_mode.family == AF_INET) in xfrm_outer_mode_prep()
75 if (x->outer_mode.family == AF_INET6) in xfrm_outer_mode_prep()
80 if (x->outer_mode.family == AF_INET) in xfrm_outer_mode_prep()
83 if (x->outer_mode.family == AF_INET6) in xfrm_outer_mode_prep()
88 if (x->outer_mode.family == AF_INET) in xfrm_outer_mode_prep()
91 if (x->outer_mode.family == AF_INET6) in xfrm_outer_mode_prep()
103 struct xfrm_offload *xo = xfrm_offload(skb); in xmit_xfrm_check_overflow() local
104 __u32 seq = xo->seq.low; in xmit_xfrm_check_overflow()
106 seq += skb_shinfo(skb)->gso_segs; in xmit_xfrm_check_overflow()
107 if (unlikely(seq < xo->seq.low)) in xmit_xfrm_check_overflow()
121 struct xfrm_offload *xo = xfrm_offload(skb); in validate_xmit_xfrm() local
122 struct net_device *dev = skb->dev; in validate_xmit_xfrm()
125 if (!xo || (xo->flags & XFRM_XMIT)) in validate_xmit_xfrm()
132 x = sp->xvec[sp->len - 1]; in validate_xmit_xfrm()
133 if (xo->flags & XFRM_GRO || x->xso.dir == XFRM_DEV_OFFLOAD_IN) in validate_xmit_xfrm()
140 if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET && x->xso.dev != dev) { in validate_xmit_xfrm()
147 if ((x->xso.dev != dev) && (x->xso.real_dev == dev)) in validate_xmit_xfrm()
152 err = !skb_queue_empty(&sd->xfrm_backlog); in validate_xmit_xfrm()
160 if (skb_is_gso(skb) && (unlikely(x->xso.dev != dev) || in validate_xmit_xfrm()
178 if (!skb->next) { in validate_xmit_xfrm()
179 esp_features |= skb->dev->gso_partial_features; in validate_xmit_xfrm()
182 xo->flags |= XFRM_DEV_RESUME; in validate_xmit_xfrm()
184 err = x->type_offload->xmit(x, skb, esp_features); in validate_xmit_xfrm()
186 if (err == -EINPROGRESS) in validate_xmit_xfrm()
194 skb_push(skb, skb->data - skb_mac_header(skb)); in validate_xmit_xfrm()
200 esp_features |= skb->dev->gso_partial_features; in validate_xmit_xfrm()
203 xo = xfrm_offload(skb2); in validate_xmit_xfrm()
204 xo->flags |= XFRM_DEV_RESUME; in validate_xmit_xfrm()
208 err = x->type_offload->xmit(x, skb2, esp_features); in validate_xmit_xfrm()
210 skb2->next = nskb; in validate_xmit_xfrm()
211 } else if (err != -EINPROGRESS) { in validate_xmit_xfrm()
213 skb2->next = nskb; in validate_xmit_xfrm()
220 pskb->next = nskb; in validate_xmit_xfrm()
225 skb_push(skb2, skb2->data - skb_mac_header(skb2)); in validate_xmit_xfrm()
240 struct xfrm_dev_offload *xso = &x->xso; in xfrm_dev_state_add()
245 if (!x->type_offload) { in xfrm_dev_state_add()
247 return -EINVAL; in xfrm_dev_state_add()
250 if (xuo->flags & in xfrm_dev_state_add()
253 return -EINVAL; in xfrm_dev_state_add()
256 if ((xuo->flags & XFRM_OFFLOAD_INBOUND && x->dir == XFRM_SA_DIR_OUT) || in xfrm_dev_state_add()
257 (!(xuo->flags & XFRM_OFFLOAD_INBOUND) && x->dir == XFRM_SA_DIR_IN)) { in xfrm_dev_state_add()
259 return -EINVAL; in xfrm_dev_state_add()
262 is_packet_offload = xuo->flags & XFRM_OFFLOAD_PACKET; in xfrm_dev_state_add()
265 if (x->tfcpad) { in xfrm_dev_state_add()
267 return -EINVAL; in xfrm_dev_state_add()
270 dev = dev_get_by_index(net, xuo->ifindex); in xfrm_dev_state_add()
274 if (!(xuo->flags & XFRM_OFFLOAD_INBOUND)) { in xfrm_dev_state_add()
275 saddr = &x->props.saddr; in xfrm_dev_state_add()
276 daddr = &x->id.daddr; in xfrm_dev_state_add()
278 saddr = &x->id.daddr; in xfrm_dev_state_add()
279 daddr = &x->props.saddr; in xfrm_dev_state_add()
287 dst = __xfrm_dst_lookup(x->props.family, ¶ms); in xfrm_dev_state_add()
289 return (is_packet_offload) ? -EINVAL : 0; in xfrm_dev_state_add()
291 dev = dst->dev; in xfrm_dev_state_add()
297 if (!dev->xfrmdev_ops || !dev->xfrmdev_ops->xdo_dev_state_add) { in xfrm_dev_state_add()
298 xso->dev = NULL; in xfrm_dev_state_add()
300 return (is_packet_offload) ? -EINVAL : 0; in xfrm_dev_state_add()
303 if (!is_packet_offload && x->props.flags & XFRM_STATE_ESN && in xfrm_dev_state_add()
304 !dev->xfrmdev_ops->xdo_dev_state_advance_esn) { in xfrm_dev_state_add()
306 xso->dev = NULL; in xfrm_dev_state_add()
308 return -EINVAL; in xfrm_dev_state_add()
311 xso->dev = dev; in xfrm_dev_state_add()
312 netdev_tracker_alloc(dev, &xso->dev_tracker, GFP_ATOMIC); in xfrm_dev_state_add()
313 xso->real_dev = dev; in xfrm_dev_state_add()
315 if (xuo->flags & XFRM_OFFLOAD_INBOUND) in xfrm_dev_state_add()
316 xso->dir = XFRM_DEV_OFFLOAD_IN; in xfrm_dev_state_add()
318 xso->dir = XFRM_DEV_OFFLOAD_OUT; in xfrm_dev_state_add()
321 xso->type = XFRM_DEV_OFFLOAD_PACKET; in xfrm_dev_state_add()
323 xso->type = XFRM_DEV_OFFLOAD_CRYPTO; in xfrm_dev_state_add()
325 err = dev->xfrmdev_ops->xdo_dev_state_add(x, extack); in xfrm_dev_state_add()
327 xso->dev = NULL; in xfrm_dev_state_add()
328 xso->dir = 0; in xfrm_dev_state_add()
329 xso->real_dev = NULL; in xfrm_dev_state_add()
330 netdev_put(dev, &xso->dev_tracker); in xfrm_dev_state_add()
331 xso->type = XFRM_DEV_OFFLOAD_UNSPECIFIED; in xfrm_dev_state_add()
337 if ((err != -EOPNOTSUPP && !is_packet_offload) || is_packet_offload) { in xfrm_dev_state_add()
351 struct xfrm_dev_offload *xdo = &xp->xdo; in xfrm_dev_policy_add()
355 if (!xuo->flags || xuo->flags & ~XFRM_OFFLOAD_PACKET) { in xfrm_dev_policy_add()
360 return -EINVAL; in xfrm_dev_policy_add()
363 dev = dev_get_by_index(net, xuo->ifindex); in xfrm_dev_policy_add()
365 return -EINVAL; in xfrm_dev_policy_add()
367 if (!dev->xfrmdev_ops || !dev->xfrmdev_ops->xdo_dev_policy_add) { in xfrm_dev_policy_add()
368 xdo->dev = NULL; in xfrm_dev_policy_add()
371 return -EINVAL; in xfrm_dev_policy_add()
374 xdo->dev = dev; in xfrm_dev_policy_add()
375 netdev_tracker_alloc(dev, &xdo->dev_tracker, GFP_ATOMIC); in xfrm_dev_policy_add()
376 xdo->real_dev = dev; in xfrm_dev_policy_add()
377 xdo->type = XFRM_DEV_OFFLOAD_PACKET; in xfrm_dev_policy_add()
380 xdo->dir = XFRM_DEV_OFFLOAD_IN; in xfrm_dev_policy_add()
383 xdo->dir = XFRM_DEV_OFFLOAD_OUT; in xfrm_dev_policy_add()
386 xdo->dir = XFRM_DEV_OFFLOAD_FWD; in xfrm_dev_policy_add()
389 xdo->dev = NULL; in xfrm_dev_policy_add()
390 netdev_put(dev, &xdo->dev_tracker); in xfrm_dev_policy_add()
392 return -EINVAL; in xfrm_dev_policy_add()
395 err = dev->xfrmdev_ops->xdo_dev_policy_add(xp, extack); in xfrm_dev_policy_add()
397 xdo->dev = NULL; in xfrm_dev_policy_add()
398 xdo->real_dev = NULL; in xfrm_dev_policy_add()
399 xdo->type = XFRM_DEV_OFFLOAD_UNSPECIFIED; in xfrm_dev_policy_add()
400 xdo->dir = 0; in xfrm_dev_policy_add()
401 netdev_put(dev, &xdo->dev_tracker); in xfrm_dev_policy_add()
415 struct net_device *dev = x->xso.dev; in xfrm_dev_offload_ok()
417 if (!x->type_offload || in xfrm_dev_offload_ok()
418 (x->xso.type == XFRM_DEV_OFFLOAD_UNSPECIFIED && x->encap)) in xfrm_dev_offload_ok()
421 if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET || in xfrm_dev_offload_ok()
422 ((!dev || (dev == xfrm_dst_path(dst)->dev)) && in xfrm_dev_offload_ok()
423 !xdst->child->xfrm)) { in xfrm_dev_offload_ok()
424 mtu = xfrm_state_mtu(x, xdst->child_mtu_cached); in xfrm_dev_offload_ok()
425 if (skb->len <= mtu) in xfrm_dev_offload_ok()
435 if (dev && dev->xfrmdev_ops && dev->xfrmdev_ops->xdo_dev_offload_ok) in xfrm_dev_offload_ok()
436 return x->xso.dev->xfrmdev_ops->xdo_dev_offload_ok(skb, x); in xfrm_dev_offload_ok()
444 struct net_device *dev = skb->dev; in xfrm_dev_resume()
461 skb_queue_tail(&sd->xfrm_backlog, skb); in xfrm_dev_resume()
471 struct sk_buff_head *xfrm_backlog = &sd->xfrm_backlog; in xfrm_dev_backlog()
480 spin_lock(&xfrm_backlog->lock); in xfrm_dev_backlog()
482 spin_unlock(&xfrm_backlog->lock); in xfrm_dev_backlog()
495 if ((dev->features & NETIF_F_HW_ESP_TX_CSUM) && in xfrm_api_check()
496 !(dev->features & NETIF_F_HW_ESP)) in xfrm_api_check()
499 if ((dev->features & NETIF_F_HW_ESP) && in xfrm_api_check()
500 (!(dev->xfrmdev_ops && in xfrm_api_check()
501 dev->xfrmdev_ops->xdo_dev_state_add && in xfrm_api_check()
502 dev->xfrmdev_ops->xdo_dev_state_delete))) in xfrm_api_check()
505 if (dev->features & (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM)) in xfrm_api_check()
514 if (dev->features & NETIF_F_HW_ESP) { in xfrm_dev_down()