Skip to content

Commit 0b772a6

Browse files
committed
add local host and port verdict
1 parent e707be0 commit 0b772a6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

03-sockops/ebpf-sockops/bpf_redir.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,26 @@ __section("sk_msg") int bpf_redir(struct sk_msg_md *msg)
2020
return SK_PASS;
2121
}
2222

23+
/*
24+
int bpf_redir(struct sk_msg_md *msg)
25+
{
26+
__u64 flags = BPF_F_INGRESS;
27+
struct sock_key key = {};
28+
29+
sk_msg_extract4_key(msg, &key);
30+
// See whether the source or destination IP is local host
31+
if (key.sip4 == 16777343 || key.dip4 == 16777343) {
32+
// See whether the source or destination port is 10000
33+
if (key.sport == 4135 || key.dport == 4135) {
34+
//int len1 = (__u64)msg->data_end - (__u64)msg->data;
35+
//printk("<<< redir_proxy port %d --> %d (%d)\n", key.sport, key.dport, len1);
36+
msg_redirect_hash(msg, &sock_ops_map, &key, flags);
37+
}
38+
}
39+
40+
return SK_PASS;
41+
}
42+
*/
43+
2344
BPF_LICENSE("GPL");
2445
int _version __section("version") = 1;

03-sockops/ebpf-sockops/bpf_sockops.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ static inline void bpf_sock_ops_ipv4(struct bpf_sock_ops *skops)
1616
printk("<<< ipv4 op = %d, port %d --> %d\n", skops->op, key.sport, bpf_ntohl(key.dport));
1717
}
1818

19+
/*
20+
static inline void bpf_sock_ops_ipv4(struct bpf_sock_ops *skops)
21+
{
22+
struct sock_key key = {};
23+
sk_extract4_key(skops, &key);
24+
// See whether the source or destination IP is local host
25+
if (key.dip4 == 16777343 || key.sip4 == 16777343 ) {
26+
// See whether the source or destination port is 10000
27+
if (key.dport == 4135 || key.sport == 4135) {
28+
int ret = sock_hash_update(skops, &sock_ops_map, &key, BPF_NOEXIST);
29+
printk("<<< ipv4 op = %d, port %d --> %d\n", skops->op, key.sport, key.dport);
30+
if (ret != 0)
31+
printk("*** FAILED %d ***\n", ret);
32+
}
33+
}
34+
}
35+
*/
36+
1937
static inline void bpf_sock_ops_ipv6(struct bpf_sock_ops *skops)
2038
{
2139
if (skops->remote_ip4)

0 commit comments

Comments
 (0)