Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
Signed-off-by: wuchangye <[email protected]>
  • Loading branch information
nlgwcy committed Jun 20, 2024
1 parent 005571b commit df475b0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ BraceWrapping:
BeforeCatch: false
# else之前
BeforeElse: false
# elseif之前
BeforeElseif: false
# 缩进大括号
IndentBraces: false
# 分离空函数
Expand Down
2 changes: 1 addition & 1 deletion bpf/include/bpf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "common.h"

#define map_of_manager kmesh_manage
#define map_of_manager kmesh_manage
#define MAP_SIZE_OF_MANAGER 8192
/*0x3a1(929) is the specific port handled by the cni to enable kmesh*/
#define ENABLE_KMESH_PORT 0x3a1
Expand Down
2 changes: 1 addition & 1 deletion bpf/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static inline int kmesh_map_update_elem(void *map, const void *key, const void *
}

#if OE_23_03
#define bpf__strncmp bpf_strncmp
#define bpf__strncmp bpf_strncmp
#define GET_SKOPS_REMOTE_PORT(sk_ops) (__u16)((sk_ops)->remote_port)
#else
#define GET_SKOPS_REMOTE_PORT(sk_ops) (__u16)((sk_ops)->remote_port >> 16)
Expand Down
36 changes: 17 additions & 19 deletions bpf/kmesh/workload/sendmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,24 @@ static inline int alloc_dst_length(struct sk_msg_md *msg, __u32 length)
return 0;
}

static inline void sk_msg_write_buf(struct sk_msg_md *msg, __u32 *off, __u8 *data, __u32 len)
{
__u8 *begin = (__u8 *)(msg->data) + *off;
if (check_overflow(msg, begin, len)) {
BPF_LOG(ERR, SENDMSG, "sk msg write buf overflow, off: %u, len: %u\n", *off, len);
return;
}

bpf_memcpy(begin, data, len);
*off += len;
return;
}
#define SK_MSG_WRITE_BUF(sk_msg, offset, payload, payloadlen) \
do { \
__u8 *begin = (__u8 *)((sk_msg)->data) + *(offset); \
if (check_overflow((sk_msg), begin, payloadlen)) { \
BPF_LOG(ERR, SENDMSG, "sk msg write buf overflow, off: %u, len: %u\n", *(offset), payloadlen); \
break; \
} \
bpf_memcpy(begin, payload, payloadlen); \
*(offset) += (payloadlen); \
} while (0)

static inline void encode_metadata_end(struct sk_msg_md *msg, __u32 *off)
{
__u8 type = TLV_PAYLOAD;
__u32 size = 0;

sk_msg_write_buf(msg, off, &type, TLV_TYPE_SIZE);
sk_msg_write_buf(msg, off, &size, TLV_LENGTH_SIZE);
SK_MSG_WRITE_BUF(msg, off, &type, TLV_TYPE_SIZE);
SK_MSG_WRITE_BUF(msg, off, &size, TLV_LENGTH_SIZE);
return;
}

Expand All @@ -152,18 +150,18 @@ static inline void encode_metadata_org_dst_addr(struct sk_msg_md *msg, __u32 *of
BPF_LOG(DEBUG, SENDMSG, "get valid dst, do encoding...\n");

// write T
sk_msg_write_buf(msg, off, &type, TLV_TYPE_SIZE);
SK_MSG_WRITE_BUF(msg, off, &type, TLV_TYPE_SIZE);

// write L
addr_size = bpf_htonl(addr_size);
sk_msg_write_buf(msg, off, &addr_size, TLV_LENGTH_SIZE);
SK_MSG_WRITE_BUF(msg, off, &addr_size, TLV_LENGTH_SIZE);

// write V
if (v4)
sk_msg_write_buf(msg, off, (__u8 *)&dst_ip.ip4, TLV_IP4_LENGTH);
SK_MSG_WRITE_BUF(msg, off, (__u8 *)&dst_ip.ip4, TLV_IP4_LENGTH);
else
sk_msg_write_buf(msg, off, (__u8 *)dst_ip.ip6, TLV_IP6_LENGTH);
sk_msg_write_buf(msg, off, &dst_port, TLV_PORT_LENGTH);
SK_MSG_WRITE_BUF(msg, off, (__u8 *)dst_ip.ip6, TLV_IP6_LENGTH);
SK_MSG_WRITE_BUF(msg, off, &dst_port, TLV_PORT_LENGTH);

// write END
encode_metadata_end(msg, off);
Expand Down

0 comments on commit df475b0

Please sign in to comment.