Lines Matching refs:ctx

76 int lookup_pass(struct bpf_sk_lookup *ctx)
82 int lookup_drop(struct bpf_sk_lookup *ctx)
88 int check_ifindex(struct bpf_sk_lookup *ctx)
90 if (ctx->ingress_ifindex == 1)
96 int reuseport_pass(struct sk_reuseport_md *ctx)
102 int reuseport_drop(struct sk_reuseport_md *ctx)
109 int redir_port(struct bpf_sk_lookup *ctx)
114 if (ctx->local_port != DST_PORT)
121 err = bpf_sk_assign(ctx, sk, 0);
128 int redir_ip4(struct bpf_sk_lookup *ctx)
133 if (ctx->family != AF_INET)
135 if (ctx->local_port != DST_PORT)
137 if (ctx->local_ip4 != DST_IP4)
144 err = bpf_sk_assign(ctx, sk, 0);
151 int redir_ip6(struct bpf_sk_lookup *ctx)
156 if (ctx->family != AF_INET6)
158 if (ctx->local_port != DST_PORT)
160 if (ctx->local_ip6[0] != DST_IP6[0] ||
161 ctx->local_ip6[1] != DST_IP6[1] ||
162 ctx->local_ip6[2] != DST_IP6[2] ||
163 ctx->local_ip6[3] != DST_IP6[3])
170 err = bpf_sk_assign(ctx, sk, 0);
176 int select_sock_a(struct bpf_sk_lookup *ctx)
185 err = bpf_sk_assign(ctx, sk, 0);
191 int select_sock_a_no_reuseport(struct bpf_sk_lookup *ctx)
200 err = bpf_sk_assign(ctx, sk, BPF_SK_LOOKUP_F_NO_REUSEPORT);
206 int select_sock_b(struct sk_reuseport_md *ctx)
211 err = bpf_sk_select_reuseport(ctx, &redir_map, &key, 0);
217 int sk_assign_eexist(struct bpf_sk_lookup *ctx)
226 err = bpf_sk_assign(ctx, sk, 0);
234 err = bpf_sk_assign(ctx, sk, 0);
250 int sk_assign_replace_flag(struct bpf_sk_lookup *ctx)
259 err = bpf_sk_assign(ctx, sk, 0);
267 err = bpf_sk_assign(ctx, sk, BPF_SK_LOOKUP_F_REPLACE);
282 int sk_assign_null(struct bpf_sk_lookup *ctx)
289 err = bpf_sk_assign(ctx, NULL, 0);
298 err = bpf_sk_assign(ctx, sk, BPF_SK_LOOKUP_F_REPLACE);
304 if (ctx->sk != sk)
306 err = bpf_sk_assign(ctx, NULL, 0);
309 err = bpf_sk_assign(ctx, NULL, BPF_SK_LOOKUP_F_REPLACE);
312 err = bpf_sk_assign(ctx, sk, BPF_SK_LOOKUP_F_REPLACE);
325 int access_ctx_sk(struct bpf_sk_lookup *ctx)
332 /* Try accessing unassigned (NULL) ctx->sk field */
333 if (ctx->sk && ctx->sk->family != AF_INET)
336 /* Assign a value to ctx->sk */
340 err = bpf_sk_assign(ctx, sk1, 0);
343 if (ctx->sk != sk1)
346 /* Access ctx->sk fields */
347 if (ctx->sk->family != AF_INET ||
348 ctx->sk->type != SOCK_STREAM ||
349 ctx->sk->state != BPF_TCP_LISTEN)
353 err = bpf_sk_assign(ctx, NULL, BPF_SK_LOOKUP_F_REPLACE);
356 if (ctx->sk)
363 err = bpf_sk_assign(ctx, sk2, BPF_SK_LOOKUP_F_REPLACE);
366 if (ctx->sk != sk2)
369 /* Access reassigned ctx->sk fields */
370 if (ctx->sk->family != AF_INET ||
371 ctx->sk->type != SOCK_STREAM ||
372 ctx->sk->state != BPF_TCP_LISTEN)
384 /* Check narrow loads from ctx fields that support them.
391 int ctx_narrow_access(struct bpf_sk_lookup *ctx)
397 v4 = (ctx->family == AF_INET);
400 if (LSB(ctx->family, 0) != (v4 ? AF_INET : AF_INET6) ||
401 LSB(ctx->family, 1) != 0 || LSB(ctx->family, 2) != 0 || LSB(ctx->family, 3) != 0)
403 if (LSW(ctx->family, 0) != (v4 ? AF_INET : AF_INET6))
407 if (LSB(ctx->protocol, 0) != IPPROTO_TCP ||
408 LSB(ctx->protocol, 1) != 0 || LSB(ctx->protocol, 2) != 0 || LSB(ctx->protocol, 3) != 0)
410 if (LSW(ctx->protocol, 0) != IPPROTO_TCP)
414 if (LSB(ctx->remote_port, 0) != ((SRC_PORT >> 0) & 0xff) ||
415 LSB(ctx->remote_port, 1) != ((SRC_PORT >> 8) & 0xff))
417 if (LSW(ctx->remote_port, 0) != SRC_PORT)
427 val_u32 = *(__u32 *)&ctx->remote_port;
432 if (LSB(ctx->local_port, 0) != ((DST_PORT >> 0) & 0xff) ||
433 LSB(ctx->local_port, 1) != ((DST_PORT >> 8) & 0xff) ||
434 LSB(ctx->local_port, 2) != 0 || LSB(ctx->local_port, 3) != 0)
436 if (LSW(ctx->local_port, 0) != DST_PORT)
442 if (LSB(ctx->remote_ip4, 0) != ((SRC_IP4 >> 0) & 0xff) ||
443 LSB(ctx->remote_ip4, 1) != ((SRC_IP4 >> 8) & 0xff) ||
444 LSB(ctx->remote_ip4, 2) != ((SRC_IP4 >> 16) & 0xff) ||
445 LSB(ctx->remote_ip4, 3) != ((SRC_IP4 >> 24) & 0xff))
447 if (LSW(ctx->remote_ip4, 0) != ((SRC_IP4 >> 0) & 0xffff) ||
448 LSW(ctx->remote_ip4, 1) != ((SRC_IP4 >> 16) & 0xffff))
452 if (LSB(ctx->local_ip4, 0) != ((DST_IP4 >> 0) & 0xff) ||
453 LSB(ctx->local_ip4, 1) != ((DST_IP4 >> 8) & 0xff) ||
454 LSB(ctx->local_ip4, 2) != ((DST_IP4 >> 16) & 0xff) ||
455 LSB(ctx->local_ip4, 3) != ((DST_IP4 >> 24) & 0xff))
457 if (LSW(ctx->local_ip4, 0) != ((DST_IP4 >> 0) & 0xffff) ||
458 LSW(ctx->local_ip4, 1) != ((DST_IP4 >> 16) & 0xffff))
462 if (LSB(ctx->remote_ip4, 0) != 0 || LSB(ctx->remote_ip4, 1) != 0 ||
463 LSB(ctx->remote_ip4, 2) != 0 || LSB(ctx->remote_ip4, 3) != 0)
465 if (LSW(ctx->remote_ip4, 0) != 0 || LSW(ctx->remote_ip4, 1) != 0)
468 if (LSB(ctx->local_ip4, 0) != 0 || LSB(ctx->local_ip4, 1) != 0 ||
469 LSB(ctx->local_ip4, 2) != 0 || LSB(ctx->local_ip4, 3) != 0)
471 if (LSW(ctx->local_ip4, 0) != 0 || LSW(ctx->local_ip4, 1) != 0)
478 if (LSB(ctx->remote_ip6[0], 0) != ((SRC_IP6[0] >> 0) & 0xff) ||
479 LSB(ctx->remote_ip6[0], 1) != ((SRC_IP6[0] >> 8) & 0xff) ||
480 LSB(ctx->remote_ip6[0], 2) != ((SRC_IP6[0] >> 16) & 0xff) ||
481 LSB(ctx->remote_ip6[0], 3) != ((SRC_IP6[0] >> 24) & 0xff) ||
482 LSB(ctx->remote_ip6[1], 0) != ((SRC_IP6[1] >> 0) & 0xff) ||
483 LSB(ctx->remote_ip6[1], 1) != ((SRC_IP6[1] >> 8) & 0xff) ||
484 LSB(ctx->remote_ip6[1], 2) != ((SRC_IP6[1] >> 16) & 0xff) ||
485 LSB(ctx->remote_ip6[1], 3) != ((SRC_IP6[1] >> 24) & 0xff) ||
486 LSB(ctx->remote_ip6[2], 0) != ((SRC_IP6[2] >> 0) & 0xff) ||
487 LSB(ctx->remote_ip6[2], 1) != ((SRC_IP6[2] >> 8) & 0xff) ||
488 LSB(ctx->remote_ip6[2], 2) != ((SRC_IP6[2] >> 16) & 0xff) ||
489 LSB(ctx->remote_ip6[2], 3) != ((SRC_IP6[2] >> 24) & 0xff) ||
490 LSB(ctx->remote_ip6[3], 0) != ((SRC_IP6[3] >> 0) & 0xff) ||
491 LSB(ctx->remote_ip6[3], 1) != ((SRC_IP6[3] >> 8) & 0xff) ||
492 LSB(ctx->remote_ip6[3], 2) != ((SRC_IP6[3] >> 16) & 0xff) ||
493 LSB(ctx->remote_ip6[3], 3) != ((SRC_IP6[3] >> 24) & 0xff))
495 if (LSW(ctx->remote_ip6[0], 0) != ((SRC_IP6[0] >> 0) & 0xffff) ||
496 LSW(ctx->remote_ip6[0], 1) != ((SRC_IP6[0] >> 16) & 0xffff) ||
497 LSW(ctx->remote_ip6[1], 0) != ((SRC_IP6[1] >> 0) & 0xffff) ||
498 LSW(ctx->remote_ip6[1], 1) != ((SRC_IP6[1] >> 16) & 0xffff) ||
499 LSW(ctx->remote_ip6[2], 0) != ((SRC_IP6[2] >> 0) & 0xffff) ||
500 LSW(ctx->remote_ip6[2], 1) != ((SRC_IP6[2] >> 16) & 0xffff) ||
501 LSW(ctx->remote_ip6[3], 0) != ((SRC_IP6[3] >> 0) & 0xffff) ||
502 LSW(ctx->remote_ip6[3], 1) != ((SRC_IP6[3] >> 16) & 0xffff))
505 if (LSB(ctx->local_ip6[0], 0) != ((DST_IP6[0] >> 0) & 0xff) ||
506 LSB(ctx->local_ip6[0], 1) != ((DST_IP6[0] >> 8) & 0xff) ||
507 LSB(ctx->local_ip6[0], 2) != ((DST_IP6[0] >> 16) & 0xff) ||
508 LSB(ctx->local_ip6[0], 3) != ((DST_IP6[0] >> 24) & 0xff) ||
509 LSB(ctx->local_ip6[1], 0) != ((DST_IP6[1] >> 0) & 0xff) ||
510 LSB(ctx->local_ip6[1], 1) != ((DST_IP6[1] >> 8) & 0xff) ||
511 LSB(ctx->local_ip6[1], 2) != ((DST_IP6[1] >> 16) & 0xff) ||
512 LSB(ctx->local_ip6[1], 3) != ((DST_IP6[1] >> 24) & 0xff) ||
513 LSB(ctx->local_ip6[2], 0) != ((DST_IP6[2] >> 0) & 0xff) ||
514 LSB(ctx->local_ip6[2], 1) != ((DST_IP6[2] >> 8) & 0xff) ||
515 LSB(ctx->local_ip6[2], 2) != ((DST_IP6[2] >> 16) & 0xff) ||
516 LSB(ctx->local_ip6[2], 3) != ((DST_IP6[2] >> 24) & 0xff) ||
517 LSB(ctx->local_ip6[3], 0) != ((DST_IP6[3] >> 0) & 0xff) ||
518 LSB(ctx->local_ip6[3], 1) != ((DST_IP6[3] >> 8) & 0xff) ||
519 LSB(ctx->local_ip6[3], 2) != ((DST_IP6[3] >> 16) & 0xff) ||
520 LSB(ctx->local_ip6[3], 3) != ((DST_IP6[3] >> 24) & 0xff))
522 if (LSW(ctx->local_ip6[0], 0) != ((DST_IP6[0] >> 0) & 0xffff) ||
523 LSW(ctx->local_ip6[0], 1) != ((DST_IP6[0] >> 16) & 0xffff) ||
524 LSW(ctx->local_ip6[1], 0) != ((DST_IP6[1] >> 0) & 0xffff) ||
525 LSW(ctx->local_ip6[1], 1) != ((DST_IP6[1] >> 16) & 0xffff) ||
526 LSW(ctx->local_ip6[2], 0) != ((DST_IP6[2] >> 0) & 0xffff) ||
527 LSW(ctx->local_ip6[2], 1) != ((DST_IP6[2] >> 16) & 0xffff) ||
528 LSW(ctx->local_ip6[3], 0) != ((DST_IP6[3] >> 0) & 0xffff) ||
529 LSW(ctx->local_ip6[3], 1) != ((DST_IP6[3] >> 16) & 0xffff))
533 if (LSB(ctx->remote_ip6[0], 0) != 0 || LSB(ctx->remote_ip6[0], 1) != 0 ||
534 LSB(ctx->remote_ip6[0], 2) != 0 || LSB(ctx->remote_ip6[0], 3) != 0 ||
535 LSB(ctx->remote_ip6[1], 0) != 0 || LSB(ctx->remote_ip6[1], 1) != 0 ||
536 LSB(ctx->remote_ip6[1], 2) != 0 || LSB(ctx->remote_ip6[1], 3) != 0 ||
537 LSB(ctx->remote_ip6[2], 0) != 0 || LSB(ctx->remote_ip6[2], 1) != 0 ||
538 LSB(ctx->remote_ip6[2], 2) != 0 || LSB(ctx->remote_ip6[2], 3) != 0 ||
539 LSB(ctx->remote_ip6[3], 0) != 0 || LSB(ctx->remote_ip6[3], 1) != 0 ||
540 LSB(ctx->remote_ip6[3], 2) != 0 || LSB(ctx->remote_ip6[3], 3) != 0)
542 if (LSW(ctx->remote_ip6[0], 0) != 0 || LSW(ctx->remote_ip6[0], 1) != 0 ||
543 LSW(ctx->remote_ip6[1], 0) != 0 || LSW(ctx->remote_ip6[1], 1) != 0 ||
544 LSW(ctx->remote_ip6[2], 0) != 0 || LSW(ctx->remote_ip6[2], 1) != 0 ||
545 LSW(ctx->remote_ip6[3], 0) != 0 || LSW(ctx->remote_ip6[3], 1) != 0)
548 if (LSB(ctx->local_ip6[0], 0) != 0 || LSB(ctx->local_ip6[0], 1) != 0 ||
549 LSB(ctx->local_ip6[0], 2) != 0 || LSB(ctx->local_ip6[0], 3) != 0 ||
550 LSB(ctx->local_ip6[1], 0) != 0 || LSB(ctx->local_ip6[1], 1) != 0 ||
551 LSB(ctx->local_ip6[1], 2) != 0 || LSB(ctx->local_ip6[1], 3) != 0 ||
552 LSB(ctx->local_ip6[2], 0) != 0 || LSB(ctx->local_ip6[2], 1) != 0 ||
553 LSB(ctx->local_ip6[2], 2) != 0 || LSB(ctx->local_ip6[2], 3) != 0 ||
554 LSB(ctx->local_ip6[3], 0) != 0 || LSB(ctx->local_ip6[3], 1) != 0 ||
555 LSB(ctx->local_ip6[3], 2) != 0 || LSB(ctx->local_ip6[3], 3) != 0)
557 if (LSW(ctx->remote_ip6[0], 0) != 0 || LSW(ctx->remote_ip6[0], 1) != 0 ||
558 LSW(ctx->remote_ip6[1], 0) != 0 || LSW(ctx->remote_ip6[1], 1) != 0 ||
559 LSW(ctx->remote_ip6[2], 0) != 0 || LSW(ctx->remote_ip6[2], 1) != 0 ||
560 LSW(ctx->remote_ip6[3], 0) != 0 || LSW(ctx->remote_ip6[3], 1) != 0)
567 bpf_sk_assign(ctx, sk, 0);
575 int sk_assign_esocknosupport(struct bpf_sk_lookup *ctx)
585 err = bpf_sk_assign(ctx, sk, 0);
600 int multi_prog_pass1(struct bpf_sk_lookup *ctx)
607 int multi_prog_pass2(struct bpf_sk_lookup *ctx)
614 int multi_prog_drop1(struct bpf_sk_lookup *ctx)
621 int multi_prog_drop2(struct bpf_sk_lookup *ctx)
627 static __always_inline int select_server_a(struct bpf_sk_lookup *ctx)
636 err = bpf_sk_assign(ctx, sk, 0);
645 int multi_prog_redir1(struct bpf_sk_lookup *ctx)
647 (void)select_server_a(ctx);
653 int multi_prog_redir2(struct bpf_sk_lookup *ctx)
655 (void)select_server_a(ctx);