Automated g4 rollback of changelist 372620094.

*** Reason for rollback ***

Breaking Endor because we bring down the TUN Device when tearing down the bonnet in the init container.

*** Original change description ***

Defer TUN device creation until after the quic connection has been established.

IOS XR's XR container takes a few seconds for networking state to be sync'd from the host -- during which time any manipulations to the linux contaier's host networking stack breaks the synchronization process.

This has the nice side-benefit of re-initializing the TUN device each time a new quic connection is established, ensuring the local interface is in a good state on each reconnect. Previously, if the interfac...

***

PiperOrigin-RevId: 373010349
diff --git a/quic/qbone/bonnet/tun_device.cc b/quic/qbone/bonnet/tun_device.cc
index c0f635d..3ca52e8 100644
--- a/quic/qbone/bonnet/tun_device.cc
+++ b/quic/qbone/bonnet/tun_device.cc
@@ -103,10 +103,6 @@
 }
 
 bool TunDevice::OpenDevice() {
-  if (file_descriptor_ != kInvalidFd) {
-    CleanUpFileDescriptor();
-  }
-
   struct ifreq if_request;
   memset(&if_request, 0, sizeof(if_request));
   // copy does not zero-terminate the result string, but we've memset the entire
diff --git a/quic/qbone/bonnet/tun_device_packet_exchanger.cc b/quic/qbone/bonnet/tun_device_packet_exchanger.cc
index 4783e9c..2119671 100644
--- a/quic/qbone/bonnet/tun_device_packet_exchanger.cc
+++ b/quic/qbone/bonnet/tun_device_packet_exchanger.cc
@@ -11,12 +11,14 @@
 namespace quic {
 
 TunDevicePacketExchanger::TunDevicePacketExchanger(
+    int fd,
     size_t mtu,
     KernelInterface* kernel,
     QbonePacketExchanger::Visitor* visitor,
     size_t max_pending_packets,
     StatsInterface* stats)
     : QbonePacketExchanger(visitor, max_pending_packets),
+      fd_(fd),
       mtu_(mtu),
       kernel_(kernel),
       stats_(stats) {}
@@ -76,8 +78,8 @@
   return std::make_unique<QuicData>(read_buffer.release(), result, true);
 }
 
-void TunDevicePacketExchanger::set_file_descriptor(int fd) {
-  fd_ = fd;
+int TunDevicePacketExchanger::file_descriptor() const {
+  return fd_;
 }
 
 const TunDevicePacketExchanger::StatsInterface*
diff --git a/quic/qbone/bonnet/tun_device_packet_exchanger.h b/quic/qbone/bonnet/tun_device_packet_exchanger.h
index 115f5b5..1d28fee 100644
--- a/quic/qbone/bonnet/tun_device_packet_exchanger.h
+++ b/quic/qbone/bonnet/tun_device_packet_exchanger.h
@@ -35,6 +35,8 @@
     ABSL_MUST_USE_RESULT virtual int64_t PacketsWritten() const = 0;
   };
 
+  // |fd| is a open file descriptor on a TUN device that's opened for both read
+  // and write.
   // |mtu| is the mtu of the TUN device.
   // |kernel| is not owned but should out live objects of this class.
   // |visitor| is not owned but should out live objects of this class.
@@ -42,13 +44,14 @@
   // the TUN device become blocked.
   // |stats| is notified about packet read/write statistics. It is not owned,
   // but should outlive objects of this class.
-  TunDevicePacketExchanger(size_t mtu,
+  TunDevicePacketExchanger(int fd,
+                           size_t mtu,
                            KernelInterface* kernel,
                            QbonePacketExchanger::Visitor* visitor,
                            size_t max_pending_packets,
                            StatsInterface* stats);
 
-  void set_file_descriptor(int fd);
+  ABSL_MUST_USE_RESULT int file_descriptor() const;
 
   ABSL_MUST_USE_RESULT const StatsInterface* stats_interface() const;
 
diff --git a/quic/qbone/bonnet/tun_device_packet_exchanger_test.cc b/quic/qbone/bonnet/tun_device_packet_exchanger_test.cc
index c8f3ff0..4a00c60 100644
--- a/quic/qbone/bonnet/tun_device_packet_exchanger_test.cc
+++ b/quic/qbone/bonnet/tun_device_packet_exchanger_test.cc
@@ -30,15 +30,14 @@
 class TunDevicePacketExchangerTest : public QuicTest {
  protected:
   TunDevicePacketExchangerTest()
-      : exchanger_(kMtu,
+      : exchanger_(kFd,
+                   kMtu,
                    &mock_kernel_,
                    &mock_visitor_,
                    kMaxPendingPackets,
-                   &mock_stats_) {
-    exchanger_.set_file_descriptor(kFd);
-  }
+                   &mock_stats_) {}
 
-  ~TunDevicePacketExchangerTest() override = default;
+  ~TunDevicePacketExchangerTest() override {}
 
   MockKernel mock_kernel_;
   StrictMock<MockVisitor> mock_visitor_;