summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortongzongzhen <[email protected]>2024-09-02 18:07:11 +0800
committertongzongzhen <[email protected]>2024-09-02 18:07:11 +0800
commit5bfc9eb0c647c7362dbca2e4fc586f33cfe0cf72 (patch)
tree1d55c11ce9d3763a37af86dd8feef7e71688d7d1
parentc2cc02d2036076a01cf0d8d69d40829cb2e7fb6c (diff)
redirect to egress stillHEADmaster
-rw-r--r--dummy_ebpf_2/send.py19
-rw-r--r--dummy_ebpf_2/src/tc_prog_kernel.c3
2 files changed, 18 insertions, 4 deletions
diff --git a/dummy_ebpf_2/send.py b/dummy_ebpf_2/send.py
index f4d86e4..fe2ff6a 100644
--- a/dummy_ebpf_2/send.py
+++ b/dummy_ebpf_2/send.py
@@ -2,7 +2,7 @@ from scapy.all import *
def arp_test():
# 构建一个 ARP 请求数据包
- arp_request = Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst="10.10.10.10")
+ arp_request = Ether(src="76:56:e5:3f:ac:8e", dst="ff:ff:ff:ff:ff:ff") / ARP(pdst="192.168.41.71")
# 在数据包负载后面追加一个不属于这个数据包的字符
extra_data = '0'
@@ -13,7 +13,7 @@ def arp_test():
def icmp_test():
- icmp_request = Ether(dst="12:34:56:78:9a:bc") / IP(dst="8.8.8.8")/ICMP()
+ icmp_request = Ether(src="76:56:e5:3f:ac:8e", dst="76:56:e5:3f:ac:8e") / IP(dst="192.168.41.71")/ICMP()
extra_data = '1'
icmp_request = icmp_request / Raw(load=extra_data)
@@ -21,6 +21,19 @@ def icmp_test():
sendp(icmp_request,iface="dummy0")
+def udp_test():
+ ip = IP(dst="192.168.1.1")
+ udp = UDP(sport=12345, dport=80)
+ data = Raw(load="Hello, UDP!")
+
+ packet = ip / udp / data
+
+ extra_data = '0'
+ packet = packet / Raw(load=extra_data)
+
+ sendp(packet, iface="dummy0")
+
if __name__ == "__main__":
arp_test()
- icmp_test() \ No newline at end of file
+ icmp_test()
+ udp_test() \ No newline at end of file
diff --git a/dummy_ebpf_2/src/tc_prog_kernel.c b/dummy_ebpf_2/src/tc_prog_kernel.c
index 7c58ff6..fb8a6ca 100644
--- a/dummy_ebpf_2/src/tc_prog_kernel.c
+++ b/dummy_ebpf_2/src/tc_prog_kernel.c
@@ -72,7 +72,8 @@ int tc_redirect_map_func(struct __sk_buff *skb) {
}
// Redirect the packet to the endpoint referenced by map at index key.
- action = bpf_redirect(*ifindex, BPF_F_INGRESS);
+ // action = bpf_redirect(*ifindex, BPF_F_INGRESS);
+ action = bpf_redirect(*ifindex, 0);
if (action != TC_ACT_REDIRECT) {
bpf_printk("bpf_redirect_map failed. return code:%d", ret);
}