Skip to content

Commit a35ad7f

Browse files
committed
remove IP-MAC cache
1 parent d4aea90 commit a35ad7f

File tree

6 files changed

+29
-79
lines changed

6 files changed

+29
-79
lines changed

landscape-ebpf/src/bpf/flow.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,22 @@ struct {
202202
__uint(pinning, LIBBPF_PIN_BY_NAME);
203203
} rt_target_map SEC(".maps");
204204

205-
struct lan_mac_cache_key {
206-
u8 ip[16];
207-
u8 l3_protocol;
208-
u8 _pad[3];
209-
};
205+
// struct lan_mac_cache_key {
206+
// u8 ip[16];
207+
// u8 l3_protocol;
208+
// u8 _pad[3];
209+
// };
210210

211-
struct lan_mac_cache {
212-
u8 mac[6];
213-
u8 _pad[2];
214-
};
211+
// struct lan_mac_cache {
212+
// u8 mac[6];
213+
// u8 _pad[2];
214+
// };
215215

216-
struct {
217-
__uint(type, BPF_MAP_TYPE_LRU_HASH);
218-
__type(key, struct lan_mac_cache_key);
219-
__type(value, struct lan_mac_cache);
220-
__uint(max_entries, 65535);
221-
} ip_mac_tab SEC(".maps");
216+
// struct {
217+
// __uint(type, BPF_MAP_TYPE_LRU_HASH);
218+
// __type(key, struct lan_mac_cache_key);
219+
// __type(value, struct lan_mac_cache);
220+
// __uint(max_entries, 65535);
221+
// } ip_mac_tab SEC(".maps");
222222

223223
#endif /* __LD_FLOW_H__ */

landscape-ebpf/src/bpf/flow_lan.bpf.c

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -205,59 +205,35 @@ static __always_inline int lan_redirect_check(struct __sk_buff *skb, int current
205205
}
206206

207207
if (current_eth_net_offset == 0 && lan_info->has_mac) {
208-
struct lan_mac_cache_key daddr = {0};
209-
daddr.l3_protocol = context->l3_protocol;
210-
COPY_ADDR_FROM(daddr.ip, context->daddr.in6_u.u6_addr8);
211-
u8 *smac = &lan_info->mac_addr;
212-
struct lan_mac_cache *dmac = bpf_map_lookup_elem(&ip_mac_tab, &daddr);
213208
bool is_ipv4 = context->l3_protocol == LANDSCAPE_IPV4_TYPE;
214-
if (dmac == NULL) {
215-
bpf_log_info("use ip: %pI6, to find mac error", &context->daddr.in6_u.u6_addr8);
216-
return TC_ACT_SHOT;
217-
}
218-
219209
unsigned char ethhdr[14];
220-
__builtin_memcpy(ethhdr, dmac->mac, 6);
221-
__builtin_memcpy(ethhdr + 6, smac, 6);
222-
223-
// PRINT_MAC_ADDR(ethhdr);
224-
// PRINT_MAC_ADDR(ethhdr + 6);
225-
226210
if (is_ipv4) {
227211
ethhdr[12] = 0x08;
228212
ethhdr[13] = 0x00;
229213
} else {
230214
ethhdr[12] = 0x86;
231215
ethhdr[13] = 0xdd;
232216
}
233-
234217
if (bpf_skb_change_head(skb, 14, 0)) return TC_ACT_SHOT;
235218

236219
if (bpf_skb_store_bytes(skb, 0, ethhdr, sizeof(ethhdr), 0)) return TC_ACT_SHOT;
237-
238-
skb->mark = 1;
239-
ret = bpf_redirect(lan_info->ifindex, 0);
240-
if (ret != 7) {
241-
bpf_log_info("bpf_redirect_neigh error: %d", ret);
242-
}
243-
220+
}
221+
struct bpf_redir_neigh param;
222+
if (context->l3_protocol == LANDSCAPE_IPV4_TYPE) {
223+
param.nh_family = AF_INET;
244224
} else {
245-
struct bpf_redir_neigh param;
246-
if (context->l3_protocol == LANDSCAPE_IPV4_TYPE) {
247-
param.nh_family = AF_INET;
248-
} else {
249-
param.nh_family = AF_INET6;
250-
}
225+
param.nh_family = AF_INET6;
226+
}
251227

252-
COPY_ADDR_FROM(param.ipv6_nh, lan_search_key.addr.in6_u.u6_addr32);
253-
ret = bpf_redirect_neigh(lan_info->ifindex, &param, sizeof(param), 0);
254-
// bpf_log_info("lan_info->ifindex: %d", lan_info->ifindex);
255-
// bpf_log_info("is_ipv4: %d", is_ipv4);
256-
// bpf_log_info("bpf_redirect_neigh ip: %pI6", lan_search_key.addr.in6_u.u6_addr8);
257-
if (ret != 7) {
258-
bpf_log_info("bpf_redirect_neigh error: %d", ret);
259-
}
228+
COPY_ADDR_FROM(param.ipv6_nh, lan_search_key.addr.in6_u.u6_addr32);
229+
ret = bpf_redirect_neigh(lan_info->ifindex, &param, sizeof(param), 0);
230+
// bpf_log_info("lan_info->ifindex: %d", lan_info->ifindex);
231+
// bpf_log_info("is_ipv4: %d", is_ipv4);
232+
// bpf_log_info("bpf_redirect_neigh ip: %pI6", lan_search_key.addr.in6_u.u6_addr8);
233+
if (ret != 7) {
234+
bpf_log_info("bpf_redirect_neigh error: %d", ret);
260235
}
236+
// bpf_log_info("bpf_redirect_neigh result: %d", ret);
261237

262238
return ret;
263239
}
@@ -550,24 +526,13 @@ int lan_route_ingress(struct __sk_buff *skb) {
550526
return TC_ACT_UNSPEC;
551527
}
552528

553-
struct lan_mac_cache_key saddr = {0};
554-
struct lan_mac_cache cache_mac = {0};
555-
saddr.l3_protocol = context.l3_protocol;
556-
COPY_ADDR_FROM(saddr.ip, context.saddr.in6_u.u6_addr8);
557-
COPY_ADDR_FROM(cache_mac.mac, context.smac);
558-
ret = bpf_map_update_elem(&ip_mac_tab, &saddr, &cache_mac, BPF_ANY);
559-
560529
// if (saddr.ip[0] == 0xfe) {
561530
// if ((saddr.ip[1] & 0xc0) == 0x80) {
562531
// bpf_log_info("fe80 %pI6 -> %pI6", context.saddr.in6_u.u6_addr8,
563532
// context.daddr.in6_u.u6_addr8);
564533
// }
565534
// }
566535

567-
if (ret != 0) {
568-
bpf_log_info("cache ip: %pI6 mac error", saddr.ip);
569-
}
570-
571536
ret = lan_redirect_check(skb, current_eth_net_offset, &context);
572537
if (ret != TC_ACT_OK) {
573538
return ret;

landscape-ebpf/src/flow/lan.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ pub fn attach_match_flow(
3939
open_skel.maps.rt_target_map.set_pin_path(&MAP_PATHS.rt_target_map)?;
4040
open_skel.maps.rt_target_map.reuse_pinned_map(&MAP_PATHS.rt_target_map)?;
4141

42-
open_skel.maps.ip_mac_tab.set_pin_path(&MAP_PATHS.ip_mac_tab)?;
43-
open_skel.maps.ip_mac_tab.reuse_pinned_map(&MAP_PATHS.ip_mac_tab)?;
44-
4542
open_skel.maps.flow_v_dns_map.set_pin_path(&MAP_PATHS.flow_verdict_dns_map)?;
4643
open_skel.maps.flow_v_dns_map.reuse_pinned_map(&MAP_PATHS.flow_verdict_dns_map)?;
4744

landscape-ebpf/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ static MAP_PATHS: Lazy<LandscapeMapPath> = Lazy::new(|| {
5454
// route
5555
rt_lan_map: PathBuf::from(format!("{}/rt_lan_map", ebpf_map_path)),
5656
rt_target_map: PathBuf::from(format!("{}/rt_target_map", ebpf_map_path)),
57-
58-
// route ip mac cache table
59-
ip_mac_tab: PathBuf::from(format!("{}/ip_mac_tab", ebpf_map_path)),
6057
};
6158
tracing::info!("ebpf map paths is: {paths:#?}");
6259
map_setting::init_path(paths.clone());
@@ -94,9 +91,6 @@ pub(crate) struct LandscapeMapPath {
9491
/// route - LAN
9592
pub rt_lan_map: PathBuf,
9693
pub rt_target_map: PathBuf,
97-
98-
/// route ip mac cache table
99-
pub ip_mac_tab: PathBuf,
10094
}
10195

10296
// pppoe -> Fire wall -> nat -> route

landscape-ebpf/src/map_setting/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ pub(crate) fn init_path(paths: LandscapeMapPath) {
6767
landscape_open.maps.rt_lan_map.set_pin_path(&paths.rt_lan_map).unwrap();
6868
landscape_open.maps.rt_target_map.set_pin_path(&paths.rt_target_map).unwrap();
6969

70-
// route ip mac cache table
71-
landscape_open.maps.ip_mac_tab.set_pin_path(&paths.ip_mac_tab).unwrap();
72-
7370
let _landscape_skel = landscape_open.load().unwrap();
7471
}
7572

landscape-ebpf/src/route/wan.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ pub fn wan_route_attach(
3939
open_skel.maps.rt_target_map.set_pin_path(&MAP_PATHS.rt_target_map)?;
4040
open_skel.maps.rt_target_map.reuse_pinned_map(&MAP_PATHS.rt_target_map)?;
4141

42-
open_skel.maps.ip_mac_tab.set_pin_path(&MAP_PATHS.ip_mac_tab)?;
43-
open_skel.maps.ip_mac_tab.reuse_pinned_map(&MAP_PATHS.ip_mac_tab)?;
44-
4542
open_skel.maps.flow_v_dns_map.set_pin_path(&MAP_PATHS.flow_verdict_dns_map)?;
4643
open_skel.maps.flow_v_dns_map.reuse_pinned_map(&MAP_PATHS.flow_verdict_dns_map)?;
4744

0 commit comments

Comments
 (0)