Set up bridge on Linux. For wired interfaces: Creates a true bridge For wireless interfaces: Uses USB network interface directly with NAT
(self)
| 172 | subprocess.run(["sleep", "2"]) |
| 173 | |
| 174 | def setup_bridge_linux(self): |
| 175 | """Set up bridge on Linux. |
| 176 | |
| 177 | For wired interfaces: Creates a true bridge |
| 178 | For wireless interfaces: Uses USB network interface directly with NAT |
| 179 | """ |
| 180 | print("\nSetting up bridge...") |
| 181 | |
| 182 | # Check if primary interface is wireless |
| 183 | is_wireless = self.is_wireless_interface(self.primary_interface) |
| 184 | |
| 185 | # 1. Enable IP forwarding |
| 186 | print(" • Enabling IP forwarding...") |
| 187 | self.run_command(["sudo", "sysctl", "-w", "net.ipv4.ip_forward=1"], capture=False) |
| 188 | |
| 189 | if is_wireless: |
| 190 | # For wireless: Skip bridge creation, use USB network interface directly |
| 191 | print(f" ⚠️ Detected wireless interface ({self.primary_interface})") |
| 192 | print(" • Setting up direct USB network routing (wireless can't bridge)") |
| 193 | print(" • Looking for USB network interface...") |
| 194 | |
| 195 | # Find USB network interfaces (usually enp*, usb*) |
| 196 | result = self.run_command(["ip", "link", "show"], check=False) |
| 197 | |
| 198 | # Show all interfaces for debugging |
| 199 | print("\n Available network interfaces:") |
| 200 | all_interfaces = [] |
| 201 | for line in result.stdout.split('\n'): |
| 202 | match = re.search(r'\d+:\s+(\S+):', line) |
| 203 | if match and '@' not in line: # Skip VLAN interfaces |
| 204 | iface = match.group(1) |
| 205 | if iface not in ['lo', self.primary_interface]: |
| 206 | all_interfaces.append(iface) |
| 207 | print(f" - {iface}") |
| 208 | |
| 209 | # Wait a moment for interface to appear |
| 210 | if not all_interfaces: |
| 211 | print(" • Waiting 3 seconds for USB interface to appear...") |
| 212 | subprocess.run(["sleep", "3"]) |
| 213 | result = self.run_command(["ip", "link", "show"], check=False) |
| 214 | for line in result.stdout.split('\n'): |
| 215 | match = re.search(r'\d+:\s+(\S+):', line) |
| 216 | if match and '@' not in line: |
| 217 | iface = match.group(1) |
| 218 | if iface not in ['lo', self.primary_interface]: |
| 219 | all_interfaces.append(iface) |
| 220 | |
| 221 | if all_interfaces: |
| 222 | # Prefer interfaces that look like USB/ethernet |
| 223 | usb_iface = None |
| 224 | for iface in all_interfaces: |
| 225 | if any(pattern in iface for pattern in ['enp', 'usb', 'eth', 'en']): |
| 226 | usb_iface = iface |
| 227 | break |
| 228 | |
| 229 | # If no specific USB pattern found, use the first available |
| 230 | if not usb_iface: |
| 231 | usb_iface = all_interfaces[0] |
no test coverage detected