Commit 112491a1 authored by zaafar's avatar zaafar Committed by 4ast

fixup the issue in which distributed_bridge example (#716)

wasn't working for kernel ver less than 4.5.
parent cb40f09a
...@@ -29,7 +29,8 @@ int handle_ingress(struct __sk_buff *skb) { ...@@ -29,7 +29,8 @@ int handle_ingress(struct __sk_buff *skb) {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet)); struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
struct bpf_tunnel_key tkey = {}; struct bpf_tunnel_key tkey = {};
bpf_skb_get_tunnel_key(skb, &tkey, sizeof(tkey), 0); bpf_skb_get_tunnel_key(skb, &tkey,
offsetof(struct bpf_tunnel_key, remote_ipv6[1]), 0);
int *ifindex = vni2if.lookup(&tkey.tunnel_id); int *ifindex = vni2if.lookup(&tkey.tunnel_id);
if (ifindex) { if (ifindex) {
...@@ -63,7 +64,8 @@ int handle_egress(struct __sk_buff *skb) { ...@@ -63,7 +64,8 @@ int handle_egress(struct __sk_buff *skb) {
u32 zero = 0; u32 zero = 0;
tkey.tunnel_id = dst_host->tunnel_id; tkey.tunnel_id = dst_host->tunnel_id;
tkey.remote_ipv4 = dst_host->remote_ipv4; tkey.remote_ipv4 = dst_host->remote_ipv4;
bpf_skb_set_tunnel_key(skb, &tkey, sizeof(tkey), 0); bpf_skb_set_tunnel_key(skb, &tkey,
offsetof(struct bpf_tunnel_key, remote_ipv6[1]), 0);
lock_xadd(&dst_host->tx_pkts, 1); lock_xadd(&dst_host->tx_pkts, 1);
} else { } else {
struct bpf_tunnel_key tkey = {}; struct bpf_tunnel_key tkey = {};
...@@ -73,7 +75,8 @@ int handle_egress(struct __sk_buff *skb) { ...@@ -73,7 +75,8 @@ int handle_egress(struct __sk_buff *skb) {
return 1; return 1;
tkey.tunnel_id = dst_host->tunnel_id; tkey.tunnel_id = dst_host->tunnel_id;
tkey.remote_ipv4 = dst_host->remote_ipv4; tkey.remote_ipv4 = dst_host->remote_ipv4;
bpf_skb_set_tunnel_key(skb, &tkey, sizeof(tkey), 0); bpf_skb_set_tunnel_key(skb, &tkey,
offsetof(struct bpf_tunnel_key, remote_ipv6[1]), 0);
} }
bpf_clone_redirect(skb, cfg->tunnel_ifindex, 0/*egress*/); bpf_clone_redirect(skb, cfg->tunnel_ifindex, 0/*egress*/);
return 1; return 1;
......
...@@ -19,7 +19,8 @@ BPF_TABLE("hash", int, struct tunnel_key, if2tunkey, 1024); ...@@ -19,7 +19,8 @@ BPF_TABLE("hash", int, struct tunnel_key, if2tunkey, 1024);
int handle_ingress(struct __sk_buff *skb) { int handle_ingress(struct __sk_buff *skb) {
struct bpf_tunnel_key tkey = {}; struct bpf_tunnel_key tkey = {};
struct tunnel_key key; struct tunnel_key key;
bpf_skb_get_tunnel_key(skb, &tkey, sizeof(tkey), 0); bpf_skb_get_tunnel_key(skb, &tkey,
offsetof(struct bpf_tunnel_key, remote_ipv6[1]), 0);
key.tunnel_id = tkey.tunnel_id; key.tunnel_id = tkey.tunnel_id;
key.remote_ipv4 = tkey.remote_ipv4; key.remote_ipv4 = tkey.remote_ipv4;
...@@ -57,7 +58,8 @@ int handle_egress(struct __sk_buff *skb) { ...@@ -57,7 +58,8 @@ int handle_egress(struct __sk_buff *skb) {
if (key_p) { if (key_p) {
tkey.tunnel_id = key_p->tunnel_id; tkey.tunnel_id = key_p->tunnel_id;
tkey.remote_ipv4 = key_p->remote_ipv4; tkey.remote_ipv4 = key_p->remote_ipv4;
bpf_skb_set_tunnel_key(skb, &tkey, sizeof(tkey), 0); bpf_skb_set_tunnel_key(skb, &tkey,
offsetof(struct bpf_tunnel_key, remote_ipv6[1]), 0);
bpf_clone_redirect(skb, cfg->tunnel_ifindex, 0/*egress*/); bpf_clone_redirect(skb, cfg->tunnel_ifindex, 0/*egress*/);
} }
return 1; return 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment