Lines Matching refs:ctx

24 static __inline int bind_to_device(struct bpf_sock_addr *ctx)
32 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
35 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_BINDTOIFINDEX,
38 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
41 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_BINDTOIFINDEX,
45 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
48 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTOIFINDEX,
51 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_BINDTODEVICE,
58 static __inline int bind_reuseport(struct bpf_sock_addr *ctx)
62 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_REUSEPORT,
65 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_REUSEPORT,
69 if (bpf_setsockopt(ctx, SOL_SOCKET, SO_REUSEPORT,
72 if (bpf_getsockopt(ctx, SOL_SOCKET, SO_REUSEPORT,
79 static __inline int misc_opts(struct bpf_sock_addr *ctx, int opt)
84 if (bpf_getsockopt(ctx, SOL_SOCKET, opt, &old, sizeof(old)) ||
87 if (bpf_setsockopt(ctx, SOL_SOCKET, opt, &new, sizeof(new)))
89 if (bpf_getsockopt(ctx, SOL_SOCKET, opt, &tmp, sizeof(tmp)) ||
92 if (bpf_setsockopt(ctx, SOL_SOCKET, opt, &old, sizeof(old)))
99 int bind_v4_prog(struct bpf_sock_addr *ctx)
105 sk = ctx->sk;
112 if (ctx->type != SOCK_STREAM && ctx->type != SOCK_DGRAM)
115 if (ctx->user_ip4 != bpf_htonl(SERV4_IP) ||
116 ctx->user_port != bpf_htons(SERV4_PORT))
121 user_ip4 |= ((volatile __u8 *)&ctx->user_ip4)[0] << 0;
122 user_ip4 |= ((volatile __u8 *)&ctx->user_ip4)[1] << 8;
123 user_ip4 |= ((volatile __u8 *)&ctx->user_ip4)[2] << 16;
124 user_ip4 |= ((volatile __u8 *)&ctx->user_ip4)[3] << 24;
125 if (ctx->user_ip4 != user_ip4)
129 user_port |= ((volatile __u8 *)&ctx->user_port)[0] << 0;
130 user_port |= ((volatile __u8 *)&ctx->user_port)[1] << 8;
131 if (ctx->user_port != user_port)
136 user_ip4 |= ((volatile __u16 *)&ctx->user_ip4)[0] << 0;
137 user_ip4 |= ((volatile __u16 *)&ctx->user_ip4)[1] << 16;
138 if (ctx->user_ip4 != user_ip4)
142 if (bind_to_device(ctx))
146 if (misc_opts(ctx, SO_MARK) || misc_opts(ctx, SO_PRIORITY))
150 if (bind_reuseport(ctx))
153 ctx->user_ip4 = bpf_htonl(SERV4_REWRITE_IP);
154 ctx->user_port = bpf_htons(SERV4_REWRITE_PORT);