refactor: remove dependency injection for IPRoute in interface and bridge functions
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 7s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 7s
This commit is contained in:
@@ -183,14 +183,14 @@ def parse_flags(flags_int: int) -> list[str]:
|
||||
result.append(name)
|
||||
return result
|
||||
|
||||
def iface_index(name: str, ip: IPRoute = Depends(get_iproute)) -> int:
|
||||
def iface_index(name: str, ip: IPRoute) -> int:
|
||||
idx = ip.link_lookup(ifname=name)
|
||||
if not idx:
|
||||
raise HTTPException(status_code=404, detail=f"Interface {name} not found")
|
||||
return idx[0]
|
||||
|
||||
|
||||
def bridge_exists(name: str, ip: IPRoute = Depends(get_iproute)) -> bool:
|
||||
def bridge_exists(name: str, ip: IPRoute) -> bool:
|
||||
return bool(ip.link_lookup(ifname=name))
|
||||
|
||||
|
||||
@@ -352,16 +352,16 @@ def full_state(
|
||||
|
||||
@router.post("/create")
|
||||
def create_bridge(req: BridgeCreateRequest, ip: IPRoute = Depends(get_iproute)):
|
||||
if bridge_exists(req.name):
|
||||
if bridge_exists(req.name, ip):
|
||||
raise HTTPException(400, f"Bridge {req.name} already exists")
|
||||
|
||||
# Bridge erzeugen
|
||||
ip.link("add", ifname=req.name, kind="bridge")
|
||||
br_idx = iface_index(req.name)
|
||||
br_idx = iface_index(req.name, ip)
|
||||
|
||||
# Interfaces hinzufügen
|
||||
for iface in req.interfaces:
|
||||
idx = iface_index(iface)
|
||||
idx = iface_index(iface, ip)
|
||||
ip.link("set", index=idx, master=br_idx)
|
||||
|
||||
# Bridge aktivieren
|
||||
@@ -376,10 +376,10 @@ def create_bridge(req: BridgeCreateRequest, ip: IPRoute = Depends(get_iproute)):
|
||||
|
||||
@router.post("/remove")
|
||||
def remove_bridge(req: BridgeRemoveRequest, ip: IPRoute = Depends(get_iproute)):
|
||||
if not bridge_exists(req.name):
|
||||
if not bridge_exists(req.name, ip):
|
||||
raise HTTPException(404, f"Bridge {req.name} not found")
|
||||
|
||||
br_idx = iface_index(req.name)
|
||||
br_idx = iface_index(req.name, ip)
|
||||
|
||||
# Bridge runterfahren
|
||||
ip.link("set", index=br_idx, state="down")
|
||||
|
||||
Reference in New Issue
Block a user