mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-02-03 18:24:27 +08:00
19 lines
556 B
C
19 lines
556 B
C
#include "bpf_sockmap.h"
|
|
|
|
char LICENSE[] SEC("license") = "Dual BSD/GPL";
|
|
|
|
SEC("sk_msg")
|
|
int bpf_redir(struct sk_msg_md *msg)
|
|
{
|
|
if(msg->remote_ip4 != LOCALHOST_IPV4 || msg->local_ip4!= LOCALHOST_IPV4)
|
|
return SK_PASS;
|
|
|
|
struct sock_key key = {
|
|
.sip = msg->remote_ip4,
|
|
.dip = msg->local_ip4,
|
|
.dport = bpf_htonl(msg->local_port), /* convert to network byte order */
|
|
.sport = msg->remote_port,
|
|
.family = msg->family,
|
|
};
|
|
return bpf_msg_redirect_hash(msg, &sock_ops_map, &key, BPF_F_INGRESS);
|
|
} |