developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (C) 2023 MediaTek Inc. |
| 4 | * |
| 5 | * Author: Chris.Chou <chris.chou@mediatek.com> |
| 6 | * Ren-Ting Wang <ren-ting.wang@mediatek.com> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/bitops.h> |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 10 | #include <linux/spinlock.h> |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 11 | |
| 12 | #include <mtk_eth_soc.h> |
developer | 49489b8 | 2024-03-28 15:18:08 +0800 | [diff] [blame] | 13 | |
| 14 | #if IS_ENABLED(CONFIG_NET_MEDIATEK_HNAT) |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 15 | #include <mtk_hnat/hnat.h> |
| 16 | #include <mtk_hnat/nf_hnat_mtk.h> |
developer | 49489b8 | 2024-03-28 15:18:08 +0800 | [diff] [blame] | 17 | #endif // HNAT |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 18 | |
| 19 | #include <pce/cdrt.h> |
| 20 | #include <pce/cls.h> |
| 21 | #include <pce/netsys.h> |
| 22 | |
| 23 | #include <crypto-eip/ddk/configs/cs_hwpal_ext.h> |
| 24 | #include <crypto-eip/ddk/kit/iotoken/iotoken.h> |
| 25 | #include <crypto-eip/ddk/kit/iotoken/iotoken_ext.h> |
| 26 | |
| 27 | #include "crypto-eip/crypto-eip.h" |
| 28 | #include "crypto-eip/ddk-wrapper.h" |
| 29 | #include "crypto-eip/internal.h" |
| 30 | |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 31 | static struct xfrm_params_list xfrm_params_list = { |
| 32 | .list = LIST_HEAD_INIT(xfrm_params_list.list), |
| 33 | .lock = __SPIN_LOCK_UNLOCKED(xfrm_params_list.lock), |
| 34 | }; |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 35 | |
developer | 49489b8 | 2024-03-28 15:18:08 +0800 | [diff] [blame] | 36 | #if IS_ENABLED(CONFIG_NET_MEDIATEK_HNAT) |
| 37 | extern int (*ra_sw_nat_hook_tx)(struct sk_buff *skb, int gmac_no); |
| 38 | |
developer | c9adb36 | 2024-07-05 13:30:41 +0800 | [diff] [blame] | 39 | static inline bool is_tops_tunnel(struct sk_buff *skb) |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 40 | { |
| 41 | return skb_hnat_tops(skb) && (ntohs(skb->protocol) == ETH_P_IP) && |
developer | c9adb36 | 2024-07-05 13:30:41 +0800 | [diff] [blame] | 42 | (ip_hdr(skb)->protocol == IPPROTO_UDP || |
| 43 | ip_hdr(skb)->protocol == IPPROTO_GRE); |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static inline bool is_tcp(struct sk_buff *skb) |
| 47 | { |
| 48 | return (ntohs(skb->protocol) == ETH_P_IP) && (ip_hdr(skb)->protocol == IPPROTO_TCP); |
| 49 | } |
| 50 | |
| 51 | static inline bool is_hnat_rate_reach(struct sk_buff *skb) |
| 52 | { |
| 53 | return is_magic_tag_valid(skb) && (skb_hnat_reason(skb) == HIT_UNBIND_RATE_REACH); |
| 54 | } |
developer | 49489b8 | 2024-03-28 15:18:08 +0800 | [diff] [blame] | 55 | #endif // HNAT |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 56 | |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 57 | struct xfrm_params_list *mtk_xfrm_params_list_get(void) |
| 58 | { |
| 59 | return &xfrm_params_list; |
| 60 | } |
| 61 | |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 62 | static void mtk_xfrm_offload_cdrt_tear_down(struct mtk_xfrm_params *xfrm_params) |
| 63 | { |
| 64 | memset(&xfrm_params->cdrt->desc, 0, sizeof(struct cdrt_desc)); |
| 65 | |
| 66 | mtk_pce_cdrt_entry_write(xfrm_params->cdrt); |
| 67 | } |
| 68 | |
| 69 | static int mtk_xfrm_offload_cdrt_setup(struct mtk_xfrm_params *xfrm_params) |
| 70 | { |
| 71 | struct cdrt_desc *cdesc = &xfrm_params->cdrt->desc; |
| 72 | |
| 73 | cdesc->desc1.common.type = 3; |
| 74 | cdesc->desc1.token_len = 48; |
| 75 | cdesc->desc1.p_tr[0] = __pa(xfrm_params->p_tr) | 2; |
| 76 | |
developer | c9adb36 | 2024-07-05 13:30:41 +0800 | [diff] [blame] | 77 | cdesc->desc2.hw_srv = 3; |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 78 | cdesc->desc2.allow_pad = 1; |
| 79 | cdesc->desc2.strip_pad = 1; |
| 80 | |
| 81 | return mtk_pce_cdrt_entry_write(xfrm_params->cdrt); |
| 82 | } |
| 83 | |
developer | 8ac909d | 2023-08-25 11:03:33 +0800 | [diff] [blame] | 84 | static void mtk_xfrm_offload_cls_entry_tear_down(struct mtk_xfrm_params *xfrm_params) |
| 85 | { |
| 86 | memset(&xfrm_params->cdrt->cls->cdesc, 0, sizeof(struct cls_desc)); |
| 87 | |
| 88 | mtk_pce_cls_entry_write(xfrm_params->cdrt->cls); |
| 89 | |
| 90 | mtk_pce_cls_entry_free(xfrm_params->cdrt->cls); |
| 91 | } |
| 92 | |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 93 | static int mtk_xfrm_offload_cls_entry_setup(struct mtk_xfrm_params *xfrm_params) |
| 94 | { |
developer | 8ac909d | 2023-08-25 11:03:33 +0800 | [diff] [blame] | 95 | struct cls_desc *cdesc; |
| 96 | |
| 97 | xfrm_params->cdrt->cls = mtk_pce_cls_entry_alloc(); |
| 98 | if (IS_ERR(xfrm_params->cdrt->cls)) |
| 99 | return PTR_ERR(xfrm_params->cdrt->cls); |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 100 | |
developer | 8ac909d | 2023-08-25 11:03:33 +0800 | [diff] [blame] | 101 | cdesc = &xfrm_params->cdrt->cls->cdesc; |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 102 | |
developer | 5922d4d | 2024-02-26 19:01:58 +0800 | [diff] [blame] | 103 | if (mtk_crypto_ppe_get_num() == 1) |
| 104 | CLS_DESC_DATA(cdesc, fport, PSE_PORT_PPE0); |
| 105 | else |
| 106 | CLS_DESC_DATA(cdesc, fport, PSE_PORT_PPE1); |
developer | 8ac909d | 2023-08-25 11:03:33 +0800 | [diff] [blame] | 107 | CLS_DESC_DATA(cdesc, tport_idx, 0x2); |
| 108 | CLS_DESC_DATA(cdesc, cdrt_idx, xfrm_params->cdrt->idx); |
| 109 | |
| 110 | CLS_DESC_MASK_DATA(cdesc, tag, |
| 111 | CLS_DESC_TAG_MASK, CLS_DESC_TAG_MATCH_L4_HDR); |
| 112 | CLS_DESC_MASK_DATA(cdesc, l4_udp_hdr_nez, |
| 113 | CLS_DESC_UDPLITE_L4_HDR_NEZ_MASK, |
| 114 | CLS_DESC_UDPLITE_L4_HDR_NEZ_MASK); |
| 115 | CLS_DESC_MASK_DATA(cdesc, l4_type, |
| 116 | CLS_DESC_L4_TYPE_MASK, IPPROTO_ESP); |
| 117 | CLS_DESC_MASK_DATA(cdesc, l4_valid, |
| 118 | 0x3, |
| 119 | CLS_DESC_VALID_UPPER_HALF_WORD_BIT | |
| 120 | CLS_DESC_VALID_LOWER_HALF_WORD_BIT); |
| 121 | CLS_DESC_MASK_DATA(cdesc, l4_hdr_usr_data, |
| 122 | 0xFFFFFFFF, be32_to_cpu(xfrm_params->xs->id.spi)); |
| 123 | |
| 124 | return mtk_pce_cls_entry_write(xfrm_params->cdrt->cls); |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static void mtk_xfrm_offload_context_tear_down(struct mtk_xfrm_params *xfrm_params) |
| 128 | { |
| 129 | mtk_xfrm_offload_cdrt_tear_down(xfrm_params); |
| 130 | |
| 131 | /* TODO: free context */ |
| 132 | devm_kfree(crypto_dev, xfrm_params->p_tr); |
| 133 | |
| 134 | /* TODO: transform record tear down */ |
| 135 | } |
| 136 | |
| 137 | static int mtk_xfrm_offload_context_setup(struct mtk_xfrm_params *xfrm_params) |
| 138 | { |
| 139 | u32 *tr; |
| 140 | int ret; |
| 141 | |
| 142 | xfrm_params->p_tr = devm_kcalloc(crypto_dev, sizeof(u32), |
| 143 | TRANSFORM_RECORD_LEN, GFP_KERNEL); |
| 144 | if (unlikely(!xfrm_params->p_tr)) |
| 145 | return -ENOMEM; |
| 146 | |
| 147 | switch (xfrm_params->xs->outer_mode.encap) { |
| 148 | case XFRM_MODE_TUNNEL: |
| 149 | tr = mtk_ddk_tr_ipsec_build(xfrm_params, SAB_IPSEC_TUNNEL); |
| 150 | break; |
| 151 | case XFRM_MODE_TRANSPORT: |
| 152 | tr = mtk_ddk_tr_ipsec_build(xfrm_params, SAB_IPSEC_TRANSPORT); |
| 153 | break; |
| 154 | default: |
| 155 | ret = -ENOMEM; |
| 156 | goto err_out; |
| 157 | } |
| 158 | |
| 159 | if (!tr) { |
| 160 | ret = -EINVAL; |
| 161 | goto err_out; |
| 162 | } |
| 163 | |
| 164 | memcpy(xfrm_params->p_tr, tr, sizeof(u32) * TRANSFORM_RECORD_LEN); |
| 165 | |
| 166 | /* TODO: free tr */ |
| 167 | |
| 168 | return mtk_xfrm_offload_cdrt_setup(xfrm_params); |
| 169 | |
| 170 | err_out: |
| 171 | devm_kfree(crypto_dev, xfrm_params->p_tr); |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | static int mtk_xfrm_offload_state_add_outbound(struct xfrm_state *xs, |
| 177 | struct mtk_xfrm_params *xfrm_params) |
| 178 | { |
| 179 | int ret; |
| 180 | |
| 181 | xfrm_params->cdrt = mtk_pce_cdrt_entry_alloc(CDRT_ENCRYPT); |
| 182 | if (IS_ERR(xfrm_params->cdrt)) |
| 183 | return PTR_ERR(xfrm_params->cdrt); |
| 184 | |
| 185 | xfrm_params->dir = SAB_DIRECTION_OUTBOUND; |
| 186 | |
| 187 | ret = mtk_xfrm_offload_context_setup(xfrm_params); |
| 188 | if (ret) |
| 189 | goto free_cdrt; |
| 190 | |
| 191 | return ret; |
| 192 | |
| 193 | free_cdrt: |
| 194 | mtk_pce_cdrt_entry_free(xfrm_params->cdrt); |
| 195 | |
| 196 | return ret; |
| 197 | } |
| 198 | |
| 199 | static int mtk_xfrm_offload_state_add_inbound(struct xfrm_state *xs, |
| 200 | struct mtk_xfrm_params *xfrm_params) |
| 201 | { |
| 202 | int ret; |
| 203 | |
| 204 | xfrm_params->cdrt = mtk_pce_cdrt_entry_alloc(CDRT_DECRYPT); |
| 205 | if (IS_ERR(xfrm_params->cdrt)) |
| 206 | return PTR_ERR(xfrm_params->cdrt); |
| 207 | |
| 208 | xfrm_params->dir = SAB_DIRECTION_INBOUND; |
| 209 | |
| 210 | ret = mtk_xfrm_offload_context_setup(xfrm_params); |
| 211 | if (ret) |
| 212 | goto free_cdrt; |
| 213 | |
| 214 | ret = mtk_xfrm_offload_cls_entry_setup(xfrm_params); |
| 215 | if (ret) |
| 216 | goto tear_down_context; |
| 217 | |
| 218 | return ret; |
| 219 | |
| 220 | tear_down_context: |
| 221 | mtk_xfrm_offload_context_tear_down(xfrm_params); |
| 222 | |
| 223 | free_cdrt: |
| 224 | mtk_pce_cdrt_entry_free(xfrm_params->cdrt); |
| 225 | |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | int mtk_xfrm_offload_state_add(struct xfrm_state *xs) |
| 230 | { |
| 231 | struct mtk_xfrm_params *xfrm_params; |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 232 | unsigned long flags; |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 233 | int ret = 0; |
| 234 | |
| 235 | /* TODO: maybe support IPv6 in the future? */ |
| 236 | if (xs->props.family != AF_INET) { |
| 237 | CRYPTO_NOTICE("Only IPv4 xfrm states may be offloaded\n"); |
| 238 | return -EINVAL; |
| 239 | } |
| 240 | |
| 241 | /* only support ESP right now */ |
| 242 | if (xs->id.proto != IPPROTO_ESP) { |
| 243 | CRYPTO_NOTICE("Unsupported protocol 0x%04x\n", xs->id.proto); |
| 244 | return -EINVAL; |
| 245 | } |
| 246 | |
| 247 | /* only support tunnel mode or transport mode */ |
| 248 | if (!(xs->outer_mode.encap == XFRM_MODE_TUNNEL |
| 249 | || xs->outer_mode.encap == XFRM_MODE_TRANSPORT)) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | xfrm_params = devm_kzalloc(crypto_dev, |
| 253 | sizeof(struct mtk_xfrm_params), |
| 254 | GFP_KERNEL); |
| 255 | if (!xfrm_params) |
| 256 | return -ENOMEM; |
| 257 | |
| 258 | xfrm_params->xs = xs; |
| 259 | INIT_LIST_HEAD(&xfrm_params->node); |
| 260 | |
| 261 | if (xs->xso.flags & XFRM_OFFLOAD_INBOUND) |
| 262 | /* rx path */ |
| 263 | ret = mtk_xfrm_offload_state_add_inbound(xs, xfrm_params); |
| 264 | else |
| 265 | /* tx path */ |
| 266 | ret = mtk_xfrm_offload_state_add_outbound(xs, xfrm_params); |
| 267 | |
| 268 | if (ret) { |
| 269 | devm_kfree(crypto_dev, xfrm_params); |
| 270 | goto out; |
| 271 | } |
| 272 | |
| 273 | xs->xso.offload_handle = (unsigned long)xfrm_params; |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 274 | |
| 275 | spin_lock_irqsave(&xfrm_params_list.lock, flags); |
| 276 | |
| 277 | list_add_tail(&xfrm_params->node, &xfrm_params_list.list); |
| 278 | |
| 279 | spin_unlock_irqrestore(&xfrm_params_list.lock, flags); |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 280 | out: |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | void mtk_xfrm_offload_state_delete(struct xfrm_state *xs) |
| 285 | { |
| 286 | } |
| 287 | |
| 288 | void mtk_xfrm_offload_state_free(struct xfrm_state *xs) |
| 289 | { |
| 290 | struct mtk_xfrm_params *xfrm_params; |
| 291 | |
| 292 | if (!xs->xso.offload_handle) |
| 293 | return; |
| 294 | |
| 295 | xfrm_params = (struct mtk_xfrm_params *)xs->xso.offload_handle; |
| 296 | |
| 297 | list_del(&xfrm_params->node); |
| 298 | |
| 299 | if (xs->xso.flags & XFRM_OFFLOAD_INBOUND) |
developer | 8ac909d | 2023-08-25 11:03:33 +0800 | [diff] [blame] | 300 | mtk_xfrm_offload_cls_entry_tear_down(xfrm_params); |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 301 | |
| 302 | mtk_xfrm_offload_context_tear_down(xfrm_params); |
| 303 | |
| 304 | mtk_pce_cdrt_entry_free(xfrm_params->cdrt); |
| 305 | |
| 306 | devm_kfree(crypto_dev, xfrm_params); |
| 307 | } |
| 308 | |
| 309 | void mtk_xfrm_offload_state_tear_down(void) |
| 310 | { |
| 311 | struct mtk_xfrm_params *xfrm_params, *tmp; |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 312 | unsigned long flags; |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 313 | |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 314 | spin_lock_irqsave(&xfrm_params_list.lock, flags); |
| 315 | |
| 316 | list_for_each_entry_safe(xfrm_params, tmp, &xfrm_params_list.list, node) |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 317 | mtk_xfrm_offload_state_free(xfrm_params->xs); |
developer | 1baf13c | 2024-07-05 15:43:05 +0800 | [diff] [blame] | 318 | |
| 319 | spin_unlock_irqrestore(&xfrm_params_list.lock, flags); |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | int mtk_xfrm_offload_policy_add(struct xfrm_policy *xp) |
| 323 | { |
| 324 | return 0; |
| 325 | } |
| 326 | |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 327 | static inline struct neighbour *mtk_crypto_find_dst_mac(struct sk_buff *skb, struct xfrm_state *xs) |
| 328 | { |
| 329 | struct neighbour *neigh; |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 330 | struct dst_entry *dst = skb_dst(skb); |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 331 | |
developer | 8ac52a6 | 2024-07-01 16:11:43 +0800 | [diff] [blame] | 332 | neigh = __ipv4_neigh_lookup_noref(dst->dev, xs->id.daddr.a4); |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 333 | if (unlikely(!neigh)) { |
| 334 | CRYPTO_INFO("%s: %s No neigh (daddr=%pI4)\n", __func__, dst->dev->name, |
| 335 | &xs->id.daddr.a4); |
| 336 | neigh = __neigh_create(&arp_tbl, &xs->id.daddr.a4, dst->dev, false); |
developer | fba064e | 2024-01-09 14:52:17 +0800 | [diff] [blame] | 337 | neigh_output(neigh, skb, false); |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 338 | return NULL; |
| 339 | } |
| 340 | |
| 341 | return neigh; |
| 342 | } |
| 343 | |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 344 | bool mtk_xfrm_offload_ok(struct sk_buff *skb, |
| 345 | struct xfrm_state *xs) |
| 346 | { |
| 347 | struct mtk_xfrm_params *xfrm_params; |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 348 | struct neighbour *neigh; |
| 349 | struct dst_entry *dst = skb_dst(skb); |
developer | 8ac52a6 | 2024-07-01 16:11:43 +0800 | [diff] [blame] | 350 | int fill_inner_info = 0; |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 351 | |
| 352 | rcu_read_lock_bh(); |
| 353 | |
| 354 | neigh = mtk_crypto_find_dst_mac(skb, xs); |
| 355 | if (!neigh) { |
| 356 | rcu_read_unlock_bh(); |
| 357 | return true; |
| 358 | } |
| 359 | |
developer | 8ac52a6 | 2024-07-01 16:11:43 +0800 | [diff] [blame] | 360 | /* |
| 361 | * For packet has pass through VTI (route-based VTI) |
| 362 | * The 'dev_queue_xmit' function called at network layer will cause both |
| 363 | * skb->mac_header and skb->network_header to point to the IP header |
| 364 | */ |
| 365 | if (skb->mac_header == skb->network_header) |
| 366 | fill_inner_info = 1; |
| 367 | |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 368 | skb_push(skb, sizeof(struct ethhdr)); |
| 369 | skb_reset_mac_header(skb); |
| 370 | |
| 371 | eth_hdr(skb)->h_proto = htons(ETH_P_IP); |
| 372 | memcpy(eth_hdr(skb)->h_dest, neigh->ha, ETH_ALEN); |
| 373 | memcpy(eth_hdr(skb)->h_source, dst->dev->dev_addr, ETH_ALEN); |
| 374 | |
| 375 | rcu_read_unlock_bh(); |
| 376 | |
| 377 | xfrm_params = (struct mtk_xfrm_params *)xs->xso.offload_handle; |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 378 | |
developer | 49489b8 | 2024-03-28 15:18:08 +0800 | [diff] [blame] | 379 | #if IS_ENABLED(CONFIG_NET_MEDIATEK_HNAT) |
| 380 | skb_hnat_cdrt(skb) = xfrm_params->cdrt->idx; |
developer | 52e00b7 | 2023-09-04 11:13:18 +0800 | [diff] [blame] | 381 | /* |
| 382 | * EIP197 does not support fragmentation. As a result, we can not bind UDP |
| 383 | * flow since it may cause network fail due to fragmentation |
| 384 | */ |
developer | 49489b8 | 2024-03-28 15:18:08 +0800 | [diff] [blame] | 385 | if (ra_sw_nat_hook_tx && |
developer | c9adb36 | 2024-07-05 13:30:41 +0800 | [diff] [blame] | 386 | ((is_tops_tunnel(skb) || is_tcp(skb)) && is_hnat_rate_reach(skb))) |
developer | 8ac52a6 | 2024-07-01 16:11:43 +0800 | [diff] [blame] | 387 | hnat_bind_crypto_entry(skb, dst->dev, fill_inner_info); |
developer | 52e00b7 | 2023-09-04 11:13:18 +0800 | [diff] [blame] | 388 | |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 389 | /* Set magic tag for tport setting, reset to 0 after tport is set */ |
| 390 | skb_hnat_magic_tag(skb) = HNAT_MAGIC_TAG; |
developer | 49489b8 | 2024-03-28 15:18:08 +0800 | [diff] [blame] | 391 | #else |
| 392 | skb_tnl_cdrt(skb) = xfrm_params->cdrt->idx; |
| 393 | skb_tnl_magic_tag(skb) = TNL_MAGIC_TAG; |
| 394 | #endif // HNAT |
| 395 | |
| 396 | /* Since we're going to tx directly, set skb->dev to dst->dev */ |
| 397 | skb->dev = dst->dev; |
developer | 05215d1 | 2024-01-04 19:14:19 +0800 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * Since skb headroom may not be copy when segment, we cannot rely on |
| 401 | * headroom data (ex. cdrt) to decide packets should send to EIP197. |
| 402 | * Here is a workaround that only skb with inner_protocol = ESP will |
| 403 | * be sent to EIP197. |
| 404 | */ |
| 405 | skb->inner_protocol = IPPROTO_ESP; |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 406 | /* |
| 407 | * Tx packet to EIP197. |
| 408 | * To avoid conflict of SW and HW sequence number |
| 409 | * All offloadable packets send to EIP197 |
| 410 | */ |
| 411 | dev_queue_xmit(skb); |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 412 | |
developer | d0a7d72 | 2023-10-19 11:24:25 +0800 | [diff] [blame] | 413 | return true; |
developer | 94c513e | 2023-08-21 17:33:25 +0800 | [diff] [blame] | 414 | } |