Lines Matching +full:sec +full:- +full:v4
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
22 /* Macros for least-significant byte and word accesses. */
26 #define LSE_INDEX(index, size) ((size) - (index) - 1)
40 } redir_map SEC(".maps");
47 } run_map SEC(".maps");
75 SEC("sk_lookup")
81 SEC("sk_lookup")
87 SEC("sk_lookup")
90 if (ctx->ingress_ifindex == 1) in check_ifindex()
95 SEC("sk_reuseport")
101 SEC("sk_reuseport")
108 SEC("sk_lookup")
114 if (ctx->local_port != DST_PORT) in redir_port()
127 SEC("sk_lookup")
133 if (ctx->family != AF_INET) in redir_ip4()
135 if (ctx->local_port != DST_PORT) in redir_ip4()
137 if (ctx->local_ip4 != DST_IP4) in redir_ip4()
150 SEC("sk_lookup")
156 if (ctx->family != AF_INET6) in redir_ip6()
158 if (ctx->local_port != DST_PORT) in redir_ip6()
160 if (ctx->local_ip6[0] != DST_IP6[0] || in redir_ip6()
161 ctx->local_ip6[1] != DST_IP6[1] || in redir_ip6()
162 ctx->local_ip6[2] != DST_IP6[2] || in redir_ip6()
163 ctx->local_ip6[3] != DST_IP6[3]) in redir_ip6()
175 SEC("sk_lookup")
190 SEC("sk_lookup")
205 SEC("sk_reuseport")
215 /* Check that bpf_sk_assign() returns -EEXIST if socket already selected. */
216 SEC("sk_lookup")
235 if (err != -EEXIST) { in sk_assign_eexist()
237 err, -EEXIST); in sk_assign_eexist()
249 SEC("sk_lookup")
281 SEC("sk_lookup")
304 if (ctx->sk != sk) in sk_assign_null()
307 if (err != -EEXIST) in sk_assign_null()
324 SEC("sk_lookup")
332 /* Try accessing unassigned (NULL) ctx->sk field */ in access_ctx_sk()
333 if (ctx->sk && ctx->sk->family != AF_INET) in access_ctx_sk()
336 /* Assign a value to ctx->sk */ in access_ctx_sk()
343 if (ctx->sk != sk1) in access_ctx_sk()
346 /* Access ctx->sk fields */ in access_ctx_sk()
347 if (ctx->sk->family != AF_INET || in access_ctx_sk()
348 ctx->sk->type != SOCK_STREAM || in access_ctx_sk()
349 ctx->sk->state != BPF_TCP_LISTEN) in access_ctx_sk()
356 if (ctx->sk) in access_ctx_sk()
366 if (ctx->sk != sk2) in access_ctx_sk()
369 /* Access reassigned ctx->sk fields */ in access_ctx_sk()
370 if (ctx->sk->family != AF_INET || in access_ctx_sk()
371 ctx->sk->type != SOCK_STREAM || in access_ctx_sk()
372 ctx->sk->state != BPF_TCP_LISTEN) in access_ctx_sk()
386 * Narrow loads of size >= target field size from a non-zero offset
390 SEC("sk_lookup")
395 bool v4; in ctx_narrow_access() local
397 v4 = (ctx->family == AF_INET); in ctx_narrow_access()
400 if (LSB(ctx->family, 0) != (v4 ? AF_INET : AF_INET6) || in ctx_narrow_access()
401 LSB(ctx->family, 1) != 0 || LSB(ctx->family, 2) != 0 || LSB(ctx->family, 3) != 0) in ctx_narrow_access()
403 if (LSW(ctx->family, 0) != (v4 ? AF_INET : AF_INET6)) in ctx_narrow_access()
407 if (LSB(ctx->protocol, 0) != IPPROTO_TCP || in ctx_narrow_access()
408 LSB(ctx->protocol, 1) != 0 || LSB(ctx->protocol, 2) != 0 || LSB(ctx->protocol, 3) != 0) in ctx_narrow_access()
410 if (LSW(ctx->protocol, 0) != IPPROTO_TCP) in ctx_narrow_access()
414 if (LSB(ctx->remote_port, 0) != ((SRC_PORT >> 0) & 0xff) || in ctx_narrow_access()
415 LSB(ctx->remote_port, 1) != ((SRC_PORT >> 8) & 0xff)) in ctx_narrow_access()
417 if (LSW(ctx->remote_port, 0) != SRC_PORT) in ctx_narrow_access()
421 * NOTE: 4-byte load from bpf_sk_lookup at remote_port offset in ctx_narrow_access()
423 * 2-byte load for backward compatibility. Treating the load in ctx_narrow_access()
425 * little- and big-endian platforms. in ctx_narrow_access()
427 val_u32 = *(__u32 *)&ctx->remote_port; in ctx_narrow_access()
432 if (LSB(ctx->local_port, 0) != ((DST_PORT >> 0) & 0xff) || in ctx_narrow_access()
433 LSB(ctx->local_port, 1) != ((DST_PORT >> 8) & 0xff) || in ctx_narrow_access()
434 LSB(ctx->local_port, 2) != 0 || LSB(ctx->local_port, 3) != 0) in ctx_narrow_access()
436 if (LSW(ctx->local_port, 0) != DST_PORT) in ctx_narrow_access()
440 if (v4) { in ctx_narrow_access()
442 if (LSB(ctx->remote_ip4, 0) != ((SRC_IP4 >> 0) & 0xff) || in ctx_narrow_access()
443 LSB(ctx->remote_ip4, 1) != ((SRC_IP4 >> 8) & 0xff) || in ctx_narrow_access()
444 LSB(ctx->remote_ip4, 2) != ((SRC_IP4 >> 16) & 0xff) || in ctx_narrow_access()
445 LSB(ctx->remote_ip4, 3) != ((SRC_IP4 >> 24) & 0xff)) in ctx_narrow_access()
447 if (LSW(ctx->remote_ip4, 0) != ((SRC_IP4 >> 0) & 0xffff) || in ctx_narrow_access()
448 LSW(ctx->remote_ip4, 1) != ((SRC_IP4 >> 16) & 0xffff)) in ctx_narrow_access()
452 if (LSB(ctx->local_ip4, 0) != ((DST_IP4 >> 0) & 0xff) || in ctx_narrow_access()
453 LSB(ctx->local_ip4, 1) != ((DST_IP4 >> 8) & 0xff) || in ctx_narrow_access()
454 LSB(ctx->local_ip4, 2) != ((DST_IP4 >> 16) & 0xff) || in ctx_narrow_access()
455 LSB(ctx->local_ip4, 3) != ((DST_IP4 >> 24) & 0xff)) in ctx_narrow_access()
457 if (LSW(ctx->local_ip4, 0) != ((DST_IP4 >> 0) & 0xffff) || in ctx_narrow_access()
458 LSW(ctx->local_ip4, 1) != ((DST_IP4 >> 16) & 0xffff)) in ctx_narrow_access()
462 if (LSB(ctx->remote_ip4, 0) != 0 || LSB(ctx->remote_ip4, 1) != 0 || in ctx_narrow_access()
463 LSB(ctx->remote_ip4, 2) != 0 || LSB(ctx->remote_ip4, 3) != 0) in ctx_narrow_access()
465 if (LSW(ctx->remote_ip4, 0) != 0 || LSW(ctx->remote_ip4, 1) != 0) in ctx_narrow_access()
468 if (LSB(ctx->local_ip4, 0) != 0 || LSB(ctx->local_ip4, 1) != 0 || in ctx_narrow_access()
469 LSB(ctx->local_ip4, 2) != 0 || LSB(ctx->local_ip4, 3) != 0) in ctx_narrow_access()
471 if (LSW(ctx->local_ip4, 0) != 0 || LSW(ctx->local_ip4, 1) != 0) in ctx_narrow_access()
476 if (!v4) { in ctx_narrow_access()
478 if (LSB(ctx->remote_ip6[0], 0) != ((SRC_IP6[0] >> 0) & 0xff) || in ctx_narrow_access()
479 LSB(ctx->remote_ip6[0], 1) != ((SRC_IP6[0] >> 8) & 0xff) || in ctx_narrow_access()
480 LSB(ctx->remote_ip6[0], 2) != ((SRC_IP6[0] >> 16) & 0xff) || in ctx_narrow_access()
481 LSB(ctx->remote_ip6[0], 3) != ((SRC_IP6[0] >> 24) & 0xff) || in ctx_narrow_access()
482 LSB(ctx->remote_ip6[1], 0) != ((SRC_IP6[1] >> 0) & 0xff) || in ctx_narrow_access()
483 LSB(ctx->remote_ip6[1], 1) != ((SRC_IP6[1] >> 8) & 0xff) || in ctx_narrow_access()
484 LSB(ctx->remote_ip6[1], 2) != ((SRC_IP6[1] >> 16) & 0xff) || in ctx_narrow_access()
485 LSB(ctx->remote_ip6[1], 3) != ((SRC_IP6[1] >> 24) & 0xff) || in ctx_narrow_access()
486 LSB(ctx->remote_ip6[2], 0) != ((SRC_IP6[2] >> 0) & 0xff) || in ctx_narrow_access()
487 LSB(ctx->remote_ip6[2], 1) != ((SRC_IP6[2] >> 8) & 0xff) || in ctx_narrow_access()
488 LSB(ctx->remote_ip6[2], 2) != ((SRC_IP6[2] >> 16) & 0xff) || in ctx_narrow_access()
489 LSB(ctx->remote_ip6[2], 3) != ((SRC_IP6[2] >> 24) & 0xff) || in ctx_narrow_access()
490 LSB(ctx->remote_ip6[3], 0) != ((SRC_IP6[3] >> 0) & 0xff) || in ctx_narrow_access()
491 LSB(ctx->remote_ip6[3], 1) != ((SRC_IP6[3] >> 8) & 0xff) || in ctx_narrow_access()
492 LSB(ctx->remote_ip6[3], 2) != ((SRC_IP6[3] >> 16) & 0xff) || in ctx_narrow_access()
493 LSB(ctx->remote_ip6[3], 3) != ((SRC_IP6[3] >> 24) & 0xff)) in ctx_narrow_access()
495 if (LSW(ctx->remote_ip6[0], 0) != ((SRC_IP6[0] >> 0) & 0xffff) || in ctx_narrow_access()
496 LSW(ctx->remote_ip6[0], 1) != ((SRC_IP6[0] >> 16) & 0xffff) || in ctx_narrow_access()
497 LSW(ctx->remote_ip6[1], 0) != ((SRC_IP6[1] >> 0) & 0xffff) || in ctx_narrow_access()
498 LSW(ctx->remote_ip6[1], 1) != ((SRC_IP6[1] >> 16) & 0xffff) || in ctx_narrow_access()
499 LSW(ctx->remote_ip6[2], 0) != ((SRC_IP6[2] >> 0) & 0xffff) || in ctx_narrow_access()
500 LSW(ctx->remote_ip6[2], 1) != ((SRC_IP6[2] >> 16) & 0xffff) || in ctx_narrow_access()
501 LSW(ctx->remote_ip6[3], 0) != ((SRC_IP6[3] >> 0) & 0xffff) || in ctx_narrow_access()
502 LSW(ctx->remote_ip6[3], 1) != ((SRC_IP6[3] >> 16) & 0xffff)) in ctx_narrow_access()
505 if (LSB(ctx->local_ip6[0], 0) != ((DST_IP6[0] >> 0) & 0xff) || in ctx_narrow_access()
506 LSB(ctx->local_ip6[0], 1) != ((DST_IP6[0] >> 8) & 0xff) || in ctx_narrow_access()
507 LSB(ctx->local_ip6[0], 2) != ((DST_IP6[0] >> 16) & 0xff) || in ctx_narrow_access()
508 LSB(ctx->local_ip6[0], 3) != ((DST_IP6[0] >> 24) & 0xff) || in ctx_narrow_access()
509 LSB(ctx->local_ip6[1], 0) != ((DST_IP6[1] >> 0) & 0xff) || in ctx_narrow_access()
510 LSB(ctx->local_ip6[1], 1) != ((DST_IP6[1] >> 8) & 0xff) || in ctx_narrow_access()
511 LSB(ctx->local_ip6[1], 2) != ((DST_IP6[1] >> 16) & 0xff) || in ctx_narrow_access()
512 LSB(ctx->local_ip6[1], 3) != ((DST_IP6[1] >> 24) & 0xff) || in ctx_narrow_access()
513 LSB(ctx->local_ip6[2], 0) != ((DST_IP6[2] >> 0) & 0xff) || in ctx_narrow_access()
514 LSB(ctx->local_ip6[2], 1) != ((DST_IP6[2] >> 8) & 0xff) || in ctx_narrow_access()
515 LSB(ctx->local_ip6[2], 2) != ((DST_IP6[2] >> 16) & 0xff) || in ctx_narrow_access()
516 LSB(ctx->local_ip6[2], 3) != ((DST_IP6[2] >> 24) & 0xff) || in ctx_narrow_access()
517 LSB(ctx->local_ip6[3], 0) != ((DST_IP6[3] >> 0) & 0xff) || in ctx_narrow_access()
518 LSB(ctx->local_ip6[3], 1) != ((DST_IP6[3] >> 8) & 0xff) || in ctx_narrow_access()
519 LSB(ctx->local_ip6[3], 2) != ((DST_IP6[3] >> 16) & 0xff) || in ctx_narrow_access()
520 LSB(ctx->local_ip6[3], 3) != ((DST_IP6[3] >> 24) & 0xff)) in ctx_narrow_access()
522 if (LSW(ctx->local_ip6[0], 0) != ((DST_IP6[0] >> 0) & 0xffff) || in ctx_narrow_access()
523 LSW(ctx->local_ip6[0], 1) != ((DST_IP6[0] >> 16) & 0xffff) || in ctx_narrow_access()
524 LSW(ctx->local_ip6[1], 0) != ((DST_IP6[1] >> 0) & 0xffff) || in ctx_narrow_access()
525 LSW(ctx->local_ip6[1], 1) != ((DST_IP6[1] >> 16) & 0xffff) || in ctx_narrow_access()
526 LSW(ctx->local_ip6[2], 0) != ((DST_IP6[2] >> 0) & 0xffff) || in ctx_narrow_access()
527 LSW(ctx->local_ip6[2], 1) != ((DST_IP6[2] >> 16) & 0xffff) || in ctx_narrow_access()
528 LSW(ctx->local_ip6[3], 0) != ((DST_IP6[3] >> 0) & 0xffff) || in ctx_narrow_access()
529 LSW(ctx->local_ip6[3], 1) != ((DST_IP6[3] >> 16) & 0xffff)) in ctx_narrow_access()
533 if (LSB(ctx->remote_ip6[0], 0) != 0 || LSB(ctx->remote_ip6[0], 1) != 0 || in ctx_narrow_access()
534 LSB(ctx->remote_ip6[0], 2) != 0 || LSB(ctx->remote_ip6[0], 3) != 0 || in ctx_narrow_access()
535 LSB(ctx->remote_ip6[1], 0) != 0 || LSB(ctx->remote_ip6[1], 1) != 0 || in ctx_narrow_access()
536 LSB(ctx->remote_ip6[1], 2) != 0 || LSB(ctx->remote_ip6[1], 3) != 0 || in ctx_narrow_access()
537 LSB(ctx->remote_ip6[2], 0) != 0 || LSB(ctx->remote_ip6[2], 1) != 0 || in ctx_narrow_access()
538 LSB(ctx->remote_ip6[2], 2) != 0 || LSB(ctx->remote_ip6[2], 3) != 0 || in ctx_narrow_access()
539 LSB(ctx->remote_ip6[3], 0) != 0 || LSB(ctx->remote_ip6[3], 1) != 0 || in ctx_narrow_access()
540 LSB(ctx->remote_ip6[3], 2) != 0 || LSB(ctx->remote_ip6[3], 3) != 0) in ctx_narrow_access()
542 if (LSW(ctx->remote_ip6[0], 0) != 0 || LSW(ctx->remote_ip6[0], 1) != 0 || in ctx_narrow_access()
543 LSW(ctx->remote_ip6[1], 0) != 0 || LSW(ctx->remote_ip6[1], 1) != 0 || in ctx_narrow_access()
544 LSW(ctx->remote_ip6[2], 0) != 0 || LSW(ctx->remote_ip6[2], 1) != 0 || in ctx_narrow_access()
545 LSW(ctx->remote_ip6[3], 0) != 0 || LSW(ctx->remote_ip6[3], 1) != 0) in ctx_narrow_access()
548 if (LSB(ctx->local_ip6[0], 0) != 0 || LSB(ctx->local_ip6[0], 1) != 0 || in ctx_narrow_access()
549 LSB(ctx->local_ip6[0], 2) != 0 || LSB(ctx->local_ip6[0], 3) != 0 || in ctx_narrow_access()
550 LSB(ctx->local_ip6[1], 0) != 0 || LSB(ctx->local_ip6[1], 1) != 0 || in ctx_narrow_access()
551 LSB(ctx->local_ip6[1], 2) != 0 || LSB(ctx->local_ip6[1], 3) != 0 || in ctx_narrow_access()
552 LSB(ctx->local_ip6[2], 0) != 0 || LSB(ctx->local_ip6[2], 1) != 0 || in ctx_narrow_access()
553 LSB(ctx->local_ip6[2], 2) != 0 || LSB(ctx->local_ip6[2], 3) != 0 || in ctx_narrow_access()
554 LSB(ctx->local_ip6[3], 0) != 0 || LSB(ctx->local_ip6[3], 1) != 0 || in ctx_narrow_access()
555 LSB(ctx->local_ip6[3], 2) != 0 || LSB(ctx->local_ip6[3], 3) != 0) in ctx_narrow_access()
557 if (LSW(ctx->remote_ip6[0], 0) != 0 || LSW(ctx->remote_ip6[0], 1) != 0 || in ctx_narrow_access()
558 LSW(ctx->remote_ip6[1], 0) != 0 || LSW(ctx->remote_ip6[1], 1) != 0 || in ctx_narrow_access()
559 LSW(ctx->remote_ip6[2], 0) != 0 || LSW(ctx->remote_ip6[2], 1) != 0 || in ctx_narrow_access()
560 LSW(ctx->remote_ip6[3], 0) != 0 || LSW(ctx->remote_ip6[3], 1) != 0) in ctx_narrow_access()
573 /* Check that sk_assign rejects SERVER_A socket with -ESOCKNOSUPPORT */
574 SEC("sk_lookup")
586 if (err != -ESOCKTNOSUPPORT) { in sk_assign_esocknosupport()
588 err, -ESOCKTNOSUPPORT); in sk_assign_esocknosupport()
599 SEC("sk_lookup")
606 SEC("sk_lookup")
613 SEC("sk_lookup")
620 SEC("sk_lookup")
644 SEC("sk_lookup")
652 SEC("sk_lookup")
660 char _license[] SEC("license") = "Dual BSD/GPL";