pub enum BytecodeOpCode {
Show 14 variants
Nop = 0,
Jmp = 1,
SportGe = 2,
SportLe = 3,
DportGe = 4,
DportLe = 5,
PortAuto = 6,
SaddrCond = 7,
DaddrCond = 8,
DevCond = 9,
MarkCond = 10,
SportEq = 11,
DportEq = 12,
CgroupCond = 13,
}inet-diag only.Expand description
Socket identity SOCK_RAW sockets require the underlied protocol to be additionally specified so we can use @pad member for this, but we can’t rename it because userspace programs still may depend on this name. Instead lets use another structure definition as an alias for struct @inet_diag_req_v2. Base info structure. It contains socket identity (addrs/ports/cookie) and, alas, the information shown by netstat. Bytecode is sequence of 4 byte commands followed by variable arguments. All the commands identified by “code” are conditional jumps forward: to offset cc+“yes” (bytes) or to offset cc+“no” (bytes). “yes” is supposed to be length of the command and its arguments (in bytes).
Termination condition is to land excactly on a len’th instruction (on address of one after the last one), overshooting means an unsucessfull termination.
If you reading this, for your own sanity, I advice you to first try reverse-lookup on the `ss` command with filters you need, and copy bytecode from there. Enum - defines an integer enumeration, with values for each entry incrementing by 1, (e.g. 0, 1, 2, 3)
Variants§
Nop = 0
Jmp = 1
unconditional jump. “no” value is ignored.
SportGe = 2
sock.sport >= next_instruction.no (big endian)
SportLe = 3
sock.sport <= next_instruction.no (big endian)
DportGe = 4
sock.dport >= next_instruction.no (big endian)
DportLe = 5
sock.dport <= next_instruction.no (big endian)
PortAuto = 6
check if sock is NOT bound to a port by user, i.e. !(sk->userlocks & SOCK_BINDPORT_LOCK)
SaddrCond = 7
Check aginst source socket addr packed as hostcond struct (hc), followed by big-endian ipv4 or ipv6 address (yes, it’s that cursed).
The check equivalent to the following (in order): no if hc.port != -1 && hc.port != sock.sport yes if hc.family == AF_INET && sock.family == AF_INET6 && &sock.saddr_u32[0..3] == &[0, 0, 0xffff.to_be()] && bits_eq(&sock.saddr_u8[12..], &hc.addr[..], hc.prefix_len) no if hc.family != AF_UNSPEC && hc.family != family yes if hc.prefix_len == 0 yes if bits_eq(&sock.addr[..], &hc.addr[..], hc.prefix_len) no
See inet_diag_bc_run() in net/ipv4/inet_diag.c
DaddrCond = 8
Check aginst source socket addr using hostcond struct. Same as `saddr-cond`, see its description.
DevCond = 9
socket ifindex == next_instruction (native endian u32)
MarkCond = 10
Check check socket mark bits against markcond struct (mc). The check is equivalent to: sock.mark & mc.mask == mc.mark
SportEq = 11
sock.sport == next_instruction.no (big endian)
DportEq = 12
sock.dport == next_instruction.no (big endian)
CgroupCond = 13
sock.cgroup_id == next_2_instructions (native endian u64)
Implementations§
Source§impl BytecodeOpCode
impl BytecodeOpCode
pub fn from_value(value: u64) -> Option<Self>
Trait Implementations§
Source§impl Clone for BytecodeOpCode
impl Clone for BytecodeOpCode
Source§fn clone(&self) -> BytecodeOpCode
fn clone(&self) -> BytecodeOpCode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more