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 14, 2024
1 parent e6b03e1 commit a06e824
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 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
4 changes: 2 additions & 2 deletions bpf/kmesh/workload/xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ int xdp_shutdown(struct xdp_md *ctx)
// never failed
parser_tuple(&info, &tuple_info);
ret = should_shutdown(&tuple_info);
if ret == AUTH_PROCESSING)
if (ret == AUTH_PROCESSING)
return XDP_DROP;

if (ret == AUTH_FORBID) {
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
Expand Down
1 change: 0 additions & 1 deletion pkg/auth/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func (r *Rbac) Run(ctx context.Context) {
continue
}
}

}
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/auth/xdp_auth_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package auth

import (
"github.com/cilium/ebpf"
"istio.io/pkg/log"

"kmesh.net/kmesh/pkg/utils"
)
Expand Down

0 comments on commit a06e824

Please sign in to comment.