Skip to content

Commit

Permalink
make gen
Browse files Browse the repository at this point in the history
Signed-off-by: superCharge-xsy <[email protected]>
  • Loading branch information
supercharge-xsy committed Jun 13, 2024
1 parent e6b03e1 commit 74f72cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bpf/include/bpf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
/*0x3a4(932) is the specific port handled by the daemon to enable bypass*/
#define DISABLE_BYPASS_PORT 0x3a4

#define AUTH_PASS 0
#define AUTH_FORBID 1
#define AUTH_PASS 0
#define AUTH_FORBID 1
#define AUTH_PROCESSING 2

typedef struct {
Expand Down
22 changes: 11 additions & 11 deletions bpf/kmesh/workload/sockops.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ static inline void clean_dstinfo_map(struct bpf_sock_ops *skops)
BPF_LOG(ERR, SOCKOPS, "bpf map delete destination info failed, ret: %d", ret);
}

// insert an init state to auth_map, indicates that auth is being performed
static inline void record_auth_processing(struct bpf_sock_ops *skops)
{
struct bpf_sock_tuple tuple_info = {0};
extract_skops_to_tuple(skops, &tuple_info);
int err = bpf_map_update_elem(&map_of_auth, &tuple_info, AUTH_PROCESSING, BPF_ANY);
if (err)
BPF_LOG(ERR, SOCKOPS, "insert auth init record failed!, err is %d", err);
}

// insert an IPv4 tuple into the ringbuf
static inline void auth_ip_tuple(struct bpf_sock_ops *skops)
{
Expand All @@ -103,20 +113,10 @@ static inline void auth_ip_tuple(struct bpf_sock_ops *skops)
// In this way, auth can be performed normally.
extract_skops_to_tuple_reverse(skops, &(*msg).tuple);
(*msg).type = (__u32)IPV4;
record_auth_running(skops);
record_auth_processing(skops);
bpf_ringbuf_submit(msg, 0);
}

// insert an init state to auth_map, indicates that auth is being performed
static inline void record_auth_running(struct bpf_sock_ops *skops)
{
struct bpf_sock_tuple tuple_info = {0};
extract_skops_to_tuple(skops, &tuple_info);
int err = bpf_map_update_elem(&map_of_auth, &tuple_info, AUTH_PROCESSING, BPF_ANY);
if (err)
BPF_LOG(ERR, SOCKOPS, "insert auth init record failed!, err is %d", err);
}

// update sockmap to trigger sk_msg prog to encode metadata before sending to waypoint
static inline void enable_encoding_metadata(struct bpf_sock_ops *skops)
{
Expand Down
12 changes: 6 additions & 6 deletions bpf/kmesh/workload/xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ int xdp_shutdown(struct xdp_md *ctx)

if (ret == AUTH_FORBID) {
shutdown_tuple(&info);
// If auth denied, it still returns XDP_PASS here, so next time when a client package is
// sent to server, it will be shutdown since server's RST has been set
return XDP_PASS;
}
// If auth denied, it still returns XDP_PASS here, so next time when a client package is
// sent to server, it will be shutdown since server's RST has been set
return XDP_PASS;
}

char _license[] SEC("license") = "Dual BSD/GPL";
int _version SEC("version") = 1;
char _license[] SEC("license") = "Dual BSD/GPL";
int _version SEC("version") = 1;

0 comments on commit 74f72cd

Please sign in to comment.