-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
some workload mode bugfix and waypoint optimization #361
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,52 +30,74 @@ static inline backend_value *map_lookup_backend(const backend_key *key) | |
return kmesh_map_lookup_elem(&map_of_backend, key); | ||
} | ||
|
||
static inline int backend_manager(ctx_buff_t *ctx, backend_value *backend_v) | ||
static inline int waypoint_manager(ctx_buff_t *ctx, __u32 addr, __u32 port) | ||
{ | ||
int ret; | ||
address_t target_addr; | ||
__u64 *sk = (__u64 *)ctx->sk; | ||
struct bpf_sock_tuple value_tuple = {0}; | ||
|
||
value_tuple.ipv4.daddr = ctx->user_ip4; | ||
value_tuple.ipv4.dport = ctx->user_port; | ||
|
||
ret = bpf_map_update_elem(&map_of_dst_info, &sk, &value_tuple, BPF_NOEXIST); | ||
if (ret) { | ||
BPF_LOG(ERR, BACKEND, "record metadata origin address and port failed, ret is %d\n", ret); | ||
return ret; | ||
} | ||
target_addr.ipv4 = addr; | ||
target_addr.port = port; | ||
SET_CTX_ADDRESS(ctx, target_addr); | ||
kmesh_workload_tail_call(ctx, TAIL_CALL_CONNECT4_INDEX); | ||
|
||
// if tail call failed will run this code | ||
BPF_LOG(ERR, BACKEND, "workload tail call failed, err is %d\n", ret); | ||
return -ENOEXEC; | ||
} | ||
|
||
static inline int backend_manager(ctx_buff_t *ctx, backend_value *backend_v, __u32 service_id, service_value *service_v) | ||
{ | ||
int ret; | ||
address_t target_addr; | ||
__u32 user_port = ctx->user_port; | ||
|
||
if (backend_v->waypoint_addr != 0 && backend_v->waypoint_port != 0) { | ||
BPF_LOG( | ||
DEBUG, | ||
BACKEND, | ||
"find waypoint addr=[%pI4h:%u]\n", | ||
&backend_v->waypoint_addr, | ||
bpf_ntohs(backend_v->waypoint_port)); | ||
value_tuple.ipv4.daddr = ctx->user_ip4; | ||
value_tuple.ipv4.dport = ctx->user_port; | ||
|
||
ret = bpf_map_update_elem(&map_of_dst_info, &sk, &value_tuple, BPF_NOEXIST); | ||
if (ret) { | ||
BPF_LOG(ERR, BACKEND, "record metadata origin address and port failed, ret is %d\n", ret); | ||
ret = waypoint_manager(ctx, backend_v->waypoint_addr, backend_v->waypoint_port); | ||
if (ret == -ENOEXEC) { | ||
BPF_LOG(ERR, BACKEND, "waypoint_manager failed, ret:%d\n", ret); | ||
return ret; | ||
} | ||
target_addr.ipv4 = backend_v->waypoint_addr; | ||
target_addr.port = backend_v->waypoint_port; | ||
SET_CTX_ADDRESS(ctx, target_addr); | ||
kmesh_workload_tail_call(ctx, TAIL_CALL_CONNECT4_INDEX); | ||
|
||
// if tail call failed will run this code | ||
BPF_LOG(ERR, BACKEND, "workload tail call failed, err is %d\n", ret); | ||
return -ENOEXEC; | ||
} | ||
|
||
#pragma unroll | ||
for (unsigned int i = 0; i < backend_v->port_count; i++) { | ||
if (i >= MAX_PORT_COUNT) { | ||
BPF_LOG(WARN, BACKEND, "exceed the max port count\n"); | ||
for (__u32 i = 0; i < backend_v->service_count; i++) { | ||
if (i >= MAX_SERVICE_COUNT) { | ||
BPF_LOG(WARN, BACKEND, "exceed the max port count:%d\n", MAX_SERVICE_COUNT); | ||
return -EINVAL; | ||
} | ||
|
||
if (ctx->user_port == backend_v->service_port[i]) { | ||
target_addr.ipv4 = backend_v->ipv4; | ||
target_addr.port = backend_v->target_port[i]; | ||
SET_CTX_ADDRESS(ctx, target_addr); | ||
BPF_LOG( | ||
DEBUG, BACKEND, "get the backend addr=[%pI4h:%u]\n", &target_addr.ipv4, bpf_ntohs(target_addr.port)); | ||
return 0; | ||
if (service_id == backend_v->service[i]) { | ||
BPF_LOG(DEBUG, BACKEND, "access the backend by service:%d\n", service_id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm \n There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that all logs have been added with ‘\n’. Do we need to delete them all together in this PR. |
||
#pragma unroll | ||
for (__u32 j = 0; j < MAX_PORT_COUNT; j++) { | ||
if (user_port == service_v->service_port[j]) { | ||
target_addr.ipv4 = backend_v->ipv4; | ||
target_addr.port = service_v->target_port[j]; | ||
SET_CTX_ADDRESS(ctx, target_addr); | ||
BPF_LOG( | ||
DEBUG, | ||
BACKEND, | ||
"get the backend addr=[%pI4h:%u]\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm \n There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
&target_addr.ipv4, | ||
bpf_ntohs(target_addr.port)); | ||
return 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,11 +50,19 @@ static inline int frontend_manager(ctx_buff_t *ctx, frontend_value *frontend_v) | |
} | ||
|
||
if (direct_backend) { | ||
ret = backend_manager(ctx, backend_v); | ||
if (ret != 0) { | ||
if (ret != -ENOENT) | ||
BPF_LOG(ERR, FRONTEND, "backend_manager failed, ret:%d\n", ret); | ||
return ret; | ||
// For pod direct access, if a pod has watpoint captured, we will redirect to waypoint, otherwise we do nothing. | ||
if (backend_v->waypoint_addr != 0 && backend_v->waypoint_port != 0) { | ||
BPF_LOG( | ||
DEBUG, | ||
FRONTEND, | ||
"find waypoint addr=[%pI4h:%u]\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm \n There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
&backend_v->waypoint_addr, | ||
bpf_ntohs(backend_v->waypoint_port)); | ||
ret = waypoint_manager(ctx, backend_v->waypoint_addr, backend_v->waypoint_port); | ||
if (ret == -ENOEXEC) { | ||
BPF_LOG(ERR, BACKEND, "waypoint_manager failed, ret:%d\n", ret); | ||
return ret; | ||
} | ||
} | ||
} else { | ||
ret = service_manager(ctx, frontend_v->upstream_id, service_v); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ static inline service_value *map_lookup_service(const service_key *key) | |
return kmesh_map_lookup_elem(&map_of_service, key); | ||
} | ||
|
||
static inline int lb_random_handle(ctx_buff_t *ctx, int service_id, service_value *service_v) | ||
static inline int lb_random_handle(ctx_buff_t *ctx, __u32 service_id, service_value *service_v) | ||
{ | ||
int ret = 0; | ||
endpoint_key endpoint_k = {0}; | ||
|
@@ -42,7 +42,7 @@ static inline int lb_random_handle(ctx_buff_t *ctx, int service_id, service_valu | |
return -ENOENT; | ||
} | ||
|
||
ret = endpoint_manager(ctx, endpoint_v); | ||
ret = endpoint_manager(ctx, endpoint_v, service_id, service_v); | ||
if (ret != 0) { | ||
if (ret != -ENOENT) | ||
BPF_LOG(ERR, SERVICE, "endpoint_manager failed, ret:%d\n", ret); | ||
|
@@ -52,10 +52,24 @@ static inline int lb_random_handle(ctx_buff_t *ctx, int service_id, service_valu | |
return 0; | ||
} | ||
|
||
static inline int service_manager(ctx_buff_t *ctx, int service_id, service_value *service_v) | ||
static inline int service_manager(ctx_buff_t *ctx, __u32 service_id, service_value *service_v) | ||
{ | ||
int ret = 0; | ||
|
||
if (service_v->waypoint_addr != 0 && service_v->waypoint_port != 0) { | ||
BPF_LOG( | ||
DEBUG, | ||
SERVICE, | ||
"find waypoint addr=[%pI4h:%u]\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm \n There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
&service_v->waypoint_addr, | ||
bpf_ntohs(service_v->waypoint_port)); | ||
ret = waypoint_manager(ctx, service_v->waypoint_addr, service_v->waypoint_port); | ||
if (ret == -ENOEXEC) { | ||
BPF_LOG(ERR, BACKEND, "waypoint_manager failed, ret:%d\n", ret); | ||
return ret; | ||
} | ||
} | ||
|
||
BPF_LOG(DEBUG, SERVICE, "load balance type:%u", service_v->lb_policy); | ||
switch (service_v->lb_policy) { | ||
case LB_POLICY_RANDOM: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,13 +20,24 @@ import ( | |
"github.com/cilium/ebpf" | ||
) | ||
|
||
const ( | ||
MaxPortNum = 10 | ||
) | ||
|
||
type ServiceKey struct { | ||
ServiceId uint32 // service id | ||
} | ||
|
||
type ServicePorts [MaxPortNum]uint32 | ||
type TargetPorts [MaxPortNum]uint32 | ||
|
||
type ServiceValue struct { | ||
EndpointCount uint32 // endpoint count of current service | ||
LbPolicy uint32 // load balancing algorithm, currently only supports random algorithm | ||
EndpointCount uint32 // endpoint count of current service | ||
LbPolicy uint32 // load balancing algorithm, currently only supports random algorithm | ||
ServicePort ServicePorts // ServicePort[i] and TargetPort[i] are a pair, i starts from 0 and max value is MaxPortNum-1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, it's better to define a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currently,we use cilium bpf interface to operate the map, and the interface cannot support self defined data struct. |
||
TargetPort TargetPorts | ||
WaypointAddr uint32 | ||
WaypointPort uint32 | ||
} | ||
|
||
func (c *Cache) ServiceUpdate(key *ServiceKey, value *ServiceValue) error { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong log, it is max service number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm \n