ajout export matrice routage | correction parsing route forcepoint/stormshield | modification main pour les output
This commit is contained in:
@@ -196,59 +196,95 @@ class StormshieldParser(ParserMixin):
|
||||
if not os.path.exists(route_path):
|
||||
return
|
||||
|
||||
virtual_routers = {}
|
||||
default_route = None
|
||||
|
||||
section = None
|
||||
with open(route_path, encoding="utf-8", errors="ignore") as f:
|
||||
for raw_line in f:
|
||||
line = raw_line.strip()
|
||||
if not line or line.startswith("#"):
|
||||
if not line or line.startswith("off") or line.startswith("#"):
|
||||
continue
|
||||
|
||||
if line.startswith("[") and line.endswith("]"):
|
||||
section = line.strip("[]")
|
||||
continue
|
||||
|
||||
# ===== Default route =====
|
||||
if section == "Config" and line.startswith("DefaultRoute="):
|
||||
self.config["default_route"] = line.split("=", 1)[1].strip()
|
||||
default_route = line.split("=", 1)[1].strip()
|
||||
|
||||
elif section == "StaticRoutes" and not line.startswith("#"):
|
||||
parts = line.split(",")
|
||||
if len(parts) >= 2:
|
||||
self.config["static_routes"].append({
|
||||
"destination": parts[0],
|
||||
"interface": parts[1],
|
||||
"extra": parts[2:] if len(parts) > 2 else []
|
||||
})
|
||||
# ===== Static routes =====
|
||||
elif section == "StaticRoutes":
|
||||
parts = [p.strip() for p in line.split(",")]
|
||||
if len(parts) < 2:
|
||||
continue
|
||||
|
||||
static_routes = []
|
||||
if self.config["default_route"]:
|
||||
static_routes.append(
|
||||
destination = parts[0]
|
||||
|
||||
vr_name = None
|
||||
interface = None
|
||||
next_hop_ip = None
|
||||
|
||||
# Format : VR->NextHop
|
||||
if "->" in parts[1]:
|
||||
vr_name, next_hop_ip = map(str.strip, parts[1].split("->", 1))
|
||||
interface = vr_name
|
||||
else:
|
||||
vr_name = parts[1]
|
||||
interface = parts[1]
|
||||
|
||||
# Création VR si absent
|
||||
if vr_name not in virtual_routers:
|
||||
virtual_routers[vr_name] = {
|
||||
"interfaces": set(),
|
||||
"static_routes": []
|
||||
}
|
||||
|
||||
virtual_routers[vr_name]["interfaces"].add(interface)
|
||||
|
||||
static_route = StaticRoute(
|
||||
name=f"{vr_name}-static-{len(virtual_routers[vr_name]['static_routes']) + 1}",
|
||||
destination=destination,
|
||||
metric=None,
|
||||
next_vr=None,
|
||||
next_hop_ip=next_hop_ip,
|
||||
interface=interface,
|
||||
bfd_profile=None
|
||||
)
|
||||
|
||||
virtual_routers[vr_name]["static_routes"].append(static_route)
|
||||
|
||||
# ===== Default VR (route par défaut) =====
|
||||
if default_route:
|
||||
vr_name = "default"
|
||||
virtual_routers.setdefault(vr_name, {
|
||||
"interfaces": set(),
|
||||
"static_routes": []
|
||||
})
|
||||
|
||||
virtual_routers[vr_name]["static_routes"].insert(
|
||||
0,
|
||||
StaticRoute(
|
||||
name="default-route",
|
||||
destination="0.0.0.0/0",
|
||||
metric=1,
|
||||
next_hop_ip=self.config["default_route"],
|
||||
interface=None
|
||||
next_vr=None,
|
||||
next_hop_ip=default_route,
|
||||
interface=None,
|
||||
bfd_profile=None
|
||||
)
|
||||
)
|
||||
|
||||
for idx, route in enumerate(self.config["static_routes"]):
|
||||
static_routes.append(
|
||||
StaticRoute(
|
||||
name=f"static-{idx+1}",
|
||||
destination=route["destination"],
|
||||
metric=1,
|
||||
next_hop_ip=None,
|
||||
interface=route["interface"]
|
||||
)
|
||||
# ===== Construction finale =====
|
||||
self.config["virtual_routers"] = [
|
||||
VirtualRouter(
|
||||
name=vr_name,
|
||||
interfaces=list(data["interfaces"]),
|
||||
static_routes=data["static_routes"]
|
||||
)
|
||||
|
||||
vr = VirtualRouter(
|
||||
name="default-vr",
|
||||
interfaces=[r["interface"] for r in self.config["static_routes"]],
|
||||
static_routes=static_routes
|
||||
)
|
||||
|
||||
self.config["virtual_routers"] = [vr]
|
||||
for vr_name, data in virtual_routers.items()
|
||||
]
|
||||
|
||||
# def _parse_slotinfo_file(self):
|
||||
# path = os.path.join(self.base_dir, "Filter", "slotinfo")
|
||||
|
||||
Reference in New Issue
Block a user