BpfMap: wrap native fd with ParcelFileDescriptor to avoid fd leak
ParcelFileDescriptor has implemented finalize(). Wrap native fd into
ParcelFileDescriptor which helps to release fd automatically.
Bug: 230880517
Test: manual test
Steps:
1. Connect to IPv6 only wifi and clat maps are created
$ adb shell cmd wifi set-wifi-enabled enabled
05-12 13:53:41.182 1793 2031 W BpfMap : open /sys/fs/bpf/net_shared/map_clatd_clat_ingress6_map..: 493
05-12 13:53:41.182 1793 2031 W BpfMap : open /sys/fs/bpf/net_shared/map_clatd_clat_egress4_map..: 546
$ adb shell ls -all proc/1793/fd | grep bpf
.. system system 64 2022-05-12 13:55:35 .. 493 -> anon_inode:bpf-map
.. system system 64 2022-05-12 13:55:35 .. 546 -> anon_inode:bpf-map
$ adb shell dumpsys connectivity
Forwarding rules:
BPF ingress map: iif nat64Prefix v6Addr -> v4Addr oif
47 /64:ff9b::/96 /2a00:79e1:abc:6f02:6efd:1d4b:f05e:25bd -> /192.0.0.4 54
BPF egress map: iif v4Addr -> v6Addr nat64Prefix oif
54 /192.0.0.4 -> /2a00:79e1:abc:6f02:6efd:1d4b:f05e:25bd /64:ff9b::/96 47 ether
2. Disconnect from IPv6 only wifi, force GC and clat map fds are released
$ adb shell cmd wifi set-wifi-enabled disabled
$ adb shell kill -10 1793
$ adb shell ls -all proc/1793/fd | grep bpf
(fd 493 and 546 are removed)
Change-Id: I26bbafbd73eccab6f4ae2c71690ecad12bbef7df
2 files changed
tree: aa07b40295c5fb0f4fec3bcde950baf5bc07db2d
- staticlibs/