Lines Matching refs:ctx
26 static __inline int bind_to_device(struct bpf_sock_addr *ctx) in bind_to_device() argument
34 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE, in bind_to_device()
37 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_BINDTOIFINDEX, in bind_to_device()
40 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE, in bind_to_device()
43 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_BINDTOIFINDEX, in bind_to_device()
47 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE, in bind_to_device()
50 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTOIFINDEX, in bind_to_device()
53 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE, in bind_to_device()
60 static __inline int bind_reuseport(struct bpf_sock_addr *ctx) in bind_reuseport() argument
64 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_REUSEPORT, in bind_reuseport()
67 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_REUSEPORT, in bind_reuseport()
71 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_REUSEPORT, in bind_reuseport()
74 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_REUSEPORT, in bind_reuseport()
81 static __inline int misc_opts(struct bpf_sock_addr *ctx, int opt) in misc_opts() argument
86 if (bpf_getsockopt(ctx, SOL_SOCKET, opt, &old, sizeof(old)) || in misc_opts()
89 if (bpf_setsockopt(ctx, SOL_SOCKET, opt, &new, sizeof(new))) in misc_opts()
91 if (bpf_getsockopt(ctx, SOL_SOCKET, opt, &tmp, sizeof(tmp)) || in misc_opts()
94 if (bpf_setsockopt(ctx, SOL_SOCKET, opt, &old, sizeof(old))) in misc_opts()
101 int bind_v4_prog(struct bpf_sock_addr *ctx) in bind_v4_prog() argument
107 sk = ctx->sk; in bind_v4_prog()
114 if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM) in bind_v4_prog()
117 if (ctx->user_ip4 != bpf_htonl(SERV4_IP) || in bind_v4_prog()
118 ctx->user_port != bpf_htons(SERV4_PORT)) in bind_v4_prog()
123 user_ip4 |= load_byte(ctx->user_ip4, 0, sizeof(user_ip4)); in bind_v4_prog()
124 user_ip4 |= load_byte(ctx->user_ip4, 1, sizeof(user_ip4)); in bind_v4_prog()
125 user_ip4 |= load_byte(ctx->user_ip4, 2, sizeof(user_ip4)); in bind_v4_prog()
126 user_ip4 |= load_byte(ctx->user_ip4, 3, sizeof(user_ip4)); in bind_v4_prog()
127 if (ctx->user_ip4 != user_ip4) in bind_v4_prog()
131 user_port |= load_byte(ctx->user_port, 0, sizeof(user_port)); in bind_v4_prog()
132 user_port |= load_byte(ctx->user_port, 1, sizeof(user_port)); in bind_v4_prog()
133 if (ctx->user_port != user_port) in bind_v4_prog()
138 user_ip4 |= load_word(ctx->user_ip4, 0, sizeof(user_ip4)); in bind_v4_prog()
139 user_ip4 |= load_word(ctx->user_ip4, 1, sizeof(user_ip4)); in bind_v4_prog()
140 if (ctx->user_ip4 != user_ip4) in bind_v4_prog()
144 if (bind_to_device(ctx)) in bind_v4_prog()
148 if (misc_opts(ctx, SO_MARK) || misc_opts(ctx, SO_PRIORITY)) in bind_v4_prog()
152 if (bind_reuseport(ctx)) in bind_v4_prog()
155 ctx->user_ip4 = bpf_htonl(SERV4_REWRITE_IP); in bind_v4_prog()
156 ctx->user_port = bpf_htons(SERV4_REWRITE_PORT); in bind_v4_prog()
162 int bind_v4_deny_prog(struct bpf_sock_addr *ctx) in bind_v4_deny_prog() argument