/**
 * Programmatic nftables rule management for agent network isolation.
 *
 * Manages RFC1918 + cloud metadata blocking rules per-interface (Firecracker/container)
 * or per-UID (bare-metal). All operations use `nft` CLI via child_process.execFile.
 *
 * Table layout:
 *   table ip kici {
 *     chain forward { type filter hook forward priority 0; policy accept; }
 *     chain output  { type filter hook output priority 0; policy accept; }
 *   }
 */
import type { NetworkPolicy } from './types.js';
/**
 * Match mode for nftables isolation rules.
 * - 'iifname': Match on input interface name (Firecracker TAP devices)
 * - 'saddr': Match on source IP address (container backends)
 */
export type NftMatchMode = 'iifname' | 'saddr';
/**
 * Options for nft command execution.
 */
interface NftOptions {
    /**
     * Wrap the `nft` invocation with `sudo -n` so non-root orchestrators (e.g.
     * Pi user-mode systemd) can manage rules. Operators must have a NOPASSWD
     * sudoers entry for /usr/sbin/nft. Default false.
     */
    requireSudo?: boolean;
}
/**
 * Validate that nftables is available and the process has NET_ADMIN capability.
 * Attempts `nft list tables` -- if it fails:
 *   - ENOENT: nft binary not installed
 *   - EPERM: nft binary present but NET_ADMIN capability missing
 * Throws with a clear error message in both cases.
 */
export declare function validateNftablesAvailability(opts?: NftOptions): Promise<void>;
/**
 * Ensure the `kici` nftables table and required chains exist.
 * Idempotent -- safe to call multiple times.
 */
export declare function ensureKiciTable(opts?: NftOptions): Promise<void>;
/** A single nft rule operation: the verb decides chain placement. */
export interface NftRuleOp {
    /** 'insert' prepends to the chain head; 'add' appends to the tail. */
    verb: 'insert' | 'add';
    /** Tokens after `nft <verb> rule ip kici forward`. */
    tokens: string[];
}
/**
 * Build the per-identifier isolation rule operations.
 *
 * Placement matters because nftables is first-match-wins and the `kici`
 * forward chain is shared: it accumulates rules for every live agent plus
 * any host-level baseline (e.g. wildcard `iifname "kici-*"` RFC1918 drops
 * installed at host bootstrap). Accepts therefore go in via `insert`
 * (chain head) so they beat any pre-existing drop that also matches the
 * traffic; an appended accept after a wildcard drop is dead code. Drops go
 * in via `add` (tail) — they only need to beat the chain's accept policy.
 *
 * Effective per-identifier order: gateway + allowlist accepts (head),
 * RFC1918 / metadata / denyAll drops (tail).
 */
export declare function buildIsolationRuleOps(matchClause: string[], gatewayIp: string, networkPolicy?: NetworkPolicy): NftRuleOp[];
/**
 * Add network isolation rules for a specific network interface.
 * Used by Firecracker and container backends.
 *
 * Rule placement (see buildIsolationRuleOps):
 * 1. Accept gateway traffic (inserted at chain head)
 * 2. Accept allowlisted CIDRs (inserted at chain head)
 * 3. Drop RFC1918 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)
 * 4. Drop cloud metadata (169.254.0.0/16)
 * 5. Drop all remaining traffic (only if denyAll is true)
 *
 * @param identifier - Network interface name or source IP to match (e.g., "veth-abc123" or "172.30.0.5")
 * @param gatewayIp - Gateway IP that must remain accessible (e.g., "10.0.0.1")
 * @param networkPolicy - Optional policy with allowlist and denyAll settings
 * @param matchMode - How to match traffic: 'iifname' for interface name (default), 'saddr' for source IP
 */
export declare function addIsolationRules(identifier: string, gatewayIp: string, networkPolicy?: NetworkPolicy, matchMode?: NftMatchMode, opts?: NftOptions): Promise<void>;
/**
 * Remove all isolation rules matching a specific interface from the kici forward chain.
 * Called during agent cleanup/destruction.
 *
 * Lists all rules with handles, finds those matching the interface name, and deletes them.
 * Best-effort: logs errors but does not throw (cleanup should not block destruction).
 *
 * @param interfaceName - Network interface whose rules should be removed
 */
export declare function removeIsolationRules(interfaceName: string, opts?: NftOptions): Promise<void>;
/**
 * Re-export NftOptions type for use by callers (Firecracker / container backends)
 * that need to pass the requireSudo flag through to these functions.
 */
export type { NftOptions };
/**
 * Parse nft rule listing output and extract handles for rules matching a given identifier.
 * Handles lines like: `  iifname "veth-abc" ip daddr 10.0.0.0/8 drop # handle 42`
 *
 * @param nftOutput - Raw output from `nft -a list chain ip kici <chain>`
 * @param identifier - String to search for in each rule line (interface name or UID)
 * @returns Array of numeric rule handles
 */
export declare function parseRuleHandles(nftOutput: string, identifier: string): number[];
//# sourceMappingURL=nftables.d.ts.map