NFTables.Expr.Port (NFTables v0.8.2)

View Source

Port matching functions for Expr.

Provides protocol-agnostic port matching for TCP, UDP, SCTP, and DCCP. The protocol context is determined by earlier protocol calls (tcp(), udp(), sctp(), or dccp()) in the match chain.

Supports both single ports and port ranges using Elixir ranges.

Import

import NFTables.Expr.Port

Examples

# TCP port matching
tcp() |> dport(80)
tcp() |> sport(1024)

# UDP port matching
udp() |> dport(53)
udp() |> sport(5353)

# SCTP port matching
sctp() |> dport(9899)
sctp() |> sport(5000)

# DCCP port matching
dccp() |> dport(6000)

# Port ranges (all protocols)
tcp() |> dport(8000..9000)
sctp() |> sport(1024..65535)

For more information, see the nftables payload expressions wiki.

Summary

Functions

Match destination port.

Alias for dport/2. Match destination port.

Convenience alias for dport/2. Match destination port.

Alias for sport/2. Match source port.

Functions

dport(builder \\ Expr.expr(), port)

Match destination port.

Works with TCP, UDP, SCTP, and DCCP based on the protocol context set by tcp(), udp(), sctp(), or dccp(). Supports single ports (integer) or port ranges (Range).

Examples

# Single port
tcp() |> dport(80)
udp() |> dport(53)
sctp() |> dport(9899)
dccp() |> dport(6000)

# Port range
tcp() |> dport(8000..9000)
sctp() |> dport(1024..65535)

Errors

Raises ArgumentError if called without a protocol context (tcp/udp/sctp/dccp).

dst_port(builder \\ Expr.expr(), port)

@spec dst_port(NFTables.Expr.t(), non_neg_integer() | Range.t()) :: NFTables.Expr.t()

Alias for dport/2. Match destination port.

Examples

tcp() |> dst_port(443)
udp() |> dst_port(53)

port(builder \\ Expr.expr(), port)

Convenience alias for dport/2. Match destination port.

Supports dual-arity: can start a new expression or continue an existing one.

Examples

# Single port
tcp() |> port(22)

# Port range
tcp() |> port(8000..9000)

sport(builder \\ Expr.expr(), port)

Match source port.

Works with TCP, UDP, SCTP, and DCCP based on the protocol context set by tcp(), udp(), sctp(), or dccp(). Supports single ports (integer) or port ranges (Range).

Examples

# Single port
tcp() |> sport(1024)
udp() |> sport(5353)
sctp() |> sport(5000)
dccp() |> sport(4000)

# Port range
tcp() |> sport(1024..65535)
udp() |> sport(10000..20000)

Errors

Raises ArgumentError if called without tcp() or udp() first.

src_port(builder \\ Expr.expr(), port)

@spec src_port(NFTables.Expr.t(), non_neg_integer() | Range.t()) :: NFTables.Expr.t()

Alias for sport/2. Match source port.

Examples

tcp() |> src_port(1024)
tcp() |> src_port(1024..65535)