Push virtio-net interface renaming into userspace (#2).

The first attempt to do the renaming in userspace did not fully work,
because the framework will enumerate the list of interfaces before they
are up, and then fail if any new interfaces appear up after booting. This
was hitting us because ril-daemon will not rename the eth0 interface to
rmnet0 until very late in the boot sequence, after this enumeration has
already completed.

We can leave the older workaround in place, as it is still very useful
for testing, but this workaround will supersede it once it has been
added to the init script.

Bug: 78482534
Test: Booted, saw rename_netiface run after 8s, interface renamed
Change-Id: I6aa41636e91cebabf9b627bf4e02b6dd3e3d333d
diff --git a/shared/config/init.vsoc.rc b/shared/config/init.vsoc.rc
index 8bf83bb..fe5734b 100644
--- a/shared/config/init.vsoc.rc
+++ b/shared/config/init.vsoc.rc
@@ -34,6 +34,9 @@
     wait /vendor/etc/selinux/nonplat_mac_permissions.xml
     restorecon_recursive /vendor
 
+    # works around framework netiface enumeration issue
+    start rename_eth0
+
     # TODO(ender): Find better way to talk to serial port.
     chmod 622 /dev/kmsg
 
@@ -75,6 +78,10 @@
     stop akmd
 
 
+service rename_eth0 /vendor/bin/rename_netiface eth0 rmnet0
+    oneshot
+
+
 service vsoc_guest_region_e2e_test /vendor/bin/vsoc_guest_region_e2e_test
     user root
     group shell
diff --git a/shared/device.mk b/shared/device.mk
index 1d498e3..e44e2ab 100644
--- a/shared/device.mk
+++ b/shared/device.mk
@@ -68,7 +68,8 @@
     wifi_relay \
     wpa_supplicant.vsoc.conf \
     vsoc_input_service \
-    vport_trigger
+    vport_trigger \
+    rename_netiface
 
 #
 # Packages for AOSP-available stuff we use from the framework
diff --git a/shared/sepolicy/file_contexts b/shared/sepolicy/file_contexts
index 81e80a7..c08de58 100644
--- a/shared/sepolicy/file_contexts
+++ b/shared/sepolicy/file_contexts
@@ -27,6 +27,7 @@
 /vendor/bin/vsoc_guest_region_e2e_test  u:object_r:vsoc_guest_region_e2e_test_exec:s0
 /vendor/bin/wifi_relay  u:object_r:wifi_relay_exec:s0
 /vendor/bin/vport_trigger  u:object_r:vport_trigger_exec:s0
+/vendor/bin/rename_netiface  u:object_r:rename_netiface_exec:s0
 /vendor/bin/hw/android\.hardware\.bluetooth@1\.0-service\.sim             u:object_r:hal_bluetooth_sim_exec:s0
 /vendor/bin/hw/android\.hardware\.dumpstate@1\.0-service\.cuttlefish      u:object_r:hal_dumpstate_impl_exec:s0
 /vendor/bin/hw/android\.hardware\.health@2\.0-service.cuttlefish          u:object_r:hal_health_default_exec:s0
diff --git a/shared/sepolicy/rename_netiface.te b/shared/sepolicy/rename_netiface.te
new file mode 100644
index 0000000..1ec0f06
--- /dev/null
+++ b/shared/sepolicy/rename_netiface.te
@@ -0,0 +1,10 @@
+type rename_netiface, domain;
+type rename_netiface_exec, exec_type, vendor_file_type, file_type;
+
+init_daemon_domain(rename_netiface)
+
+allow rename_netiface self:capability { net_admin net_raw sys_module };
+allow rename_netiface self:udp_socket { create ioctl };
+allow rename_netiface self:netlink_route_socket { bind create nlmsg_write read write };
+
+allow rename_netiface kernel:system module_request;