Skip to content

Commit 9d08062

Browse files
fix: Update struct references from config to dynptr_cfg in README files
1 parent c42ba4f commit 9d08062

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/features/dynptr/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ struct {
8989
__uint(type, BPF_MAP_TYPE_ARRAY);
9090
__uint(max_entries, 1);
9191
__type(key, __u32);
92-
__type(value, struct config);
92+
__type(value, struct dynptr_cfg);
9393
} cfg_map SEC(".maps");
9494

9595
SEC("tc")
9696
int dynptr_tc_ingress(struct __sk_buff *ctx)
9797
{
98-
const struct config *cfg;
98+
const struct dynptr_cfg *cfg;
9999
struct bpf_dynptr skb_ptr;
100100

101101
/* Temporary buffers for slice (data may be copied here) */
@@ -136,7 +136,8 @@ int dynptr_tc_ingress(struct __sk_buff *ctx)
136136
return TC_ACT_OK;
137137

138138
__u16 dport = bpf_ntohs(tcp->dest);
139-
__u8 drop = (cfg->blocked_port && dport == cfg->blocked_port);
139+
__u16 sport = bpf_ntohs(tcp->source);
140+
__u8 drop = (cfg->blocked_port && (sport == cfg->blocked_port || dport == cfg->blocked_port));
140141

141142
/* Output variable-length event using ringbuf dynptr */
142143
if (cfg->enable_ringbuf) {
@@ -250,7 +251,7 @@ static int handle_event(void *ctx, void *data, size_t data_sz)
250251
int main(int argc, char **argv)
251252
{
252253
const char *ifname = NULL;
253-
struct config cfg = { .blocked_port = 0, .snap_len = 64, .enable_ringbuf = 1 };
254+
struct dynptr_cfg cfg = { .blocked_port = 0, .snap_len = 64, .enable_ringbuf = 1 };
254255
255256
/* Parse arguments */
256257
for (int i = 1; i < argc; i++) {

src/features/dynptr/README.zh.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ struct {
8989
__uint(type, BPF_MAP_TYPE_ARRAY);
9090
__uint(max_entries, 1);
9191
__type(key, __u32);
92-
__type(value, struct config);
92+
__type(value, struct dynptr_cfg);
9393
} cfg_map SEC(".maps");
9494

9595
SEC("tc")
9696
int dynptr_tc_ingress(struct __sk_buff *ctx)
9797
{
98-
const struct config *cfg;
98+
const struct dynptr_cfg *cfg;
9999
struct bpf_dynptr skb_ptr;
100100

101101
/* 用于切片的临时缓冲区(数据可能被复制到这里) */
@@ -136,7 +136,8 @@ int dynptr_tc_ingress(struct __sk_buff *ctx)
136136
return TC_ACT_OK;
137137

138138
__u16 dport = bpf_ntohs(tcp->dest);
139-
__u8 drop = (cfg->blocked_port && dport == cfg->blocked_port);
139+
__u16 sport = bpf_ntohs(tcp->source);
140+
__u8 drop = (cfg->blocked_port && (sport == cfg->blocked_port || dport == cfg->blocked_port));
140141

141142
/* 使用 ringbuf dynptr 输出可变长度事件 */
142143
if (cfg->enable_ringbuf) {
@@ -250,7 +251,7 @@ static int handle_event(void *ctx, void *data, size_t data_sz)
250251
int main(int argc, char **argv)
251252
{
252253
const char *ifname = NULL;
253-
struct config cfg = { .blocked_port = 0, .snap_len = 64, .enable_ringbuf = 1 };
254+
struct dynptr_cfg cfg = { .blocked_port = 0, .snap_len = 64, .enable_ringbuf = 1 };
254255
255256
/* 解析参数 */
256257
for (int i = 1; i < argc; i++) {

0 commit comments

Comments
 (0)