Compare commits
20
Commits
1ec2b92c87
..
v1.0.0
@@ -10,6 +10,3 @@ git-fetch-with-cli = true
|
|||||||
|
|
||||||
[target.aarch64-unknown-linux-gnu]
|
[target.aarch64-unknown-linux-gnu]
|
||||||
linker = "aarch64-linux-gnu-gcc"
|
linker = "aarch64-linux-gnu-gcc"
|
||||||
|
|
||||||
[target.i686-unknown-linux-gnu]
|
|
||||||
linker = "i686-linux-gnu-gcc"
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ jobs:
|
|||||||
- name: Install Cross-Compilation Toolchains (apt)
|
- name: Install Cross-Compilation Toolchains (apt)
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y gcc-aarch64-linux-gnu gcc-i686-linux-gnu
|
sudo apt-get install -y gcc-aarch64-linux-gnu
|
||||||
|
|
||||||
- name: Ermittle Rust-Version für Rustup-Target-Cache-Key
|
- name: Ermittle Rust-Version für Rustup-Target-Cache-Key
|
||||||
run: echo "RUST_VERSION=$(rustc --version | awk '{print $2}')" >> "$GITHUB_ENV"
|
run: echo "RUST_VERSION=$(rustc --version | awk '{print $2}')" >> "$GITHUB_ENV"
|
||||||
@@ -75,12 +75,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu
|
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu
|
||||||
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu
|
|
||||||
key: rustup-targets-${{ runner.os }}-${{ env.RUST_VERSION }}
|
key: rustup-targets-${{ runner.os }}-${{ env.RUST_VERSION }}
|
||||||
|
|
||||||
- name: Add Rust Cross-Compilation Targets
|
- name: Add Rust Cross-Compilation Targets
|
||||||
if: steps.cache-rustup-targets.outputs.cache-hit != 'true'
|
if: steps.cache-rustup-targets.outputs.cache-hit != 'true'
|
||||||
run: rustup target add aarch64-unknown-linux-gnu i686-unknown-linux-gnu
|
run: rustup target add aarch64-unknown-linux-gnu
|
||||||
|
|
||||||
- name: PATH um Cargo-bin-Verzeichnis ergänzen
|
- name: PATH um Cargo-bin-Verzeichnis ergänzen
|
||||||
run: |
|
run: |
|
||||||
@@ -111,7 +110,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cargo build --release --target x86_64-unknown-linux-gnu
|
cargo build --release --target x86_64-unknown-linux-gnu
|
||||||
cargo build --release --target aarch64-unknown-linux-gnu
|
cargo build --release --target aarch64-unknown-linux-gnu
|
||||||
cargo build --release --target i686-unknown-linux-gnu
|
|
||||||
|
|
||||||
- name: Determine Build Number
|
- name: Determine Build Number
|
||||||
id: build_num
|
id: build_num
|
||||||
@@ -130,20 +128,17 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cargo deb --target x86_64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
cargo deb --target x86_64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
||||||
cargo deb --target aarch64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
cargo deb --target aarch64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
||||||
cargo deb --target i686-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
|
||||||
|
|
||||||
- name: Build Fedora / RPM Packages (.rpm)
|
- name: Build Fedora / RPM Packages (.rpm)
|
||||||
run: |
|
run: |
|
||||||
mkdir -p target/generate-rpm
|
mkdir -p target/generate-rpm
|
||||||
cargo generate-rpm --target x86_64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
cargo generate-rpm --target x86_64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
||||||
cargo generate-rpm --target aarch64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
cargo generate-rpm --target aarch64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
||||||
cargo generate-rpm --target i686-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
|
||||||
|
|
||||||
- name: Build Arch Linux Packages (.pkg.tar.zst)
|
- name: Build Arch Linux Packages (.pkg.tar.zst)
|
||||||
run: |
|
run: |
|
||||||
python3 scripts/package-arch.py --target x86_64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
python3 scripts/package-arch.py --target x86_64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
||||||
python3 scripts/package-arch.py --target aarch64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
python3 scripts/package-arch.py --target aarch64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
||||||
python3 scripts/package-arch.py --target i686-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
|
||||||
|
|
||||||
- name: Publish Packages to Gitea Package Registry
|
- name: Publish Packages to Gitea Package Registry
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ jobs:
|
|||||||
renovate:
|
renovate:
|
||||||
name: Dependency-Updates prüfen & Pull Requests erstellen
|
name: Dependency-Updates prüfen & Pull Requests erstellen
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container: ghcr.io/renovatebot/renovate:44.82.0
|
container: ghcr.io/renovatebot/renovate:44.83.0
|
||||||
steps:
|
steps:
|
||||||
- name: Renovate ausführen
|
- name: Renovate ausführen
|
||||||
run: renovate
|
run: renovate
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ jobs:
|
|||||||
- name: Install Cross-Compilation Toolchains (apt)
|
- name: Install Cross-Compilation Toolchains (apt)
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y gcc-aarch64-linux-gnu gcc-i686-linux-gnu
|
sudo apt-get install -y gcc-aarch64-linux-gnu
|
||||||
|
|
||||||
- name: Ermittle Rust-Version für Rustup-Target-Cache-Key
|
- name: Ermittle Rust-Version für Rustup-Target-Cache-Key
|
||||||
run: echo "RUST_VERSION=$(rustc --version | awk '{print $2}')" >> "$GITHUB_ENV"
|
run: echo "RUST_VERSION=$(rustc --version | awk '{print $2}')" >> "$GITHUB_ENV"
|
||||||
@@ -75,12 +75,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
path: |
|
path: |
|
||||||
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu
|
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu
|
||||||
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-unknown-linux-gnu
|
|
||||||
key: rustup-targets-${{ runner.os }}-${{ env.RUST_VERSION }}
|
key: rustup-targets-${{ runner.os }}-${{ env.RUST_VERSION }}
|
||||||
|
|
||||||
- name: Add Rust Cross-Compilation Targets
|
- name: Add Rust Cross-Compilation Targets
|
||||||
if: steps.cache-rustup-targets.outputs.cache-hit != 'true'
|
if: steps.cache-rustup-targets.outputs.cache-hit != 'true'
|
||||||
run: rustup target add aarch64-unknown-linux-gnu i686-unknown-linux-gnu
|
run: rustup target add aarch64-unknown-linux-gnu
|
||||||
|
|
||||||
- name: PATH um Cargo-bin-Verzeichnis ergänzen
|
- name: PATH um Cargo-bin-Verzeichnis ergänzen
|
||||||
run: |
|
run: |
|
||||||
@@ -111,7 +110,6 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cargo build --release --target x86_64-unknown-linux-gnu
|
cargo build --release --target x86_64-unknown-linux-gnu
|
||||||
cargo build --release --target aarch64-unknown-linux-gnu
|
cargo build --release --target aarch64-unknown-linux-gnu
|
||||||
cargo build --release --target i686-unknown-linux-gnu
|
|
||||||
|
|
||||||
- name: Determine Build Number
|
- name: Determine Build Number
|
||||||
id: build_num
|
id: build_num
|
||||||
@@ -130,20 +128,17 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cargo deb --target x86_64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
cargo deb --target x86_64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
||||||
cargo deb --target aarch64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
cargo deb --target aarch64-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
||||||
cargo deb --target i686-unknown-linux-gnu --deb-revision "${BUILD_NUMBER}" --no-build
|
|
||||||
|
|
||||||
- name: Build Fedora / RPM Packages (.rpm)
|
- name: Build Fedora / RPM Packages (.rpm)
|
||||||
run: |
|
run: |
|
||||||
mkdir -p target/generate-rpm
|
mkdir -p target/generate-rpm
|
||||||
cargo generate-rpm --target x86_64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
cargo generate-rpm --target x86_64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
||||||
cargo generate-rpm --target aarch64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
cargo generate-rpm --target aarch64-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
||||||
cargo generate-rpm --target i686-unknown-linux-gnu -s "release=\"${BUILD_NUMBER}\"" -o target/generate-rpm
|
|
||||||
|
|
||||||
- name: Build Arch Linux Packages (.pkg.tar.zst)
|
- name: Build Arch Linux Packages (.pkg.tar.zst)
|
||||||
run: |
|
run: |
|
||||||
python3 scripts/package-arch.py --target x86_64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
python3 scripts/package-arch.py --target x86_64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
||||||
python3 scripts/package-arch.py --target aarch64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
python3 scripts/package-arch.py --target aarch64-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
||||||
python3 scripts/package-arch.py --target i686-unknown-linux-gnu --pkgrel "${BUILD_NUMBER}"
|
|
||||||
|
|
||||||
- name: Publish Packages to Gitea Package Registry
|
- name: Publish Packages to Gitea Package Registry
|
||||||
env:
|
env:
|
||||||
|
|||||||
Generated
+6
@@ -32,6 +32,12 @@
|
|||||||
<Item>
|
<Item>
|
||||||
<option name="path" value=".gitea/workflows/code-quality.yaml" />
|
<option name="path" value=".gitea/workflows/code-quality.yaml" />
|
||||||
</Item>
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<option name="path" value=".gitea/workflows/testing-to-main-pr.yaml" />
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<option name="path" value=".gitea/workflows/version-bump.yaml" />
|
||||||
|
</Item>
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</SchemaInfo>
|
</SchemaInfo>
|
||||||
|
|||||||
Generated
+1
@@ -3,6 +3,7 @@
|
|||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
|||||||
@@ -6,17 +6,28 @@ Dieses Dokument dient als technischer Leitfaden und Kontextdokument für KI-Codi
|
|||||||
|
|
||||||
## 1. Projektübersicht & Philosophie
|
## 1. Projektübersicht & Philosophie
|
||||||
|
|
||||||
Dieses Repository ist ein **Rust-Projekt-Template** für Linux-Anwendungen und CLI-Tools mit Fokus auf:
|
**mac2ip** ist ein CLI-Tool, das zuverlässig die aktuelle IP-Adresse zu einer gegebenen MAC-Adresse im lokalen Netzwerk findet, über einen 3-stufigen Algorithmus:
|
||||||
- Automatisierte Multi-Architektur-Kompilierung (`x86_64`, `aarch64`, `i686`).
|
|
||||||
- Native Paketierung für Debian (`.deb`), Fedora/RHEL (`.rpm`) und Arch Linux (`.pkg.tar.zst`) sowie Docker-Container-Images.
|
1. **Cache** (`src/cache.rs`): globaler, systemweiter Cache auf Basis der `turso`-Crate (lokale Datei, Standard `/var/lib/mac2ip/cache.db`). Ein Treffer wird nur verwendet, wenn er nicht abgelaufen ist (TTL, `src/config.rs`) **und** die IP per Ping erreichbar ist.
|
||||||
|
2. **`ip neigh`** (`src/network.rs`): moderner Ersatz für `arp`. Treffer nur bei Ping-Erreichbarkeit.
|
||||||
|
3. **`nmap -sn`** (`src/network.rs`): ARP-/Ping-Scan der lokal angeschlossenen Subnetze. MAC-Adressen erscheinen in der nmap-Ausgabe nur mit Root-Rechten (Raw-Socket/libpcap), daher läuft dieser Schritt über `sudo nmap` (bzw. `nmap` direkt, falls schon root). Kein Treffer → Fehler ("nicht gefunden").
|
||||||
|
|
||||||
|
Vor Schritt 3 prüft `src/trust.rs`, ob das aktuelle Netzwerk (identifiziert über die MAC-Adresse seines Default-Gateways) für einen nmap-Scan vertrauenswürdig ist (statische Liste in `AppConfig::trusted_networks`, zuvor per interaktiver Rückfrage/`--auto-trust-networks` im Cache bestätigtes Netzwerk). Ist das Netzwerk unbekannt, wird im interaktiven Modus nachgefragt; im `--json`-Modus (keine Rückfrage möglich) wird der Scan abgelehnt.
|
||||||
|
|
||||||
|
Die Orchestrierung dieser drei Schritte liegt in `src/resolver.rs`; `src/main.rs` ist nur ein dünner Entry-Point (CLI-Parsing via `src/cli.rs`, Konfiguration via `src/config.rs` + `config-ctdra`, Logging via `src/log.rs` + `logger-ctdra`).
|
||||||
|
|
||||||
|
Zur Laufzeit werden folgende System-Tools benötigt: `ip` (iproute2), `ping` (iputils), `nmap`, `sudo` (nur für Schritt 3, falls nicht schon root). Diese sind in den Paketierungs-Metadaten (`Cargo.toml`, siehe §3.2) als Abhängigkeiten hinterlegt.
|
||||||
|
|
||||||
|
Das Projekt basiert auf einem generischen **Rust-Projekt-Template** für Linux-Anwendungen/CLI-Tools mit Fokus auf:
|
||||||
|
- Automatisierte Multi-Architektur-Kompilierung (`x86_64`, `aarch64`; `i686` derzeit ausgesetzt, siehe §5.2.1).
|
||||||
|
- Native Paketierung für Debian (`.deb`), Fedora/RHEL (`.rpm`) und Arch Linux (`.pkg.tar.zst`).
|
||||||
- Vollständig automatisierte CI/CD-Pipelines via Gitea Actions (kompatibel mit Forgejo / GitHub Actions).
|
- Vollständig automatisierte CI/CD-Pipelines via Gitea Actions (kompatibel mit Forgejo / GitHub Actions).
|
||||||
- Automatisierte Sicherheits-Scans (Schwachstellen, Secrets) und Dependency-Updates.
|
- Automatisierte Sicherheits-Scans (Schwachstellen, Secrets) und Dependency-Updates.
|
||||||
|
|
||||||
### Standards & Tech-Stack
|
### Standards & Tech-Stack
|
||||||
- **Sprache**: Rust (Edition 2024), Python 3 (für Hilfsskripte in `scripts/`).
|
- **Sprache**: Rust (Edition 2024), Python 3 (für Hilfsskripte in `scripts/`).
|
||||||
- **Rust Toolchain**: Stable.
|
- **Rust Toolchain**: Stable.
|
||||||
- **Zielplattform**: Linux (GLIBC-basiert, Cross-Kompilierung für `x86_64-unknown-linux-gnu`, `aarch64-unknown-linux-gnu`, `i686-unknown-linux-gnu`).
|
- **Zielplattform**: Linux (GLIBC-basiert, Cross-Kompilierung für `x86_64-unknown-linux-gnu`, `aarch64-unknown-linux-gnu`; `i686-unknown-linux-gnu` derzeit ausgesetzt, siehe §5.2.1).
|
||||||
- **Container**: Docker-Images werden zusätzlich zu den nativen Paketen gebaut und in die Gitea Container Registry veröffentlicht.
|
|
||||||
- **Sicherheits-Tooling**: Trivy, OSV-Scanner, TruffleHog (Secret-Scanning), Renovate (Dependency-Updates), Qodana (statische Codeanalyse).
|
- **Sicherheits-Tooling**: Trivy, OSV-Scanner, TruffleHog (Secret-Scanning), Renovate (Dependency-Updates), Qodana (statische Codeanalyse).
|
||||||
- **Lizenz**: GPL-3.0-or-later (sofern nicht im abgeleiteten Projekt anders definiert).
|
- **Lizenz**: GPL-3.0-or-later (sofern nicht im abgeleiteten Projekt anders definiert).
|
||||||
|
|
||||||
@@ -29,27 +40,41 @@ Dieses Repository ist ein **Rust-Projekt-Template** für Linux-Anwendungen und C
|
|||||||
│ └── config.toml # Linker für Cross-Target-Kompilierung & Registry-Konfiguration
|
│ └── config.toml # Linker für Cross-Target-Kompilierung & Registry-Konfiguration
|
||||||
├── .gitea/
|
├── .gitea/
|
||||||
│ └── workflows/
|
│ └── workflows/
|
||||||
│ ├── main.yaml # CI/CD: Stabile Builds, Multi-Arch-Paketierung, Docker-Image, Release & Upload
|
│ ├── main.yaml # CI/CD: Stabile Builds, Multi-Arch-Paketierung, Release & Upload
|
||||||
│ ├── testing.yaml # CI/CD: Preview-Builds, Docker-Image & Testing-Pakete
|
│ ├── testing.yaml # CI/CD: Preview-Builds & Testing-Pakete
|
||||||
│ ├── unit-tests.yaml # CI: Unit-Tests für Pull Requests gegen 'testing'
|
│ ├── unit-tests.yaml # CI: Unit-Tests für Pull Requests gegen 'testing'
|
||||||
│ ├── security-scan.yaml # CI: Trivy & OSV-Scanner (Schwachstellen/Misconfig/Secrets)
|
│ ├── security-scan.yaml # CI: Trivy & OSV-Scanner (Schwachstellen/Misconfig/Secrets)
|
||||||
│ ├── trufflehog-scan.yaml # CI: TruffleHog Secret-Scan (inkl. Git-Historie)
|
│ ├── trufflehog-scan.yaml # CI: TruffleHog Secret-Scan (inkl. Git-Historie)
|
||||||
│ └── renovate.yaml # CI: Wöchentlicher Renovate-Lauf für Dependency-Updates
|
│ └── renovate.yaml # CI: Wöchentlicher Renovate-Lauf für Dependency-Updates
|
||||||
|
├── packaging/
|
||||||
|
│ ├── deb/postinst # Debian-Postinstall: legt /var/lib/mac2ip an
|
||||||
|
│ └── arch/mac2ip.install # Arch-Install-Skriptlet: legt /var/lib/mac2ip an
|
||||||
├── scripts/
|
├── scripts/
|
||||||
│ ├── get-build-number.py # Ermittelt automatisch die nächste Revisions-/Build-Nummer
|
│ ├── get-build-number.py # Ermittelt automatisch die nächste Revisions-/Build-Nummer
|
||||||
│ ├── package-arch.py # Erzeugt native Arch Linux .pkg.tar.zst Pakete
|
│ ├── package-arch.py # Erzeugt native Arch Linux .pkg.tar.zst Pakete (inkl. optionalem Install-Skriptlet)
|
||||||
│ └── report-security-issue.py # Meldet Scan-Ergebnisse (Trivy/OSV/TruffleHog) als Gitea-Issue
|
│ └── report-security-issue.py # Meldet Scan-Ergebnisse (Trivy/OSV/TruffleHog) als Gitea-Issue
|
||||||
├── src/
|
├── src/
|
||||||
│ └── main.rs # Einstiegspunkt der Anwendung
|
│ ├── main.rs # Einstiegspunkt (CLI-Parsing, Wiring)
|
||||||
|
│ ├── lib.rs # Modul-Wurzel (für Integrationstests)
|
||||||
|
│ ├── cli.rs # clap-Kommandozeilen-Definition
|
||||||
|
│ ├── config.rs # AppConfig + config-ctdra-Integration + CLI-Overlay
|
||||||
|
│ ├── log.rs # JSON-Modus-bewusster logger-ctdra-Wrapper
|
||||||
|
│ ├── mac.rs # MacAddress-Typ (Parsing/Kanonisierung)
|
||||||
|
│ ├── cache.rs # Globaler Turso-Cache (MAC -> IP)
|
||||||
|
│ ├── network.rs # ip neigh / ping / nmap: Exec- und Parse-Funktionen
|
||||||
|
│ ├── trust.rs # Netzwerk-Vertrauensprüfung vor Schritt 3 (Gateway-MAC, Rückfrage, Cache)
|
||||||
|
│ ├── resolver.rs # 3-Stufen-Algorithmus (Orchestrierung)
|
||||||
|
│ └── output.rs # Human- und JSON-Ausgabe
|
||||||
|
├── tests/ # Integrationstests (pure Parsing-/Logik-Funktionen, kein Netzwerk/root/nmap nötig)
|
||||||
├── Cargo.toml # Projekt-Manifest & Metadaten für deb, rpm und arch
|
├── Cargo.toml # Projekt-Manifest & Metadaten für deb, rpm und arch
|
||||||
├── qodana.yaml # Konfiguration für JetBrains Qodana (statische Analyse)
|
├── qodana.yaml # Konfiguration für JetBrains Qodana (statische Analyse)
|
||||||
├── renovate.json # Renovate-Konfiguration (Gruppierung, Versions-Pins in Workflows)
|
├── renovate.json # Renovate-Konfiguration (Gruppierung, Versions-Pins in Workflows)
|
||||||
├── LICENSE # Lizenztext
|
├── LICENSE # Lizenztext
|
||||||
├── README.md # Benutzerdokumentation & Setup-Checkliste
|
├── README.md # Benutzerdokumentation
|
||||||
└── AGENTS.md # Dieses Agenten-Handbuch
|
└── AGENTS.md # Dieses Agenten-Handbuch
|
||||||
```
|
```
|
||||||
|
|
||||||
> **Hinweis:** `main.yaml`/`testing.yaml` bauen zusätzlich ein Docker-Image (`docker build .` mit `--build-arg TARGET_BIN=...`). Ein `Dockerfile` ist im Template noch **nicht** enthalten und muss von abgeleiteten Projekten ergänzt werden; der aktuell hartkodierte `TARGET_BIN`-Pfad (`.../release/mirror-package`) ist ein Platzhalter aus einem Referenzprojekt und muss beim Ableiten des Templates auf den tatsächlichen Binärnamen (`Cargo.toml` → `[package] name`) angepasst werden.
|
> **Hinweis:** Dieses Projekt baut aktuell **kein** Docker-Image — keiner der Workflows unter `.gitea/workflows/` enthält einen Docker-Build-Schritt. Sollte das zukünftig ergänzt werden, muss ein `Dockerfile` hinzugefügt und der Binärname konsistent mit `[package] name` in `Cargo.toml` gehalten werden.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -68,12 +93,13 @@ Bei Änderungen an Binärnamen, Abhängigkeiten oder Beschreibungen müssen die
|
|||||||
2. `[package.metadata.generate-rpm]` (für `cargo-generate-rpm`):
|
2. `[package.metadata.generate-rpm]` (für `cargo-generate-rpm`):
|
||||||
- `requires`, `assets`.
|
- `requires`, `assets`.
|
||||||
3. `[package.metadata.arch]` (für `scripts/package-arch.py`):
|
3. `[package.metadata.arch]` (für `scripts/package-arch.py`):
|
||||||
- `pkgrel`, `arch`, `depends`, `optdepends`.
|
- `pkgrel`, `arch`, `depends`, `optdepends`, optional `install_script` (Pfad zu einem pacman-Install-Skriptlet, siehe §3.3).
|
||||||
|
|
||||||
Ändert sich der Binärname (`[package] name`), muss auch der `TARGET_BIN`-Build-Arg im Docker-Build-Step von `main.yaml`/`testing.yaml` sowie das (abzuleitende) `Dockerfile` angepasst werden.
|
Alle drei Blöcke listen bei mac2ip zusätzlich `sudo`, `iproute2`/`iproute`, `iputils`/`iputils-ping` und `nmap` als Laufzeit-Abhängigkeiten (benötigt für den 3-Stufen-Algorithmus, siehe §1). `[package.metadata.deb].maintainer-scripts` sowie `[package.metadata.generate-rpm].post_install_script` legen beim Paket-Install `/var/lib/mac2ip` mit den nötigen Rechten an (siehe §1, "Caching & TTL" in README.md).
|
||||||
|
|
||||||
### 3.3 Skripte in `scripts/`
|
### 3.3 Skripte in `scripts/`
|
||||||
- **Generizität**: Die Skripte dürfen keine hardcodierten Anwendungsnamen, spezifischen Abhängigkeiten oder projektspezifischen URLs enthalten. Alle Werte müssen dynamisch aus `Cargo.toml` (via `cargo metadata` oder Dateiparsing) oder Umgebungsvariablen (`BUILD_NUMBER`, `GITEA_URL`, `REPO`, `TOKEN`) ermittelt werden.
|
- **Generizität**: Die Skripte dürfen keine hardcodierten Anwendungsnamen, spezifischen Abhängigkeiten oder projektspezifischen URLs enthalten. Alle Werte müssen dynamisch aus `Cargo.toml` (via `cargo metadata` oder Dateiparsing) oder Umgebungsvariablen (`BUILD_NUMBER`, `GITEA_URL`, `REPO`, `TOKEN`) ermittelt werden.
|
||||||
|
- **`package-arch.py`-Install-Skriptlet**: Liest optional `[package.metadata.arch].install_script` aus `cargo metadata` und bettet die referenzierte Datei pacman-konform als `.INSTALL` in das erzeugte `.pkg.tar.zst` ein — weiterhin vollständig metadatengetrieben, kein hartkodierter Anwendungsname im Skript selbst.
|
||||||
- **Python-Kompatibilität**: Verwende Standard-Python 3 ohne externe PyPI-Abhängigkeiten (nur Standardbibliothek: `json`, `subprocess`, `urllib`, `argparse`, `os`, `re`, `tempfile`, `tarfile` etc.).
|
- **Python-Kompatibilität**: Verwende Standard-Python 3 ohne externe PyPI-Abhängigkeiten (nur Standardbibliothek: `json`, `subprocess`, `urllib`, `argparse`, `os`, `re`, `tempfile`, `tarfile` etc.).
|
||||||
- **`get-build-number.py`**: Ermittelt die nächste Build-/Revisions-Nummer nicht mehr rein lokal, sondern dynamisch über:
|
- **`get-build-number.py`**: Ermittelt die nächste Build-/Revisions-Nummer nicht mehr rein lokal, sondern dynamisch über:
|
||||||
1. Gitea Releases API (Tag-/Asset-Namen),
|
1. Gitea Releases API (Tag-/Asset-Namen),
|
||||||
@@ -126,6 +152,23 @@ Alle Workflows liegen unter `.gitea/workflows/` und nutzen gecachte Abhängigkei
|
|||||||
- **`qodana.yaml`**: Konfiguration für JetBrains Qodana (statische Codeanalyse, Profil `qodana.starter`); wird über eine externe/IDE-seitige Qodana-CI-Integration ausgeführt, nicht über einen eigenen Gitea-Workflow in diesem Template.
|
- **`qodana.yaml`**: Konfiguration für JetBrains Qodana (statische Codeanalyse, Profil `qodana.starter`); wird über eine externe/IDE-seitige Qodana-CI-Integration ausgeführt, nicht über einen eigenen Gitea-Workflow in diesem Template.
|
||||||
- **`renovate.yaml`** (Trigger: wöchentlich montags 04:00 UTC, `workflow_dispatch`): Führt Renovate (Container-Image, gepinnte Version) gegen die Gitea-Plattform aus und erstellt Pull Requests für veraltete Abhängigkeiten gemäß `renovate.json`.
|
- **`renovate.yaml`** (Trigger: wöchentlich montags 04:00 UTC, `workflow_dispatch`): Führt Renovate (Container-Image, gepinnte Version) gegen die Gitea-Plattform aus und erstellt Pull Requests für veraltete Abhängigkeiten gemäß `renovate.json`.
|
||||||
|
|
||||||
|
### 5.2.1 Bekannte Sicherheits-Workarounds (temporär, mit Revert-Bedingung)
|
||||||
|
|
||||||
|
Workarounds für Schwachstellen in transitiven Abhängigkeiten, die nicht direkt
|
||||||
|
per Versions-Bump behoben werden können (z. B. weil ein Zwischenpaket eine zu
|
||||||
|
enge Versionsanforderung pinnt). Vor jedem Renovate-Merge/Dependency-Update
|
||||||
|
prüfen, ob die Revert-Bedingung inzwischen erfüllt ist.
|
||||||
|
|
||||||
|
| Advisory | Betroffenes Paket | Workaround | Wo dokumentiert | Revert-Bedingung |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| [RUSTSEC-2026-0253](https://rustsec.org/advisories/RUSTSEC-2026-0253.html) (Use-after-free in `LruCache::pop()`) | `lru` < 0.18.2, transitiv über `turso -> turso_core -> tantivy` | `fts`-Default-Feature von `turso` deaktiviert (`Cargo.toml`) — mac2ip nutzt keine Volltextsuche, dadurch entfällt `tantivy`/`lru` komplett aus dem Dependency-Baum | Kommentar direkt über der `turso`-Zeile in `Cargo.toml` | Sobald `cargo update -p lru --precise 0.18.2` erfolgreich ist (d. h. eine stabile `turso`-Version eine `tantivy`-Version mit `lru >= 0.18.2` zulässt): `turso`-Zeile zurück auf `turso = "0.7"` (oder aktueller) ändern, `cargo update -p turso`, und `cargo tree -i lru` zur Kontrolle. |
|
||||||
|
|
||||||
|
### 5.2.2 Bekannte Build-Einschränkungen (temporär, mit Revert-Bedingung)
|
||||||
|
|
||||||
|
| Einschränkung | Ursache | Workaround | Wo dokumentiert | Revert-Bedingung |
|
||||||
|
| :--- | :--- | :--- | :--- | :--- |
|
||||||
|
| Kein `i686-unknown-linux-gnu`-Build/-Paket mehr | `turso_sdk_kit` (Abhängigkeit von `turso`) fordert von `turso_core` unconditional das Feature `io_uring` an (nicht abschaltbar wie `fts`). Die `io-uring`-Crate (aktuell 0.7.15, neueste Version) liefert vorgefertigte FFI-Bindings nur für `x86_64`, `aarch64`, `riscv64`, `powerpc64`, `loongarch64` - **nicht** für `i686`. `--cfg=io_uring_skip_arch_check` würde auf i686 stillschweigend die x86_64-Bindings verwenden (falsche Struct-Layouts/Pointer-Breite -> potenzielle Speicherkorruption bei io_uring-Syscalls) und wurde deshalb bewusst NICHT verwendet. | `i686-unknown-linux-gnu` komplett aus den Build-Targets entfernt: `.cargo/config.toml` (Linker-Eintrag), `.gitea/workflows/main.yaml` + `testing.yaml` (Toolchain-Install, `rustup target add`, `cargo build`/`cargo deb`/`cargo generate-rpm`/`package-arch.py`-Aufrufe), `README.md`/`AGENTS.md` (Zielarchitektur-Angaben) | Diese Tabelle; `git log` nach "i686" für die genauen Commits | Sobald eine neue `io-uring`-Version vorgefertigte `i686`-Bindings mitbringt (`cargo info io-uring` prüfen) ODER eine neue `turso`-Version `io_uring` optional/abschaltbar macht: i686 wieder in allen oben genannten Dateien ergänzen und mit einem echten i686-Cross-Build verifizieren, bevor gemergt wird. |
|
||||||
|
|
||||||
### 5.3 Renovate-Konfiguration (`renovate.json`)
|
### 5.3 Renovate-Konfiguration (`renovate.json`)
|
||||||
- Basis-Branch für PRs: `dev`.
|
- Basis-Branch für PRs: `dev`.
|
||||||
- Gruppiert Updates nach `Gitea Actions`, `Cargo Dependencies` und `Docker-Images`.
|
- Gruppiert Updates nach `Gitea Actions`, `Cargo Dependencies` und `Docker-Images`.
|
||||||
|
|||||||
Generated
+4
-589
@@ -56,12 +56,6 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "allocator-api2"
|
|
||||||
version = "0.2.21"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "allocator-api2"
|
name = "allocator-api2"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@@ -184,17 +178,6 @@ version = "0.1.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bfdc70193dadb9d7287fa4b633f15f90c876915b31f6af17da307fc59c9859a8"
|
checksum = "bfdc70193dadb9d7287fa4b633f15f90c876915b31f6af17da307fc59c9859a8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "async-trait"
|
|
||||||
version = "0.1.92"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 3.0.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.5.1"
|
version = "1.5.1"
|
||||||
@@ -233,7 +216,7 @@ dependencies = [
|
|||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lazycell",
|
"lazycell",
|
||||||
"log",
|
"log",
|
||||||
"prettyplease 0.2.37",
|
"prettyplease",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"regex",
|
"regex",
|
||||||
@@ -249,15 +232,6 @@ version = "2.13.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitpacking"
|
|
||||||
version = "0.9.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "96a7139abd3d9cebf8cd6f920a389cf3dc9576172e32f4563f188cae3c3eb019"
|
|
||||||
dependencies = [
|
|
||||||
"crunchy",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitvec"
|
name = "bitvec"
|
||||||
version = "1.1.1"
|
version = "1.1.1"
|
||||||
@@ -270,29 +244,6 @@ dependencies = [
|
|||||||
"wyz",
|
"wyz",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bon"
|
|
||||||
version = "3.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "60eafe0d77c3a2fc292c1d1346c3041b33c0a108085a2afabf672b70f69dbbc9"
|
|
||||||
dependencies = [
|
|
||||||
"bon-macros",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bon-macros"
|
|
||||||
version = "3.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bd0f9631d8aaaee112c41985d675ef269e02acbd4f33122836af4f0c5f699ff6"
|
|
||||||
dependencies = [
|
|
||||||
"darling",
|
|
||||||
"ident_case",
|
|
||||||
"prettyplease 0.3.0",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 3.0.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "branches"
|
name = "branches"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -347,17 +298,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "a3eb0f42d6c360dc3f8a821f6bf2fdea7f72bfd36b3076eb0e6d1e9e0752fff4"
|
checksum = "a3eb0f42d6c360dc3f8a821f6bf2fdea7f72bfd36b3076eb0e6d1e9e0752fff4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"find-msvc-tools",
|
"find-msvc-tools",
|
||||||
"jobserver",
|
|
||||||
"libc 0.2.189",
|
|
||||||
"shlex 2.0.1",
|
"shlex 2.0.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "census"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4f4c707c6a209cbe82d10abd08e1ea8995e9ea937d2550646e02798948992be0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cexpr"
|
name = "cexpr"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
@@ -543,15 +486,6 @@ dependencies = [
|
|||||||
"rustc_version",
|
"rustc_version",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crc32fast"
|
|
||||||
version = "1.5.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "01a7799fd6b852db0e61728dde9a204c423b44d689dbd432522543614b490e78"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-channel"
|
name = "crossbeam-channel"
|
||||||
version = "0.5.17"
|
version = "0.5.17"
|
||||||
@@ -561,16 +495,6 @@ dependencies = [
|
|||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crossbeam-deque"
|
|
||||||
version = "0.8.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-epoch",
|
|
||||||
"crossbeam-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-epoch"
|
name = "crossbeam-epoch"
|
||||||
version = "0.9.21"
|
version = "0.9.21"
|
||||||
@@ -586,12 +510,6 @@ version = "0.8.23"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crunchy"
|
|
||||||
version = "0.2.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crypto-common"
|
name = "crypto-common"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
@@ -612,54 +530,11 @@ dependencies = [
|
|||||||
"cipher",
|
"cipher",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "darling"
|
|
||||||
version = "0.24.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ed17f5901b6630b993ca003def43f2f8ef4014fc13b047b57aad617ff32bc2ec"
|
|
||||||
dependencies = [
|
|
||||||
"darling_core",
|
|
||||||
"darling_macro",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "darling_core"
|
|
||||||
version = "0.24.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6837e2cf7485aaae18f86181d2f0e9a7ed297a025e220aeabf63fdebd3a2ddff"
|
|
||||||
dependencies = [
|
|
||||||
"ident_case",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"strsim",
|
|
||||||
"syn 3.0.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "darling_macro"
|
|
||||||
version = "0.24.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2ac7135c3ef02b2f7833bbeb1be5ba7f966dcde8a87c6b87f65a778d71a02785"
|
|
||||||
dependencies = [
|
|
||||||
"darling_core",
|
|
||||||
"quote",
|
|
||||||
"syn 3.0.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "datasketches"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c286de4e81ea2590afc24d754e0f83810c566f50a1388fa75ebd57928c0d9745"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deranged"
|
name = "deranged"
|
||||||
version = "0.5.8"
|
version = "0.5.8"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c"
|
||||||
dependencies = [
|
|
||||||
"serde_core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "displaydoc"
|
name = "displaydoc"
|
||||||
@@ -672,12 +547,6 @@ dependencies = [
|
|||||||
"syn 3.0.5",
|
"syn 3.0.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "downcast-rs"
|
|
||||||
version = "2.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "117240f60069e65410b3ae1bb213295bd828f707b5bec6596a1afc8793ce0cbc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.18.0"
|
version = "1.18.0"
|
||||||
@@ -710,17 +579,6 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "erased-serde"
|
|
||||||
version = "0.4.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2add8a07dd6a8d93ff627029c51de145e12686fbc36ecb298ac22e74cf02dec"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
"serde_core",
|
|
||||||
"typeid",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "errno"
|
name = "errno"
|
||||||
version = "0.3.14"
|
version = "0.3.14"
|
||||||
@@ -759,12 +617,6 @@ dependencies = [
|
|||||||
"siphasher",
|
"siphasher",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fastdivide"
|
|
||||||
version = "0.4.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9afc2bd4d5a73106dd53d10d73d3401c2f32730ba2c0b93ddb888a8983680471"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@@ -777,28 +629,6 @@ version = "0.1.12"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d"
|
checksum = "3e0f1c7c3a72c66fd80abe965175f7523475c0489a87d3ff9d6e8c87d87a9d2d"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fnv"
|
|
||||||
version = "1.0.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "foldhash"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "fs4"
|
|
||||||
version = "0.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8640e34b88f7652208ce9e88b1a37a2ae95227d84abec377ccd3c5cfeb141ed4"
|
|
||||||
dependencies = [
|
|
||||||
"rustix 1.1.4",
|
|
||||||
"windows-sys 0.59.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "funty"
|
name = "funty"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@@ -811,17 +641,6 @@ version = "0.3.34"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-macro"
|
|
||||||
version = "0.3.34"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 3.0.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-task"
|
name = "futures-task"
|
||||||
version = "0.3.34"
|
version = "0.3.34"
|
||||||
@@ -835,7 +654,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-macro",
|
|
||||||
"futures-task",
|
"futures-task",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"slab",
|
"slab",
|
||||||
@@ -932,17 +750,6 @@ version = "0.3.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
|
checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "hashbrown"
|
|
||||||
version = "0.16.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
|
|
||||||
dependencies = [
|
|
||||||
"allocator-api2 0.2.21",
|
|
||||||
"equivalent",
|
|
||||||
"foldhash",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashbrown"
|
name = "hashbrown"
|
||||||
version = "0.17.1"
|
version = "0.17.1"
|
||||||
@@ -976,12 +783,6 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "htmlescape"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e9025058dae765dee5070ec375f591e2ba14638c63feff74f13805a72e523163"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@@ -1171,12 +972,6 @@ dependencies = [
|
|||||||
"zerovec",
|
"zerovec",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ident_case"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "indexmap"
|
name = "indexmap"
|
||||||
version = "2.14.2"
|
version = "2.14.2"
|
||||||
@@ -1184,7 +979,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
|
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"equivalent",
|
"equivalent",
|
||||||
"hashbrown 0.17.1",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1205,15 +1000,6 @@ dependencies = [
|
|||||||
"memoffset",
|
"memoffset",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "inventory"
|
|
||||||
version = "0.3.24"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a4f0c30c76f2f4ccee3fe55a2435f691ca00c0e4bd87abe4f4a851b1d4dac39b"
|
|
||||||
dependencies = [
|
|
||||||
"rustversion",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "io-uring"
|
name = "io-uring"
|
||||||
version = "0.7.15"
|
version = "0.7.15"
|
||||||
@@ -1255,16 +1041,6 @@ version = "1.0.18"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "jobserver"
|
|
||||||
version = "0.1.35"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
|
|
||||||
dependencies = [
|
|
||||||
"getrandom 0.4.3",
|
|
||||||
"libc 0.2.189",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.105"
|
version = "0.3.105"
|
||||||
@@ -1288,12 +1064,6 @@ version = "1.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "levenshtein_automata"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0c2cdeb66e45e9f36bfad5bbdb4d2384e70936afbee843c6f6543f0c551ebb25"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.189"
|
version = "0.2.189"
|
||||||
@@ -1407,29 +1177,13 @@ dependencies = [
|
|||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lru"
|
|
||||||
version = "0.16.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39"
|
|
||||||
dependencies = [
|
|
||||||
"hashbrown 0.16.1",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lz4_flex"
|
|
||||||
version = "0.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7ef0d4ed8669f8f8826eb00dc878084aa8f253506c4fd5e8f58f5bce72ddb97e"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mac2ip"
|
name = "mac2ip"
|
||||||
version = "0.1.0"
|
version = "1.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"config-ctdra",
|
"config-ctdra",
|
||||||
"logger-ctdra",
|
"logger-ctdra",
|
||||||
"program-ctdra",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"sudo-ctdra",
|
"sudo-ctdra",
|
||||||
@@ -1447,30 +1201,12 @@ dependencies = [
|
|||||||
"regex-automata",
|
"regex-automata",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "measure_time"
|
|
||||||
version = "0.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "51c55d61e72fc3ab704396c5fa16f4c184db37978ae4e94ca8959693a235fc0e"
|
|
||||||
dependencies = [
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memchr"
|
name = "memchr"
|
||||||
version = "2.8.3"
|
version = "2.8.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memmap2"
|
|
||||||
version = "0.9.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d1219ed1b7f229ee7104d281dd01d6802fe28bb6e95d292942c4daacdeb798c0"
|
|
||||||
dependencies = [
|
|
||||||
"libc 0.2.189",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.9.1"
|
version = "0.9.1"
|
||||||
@@ -1528,12 +1264,6 @@ dependencies = [
|
|||||||
"windows-sys 0.61.2",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "murmurhash32"
|
|
||||||
version = "0.3.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2195bf6aa996a481483b29d62a7663eed3fe39600c460e323f8ff41e90bdd89b"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nom"
|
name = "nom"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
@@ -1608,36 +1338,12 @@ version = "1.70.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "oneshot"
|
|
||||||
version = "0.1.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "269bca4c2591a28585d6bf10d9ed0332b7d76900a1b02bec41bdc3a2cdcda107"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "opaque-debug"
|
name = "opaque-debug"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
|
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ordered-float"
|
|
||||||
version = "5.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8c7c9e0d9b23589f26070720bac724174bfec1083e82f7854cdd0267518343c0"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ownedbytes"
|
|
||||||
version = "0.9.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2fbd56f7631767e61784dc43f8580f403f4475bd4aaa4da003e6295e1bab4a7e"
|
|
||||||
dependencies = [
|
|
||||||
"stable_deref_trait",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "owo-colors"
|
name = "owo-colors"
|
||||||
version = "3.5.0"
|
version = "3.5.0"
|
||||||
@@ -1688,12 +1394,6 @@ version = "0.2.17"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pkg-config"
|
|
||||||
version = "0.3.34"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "polling"
|
name = "polling"
|
||||||
version = "3.11.0"
|
version = "3.11.0"
|
||||||
@@ -1756,16 +1456,6 @@ dependencies = [
|
|||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "prettyplease"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"syn 3.0.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.107"
|
version = "1.0.107"
|
||||||
@@ -1925,26 +1615,6 @@ dependencies = [
|
|||||||
"rustversion",
|
"rustversion",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon"
|
|
||||||
version = "1.12.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
"rayon-core",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rayon-core"
|
|
||||||
version = "1.13.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
|
|
||||||
dependencies = [
|
|
||||||
"crossbeam-deque",
|
|
||||||
"crossbeam-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.5.18"
|
version = "0.5.18"
|
||||||
@@ -1993,16 +1663,6 @@ dependencies = [
|
|||||||
"byteorder",
|
"byteorder",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rust-stemmers"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e46a2036019fdb888131db7a4c847a1063a7493f971ed94ea82c67eada63ca54"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
"serde_derive",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-hash"
|
name = "rustc-hash"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -2214,15 +1874,6 @@ version = "1.0.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sketches-ddsketch"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "513c3f5f732bfd6fbb187619c2dfe9d2f25f1a2976f01d575f0fd329d565df56"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.12"
|
version = "0.4.12"
|
||||||
@@ -2329,154 +1980,6 @@ dependencies = [
|
|||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy"
|
|
||||||
version = "0.26.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "861facfabd71044968f364837f9a083b56464ba5a59079f88706ee5c451ca069"
|
|
||||||
dependencies = [
|
|
||||||
"aho-corasick",
|
|
||||||
"arc-swap",
|
|
||||||
"base64",
|
|
||||||
"bitpacking",
|
|
||||||
"bon",
|
|
||||||
"byteorder",
|
|
||||||
"census",
|
|
||||||
"crc32fast",
|
|
||||||
"crossbeam-channel",
|
|
||||||
"datasketches",
|
|
||||||
"downcast-rs",
|
|
||||||
"fastdivide",
|
|
||||||
"fnv",
|
|
||||||
"fs4",
|
|
||||||
"htmlescape",
|
|
||||||
"itertools 0.14.0",
|
|
||||||
"levenshtein_automata",
|
|
||||||
"log",
|
|
||||||
"lru",
|
|
||||||
"lz4_flex",
|
|
||||||
"measure_time",
|
|
||||||
"memmap2",
|
|
||||||
"once_cell",
|
|
||||||
"oneshot",
|
|
||||||
"rayon",
|
|
||||||
"regex",
|
|
||||||
"rust-stemmers",
|
|
||||||
"rustc-hash 2.1.3",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"sketches-ddsketch",
|
|
||||||
"smallvec",
|
|
||||||
"tantivy-bitpacker",
|
|
||||||
"tantivy-columnar",
|
|
||||||
"tantivy-common",
|
|
||||||
"tantivy-fst",
|
|
||||||
"tantivy-query-grammar",
|
|
||||||
"tantivy-stacker",
|
|
||||||
"tantivy-tokenizer-api",
|
|
||||||
"tempfile",
|
|
||||||
"thiserror",
|
|
||||||
"time",
|
|
||||||
"typetag",
|
|
||||||
"uuid",
|
|
||||||
"winapi",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-bitpacker"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4fed3d674429bcd2de5d0a6d1aa5495fed8afd9c5ecce993019caf7615f53fa4"
|
|
||||||
dependencies = [
|
|
||||||
"bitpacking",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-columnar"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c57166f5bcfd478f370ab8445afb4678dce44801fa5ce5c451aaf8595583c5dc"
|
|
||||||
dependencies = [
|
|
||||||
"downcast-rs",
|
|
||||||
"fastdivide",
|
|
||||||
"itertools 0.14.0",
|
|
||||||
"serde",
|
|
||||||
"tantivy-bitpacker",
|
|
||||||
"tantivy-common",
|
|
||||||
"tantivy-sstable",
|
|
||||||
"tantivy-stacker",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-common"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bbf10915aa75da3c3b0d58b58853d2e889efbaf32d4982a4c3715dde6bba23e5"
|
|
||||||
dependencies = [
|
|
||||||
"async-trait",
|
|
||||||
"byteorder",
|
|
||||||
"ownedbytes",
|
|
||||||
"serde",
|
|
||||||
"time",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-fst"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d60769b80ad7953d8a7b2c70cdfe722bbcdcac6bccc8ac934c40c034d866fc18"
|
|
||||||
dependencies = [
|
|
||||||
"byteorder",
|
|
||||||
"regex-syntax",
|
|
||||||
"utf8-ranges",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-query-grammar"
|
|
||||||
version = "0.26.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dfadb8526b6da90704feb293b0701a6aae62ea14983143344be2dc5ce30f1d82"
|
|
||||||
dependencies = [
|
|
||||||
"fnv",
|
|
||||||
"nom",
|
|
||||||
"ordered-float",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-sstable"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8a2cfc3ac5164cbadc28965ffb145a8f47582a60ae5897859ad8d4316596c606"
|
|
||||||
dependencies = [
|
|
||||||
"futures-util",
|
|
||||||
"itertools 0.14.0",
|
|
||||||
"tantivy-bitpacker",
|
|
||||||
"tantivy-common",
|
|
||||||
"tantivy-fst",
|
|
||||||
"zstd",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-stacker"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6cbb051742da9d53ca9e8fff43a9b10e319338b24e2c0e15d0372df19ffeb951"
|
|
||||||
dependencies = [
|
|
||||||
"murmurhash32",
|
|
||||||
"tantivy-common",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "tantivy-tokenizer-api"
|
|
||||||
version = "0.7.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "eac258c2c6390673f2685813afeeafcb8c4e0ee7de8dd3fc46838dcc37263f98"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tap"
|
name = "tap"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
@@ -2731,7 +2234,7 @@ dependencies = [
|
|||||||
"aegis",
|
"aegis",
|
||||||
"aes",
|
"aes",
|
||||||
"aes-gcm",
|
"aes-gcm",
|
||||||
"allocator-api2 0.4.0",
|
"allocator-api2",
|
||||||
"antithesis_sdk",
|
"antithesis_sdk",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
"aristo",
|
"aristo",
|
||||||
@@ -2779,7 +2282,6 @@ dependencies = [
|
|||||||
"smallvec",
|
"smallvec",
|
||||||
"strum",
|
"strum",
|
||||||
"strum_macros",
|
"strum_macros",
|
||||||
"tantivy",
|
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tracing",
|
"tracing",
|
||||||
@@ -2909,42 +2411,12 @@ dependencies = [
|
|||||||
"rand 0.10.2",
|
"rand 0.10.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typeid"
|
|
||||||
version = "1.0.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "typenum"
|
name = "typenum"
|
||||||
version = "1.20.1"
|
version = "1.20.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typetag"
|
|
||||||
version = "0.2.23"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c90e86058a30d42a1a928dfb4b49bb33c98c3a2b4909492e6b0881cd94798ec2"
|
|
||||||
dependencies = [
|
|
||||||
"erased-serde",
|
|
||||||
"inventory",
|
|
||||||
"once_cell",
|
|
||||||
"serde",
|
|
||||||
"typetag-impl",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "typetag-impl"
|
|
||||||
version = "0.2.23"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f153acc4e99a5f2a5aefa09fb078be54e26271b2813f6041200b224c098d8328"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 3.0.5",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uncased"
|
name = "uncased"
|
||||||
version = "0.9.10"
|
version = "0.9.10"
|
||||||
@@ -2982,12 +2454,6 @@ version = "1.0.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246"
|
checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "utf8-ranges"
|
|
||||||
version = "1.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7fcfc827f90e53a02eaef5e535ee14266c1d569214c6aa70133a624d8a3164ba"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8_iter"
|
name = "utf8_iter"
|
||||||
version = "1.0.4"
|
version = "1.0.4"
|
||||||
@@ -3008,7 +2474,6 @@ checksum = "2ef6dac1e96601b4fb3acccccff2139741fcb757cb9a36089bf5be91cfb285ce"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom 0.4.3",
|
"getrandom 0.4.3",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"serde_core",
|
|
||||||
"sha1_smol",
|
"sha1_smol",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
@@ -3097,28 +2562,6 @@ dependencies = [
|
|||||||
"rustix 0.38.44",
|
"rustix 0.38.44",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.3.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-i686-pc-windows-gnu",
|
|
||||||
"winapi-x86_64-pc-windows-gnu",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-x86_64-pc-windows-gnu"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-core"
|
name = "windows-core"
|
||||||
version = "0.62.2"
|
version = "0.62.2"
|
||||||
@@ -3403,31 +2846,3 @@ name = "zmij"
|
|||||||
version = "1.0.23"
|
version = "1.0.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zstd"
|
|
||||||
version = "0.13.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
|
|
||||||
dependencies = [
|
|
||||||
"zstd-safe",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zstd-safe"
|
|
||||||
version = "7.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "64d80649ab6db9d9f6f9c80a40becd948eda4714a0a5ac8c4d157a32231c7882"
|
|
||||||
dependencies = [
|
|
||||||
"zstd-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zstd-sys"
|
|
||||||
version = "2.1.0+zstd.1.5.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0ef0a8027ec3ee71300ab3bcbcd0393f434aa72b91ca6d635a39941deae8eea0"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
"pkg-config",
|
|
||||||
]
|
|
||||||
|
|||||||
+15
-3
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mac2ip"
|
name = "mac2ip"
|
||||||
version = "0.1.0"
|
version = "1.0.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ['DragonSlayer_14']
|
authors = ['DragonSlayer_14']
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@@ -11,10 +11,22 @@ description = "Findet zuverlässig die aktuelle IP-Adresse zu einer MAC-Adresse
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
config-ctdra = { version = "1.0.6", registry = "gitea" }
|
config-ctdra = { version = "1.0.6", registry = "gitea" }
|
||||||
logger-ctdra = { version = "1.0.5", registry = "gitea" }
|
logger-ctdra = { version = "1.0.5", registry = "gitea" }
|
||||||
program-ctdra = { version = "1.0.1", registry = "gitea" }
|
|
||||||
sudo-ctdra = { version = "1.0.1", registry = "gitea" }
|
sudo-ctdra = { version = "1.0.1", registry = "gitea" }
|
||||||
tokio = { version = "1", features = ["macros", "rt-multi-thread", "process", "time"] }
|
tokio = { version = "1", features = ["macros", "rt-multi-thread", "process", "time"] }
|
||||||
turso = "0.7"
|
# WORKAROUND für RUSTSEC-2026-0253 (Use-after-free in lru < 0.18.2): das
|
||||||
|
# Default-Feature "fts" zieht tantivy 0.26.2 -> lru "^0.16.3" (verwundbar) ein,
|
||||||
|
# obwohl mac2ip keine Volltextsuche nutzt. "fts" bleibt deaktiviert, bis eine
|
||||||
|
# stabile turso-Version tantivy>=eine lru>=0.18.2 zulassende Version pinnt.
|
||||||
|
#
|
||||||
|
# Revert, sobald behoben (z. B. Renovate-PR/manuelle Prüfung):
|
||||||
|
# 1. `cargo update -p lru --precise 0.18.2` probieren - schlägt fehl, solange
|
||||||
|
# das o. g. Problem besteht (siehe Fehlermeldung mit dem Pfad turso ->
|
||||||
|
# turso_core -> tantivy -> lru "^0.16.3").
|
||||||
|
# 2. Sobald das gelingt (oder eine neue stabile turso-Version das Problem
|
||||||
|
# upstream behebt): diese Zeile zurück zu `turso = "0.7"` (oder aktueller)
|
||||||
|
# ändern und `cargo update -p turso` laufen lassen.
|
||||||
|
# 3. `cargo tree -i lru` zur Kontrolle - keine Version < 0.18.2 mehr vorhanden.
|
||||||
|
turso = { version = "0.7", default-features = false, features = ["mimalloc"] }
|
||||||
clap = { version = "4", features = ["derive", "env"] }
|
clap = { version = "4", features = ["derive", "env"] }
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
|||||||
@@ -1,29 +1,134 @@
|
|||||||
# rust-template
|
# mac2ip
|
||||||
|
|
||||||
Ein modernes Template-Projekt für Rust-basierte Linux-Anwendungen und Kommandozeilen-Tools (CLI).
|
[](https://gitea.creative-dragonslayer.de/Linuxapps/Mac2Ip/actions?workflow=main.yaml)
|
||||||
|
[](https://gitea.creative-dragonslayer.de/Linuxapps/Mac2Ip/actions?workflow=testing.yaml)
|
||||||
|
|
||||||
Dieses Template bietet eine vorkonfigurierte Umgebung für modernes Rust (Edition 2024), automatisierte Multi-Architektur-Kompilierung und native Paketierung für die gängigsten Linux-Distributionen (Debian/Ubuntu, Fedora/RHEL, Arch Linux) sowie vollständige CI/CD-Pipelines für Gitea Actions (kompatibel mit Forgejo und GitHub Actions).
|
Ein Kommandozeilen-Tool (CLI), das zuverlässig die aktuelle IP-Adresse zu einer gegebenen MAC-Adresse im lokalen Netzwerk findet.
|
||||||
|
|
||||||
|
Dazu wird ein 3-stufiger Algorithmus verwendet:
|
||||||
|
|
||||||
|
1. **Cache**: Ein globaler, systemweiter Cache (für alle Nutzer dieses Rechners) wird geprüft. Ein Treffer wird nur verwendet, wenn er noch nicht abgelaufen ist (TTL) **und** die IP per Ping erreichbar ist.
|
||||||
|
2. **`ip neigh`**: Die Linux-Nachbartabelle (`ip neigh show`, der moderne Ersatz für den veralteten `arp`-Befehl) wird nach der MAC-Adresse durchsucht. Ein Treffer wird nur verwendet, wenn die IP per Ping erreichbar ist.
|
||||||
|
3. **`nmap`**: Als letzter Schritt wird ein Ping-/ARP-Scan (`nmap -sn`) der lokal angeschlossenen Subnetze durchgeführt. Da MAC-Adressen in der nmap-Ausgabe nur mit Root-Rechten sichtbar sind (ARP-Scans benötigen Raw-Socket-/libpcap-Zugriff), läuft dieser Schritt über `sudo nmap` (bzw. direkt `nmap`, falls das Programm bereits als root läuft). Da ein Subnetz-Scan auf fremden Netzwerken heikel sein kann, wird dieser Schritt nur in einem als vertrauenswürdig eingestuften Netzwerk ausgeführt (siehe [Netzwerk-Vertrauen](#netzwerk-vertrauen)). Wird auch hier keine erreichbare IP gefunden, bricht das Programm mit einem Fehler ("nicht gefunden") ab.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **Rust Edition 2024**: Moderner Rust-Sprachstandard.
|
- **Zuverlässige MAC → IP-Auflösung** über Cache, `ip neigh` und `nmap`, jeweils mit Erreichbarkeitsprüfung per Ping.
|
||||||
- **Multi-Architektur-Kompilierung**:
|
- **Globaler, systemweiter Cache** (via [`turso`](https://turso.tech), lokal-dateibasiert) mit konfigurierbarer TTL.
|
||||||
- `x86_64-unknown-linux-gnu` (64-Bit x86)
|
- **Maschinenlesbare Ausgabe** über `--json` (unattended-Modus) — unterdrückt dabei alle sonstigen Log-Ausgaben.
|
||||||
- `aarch64-unknown-linux-gnu` (64-Bit ARM / ARM64)
|
- **Vollständig über die Kommandozeile konfigurierbar**, mit Overlay-Kette CLI > Umgebungsvariable > Konfigurationsdatei > Standardwert.
|
||||||
- `i686-unknown-linux-gnu` (32-Bit x86)
|
- **Funktioniert mit und ohne `sudo`** — Root-Rechte werden nur für den nmap-Schritt benötigt.
|
||||||
- **Linux-Paketierung out-of-the-box**:
|
- **Rust Edition 2024**, Multi-Architektur-Kompilierung (`x86_64`, `aarch64`), native Linux-Paketierung (`.deb`, `.rpm`, `.pkg.tar.zst`) und automatisierte CI/CD-Pipelines via Gitea Actions.
|
||||||
- **Debian / Ubuntu** (`.deb` via `cargo-deb`)
|
|
||||||
- **Fedora / RHEL / openSUSE** (`.rpm` via `cargo-generate-rpm`)
|
---
|
||||||
- **Arch Linux** (`.pkg.tar.zst` via mitgeliefertem `scripts/package-arch.py`)
|
|
||||||
- **Automatisierte CI/CD-Pipelines**:
|
## CLI-Nutzung
|
||||||
- `main`-Branch: Erstellt stabile Builds, ermittelt dynamisch Build-Nummern, paketiert für alle Architekturen, lädt Pakete in die Gitea Package Registry und erstellt Gitea Releases mit Dateianhängen.
|
|
||||||
- `testing`-Branch: Erstellt Preview-Builds und Pre-Releases mit Testing-Paketen.
|
```bash
|
||||||
- **Automatisierte Versions- & Build-Nummern**:
|
mac2ip <MAC> [OPTIONEN]
|
||||||
- `scripts/get-build-number.py` fragt Gitea Releases, die Package Registry sowie lokale Artefakte ab, um Revisions-/Release-Nummern (z. B. `1.0.0-1`, `1.0.0-2`) automatisch zu erhöhen.
|
```
|
||||||
- **Vorkonfigurierte Cargo-Einstellungen**:
|
|
||||||
- `.cargo/config.toml` mit vorkonfigurierten Cross-Compilation-Linkern und Unterstützung für private/öffentliche Cargo Registries.
|
Beispiel:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mac2ip aa:bb:cc:dd:ee:ff
|
||||||
|
aa:bb:cc:dd:ee:ff -> 192.168.1.42 (Quelle: cache)
|
||||||
|
```
|
||||||
|
|
||||||
|
Maschinenlesbare Ausgabe (unattended-Modus):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ mac2ip aa:bb:cc:dd:ee:ff --json
|
||||||
|
{"status":"ok","mac":"aa:bb:cc:dd:ee:ff","ip":"192.168.1.42","source":"cache"}
|
||||||
|
```
|
||||||
|
|
||||||
|
Bei Fehlern (`status: "error"`) ist `source` nicht enthalten, dafür ein `error`-Feld mit einer Beschreibung; der Exit-Code ist in beiden Fällen ungleich 0 (`1`) bei Fehlschlag.
|
||||||
|
|
||||||
|
### Optionen
|
||||||
|
|
||||||
|
| Option | Umgebungsvariable | Standard | Beschreibung |
|
||||||
|
| :--- | :--- | :--- | :--- |
|
||||||
|
| `--json` | - | aus | Gibt das Ergebnis als einzeiliges JSON-Objekt aus; unterdrückt alle sonstigen Log-Ausgaben. |
|
||||||
|
| `--config <PATH>` | - | siehe unten | Benutzerdefinierter Pfad zur Konfigurationsdatei. |
|
||||||
|
| `--log-level <LEVEL>` | `MAC2IP_LOG_LEVEL` | `info` | Logging-Level: `error`, `warn`, `info`, `debug`. |
|
||||||
|
| `--cache-ttl-seconds <N>` | `MAC2IP_CACHE_TTL_SECONDS` | `1800` | Wie lange ein Cache-Eintrag als gültig angesehen wird (zusätzlich zur Ping-Prüfung). |
|
||||||
|
| `--cache-db-path <PATH>` | `MAC2IP_CACHE_DB_PATH` | `/var/lib/mac2ip/cache.db` | Pfad zur globalen Cache-Datenbankdatei. |
|
||||||
|
| `--nmap-timeout-seconds <N>` | `MAC2IP_NMAP_TIMEOUT_SECONDS` | `120` | Timeout für einen einzelnen nmap-Subnetz-Scan. |
|
||||||
|
| `--networks <CIDR,CIDR,...>` | `MAC2IP_NETWORKS` | Auto-Erkennung | Kommagetrennte Liste von Subnetzen für den nmap-Scan; überschreibt die automatische Erkennung über `ip route`. |
|
||||||
|
| `--trusted-networks <MAC,MAC,...>` | `MAC2IP_TRUSTED_NETWORKS` | leer | Kommagetrennte Liste von Gateway-MAC-Adressen, deren Netzwerke ohne Rückfrage für nmap-Scans (Schritt 3) vertraut werden; überschreibt die Konfigurationsdatei vollständig. |
|
||||||
|
| `--auto-trust-networks` | - | aus | Beantwortet die "Netzwerk vertrauen?"-Rückfrage vor Schritt 3 automatisch mit Ja (und merkt sich das Netzwerk dauerhaft im Cache), statt interaktiv nachzufragen bzw. im `--json`-Modus abzulehnen. |
|
||||||
|
|
||||||
|
Die Überschreibungs-Reihenfolge ist immer: **CLI-Flag > Umgebungsvariable > Konfigurationsdatei > Standardwert.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Konfigurationsdatei
|
||||||
|
|
||||||
|
Die Konfiguration wird über [`config-ctdra`](https://gitea.creative-dragonslayer.de/Rust-Crates) verwaltet:
|
||||||
|
|
||||||
|
- Als **root** (bzw. beim nmap-Schritt via `sudo`): `/etc/mac2ip/config.toml`
|
||||||
|
- Als **normaler Nutzer**: `~/.config/mac2ip/config.toml`
|
||||||
|
- Oder explizit über `--config <PATH>`
|
||||||
|
|
||||||
|
Beispiel:
|
||||||
|
|
||||||
|
```toml
|
||||||
|
cache_ttl_seconds = 1800
|
||||||
|
cache_db_path = "/var/lib/mac2ip/cache.db"
|
||||||
|
log_level = "info"
|
||||||
|
nmap_timeout_seconds = 120
|
||||||
|
networks = []
|
||||||
|
trusted_networks = []
|
||||||
|
```
|
||||||
|
|
||||||
|
Alle Felder sind optional (fehlende Felder verwenden den Standardwert) und können, wie oben beschrieben, zusätzlich per CLI-Flag oder Umgebungsvariable überschrieben werden.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Caching & TTL
|
||||||
|
|
||||||
|
Der Cache liegt standardmäßig unter `/var/lib/mac2ip/cache.db` — **global für alle Nutzer des Rechners**, nicht pro Benutzerkonto. Verzeichnis und Datei sind bewusst world-writable (`0777`/`0666`), damit auch unprivilegierte Nutzer den Cache lesen und schreiben können, ohne dass mac2ip dafür Root-Rechte bräuchte.
|
||||||
|
|
||||||
|
Ein Cache-Treffer wird nur verwendet, wenn:
|
||||||
|
1. der Eintrag noch nicht älter als `cache_ttl_seconds` ist (Standard: 30 Minuten), **und**
|
||||||
|
2. die gespeicherte IP-Adresse aktuell per Ping erreichbar ist.
|
||||||
|
|
||||||
|
Die Ping-Prüfung ist die primäre Absicherung gegen veraltete Zuordnungen; die TTL ist eine zusätzliche Absicherung für den Fall, dass eine alte IP-Adresse inzwischen an ein anderes, ebenfalls erreichbares Gerät vergeben wurde (z. B. nach einem DHCP-Lease-Wechsel).
|
||||||
|
|
||||||
|
Kann das Cache-Verzeichnis beim Programmstart nicht angelegt/beschrieben werden (z. B. bei einem Entwicklungslauf ohne vorherige Paketinstallation), wird der Cache für diesen Lauf einfach deaktiviert (eine Warnung wird geloggt, im `--json`-Modus unterdrückt) — mac2ip führt den Lookup dann ohne Cache über `ip neigh`/`nmap` durch. Bei einer Installation über `.deb`/`.rpm`/`.pkg.tar.zst` wird das Verzeichnis automatisch mit den richtigen Rechten angelegt (siehe Paketierungs-Postinstall-Skripte unter `packaging/`).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Netzwerk-Vertrauen
|
||||||
|
|
||||||
|
Ein `nmap`-Subnetz-Scan (Schritt 3) ist auf Netzwerken, die man nicht selbst administriert (Firmen-/Gast-WLAN, Kundenstandort etc.), potenziell heikel — er kann IDS-Alarme auslösen oder gegen eine Nutzungsordnung verstoßen. mac2ip führt Schritt 3 deshalb nur in einem als vertrauenswürdig eingestuften Netzwerk aus.
|
||||||
|
|
||||||
|
Das aktuelle Netzwerk wird über die **MAC-Adresse seines Default-Gateways** identifiziert — sie bleibt stabil, solange derselbe Router im Einsatz ist, unabhängig von SSID oder wechselndem DHCP-Subnetz. Ein Netzwerk gilt als vertrauenswürdig, wenn eine der folgenden Bedingungen zutrifft:
|
||||||
|
|
||||||
|
1. Die Gateway-MAC steht in `trusted_networks` (Konfigurationsdatei oder `--trusted-networks`).
|
||||||
|
2. Das Netzwerk wurde bereits einmal per Rückfrage bestätigt — das Ergebnis wird dauerhaft im globalen Cache gespeichert, sodass beim nächsten Besuch (auch nach Neustart) keine erneute Rückfrage nötig ist.
|
||||||
|
3. `--auto-trust-networks` ist gesetzt: Die Rückfrage wird automatisch mit Ja beantwortet und das Ergebnis ebenfalls im Cache gemerkt.
|
||||||
|
|
||||||
|
Ist keine der Bedingungen erfüllt:
|
||||||
|
- Im **interaktiven Modus** fragt mac2ip auf stderr nach, ob der Scan in diesem Netzwerk erlaubt werden soll.
|
||||||
|
- Im **`--json`-Modus** ist keine Rückfrage möglich (die Ausgabe darf nicht durch einen Prompt verunreinigt werden) — der Scan wird sicherheitshalber abgelehnt und ein Fehler zurückgegeben. Für unbeaufsichtigte Läufe in bekannten Netzwerken also entweder `trusted_networks` vorkonfigurieren oder einmalig interaktiv (ohne `--json`) bestätigen.
|
||||||
|
|
||||||
|
Kann die Gateway-MAC nicht ermittelt werden (z. B. kein Default-Gateway vorhanden), wird der Scan ebenfalls abgelehnt, außer `--auto-trust-networks` ist gesetzt.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Voraussetzungen
|
||||||
|
|
||||||
|
Neben Rust/Cargo zur Laufzeit benötigt werden folgende System-Tools:
|
||||||
|
|
||||||
|
- `ip` (Paket `iproute2`) — für Schritt 2 (`ip neigh`) und die automatische Subnetz-Erkennung.
|
||||||
|
- `ping` (Paket `iputils`/`iputils-ping`) — für die Erreichbarkeitsprüfung.
|
||||||
|
- `nmap` — für Schritt 3.
|
||||||
|
- `sudo` — nur nötig, wenn Schritt 3 erreicht wird und das Programm nicht bereits als root läuft.
|
||||||
|
|
||||||
|
Im `--json`-Modus wird für Schritt 3 ausschließlich `sudo -n` (nicht-interaktiv) verwendet, damit das Programm niemals interaktiv nach einem Passwort fragt und dadurch ein Skript blockiert. Ist keine gültige sudo-Sitzung/NOPASSWD-Regel vorhanden, wird Schritt 3 abgebrochen und das Ergebnis als "nicht gefunden" zurückgegeben. Im interaktiven (Nicht-JSON-)Modus darf `sudo` regulär nach einem Passwort fragen.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -36,11 +141,24 @@ Dieses Template bietet eine vorkonfigurierte Umgebung für modernes Rust (Editio
|
|||||||
│ └── workflows/
|
│ └── workflows/
|
||||||
│ ├── main.yaml # CI/CD-Workflow für stabile Releases (main-Branch)
|
│ ├── main.yaml # CI/CD-Workflow für stabile Releases (main-Branch)
|
||||||
│ └── testing.yaml # CI/CD-Workflow für Pre-Releases (testing-Branch)
|
│ └── testing.yaml # CI/CD-Workflow für Pre-Releases (testing-Branch)
|
||||||
|
├── packaging/
|
||||||
|
│ ├── deb/postinst # Debian-Postinstall: legt /var/lib/mac2ip an
|
||||||
|
│ └── arch/mac2ip.install # Arch-Install-Skriptlet: legt /var/lib/mac2ip an
|
||||||
├── scripts/
|
├── scripts/
|
||||||
│ ├── get-build-number.py # Dynamische Ermittlung der nächsten Paket-Revisionsnummer
|
│ ├── get-build-number.py # Dynamische Ermittlung der nächsten Paket-Revisionsnummer
|
||||||
│ └── package-arch.py # Erstellung von Arch Linux .pkg.tar.zst Paketen
|
│ └── package-arch.py # Erstellung von Arch Linux .pkg.tar.zst Paketen
|
||||||
├── src/
|
├── src/
|
||||||
│ └── main.rs # Quellcode & Einstiegspunkt der Anwendung
|
│ ├── main.rs # Einstiegspunkt (CLI-Parsing, Wiring)
|
||||||
|
│ ├── lib.rs # Modul-Wurzel (für Integrationstests)
|
||||||
|
│ ├── cli.rs # clap-Kommandozeilen-Definition
|
||||||
|
│ ├── config.rs # AppConfig + config-ctdra-Integration + CLI-Overlay
|
||||||
|
│ ├── log.rs # JSON-Modus-bewusster logger-ctdra-Wrapper
|
||||||
|
│ ├── mac.rs # MacAddress-Typ (Parsing/Kanonisierung)
|
||||||
|
│ ├── cache.rs # Globaler Turso-Cache (MAC -> IP)
|
||||||
|
│ ├── network.rs # ip neigh / ping / nmap: Exec- und Parse-Funktionen
|
||||||
|
│ ├── resolver.rs # 3-Stufen-Algorithmus (Orchestrierung)
|
||||||
|
│ └── output.rs # Human- und JSON-Ausgabe
|
||||||
|
├── tests/ # Integrationstests (pure Parsing-/Logik-Funktionen)
|
||||||
├── Cargo.toml # Cargo Manifest & Paketierungsmetadaten (deb, rpm, arch)
|
├── Cargo.toml # Cargo Manifest & Paketierungsmetadaten (deb, rpm, arch)
|
||||||
├── LICENSE # Lizenzdatei (Standard: GPL-3.0-or-later)
|
├── LICENSE # Lizenzdatei (Standard: GPL-3.0-or-later)
|
||||||
├── AGENTS.md # Richtlinien und Leitfaden für KI-Coding-Agenten
|
├── AGENTS.md # Richtlinien und Leitfaden für KI-Coding-Agenten
|
||||||
@@ -49,39 +167,16 @@ Dieses Template bietet eine vorkonfigurierte Umgebung für modernes Rust (Editio
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Checkliste zur Verwendung als Template
|
|
||||||
|
|
||||||
Wenn du ein neues Projekt aus diesem Template erstellst, gehe folgende Schritte durch:
|
|
||||||
|
|
||||||
1. **`Cargo.toml` anpassen**:
|
|
||||||
- `name`: Den Namen deiner Anwendung setzen.
|
|
||||||
- `version`: Initiale Version festlegen (z. B. `0.1.0`).
|
|
||||||
- `authors`, `repository`, `description`, `license`: Projektdaten eintragen.
|
|
||||||
- Paketierungsabschnitte prüfen:
|
|
||||||
- `[package.metadata.deb]`: `maintainer`, `copyright`, `section`, `extended-description` setzen.
|
|
||||||
- `[package.metadata.generate-rpm]`: `requires` anpassen.
|
|
||||||
- `[package.metadata.arch]`: `depends` und `optdepends` anpassen.
|
|
||||||
2. **`src/` implementieren**:
|
|
||||||
- Eigene Anwendungslogik in `src/main.rs` (bzw. Modulen / `src/lib.rs`) implementieren.
|
|
||||||
- Tests in `src/` oder `tests/` ergänzen.
|
|
||||||
3. **`.cargo/config.toml` prüfen**:
|
|
||||||
- Falls crates.io statt einer privaten Registry genutzt werden soll, den Standard-Registry-Eintrag anpassen oder auskommentieren.
|
|
||||||
4. **CI/CD Secrets konfigurieren**:
|
|
||||||
- In den Repository-Einstellungen von Gitea/Forgejo ein Secret `PACKAGE_TOKEN` (bzw. `GITEA_TOKEN`) mit Rechten für Pakete und Releases hinterlegen.
|
|
||||||
5. **Dokumentation aktualisieren**:
|
|
||||||
- `README.md` an die konkrete Funktionsweise deiner Anwendung anpassen.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Lokale Entwicklung
|
## Lokale Entwicklung
|
||||||
|
|
||||||
### Voraussetzungen
|
### Voraussetzungen
|
||||||
|
|
||||||
- **Rust & Cargo** (aktuelle Stable-Version, Edition 2024 unterstützt)
|
- **Rust & Cargo** (aktuelle Stable-Version, Edition 2024 unterstützt)
|
||||||
- **Python 3** (für Hilfsskripte in `scripts/`)
|
- **Python 3** (für Hilfsskripte in `scripts/`)
|
||||||
|
- Zur Laufzeit: `ip`, `ping`, `nmap`, `sudo` (siehe "Voraussetzungen" oben)
|
||||||
- Für Cross-Compilation (optional):
|
- Für Cross-Compilation (optional):
|
||||||
- `rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu i686-unknown-linux-gnu`
|
- `rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu`
|
||||||
- Cross-Toolchains: `gcc-aarch64-linux-gnu`, `gcc-i686-linux-gnu`
|
- Cross-Toolchains: `gcc-aarch64-linux-gnu`
|
||||||
- Für lokales Paketieren (optional):
|
- Für lokales Paketieren (optional):
|
||||||
- `cargo install cargo-deb cargo-generate-rpm`
|
- `cargo install cargo-deb cargo-generate-rpm`
|
||||||
|
|
||||||
@@ -126,6 +221,7 @@ Erstellt native Arch Linux-Pakete (`.pkg.tar.zst`), ohne dass `makepkg` oder ein
|
|||||||
- Liest Konfiguration aus `[package.metadata.arch]` in `Cargo.toml`.
|
- Liest Konfiguration aus `[package.metadata.arch]` in `Cargo.toml`.
|
||||||
- Installiert die Binary nach `/usr/bin/`, sowie `LICENSE` und `README.md` nach `/usr/share/`.
|
- Installiert die Binary nach `/usr/bin/`, sowie `LICENSE` und `README.md` nach `/usr/share/`.
|
||||||
- Erzeugt eine standardkonforme `.PKGINFO`-Datei und komprimiert das Paket mit `zstandard`.
|
- Erzeugt eine standardkonforme `.PKGINFO`-Datei und komprimiert das Paket mit `zstandard`.
|
||||||
|
- Unterstützt optional ein Install-Skriptlet (`[package.metadata.arch].install_script`), das pacman-konform als `<name>.install` mit `post_install()`/`post_upgrade()` eingebettet wird (bei mac2ip: legt `/var/lib/mac2ip` an).
|
||||||
- Parameter:
|
- Parameter:
|
||||||
- `--target`: Rust Target-Triple (z. B. `x86_64-unknown-linux-gnu`)
|
- `--target`: Rust Target-Triple (z. B. `x86_64-unknown-linux-gnu`)
|
||||||
- `--arch`: Zielarchitektur (z. B. `x86_64`, `aarch64`, `i686`)
|
- `--arch`: Zielarchitektur (z. B. `x86_64`, `aarch64`, `i686`)
|
||||||
@@ -144,5 +240,4 @@ Erstellt native Arch Linux-Pakete (`.pkg.tar.zst`), ohne dass `makepkg` oder ein
|
|||||||
|
|
||||||
## Lizenz
|
## Lizenz
|
||||||
|
|
||||||
Dieses Template steht standardmäßig unter der [GPL-3.0-or-later](LICENSE)-Lizenz. Die Lizenz kann bei Bedarf in `LICENSE` und `Cargo.toml` angepasst werden.
|
mac2ip steht unter der [GPL-3.0-or-later](LICENSE)-Lizenz.
|
||||||
|
|
||||||
|
|||||||
@@ -103,11 +103,11 @@ def build_package(target_triple=None, target_arch=None, pkgrel=None):
|
|||||||
if os.path.exists("README.md"):
|
if os.path.exists("README.md"):
|
||||||
subprocess.run(["install", "-m", "644", "README.md", f"{doc_dir}/README.md"], check=True)
|
subprocess.run(["install", "-m", "644", "README.md", f"{doc_dir}/README.md"], check=True)
|
||||||
|
|
||||||
install_scriptlet_name = None
|
has_install_scriptlet = False
|
||||||
if install_rel_path and os.path.exists(install_rel_path):
|
if install_rel_path and os.path.exists(install_rel_path):
|
||||||
install_scriptlet_name = f"{name}.install"
|
has_install_scriptlet = True
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
["install", "-m", "644", install_rel_path, os.path.join(build_dir, install_scriptlet_name)],
|
["install", "-m", "644", install_rel_path, os.path.join(build_dir, ".INSTALL")],
|
||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -126,8 +126,6 @@ def build_package(target_triple=None, target_arch=None, pkgrel=None):
|
|||||||
f"arch = {arch}",
|
f"arch = {arch}",
|
||||||
f"license = {license_name}",
|
f"license = {license_name}",
|
||||||
]
|
]
|
||||||
if install_scriptlet_name:
|
|
||||||
pkginfo_lines.append(f"install = {install_scriptlet_name}")
|
|
||||||
for dep in depends:
|
for dep in depends:
|
||||||
pkginfo_lines.append(f"depend = {dep}")
|
pkginfo_lines.append(f"depend = {dep}")
|
||||||
for optdep in optdepends:
|
for optdep in optdepends:
|
||||||
@@ -140,8 +138,8 @@ def build_package(target_triple=None, target_arch=None, pkgrel=None):
|
|||||||
os.makedirs("target/arch", exist_ok=True)
|
os.makedirs("target/arch", exist_ok=True)
|
||||||
output_file = os.path.abspath(f"target/arch/{name}-{version}-{pkgrel}-{arch}.pkg.tar.zst")
|
output_file = os.path.abspath(f"target/arch/{name}-{version}-{pkgrel}-{arch}.pkg.tar.zst")
|
||||||
tar_members = [".PKGINFO"]
|
tar_members = [".PKGINFO"]
|
||||||
if install_scriptlet_name:
|
if has_install_scriptlet:
|
||||||
tar_members.append(install_scriptlet_name)
|
tar_members.append(".INSTALL")
|
||||||
tar_members.append("usr")
|
tar_members.append("usr")
|
||||||
subprocess.run(["tar", "--zstd", "-cf", output_file, *tar_members], cwd=build_dir, check=True)
|
subprocess.run(["tar", "--zstd", "-cf", output_file, *tar_members], cwd=build_dir, check=True)
|
||||||
print(f"Arch-Paket erfolgreich erstellt: {output_file}")
|
print(f"Arch-Paket erfolgreich erstellt: {output_file}")
|
||||||
|
|||||||
+84
-1
@@ -38,9 +38,63 @@ impl Cache {
|
|||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
self.conn
|
||||||
|
.execute(
|
||||||
|
"CREATE TABLE IF NOT EXISTS trusted_networks (\
|
||||||
|
gateway_mac TEXT PRIMARY KEY, \
|
||||||
|
trusted_at INTEGER NOT NULL\
|
||||||
|
)",
|
||||||
|
(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Best-effort: gibt bei jedem Fehler `false` zurück (nur eine Warnung wird geloggt) -
|
||||||
|
/// ein Cache-Lesefehler darf ein zuvor bereits bestätigtes Netzwerk nicht plötzlich
|
||||||
|
/// als unbekannt erscheinen lassen, aber sicherheitshalber auch nicht automatisch
|
||||||
|
/// als vertrauenswürdig gelten lassen; der Aufrufer fragt in diesem Fall erneut nach.
|
||||||
|
pub async fn is_trusted_network(&self, gateway_mac: &MacAddress) -> bool {
|
||||||
|
let key = gateway_mac.to_lower_colon();
|
||||||
|
match self
|
||||||
|
.conn
|
||||||
|
.query(
|
||||||
|
"SELECT 1 FROM trusted_networks WHERE gateway_mac = ?1",
|
||||||
|
(key,),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(mut rows) => matches!(rows.next().await, Ok(Some(_))),
|
||||||
|
Err(e) => {
|
||||||
|
crate::log::warn(
|
||||||
|
"cache",
|
||||||
|
&format!("Cache-Lesefehler (trusted_networks): {e}"),
|
||||||
|
);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Best-effort Upsert: merkt sich ein Netzwerk (identifiziert über die Gateway-MAC)
|
||||||
|
/// dauerhaft als vertrauenswürdig für zukünftige nmap-Scans.
|
||||||
|
pub async fn trust_network(&self, gateway_mac: &MacAddress, now: i64) {
|
||||||
|
let key = gateway_mac.to_lower_colon();
|
||||||
|
if let Err(e) = self
|
||||||
|
.conn
|
||||||
|
.execute(
|
||||||
|
"INSERT INTO trusted_networks (gateway_mac, trusted_at) VALUES (?1, ?2) \
|
||||||
|
ON CONFLICT(gateway_mac) DO UPDATE SET trusted_at = excluded.trusted_at",
|
||||||
|
(key, now),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
crate::log::warn(
|
||||||
|
"cache",
|
||||||
|
&format!("Cache-Schreibfehler (trusted_networks, ignoriert): {e}"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Best-effort: gibt bei jedem Fehler `None` zurück (nur eine Warnung wird geloggt).
|
/// Best-effort: gibt bei jedem Fehler `None` zurück (nur eine Warnung wird geloggt).
|
||||||
pub async fn get(&self, mac: &MacAddress) -> Option<CacheEntry> {
|
pub async fn get(&self, mac: &MacAddress) -> Option<CacheEntry> {
|
||||||
let key = mac.to_lower_colon();
|
let key = mac.to_lower_colon();
|
||||||
@@ -109,12 +163,14 @@ fn ensure_cache_dir(dir: &Path) -> Result<(), String> {
|
|||||||
dir.display()
|
dir.display()
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
}
|
|
||||||
// create_dir_all() unterliegt dem Prozess-Umask; explizites chmod ist nötig, um
|
// create_dir_all() unterliegt dem Prozess-Umask; explizites chmod ist nötig, um
|
||||||
// wirklich 0777 zu erreichen (Verzeichnis-Rechte steuern nicht die Umask neuer Dateien).
|
// wirklich 0777 zu erreichen (Verzeichnis-Rechte steuern nicht die Umask neuer Dateien).
|
||||||
|
// Wird nur beim Neuanlegen ausgeführt; bei existierenden Verzeichnissen würde ein
|
||||||
|
// unprivilegierter Aufruf auf root-eigenen Pfaden mit EPERM fehlschlagen.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
std::fs::set_permissions(dir, std::fs::Permissions::from_mode(0o777))
|
std::fs::set_permissions(dir, std::fs::Permissions::from_mode(0o777))
|
||||||
.map_err(|e| format!("Verzeichnis-Rechte konnten nicht gesetzt werden: {e}"))?;
|
.map_err(|e| format!("Verzeichnis-Rechte konnten nicht gesetzt werden: {e}"))?;
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,3 +229,30 @@ pub async fn try_open_cache(db_path: &Path) -> Option<Cache> {
|
|||||||
chmod_cache_sidecars(db_path);
|
chmod_cache_sidecars(db_path);
|
||||||
Some(cache)
|
Some(cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ensure_cache_dir_existing_directory_does_not_fail() {
|
||||||
|
// Bestehende Systemverzeichnisse (die einem unprivilegierten Nutzer nicht gehören)
|
||||||
|
// dürfen beim Überprüfen keinen EPERM-Fehler werfen.
|
||||||
|
assert!(ensure_cache_dir(Path::new("/tmp")).is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ensure_cache_dir_creates_new_directory() {
|
||||||
|
let temp_dir = std::env::temp_dir().join(format!(
|
||||||
|
"mac2ip_test_{}",
|
||||||
|
std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.unwrap()
|
||||||
|
.as_nanos()
|
||||||
|
));
|
||||||
|
assert!(!temp_dir.exists());
|
||||||
|
assert!(ensure_cache_dir(&temp_dir).is_ok());
|
||||||
|
assert!(temp_dir.exists());
|
||||||
|
let _ = std::fs::remove_dir(&temp_dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+11
@@ -45,6 +45,17 @@ pub struct Cli {
|
|||||||
/// Kommagetrennte Liste von CIDR-Subnetzen für den nmap-Scan (überschreibt Auto-Erkennung)
|
/// Kommagetrennte Liste von CIDR-Subnetzen für den nmap-Scan (überschreibt Auto-Erkennung)
|
||||||
#[arg(long, env = "MAC2IP_NETWORKS", value_delimiter = ',')]
|
#[arg(long, env = "MAC2IP_NETWORKS", value_delimiter = ',')]
|
||||||
pub networks: Option<Vec<String>>,
|
pub networks: Option<Vec<String>>,
|
||||||
|
|
||||||
|
/// Kommagetrennte Liste von Gateway-MAC-Adressen, deren Netzwerke ohne Rückfrage für
|
||||||
|
/// nmap-Scans (Schritt 3) vertraut werden (überschreibt die Konfigurationsdatei vollständig)
|
||||||
|
#[arg(long, env = "MAC2IP_TRUSTED_NETWORKS", value_delimiter = ',')]
|
||||||
|
pub trusted_networks: Option<Vec<MacAddress>>,
|
||||||
|
|
||||||
|
/// Beantwortet die "nmap-Scan in diesem Netzwerk erlauben?"-Rückfrage vor Schritt 3
|
||||||
|
/// automatisch mit Ja (und merkt sich das Netzwerk dauerhaft im Cache), statt
|
||||||
|
/// interaktiv nachzufragen bzw. im --json-Modus den Scan abzulehnen
|
||||||
|
#[arg(long)]
|
||||||
|
pub auto_trust_networks: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};
|
|||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::mac::MacAddress;
|
||||||
|
|
||||||
pub const DEFAULT_CACHE_TTL_SECONDS: u64 = 1800; // 30 Min: Ping-Check ist die primäre
|
pub const DEFAULT_CACHE_TTL_SECONDS: u64 = 1800; // 30 Min: Ping-Check ist die primäre
|
||||||
// Absicherung gegen veraltete Einträge, die TTL ist nur eine zusätzliche Absicherung
|
// Absicherung gegen veraltete Einträge, die TTL ist nur eine zusätzliche Absicherung
|
||||||
// gegen den Fall, dass eine alte IP inzwischen an ein anderes, ebenfalls
|
// gegen den Fall, dass eine alte IP inzwischen an ein anderes, ebenfalls
|
||||||
@@ -40,6 +42,11 @@ pub struct AppConfig {
|
|||||||
pub nmap_timeout_seconds: u64,
|
pub nmap_timeout_seconds: u64,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub networks: Vec<String>,
|
pub networks: Vec<String>,
|
||||||
|
/// Gateway-MAC-Adressen von Netzwerken, in denen ein nmap-Scan (Schritt 3) ohne
|
||||||
|
/// interaktive Rückfrage erlaubt ist. Wird um per Rückfrage/`--auto-trust-networks`
|
||||||
|
/// bestätigte Netzwerke ergänzt, die im Cache gespeichert werden (siehe `src/trust.rs`).
|
||||||
|
#[serde(default)]
|
||||||
|
pub trusted_networks: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AppConfig {
|
impl Default for AppConfig {
|
||||||
@@ -50,10 +57,23 @@ impl Default for AppConfig {
|
|||||||
log_level: DEFAULT_LOG_LEVEL.to_string(),
|
log_level: DEFAULT_LOG_LEVEL.to_string(),
|
||||||
nmap_timeout_seconds: DEFAULT_NMAP_TIMEOUT_SECONDS,
|
nmap_timeout_seconds: DEFAULT_NMAP_TIMEOUT_SECONDS,
|
||||||
networks: Vec::new(),
|
networks: Vec::new(),
|
||||||
|
trusted_networks: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AppConfig {
|
||||||
|
/// Reine, testbare Funktion: validiert die konfigurierten vertrauten Netzwerke.
|
||||||
|
/// Nicht als MAC-Adresse parsbare Einträge werden übersprungen (kein harter Fehler,
|
||||||
|
/// da eine fehlerhafte Config-Zeile den Lookup nicht insgesamt scheitern lassen soll).
|
||||||
|
pub fn trusted_network_macs(&self) -> Vec<MacAddress> {
|
||||||
|
self.trusted_networks
|
||||||
|
.iter()
|
||||||
|
.filter_map(|s| MacAddress::parse(s).ok())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Initialisiert den Konfigurationspfad bei `config-ctdra` (Standardname "config",
|
/// Initialisiert den Konfigurationspfad bei `config-ctdra` (Standardname "config",
|
||||||
/// optionaler expliziter Pfad via `--config`).
|
/// optionaler expliziter Pfad via `--config`).
|
||||||
pub fn init_config_path(custom_path: Option<&Path>) {
|
pub fn init_config_path(custom_path: Option<&Path>) {
|
||||||
@@ -90,4 +110,7 @@ pub fn apply_cli_overrides(config: &mut AppConfig, cli: &crate::cli::Cli) {
|
|||||||
if let Some(networks) = &cli.networks {
|
if let Some(networks) = &cli.networks {
|
||||||
config.networks = networks.clone();
|
config.networks = networks.clone();
|
||||||
}
|
}
|
||||||
|
if let Some(trusted) = &cli.trusted_networks {
|
||||||
|
config.trusted_networks = trusted.iter().map(MacAddress::to_lower_colon).collect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ use crate::mac::MacAddressError;
|
|||||||
pub enum Mac2IpError {
|
pub enum Mac2IpError {
|
||||||
#[error("keine IP-Adresse für MAC '{mac}' gefunden")]
|
#[error("keine IP-Adresse für MAC '{mac}' gefunden")]
|
||||||
NotFound { mac: String },
|
NotFound { mac: String },
|
||||||
|
#[error(
|
||||||
|
"nmap-Scan abgelehnt: Netzwerk nicht vertrauenswürdig{}",
|
||||||
|
.gateway_mac.as_ref().map(|m| format!(" (Gateway-MAC {m})")).unwrap_or_default()
|
||||||
|
)]
|
||||||
|
UntrustedNetwork { gateway_mac: Option<String> },
|
||||||
#[error("MAC-Adresse ungültig: {0}")]
|
#[error("MAC-Adresse ungültig: {0}")]
|
||||||
InvalidMac(#[from] MacAddressError),
|
InvalidMac(#[from] MacAddressError),
|
||||||
#[error("E/A-Fehler: {0}")]
|
#[error("E/A-Fehler: {0}")]
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ pub mod mac;
|
|||||||
pub mod network;
|
pub mod network;
|
||||||
pub mod output;
|
pub mod output;
|
||||||
pub mod resolver;
|
pub mod resolver;
|
||||||
|
pub mod trust;
|
||||||
|
|||||||
+9
-1
@@ -23,7 +23,15 @@ async fn main() -> ExitCode {
|
|||||||
|
|
||||||
let cache = cache::try_open_cache(&app_config.cache_db_path).await;
|
let cache = cache::try_open_cache(&app_config.cache_db_path).await;
|
||||||
|
|
||||||
match resolver::resolve(&cli.mac, &app_config, cache.as_ref(), cli.json).await {
|
match resolver::resolve(
|
||||||
|
&cli.mac,
|
||||||
|
&app_config,
|
||||||
|
cache.as_ref(),
|
||||||
|
cli.json,
|
||||||
|
cli.auto_trust_networks,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
output::print_success(&result, cli.json);
|
output::print_success(&result, cli.json);
|
||||||
ExitCode::SUCCESS
|
ExitCode::SUCCESS
|
||||||
|
|||||||
+79
-2
@@ -30,6 +30,31 @@ pub async fn run_ip_route_show_scope_link() -> std::io::Result<String> {
|
|||||||
Ok(String::from_utf8_lossy(&out.stdout).into_owned())
|
Ok(String::from_utf8_lossy(&out.stdout).into_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn run_ip_route_show_default() -> std::io::Result<String> {
|
||||||
|
let out = tokio::process::Command::new("ip")
|
||||||
|
.args(["-4", "route", "show", "default"])
|
||||||
|
.output()
|
||||||
|
.await?;
|
||||||
|
Ok(String::from_utf8_lossy(&out.stdout).into_owned())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ermittelt die MAC-Adresse des aktuellen Default-Gateways - dient als stabiler
|
||||||
|
/// Identifikator für "dieses Netzwerk" (bleibt bei DHCP-Subnetzwechsel gleich,
|
||||||
|
/// solange derselbe Router im Einsatz ist), unabhängig von SSID/CIDR.
|
||||||
|
/// Gibt `None` zurück, wenn kein Default-Gateway existiert oder dessen MAC nicht
|
||||||
|
/// ermittelt werden kann (z. B. kein Nachbar-Eintrag trotz Ping).
|
||||||
|
pub async fn detect_default_gateway_mac() -> Option<MacAddress> {
|
||||||
|
let route_output = run_ip_route_show_default().await.ok()?;
|
||||||
|
let gateway_ip = parse_default_gateway_ip(&route_output)?;
|
||||||
|
|
||||||
|
// Erzwingt best-effort einen frischen Nachbar-Tabelleneintrag; Ergebnis wird
|
||||||
|
// ignoriert, da `ip neigh` auch von einem veralteten/STALE-Eintrag profitiert.
|
||||||
|
let _ = ping_check(gateway_ip).await;
|
||||||
|
|
||||||
|
let neigh_output = run_ip_neigh_show().await.ok()?;
|
||||||
|
parse_ip_neigh_mac_for_ip(&neigh_output, gateway_ip)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn ping_check(ip: IpAddr) -> bool {
|
pub async fn ping_check(ip: IpAddr) -> bool {
|
||||||
tokio::process::Command::new("ping")
|
tokio::process::Command::new("ping")
|
||||||
.args([
|
.args([
|
||||||
@@ -95,10 +120,34 @@ pub async fn run_nmap_scan(
|
|||||||
// unabhängig von der System-Locale funktioniert (z. B. "Passwort ist notwendig"
|
// unabhängig von der System-Locale funktioniert (z. B. "Passwort ist notwendig"
|
||||||
// auf einem deutschen System würde sonst nicht erkannt werden).
|
// auf einem deutschen System würde sonst nicht erkannt werden).
|
||||||
cmd.env("LC_ALL", "C").env("LANG", "C");
|
cmd.env("LC_ALL", "C").env("LANG", "C");
|
||||||
|
cmd.kill_on_drop(true);
|
||||||
|
// Eigene Prozessgruppe: `kill_on_drop`/Child::kill() signalisiert bei einem
|
||||||
|
// Timeout nur den direkten Kind-Prozess. Im Sudo-Fall ist das `sudo` selbst,
|
||||||
|
// nicht das von `sudo` geforkte (als root laufende) `nmap`. Ohne eigene
|
||||||
|
// Prozessgruppe würde `sudo` beim SIGKILL sterben, während `nmap` als
|
||||||
|
// root-Waise weiterläuft und den Scan fortsetzt.
|
||||||
|
cmd.process_group(0);
|
||||||
|
|
||||||
let out = tokio::time::timeout(Duration::from_secs(timeout_secs), cmd.output())
|
let child = cmd.spawn()?;
|
||||||
|
let pgid = child.id();
|
||||||
|
|
||||||
|
let out =
|
||||||
|
match tokio::time::timeout(Duration::from_secs(timeout_secs), child.wait_with_output())
|
||||||
.await
|
.await
|
||||||
.map_err(|_| NmapRunError::Timeout)??;
|
{
|
||||||
|
Ok(out) => out?,
|
||||||
|
Err(_) => {
|
||||||
|
if let Some(pgid) = pgid {
|
||||||
|
// Negative PID = Signal an die gesamte Prozessgruppe (sudo + nmap).
|
||||||
|
let _ = tokio::process::Command::new("kill")
|
||||||
|
.arg("-KILL")
|
||||||
|
.arg(format!("-{pgid}"))
|
||||||
|
.output()
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
return Err(NmapRunError::Timeout);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if !out.status.success() {
|
if !out.status.success() {
|
||||||
let stderr = String::from_utf8_lossy(&out.stderr);
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||||
@@ -136,6 +185,34 @@ pub fn parse_ip_neigh_output(output: &str, mac: &MacAddress) -> Option<IpAddr> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Parst `ip -4 route show default`, z. B. "default via 192.168.1.1 dev eth0 proto dhcp
|
||||||
|
/// metric 100". Gibt die Gateway-IP zurück (Token direkt nach "via").
|
||||||
|
pub fn parse_default_gateway_ip(output: &str) -> Option<IpAddr> {
|
||||||
|
output.lines().find_map(|line| {
|
||||||
|
let tokens: Vec<&str> = line.split_whitespace().collect();
|
||||||
|
let pos = tokens.iter().position(|&t| t == "via")?;
|
||||||
|
tokens.get(pos + 1)?.parse().ok()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parst `ip neigh show`-Ausgabe und gibt die `lladdr`-MAC des Eintrags zurück, dessen
|
||||||
|
/// erste Spalte (IP) mit `target_ip` übereinstimmt. Kehrbild zu [`parse_ip_neigh_output`].
|
||||||
|
pub fn parse_ip_neigh_mac_for_ip(output: &str, target_ip: IpAddr) -> Option<MacAddress> {
|
||||||
|
for line in output.lines() {
|
||||||
|
let tokens: Vec<&str> = line.split_whitespace().collect();
|
||||||
|
if tokens.first().and_then(|t| t.parse::<IpAddr>().ok()) != Some(target_ip) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if let Some(pos) = tokens.iter().position(|&t| t == "lladdr")
|
||||||
|
&& let Some(&mac_str) = tokens.get(pos + 1)
|
||||||
|
&& let Ok(mac) = mac_str.parse()
|
||||||
|
{
|
||||||
|
return Some(mac);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Extrahiert lokale CIDR-Subnetze aus `ip -4 route show scope link`.
|
/// Extrahiert lokale CIDR-Subnetze aus `ip -4 route show scope link`.
|
||||||
/// Die CIDR ist bereits das erste whitespace-getrennte Token pro passender Zeile.
|
/// Die CIDR ist bereits das erste whitespace-getrennte Token pro passender Zeile.
|
||||||
/// Überspringt `default`-Zeilen und das Loopback-Interface.
|
/// Überspringt `default`-Zeilen und das Loopback-Interface.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::config::AppConfig;
|
|||||||
use crate::error::Mac2IpError;
|
use crate::error::Mac2IpError;
|
||||||
use crate::mac::MacAddress;
|
use crate::mac::MacAddress;
|
||||||
use crate::network::{self, NmapRunError, SudoMode};
|
use crate::network::{self, NmapRunError, SudoMode};
|
||||||
|
use crate::trust::{self, TrustDecision};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum MatchSource {
|
pub enum MatchSource {
|
||||||
@@ -44,6 +45,7 @@ pub async fn resolve(
|
|||||||
config: &AppConfig,
|
config: &AppConfig,
|
||||||
cache: Option<&Cache>,
|
cache: Option<&Cache>,
|
||||||
json_mode: bool,
|
json_mode: bool,
|
||||||
|
auto_trust_networks: bool,
|
||||||
) -> Result<ResolveResult, Mac2IpError> {
|
) -> Result<ResolveResult, Mac2IpError> {
|
||||||
let now = now_unix();
|
let now = now_unix();
|
||||||
|
|
||||||
@@ -86,6 +88,20 @@ pub async fn resolve(
|
|||||||
|
|
||||||
// Schritt 3: nmap
|
// Schritt 3: nmap
|
||||||
crate::log::debug("resolver", "Kein Treffer via ip neigh, starte nmap-Scan");
|
crate::log::debug("resolver", "Kein Treffer via ip neigh, starte nmap-Scan");
|
||||||
|
|
||||||
|
match trust::ensure_network_trusted(config, cache, auto_trust_networks, json_mode, now).await {
|
||||||
|
TrustDecision::Allowed => {}
|
||||||
|
TrustDecision::Denied { gateway_mac } => {
|
||||||
|
crate::log::warn(
|
||||||
|
"resolver",
|
||||||
|
"nmap-Scan übersprungen: Netzwerk nicht als vertrauenswürdig bestätigt",
|
||||||
|
);
|
||||||
|
return Err(Mac2IpError::UntrustedNetwork {
|
||||||
|
gateway_mac: gateway_mac.map(|m| m.to_string()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let subnets = if !config.networks.is_empty() {
|
let subnets = if !config.networks.is_empty() {
|
||||||
config.networks.clone()
|
config.networks.clone()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
//! Netzwerk-Vertrauensprüfung vor dem nmap-Scan (Schritt 3).
|
||||||
|
//!
|
||||||
|
//! Ein ARP-/Ping-Scan ganzer Subnetze ist auf Netzwerken, die man nicht selbst
|
||||||
|
//! administriert (Firmen-/Gast-WLAN etc.), potenziell heikel (IDS-Alarm, Verstoß gegen
|
||||||
|
//! Nutzungsordnungen). Das aktuelle Netzwerk wird daher über die MAC-Adresse seines
|
||||||
|
//! Default-Gateways identifiziert (stabil über IP-/Subnetzwechsel hinweg) und nmap darf
|
||||||
|
//! nur laufen, wenn dieses Netzwerk explizit vertraut ist:
|
||||||
|
//! - statisch über `AppConfig::trusted_networks` (Config-Datei/CLI/ENV), oder
|
||||||
|
//! - dynamisch über eine frühere Bestätigung, die im Cache gespeichert wurde, oder
|
||||||
|
//! - automatisch, wenn `--auto-trust-networks` gesetzt ist (merkt sich das Netzwerk
|
||||||
|
//! danach ebenfalls im Cache).
|
||||||
|
//!
|
||||||
|
//! Ist keins davon der Fall, wird im interaktiven Modus nachgefragt; im --json-Modus
|
||||||
|
//! ist keine Rückfrage möglich, daher wird sicherheitshalber abgelehnt.
|
||||||
|
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
|
use crate::cache::Cache;
|
||||||
|
use crate::config::AppConfig;
|
||||||
|
use crate::mac::MacAddress;
|
||||||
|
use crate::network;
|
||||||
|
|
||||||
|
pub enum TrustDecision {
|
||||||
|
Allowed,
|
||||||
|
Denied { gateway_mac: Option<MacAddress> },
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn ensure_network_trusted(
|
||||||
|
config: &AppConfig,
|
||||||
|
cache: Option<&Cache>,
|
||||||
|
auto_trust: bool,
|
||||||
|
json_mode: bool,
|
||||||
|
now: i64,
|
||||||
|
) -> TrustDecision {
|
||||||
|
let Some(gateway_mac) = network::detect_default_gateway_mac().await else {
|
||||||
|
crate::log::warn(
|
||||||
|
"trust",
|
||||||
|
"Gateway-MAC konnte nicht ermittelt werden, Netzwerk kann nicht identifiziert werden",
|
||||||
|
);
|
||||||
|
if auto_trust {
|
||||||
|
crate::log::warn(
|
||||||
|
"trust",
|
||||||
|
"--auto-trust-networks gesetzt: nmap-Scan wird trotz unbekannter Gateway-MAC ausgeführt",
|
||||||
|
);
|
||||||
|
return TrustDecision::Allowed;
|
||||||
|
}
|
||||||
|
return TrustDecision::Denied { gateway_mac: None };
|
||||||
|
};
|
||||||
|
|
||||||
|
if config.trusted_network_macs().contains(&gateway_mac) {
|
||||||
|
return TrustDecision::Allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(cache) = cache
|
||||||
|
&& cache.is_trusted_network(&gateway_mac).await
|
||||||
|
{
|
||||||
|
return TrustDecision::Allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if auto_trust {
|
||||||
|
crate::log::info(
|
||||||
|
"trust",
|
||||||
|
&format!(
|
||||||
|
"Netzwerk (Gateway-MAC {gateway_mac}) automatisch als vertrauenswürdig markiert"
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if let Some(cache) = cache {
|
||||||
|
cache.trust_network(&gateway_mac, now).await;
|
||||||
|
}
|
||||||
|
return TrustDecision::Allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if json_mode {
|
||||||
|
// Keine Rückfrage im --json-Modus möglich (stdin ggf. nicht an ein Terminal
|
||||||
|
// gebunden, Ausgabe darf nicht durch einen Prompt verunreinigt werden).
|
||||||
|
return TrustDecision::Denied {
|
||||||
|
gateway_mac: Some(gateway_mac),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if prompt_trust_confirmation(gateway_mac).await {
|
||||||
|
if let Some(cache) = cache {
|
||||||
|
cache.trust_network(&gateway_mac, now).await;
|
||||||
|
}
|
||||||
|
TrustDecision::Allowed
|
||||||
|
} else {
|
||||||
|
TrustDecision::Denied {
|
||||||
|
gateway_mac: Some(gateway_mac),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Blockierende stdin-Abfrage, daher in `spawn_blocking` ausgelagert, damit der
|
||||||
|
/// Tokio-Runtime-Thread währenddessen nicht blockiert.
|
||||||
|
async fn prompt_trust_confirmation(gateway_mac: MacAddress) -> bool {
|
||||||
|
tokio::task::spawn_blocking(move || {
|
||||||
|
eprint!(
|
||||||
|
"Unbekanntes Netzwerk (Gateway-MAC {gateway_mac}). nmap-Scan in diesem Netzwerk erlauben und dauerhaft merken? [y/N]: "
|
||||||
|
);
|
||||||
|
let _ = std::io::stderr().flush();
|
||||||
|
|
||||||
|
let mut input = String::new();
|
||||||
|
if std::io::stdin().read_line(&mut input).is_err() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
matches!(input.trim().to_lowercase().as_str(), "y" | "yes" | "j" | "ja")
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
use mac2ip::cache::is_expired;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fresh_entry_is_not_expired() {
|
||||||
|
assert!(!is_expired(1000, 1000, 1800));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn entry_exactly_at_ttl_boundary_is_not_expired() {
|
||||||
|
// now - updated_at == ttl_seconds -> nicht abgelaufen (strikt größer nötig)
|
||||||
|
assert!(!is_expired(1000, 1000 + 1800, 1800));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn entry_one_second_past_ttl_is_expired() {
|
||||||
|
assert!(is_expired(1000, 1000 + 1801, 1800));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn zero_ttl_expires_immediately_after_any_elapsed_time() {
|
||||||
|
assert!(is_expired(1000, 1001, 0));
|
||||||
|
assert!(!is_expired(1000, 1000, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn large_gap_is_expired() {
|
||||||
|
assert!(is_expired(0, 1_000_000, 1800));
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use mac2ip::cli::Cli;
|
||||||
|
use mac2ip::config::{AppConfig, apply_cli_overrides};
|
||||||
|
use mac2ip::mac::MacAddress;
|
||||||
|
|
||||||
|
fn base_cli() -> Cli {
|
||||||
|
Cli {
|
||||||
|
mac: MacAddress::parse("aa:bb:cc:dd:ee:ff").unwrap(),
|
||||||
|
json: false,
|
||||||
|
config: None,
|
||||||
|
log_level: None,
|
||||||
|
cache_ttl_seconds: None,
|
||||||
|
cache_db_path: None,
|
||||||
|
nmap_timeout_seconds: None,
|
||||||
|
networks: None,
|
||||||
|
trusted_networks: None,
|
||||||
|
auto_trust_networks: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_overrides_leaves_config_untouched() {
|
||||||
|
let default_config = AppConfig::default();
|
||||||
|
let mut config = default_config.clone();
|
||||||
|
apply_cli_overrides(&mut config, &base_cli());
|
||||||
|
assert_eq!(config, default_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overrides_cache_ttl_seconds() {
|
||||||
|
let mut config = AppConfig::default();
|
||||||
|
let mut cli = base_cli();
|
||||||
|
cli.cache_ttl_seconds = Some(60);
|
||||||
|
apply_cli_overrides(&mut config, &cli);
|
||||||
|
assert_eq!(config.cache_ttl_seconds, 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overrides_cache_db_path() {
|
||||||
|
let mut config = AppConfig::default();
|
||||||
|
let mut cli = base_cli();
|
||||||
|
cli.cache_db_path = Some(PathBuf::from("/tmp/custom-cache.db"));
|
||||||
|
apply_cli_overrides(&mut config, &cli);
|
||||||
|
assert_eq!(config.cache_db_path, PathBuf::from("/tmp/custom-cache.db"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overrides_nmap_timeout_seconds() {
|
||||||
|
let mut config = AppConfig::default();
|
||||||
|
let mut cli = base_cli();
|
||||||
|
cli.nmap_timeout_seconds = Some(30);
|
||||||
|
apply_cli_overrides(&mut config, &cli);
|
||||||
|
assert_eq!(config.nmap_timeout_seconds, 30);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overrides_networks() {
|
||||||
|
let mut config = AppConfig::default();
|
||||||
|
let mut cli = base_cli();
|
||||||
|
cli.networks = Some(vec!["10.0.0.0/24".to_string()]);
|
||||||
|
apply_cli_overrides(&mut config, &cli);
|
||||||
|
assert_eq!(config.networks, vec!["10.0.0.0/24".to_string()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn overrides_trusted_networks() {
|
||||||
|
let mut config = AppConfig::default();
|
||||||
|
let mut cli = base_cli();
|
||||||
|
cli.trusted_networks = Some(vec![MacAddress::parse("aa:bb:cc:dd:ee:ff").unwrap()]);
|
||||||
|
apply_cli_overrides(&mut config, &cli);
|
||||||
|
assert_eq!(
|
||||||
|
config.trusted_networks,
|
||||||
|
vec!["aa:bb:cc:dd:ee:ff".to_string()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn partial_overrides_only_touch_provided_fields() {
|
||||||
|
let default_config = AppConfig::default();
|
||||||
|
let mut config = default_config.clone();
|
||||||
|
let mut cli = base_cli();
|
||||||
|
cli.cache_ttl_seconds = Some(999);
|
||||||
|
apply_cli_overrides(&mut config, &cli);
|
||||||
|
|
||||||
|
assert_eq!(config.cache_ttl_seconds, 999);
|
||||||
|
assert_eq!(config.cache_db_path, default_config.cache_db_path);
|
||||||
|
assert_eq!(config.log_level, default_config.log_level);
|
||||||
|
assert_eq!(
|
||||||
|
config.nmap_timeout_seconds,
|
||||||
|
default_config.nmap_timeout_seconds
|
||||||
|
);
|
||||||
|
assert_eq!(config.networks, default_config.networks);
|
||||||
|
assert_eq!(config.trusted_networks, default_config.trusted_networks);
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
use std::net::IpAddr;
|
||||||
|
|
||||||
|
use mac2ip::config::AppConfig;
|
||||||
|
use mac2ip::mac::MacAddress;
|
||||||
|
use mac2ip::network::{parse_default_gateway_ip, parse_ip_neigh_mac_for_ip};
|
||||||
|
|
||||||
|
fn mac(s: &str) -> MacAddress {
|
||||||
|
MacAddress::parse(s).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ip(s: &str) -> IpAddr {
|
||||||
|
s.parse().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- parse_default_gateway_ip ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_gateway_ip_from_default_route() {
|
||||||
|
let output = "default via 192.168.1.1 dev eth0 proto dhcp metric 100\n";
|
||||||
|
assert_eq!(parse_default_gateway_ip(output), Some(ip("192.168.1.1")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_gateway_ip_ignoring_extra_trailing_fields() {
|
||||||
|
let output = "default via 10.0.0.254 dev wlan0 proto static metric 600 onlink\n";
|
||||||
|
assert_eq!(parse_default_gateway_ip(output), Some(ip("10.0.0.254")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_default_route_returns_none() {
|
||||||
|
assert!(parse_default_gateway_ip("").is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn missing_via_token_returns_none() {
|
||||||
|
let output = "default dev eth0 proto dhcp metric 100\n";
|
||||||
|
assert!(parse_default_gateway_ip(output).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- parse_ip_neigh_mac_for_ip ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn finds_mac_for_matching_ip() {
|
||||||
|
let output = "192.168.1.1 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE\n";
|
||||||
|
let result = parse_ip_neigh_mac_for_ip(output, ip("192.168.1.1"));
|
||||||
|
assert_eq!(result, Some(mac("aa:bb:cc:dd:ee:ff")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ignores_entries_for_other_ips() {
|
||||||
|
let output = "\
|
||||||
|
192.168.1.2 dev eth0 lladdr 11:22:33:44:55:66 STALE
|
||||||
|
192.168.1.1 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE
|
||||||
|
";
|
||||||
|
let result = parse_ip_neigh_mac_for_ip(output, ip("192.168.1.1"));
|
||||||
|
assert_eq!(result, Some(mac("aa:bb:cc:dd:ee:ff")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn returns_none_when_ip_not_present() {
|
||||||
|
let output = "192.168.1.2 dev eth0 lladdr 11:22:33:44:55:66 STALE\n";
|
||||||
|
assert!(parse_ip_neigh_mac_for_ip(output, ip("192.168.1.1")).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- AppConfig::trusted_network_macs ---
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trusted_network_macs_parses_valid_entries() {
|
||||||
|
let config = AppConfig {
|
||||||
|
trusted_networks: vec!["aa:bb:cc:dd:ee:ff".to_string()],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
config.trusted_network_macs(),
|
||||||
|
vec![mac("aa:bb:cc:dd:ee:ff")]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trusted_network_macs_skips_invalid_entries() {
|
||||||
|
let config = AppConfig {
|
||||||
|
trusted_networks: vec!["not-a-mac".to_string(), "aa:bb:cc:dd:ee:ff".to_string()],
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
assert_eq!(
|
||||||
|
config.trusted_network_macs(),
|
||||||
|
vec![mac("aa:bb:cc:dd:ee:ff")]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trusted_network_macs_empty_by_default() {
|
||||||
|
assert!(AppConfig::default().trusted_network_macs().is_empty());
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
use mac2ip::mac::MacAddress;
|
||||||
|
use mac2ip::network::parse_ip_neigh_output;
|
||||||
|
|
||||||
|
fn mac(s: &str) -> MacAddress {
|
||||||
|
MacAddress::parse(s).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn finds_matching_entry() {
|
||||||
|
let output = "192.168.1.5 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE\n";
|
||||||
|
let ip = parse_ip_neigh_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn picks_correct_entry_among_multiple() {
|
||||||
|
let output = "\
|
||||||
|
192.168.1.4 dev eth0 lladdr 11:22:33:44:55:66 STALE
|
||||||
|
192.168.1.5 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE
|
||||||
|
192.168.1.6 dev eth0 lladdr 77:88:99:aa:bb:cc STALE
|
||||||
|
";
|
||||||
|
let ip = parse_ip_neigh_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn skips_entries_without_lladdr() {
|
||||||
|
let output = "\
|
||||||
|
192.168.1.7 dev eth0 FAILED
|
||||||
|
192.168.1.5 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE
|
||||||
|
";
|
||||||
|
let ip = parse_ip_neigh_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn returns_none_when_no_match() {
|
||||||
|
let output = "192.168.1.4 dev eth0 lladdr 11:22:33:44:55:66 STALE\n";
|
||||||
|
assert!(parse_ip_neigh_output(output, &mac("aa:bb:cc:dd:ee:ff")).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn tolerates_blank_lines_and_extra_whitespace() {
|
||||||
|
let output = "\n \n192.168.1.5 dev eth0 lladdr aa:bb:cc:dd:ee:ff REACHABLE\n\n";
|
||||||
|
let ip = parse_ip_neigh_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_output_returns_none() {
|
||||||
|
assert!(parse_ip_neigh_output("", &mac("aa:bb:cc:dd:ee:ff")).is_none());
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
use std::net::IpAddr;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use mac2ip::error::Mac2IpError;
|
||||||
|
use mac2ip::mac::MacAddress;
|
||||||
|
use mac2ip::output::{SuccessJson, failure_json, success_json};
|
||||||
|
use mac2ip::resolver::{MatchSource, ResolveResult};
|
||||||
|
|
||||||
|
fn mac() -> MacAddress {
|
||||||
|
MacAddress::parse("aa:bb:cc:dd:ee:ff").unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ip() -> IpAddr {
|
||||||
|
IpAddr::from_str("192.168.1.5").unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn success_json_has_expected_shape_for_cache_source() {
|
||||||
|
let result = ResolveResult {
|
||||||
|
mac: mac(),
|
||||||
|
ip: ip(),
|
||||||
|
source: MatchSource::Cache,
|
||||||
|
};
|
||||||
|
let json = success_json(&result);
|
||||||
|
assert_eq!(
|
||||||
|
json,
|
||||||
|
SuccessJson {
|
||||||
|
status: "ok",
|
||||||
|
mac: "aa:bb:cc:dd:ee:ff".to_string(),
|
||||||
|
ip: "192.168.1.5".to_string(),
|
||||||
|
source: "cache",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn success_json_has_expected_shape_for_arp_source() {
|
||||||
|
let result = ResolveResult {
|
||||||
|
mac: mac(),
|
||||||
|
ip: ip(),
|
||||||
|
source: MatchSource::Arp,
|
||||||
|
};
|
||||||
|
assert_eq!(success_json(&result).source, "arp");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn success_json_has_expected_shape_for_nmap_source() {
|
||||||
|
let result = ResolveResult {
|
||||||
|
mac: mac(),
|
||||||
|
ip: ip(),
|
||||||
|
source: MatchSource::Nmap,
|
||||||
|
};
|
||||||
|
assert_eq!(success_json(&result).source, "nmap");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn failure_json_has_expected_shape() {
|
||||||
|
let err = Mac2IpError::NotFound {
|
||||||
|
mac: mac().to_string(),
|
||||||
|
};
|
||||||
|
let json = failure_json(&mac(), &err);
|
||||||
|
assert_eq!(json.status, "error");
|
||||||
|
assert_eq!(json.mac, "aa:bb:cc:dd:ee:ff");
|
||||||
|
assert_eq!(json.error, err.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn success_json_serializes_with_stable_field_names() {
|
||||||
|
let result = ResolveResult {
|
||||||
|
mac: mac(),
|
||||||
|
ip: ip(),
|
||||||
|
source: MatchSource::Arp,
|
||||||
|
};
|
||||||
|
let value = serde_json::to_value(success_json(&result)).unwrap();
|
||||||
|
assert_eq!(value["status"], "ok");
|
||||||
|
assert_eq!(value["mac"], "aa:bb:cc:dd:ee:ff");
|
||||||
|
assert_eq!(value["ip"], "192.168.1.5");
|
||||||
|
assert_eq!(value["source"], "arp");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn failure_json_serializes_with_stable_field_names() {
|
||||||
|
let err = Mac2IpError::NotFound {
|
||||||
|
mac: mac().to_string(),
|
||||||
|
};
|
||||||
|
let value = serde_json::to_value(failure_json(&mac(), &err)).unwrap();
|
||||||
|
assert_eq!(value["status"], "error");
|
||||||
|
assert_eq!(value["mac"], "aa:bb:cc:dd:ee:ff");
|
||||||
|
assert!(value["error"].is_string());
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
use mac2ip::mac::MacAddress;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_lowercase_colon_separated() {
|
||||||
|
let mac = MacAddress::parse("aa:bb:cc:dd:ee:ff").unwrap();
|
||||||
|
assert_eq!(mac.to_lower_colon(), "aa:bb:cc:dd:ee:ff");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_uppercase_colon_separated() {
|
||||||
|
let mac = MacAddress::parse("AA:BB:CC:DD:EE:FF").unwrap();
|
||||||
|
assert_eq!(mac.to_lower_colon(), "aa:bb:cc:dd:ee:ff");
|
||||||
|
assert_eq!(mac.to_upper_colon(), "AA:BB:CC:DD:EE:FF");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_hyphen_separated() {
|
||||||
|
let mac = MacAddress::parse("aa-bb-cc-dd-ee-ff").unwrap();
|
||||||
|
assert_eq!(mac.to_lower_colon(), "aa:bb:cc:dd:ee:ff");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_mixed_case() {
|
||||||
|
let mac = MacAddress::parse("Aa:bB:Cc:dD:eE:fF").unwrap();
|
||||||
|
assert_eq!(mac.to_lower_colon(), "aa:bb:cc:dd:ee:ff");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn different_notations_are_equal_after_canonicalization() {
|
||||||
|
let a = MacAddress::parse("AA:BB:CC:DD:EE:FF").unwrap();
|
||||||
|
let b = MacAddress::parse("aa-bb-cc-dd-ee-ff").unwrap();
|
||||||
|
assert_eq!(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn from_str_matches_parse() {
|
||||||
|
use std::str::FromStr;
|
||||||
|
let mac: MacAddress = "aa:bb:cc:dd:ee:ff".parse().unwrap();
|
||||||
|
assert_eq!(mac, MacAddress::from_str("aa:bb:cc:dd:ee:ff").unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_too_short() {
|
||||||
|
assert!(MacAddress::parse("aa:bb:cc:dd:ee").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_too_long() {
|
||||||
|
assert!(MacAddress::parse("aa:bb:cc:dd:ee:ff:00").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_non_hex_characters() {
|
||||||
|
assert!(MacAddress::parse("gg:bb:cc:dd:ee:ff").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_wrong_separator_count() {
|
||||||
|
assert!(MacAddress::parse("aabbccddeeff").is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn rejects_empty_string() {
|
||||||
|
assert!(MacAddress::parse("").is_err());
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
use mac2ip::mac::MacAddress;
|
||||||
|
use mac2ip::network::parse_nmap_output;
|
||||||
|
|
||||||
|
fn mac(s: &str) -> MacAddress {
|
||||||
|
MacAddress::parse(s).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn finds_matching_host_among_multiple_blocks() {
|
||||||
|
let output = "\
|
||||||
|
Nmap scan report for 192.168.1.4
|
||||||
|
Host is up (0.0010s latency).
|
||||||
|
MAC Address: 11:22:33:44:55:66 (Some Vendor)
|
||||||
|
Nmap scan report for 192.168.1.5
|
||||||
|
Host is up (0.0020s latency).
|
||||||
|
MAC Address: AA:BB:CC:DD:EE:FF (Other Vendor)
|
||||||
|
Nmap scan report for 192.168.1.6
|
||||||
|
Host is up (0.0030s latency).
|
||||||
|
MAC Address: 77:88:99:AA:BB:CC (Third Vendor)
|
||||||
|
";
|
||||||
|
let ip = parse_nmap_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn host_without_mac_line_does_not_leak_into_next_block() {
|
||||||
|
let output = "\
|
||||||
|
Nmap scan report for 192.168.1.4
|
||||||
|
Host is up (0.0010s latency).
|
||||||
|
Nmap scan report for 192.168.1.5
|
||||||
|
Host is up (0.0020s latency).
|
||||||
|
MAC Address: AA:BB:CC:DD:EE:FF (Vendor)
|
||||||
|
";
|
||||||
|
// Even if we searched for a MAC that never appears, the missing MAC line for
|
||||||
|
// 192.168.1.4 must not accidentally get associated with 192.168.1.5's MAC.
|
||||||
|
assert!(parse_nmap_output(output, &mac("11:22:33:44:55:66")).is_none());
|
||||||
|
let ip = parse_nmap_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn parses_hostname_plus_ip_form() {
|
||||||
|
let output = "\
|
||||||
|
Nmap scan report for myhost.lan (192.168.1.5)
|
||||||
|
Host is up (0.0020s latency).
|
||||||
|
MAC Address: AA:BB:CC:DD:EE:FF (Vendor)
|
||||||
|
";
|
||||||
|
let ip = parse_nmap_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn is_case_insensitive_against_uppercase_nmap_output() {
|
||||||
|
let output = "\
|
||||||
|
Nmap scan report for 192.168.1.5
|
||||||
|
MAC Address: AA:BB:CC:DD:EE:FF (Vendor)
|
||||||
|
";
|
||||||
|
let ip = parse_nmap_output(output, &mac("aa:bb:cc:dd:ee:ff")).unwrap();
|
||||||
|
assert_eq!(ip.to_string(), "192.168.1.5");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn returns_none_when_no_match() {
|
||||||
|
let output = "\
|
||||||
|
Nmap scan report for 192.168.1.4
|
||||||
|
MAC Address: 11:22:33:44:55:66 (Vendor)
|
||||||
|
";
|
||||||
|
assert!(parse_nmap_output(output, &mac("aa:bb:cc:dd:ee:ff")).is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_output_returns_none() {
|
||||||
|
assert!(parse_nmap_output("", &mac("aa:bb:cc:dd:ee:ff")).is_none());
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
use mac2ip::network::parse_local_subnets;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extracts_cidrs_from_multiple_interfaces() {
|
||||||
|
let output = "\
|
||||||
|
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.23
|
||||||
|
10.0.0.0/8 dev wlan0 proto kernel scope link src 10.0.0.5
|
||||||
|
";
|
||||||
|
let subnets = parse_local_subnets(output);
|
||||||
|
assert_eq!(
|
||||||
|
subnets,
|
||||||
|
vec!["192.168.1.0/24".to_string(), "10.0.0.0/8".to_string()]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn excludes_default_route() {
|
||||||
|
let output = "\
|
||||||
|
default via 192.168.1.1 dev eth0
|
||||||
|
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.23
|
||||||
|
";
|
||||||
|
let subnets = parse_local_subnets(output);
|
||||||
|
assert_eq!(subnets, vec!["192.168.1.0/24".to_string()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn excludes_loopback_interface() {
|
||||||
|
let output = "\
|
||||||
|
127.0.0.0/8 dev lo proto kernel scope link src 127.0.0.1
|
||||||
|
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.23
|
||||||
|
";
|
||||||
|
let subnets = parse_local_subnets(output);
|
||||||
|
assert_eq!(subnets, vec!["192.168.1.0/24".to_string()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn empty_input_returns_empty_vec() {
|
||||||
|
let subnets = parse_local_subnets("");
|
||||||
|
assert!(subnets.is_empty());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user