[package]
name = "nlink"
version.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
authors.workspace = true
documentation = "https://docs.rs/nlink"
readme = "../../README.md"
description = "Async netlink library for Linux network configuration"
keywords = ["netlink", "linux", "networking", "async", "iproute2"]
categories = ["network-programming", "os::linux-apis", "asynchronous"]

[features]
default = []
# Socket diagnostics (NETLINK_SOCK_DIAG)
sockdiag = ["dep:serde"]
# TUN/TAP device management
tuntap = []
# TUN/TAP async support
tuntap-async = ["tuntap"]
# Output formatting (JSON/text)
output = ["dep:serde", "dep:serde_json"]
# Namespace watcher (inotify-based)
namespace_watcher = ["dep:inotify"]
# Lab / integration-test helpers (LabNamespace, with_namespace, require_root!)
lab = []
# All features
full = ["sockdiag", "tuntap", "tuntap-async", "output", "namespace_watcher", "lab"]
# Enable integration tests (require root or network namespace)
integration = []

[dependencies]
# Core dependencies (always needed)
tokio = { workspace = true }
netlink-sys = { workspace = true }
thiserror = { workspace = true }
tracing = { workspace = true }
bytes = { workspace = true }
libc = { workspace = true }
winnow = { workspace = true }
serde_json = { workspace = true, optional = true }
zerocopy = { workspace = true }
tokio-stream = { workspace = true }

# Optional dependencies
serde = { workspace = true, optional = true }
inotify = { version = "0.11", default-features = false, features = ["stream"], optional = true }

[dev-dependencies]
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[package.metadata.docs.rs]
all-features = true
targets = ["x86_64-unknown-linux-gnu"]
rustdoc-args = ["--cfg", "docsrs"]

# Integration tests build on top of the public `nlink::lab` module, so
# they require the `lab` feature. `cargo test --test integration` alone
# will be a no-op; use `cargo test --test integration --features lab`.
[[test]]
name = "integration"
path = "tests/integration.rs"
required-features = ["lab"]

# Route protocol examples
[[example]]
name = "route_list_interfaces"
path = "examples/route/list_interfaces.rs"

[[example]]
name = "route_addresses"
path = "examples/route/addresses.rs"

[[example]]
name = "route_routes"
path = "examples/route/routes.rs"

[[example]]
name = "route_neighbors"
path = "examples/route/neighbors.rs"

[[example]]
name = "route_stats"
path = "examples/route/stats.rs"

[[example]]
name = "route_link_create"
path = "examples/route/link_create.rs"

[[example]]
name = "route_error_handling"
path = "examples/route/error_handling.rs"

[[example]]
name = "route_namespaces"
path = "examples/route/namespaces.rs"

# Traffic control examples
[[example]]
name = "route_tc_netem"
path = "examples/route/tc/netem.rs"

[[example]]
name = "route_tc_htb"
path = "examples/route/tc/htb.rs"

[[example]]
name = "route_tc_stats"
path = "examples/route/tc/stats.rs"

# Event monitoring examples
[[example]]
name = "events_monitor"
path = "examples/events/monitor.rs"

[[example]]
name = "events_monitor_namespace"
path = "examples/events/monitor_namespace.rs"

[[example]]
name = "events_ip_monitor"
path = "examples/events/ip_monitor.rs"

[[example]]
name = "events_tc_monitor"
path = "examples/events/tc_monitor.rs"

# Namespace examples
[[example]]
name = "namespace_events"
path = "examples/namespace/events.rs"

[[example]]
name = "namespace_watch"
path = "examples/namespace/watch.rs"
required-features = ["namespace_watcher"]

# Socket diagnostics examples
[[example]]
name = "sockdiag_list_sockets"
path = "examples/sockdiag/list_sockets.rs"
required-features = ["sockdiag"]

[[example]]
name = "sockdiag_tcp_connections"
path = "examples/sockdiag/tcp_connections.rs"
required-features = ["sockdiag"]

[[example]]
name = "sockdiag_unix_sockets"
path = "examples/sockdiag/unix_sockets.rs"
required-features = ["sockdiag"]

# Generic Netlink examples
[[example]]
name = "genl_wireguard"
path = "examples/genl/wireguard.rs"

[[example]]
name = "genl_mptcp"
path = "examples/genl/mptcp.rs"

[[example]]
name = "genl_macsec"
path = "examples/genl/macsec.rs"

[[example]]
name = "ethtool_link_state"
path = "examples/genl/ethtool_link_state.rs"

[[example]]
name = "ethtool_features"
path = "examples/genl/ethtool_features.rs"

[[example]]
name = "ethtool_rings"
path = "examples/genl/ethtool_rings.rs"

[[example]]
name = "ethtool_monitor"
path = "examples/genl/ethtool_monitor.rs"

# Uevent examples (device hotplug)
[[example]]
name = "uevent_device_monitor"
path = "examples/uevent/device_monitor.rs"

[[example]]
name = "uevent_device_monitor_stream"
path = "examples/uevent/device_monitor_stream.rs"

# Connector examples (process events)
[[example]]
name = "connector_process_monitor"
path = "examples/connector/process_monitor.rs"

[[example]]
name = "connector_process_monitor_stream"
path = "examples/connector/process_monitor_stream.rs"

# Netfilter examples (connection tracking)
[[example]]
name = "netfilter_conntrack"
path = "examples/netfilter/conntrack.rs"

[[example]]
name = "netfilter_conntrack_events"
path = "examples/netfilter/conntrack_events.rs"

# XFRM examples (IPsec)
# `--apply` codepath uses `nlink::lab::with_namespace`, so the example
# requires the `lab` feature.
[[example]]
name = "xfrm_ipsec_monitor"
path = "examples/xfrm/ipsec_monitor.rs"
required-features = ["lab"]

# FIB lookup examples
[[example]]
name = "fib_lookup_route_lookup"
path = "examples/fib_lookup/route_lookup.rs"

# Audit examples
[[example]]
name = "audit_status"
path = "examples/audit/audit_status.rs"

# SELinux examples
[[example]]
name = "selinux_monitor"
path = "examples/selinux/selinux_monitor.rs"

[[example]]
name = "selinux_monitor_stream"
path = "examples/selinux/selinux_monitor_stream.rs"

# Multi-source event monitoring
[[example]]
name = "events_multi_source"
path = "examples/events/multi_source.rs"

# nftables examples
[[example]]
name = "nftables_firewall"
path = "examples/nftables/firewall.rs"

# nl80211 WiFi examples
[[example]]
name = "genl_nl80211"
path = "examples/genl/nl80211.rs"

# Devlink examples
[[example]]
name = "genl_devlink"
path = "examples/genl/devlink.rs"

# Bond interface examples
[[example]]
name = "route_bond"
path = "examples/route/bond.rs"

# BPF/TC attachment examples
[[example]]
name = "route_tc_bpf"
path = "examples/route/tc/bpf.rs"

# Socket diagnostics - summary and kill
[[example]]
name = "sockdiag_summary"
path = "examples/sockdiag/summary.rs"
required-features = ["sockdiag"]

[[example]]
name = "sockdiag_kill"
path = "examples/sockdiag/kill.rs"
required-features = ["sockdiag"]

# Batching and timeout examples
[[example]]
name = "route_batch"
path = "examples/route/batch.rs"

[[example]]
name = "route_timeout"
path = "examples/route/timeout.rs"

# Per-peer impairment helper
[[example]]
name = "impair_per_peer"
path = "examples/impair/per_peer.rs"

# High-level rate limiting (RateLimiter + PerHostLimiter + reconcile)
[[example]]
name = "ratelimit_simple"
path = "examples/ratelimit/simple.rs"

# Lab module (LabNamespace / LabBridge / LabVeth) demos
[[example]]
name = "lab_three_namespace"
path = "examples/lab/three_namespace.rs"
required-features = ["lab"]
