diff --git a/doc/Makefile b/doc/Makefile index 8eb455c..31a39c1 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -36,7 +36,12 @@ EXAMPLES = \ decnet-host-10.15.md \ l1.md \ icmp6.md \ - sctp.md + sctp.md \ + packet-access-igmp.md \ + packet-access-pim.md \ + packet-access-igrp.md \ + packet-access-vrrp.md \ + packet-access-sctp.md PFLUA = \ ../src/pf.lua \ @@ -161,3 +166,18 @@ icmp6.md: $(PFLUA) sctp.md: $(PFLUA) ../tools/dump-markdown "sctp" > $@.tmp && mv $@.tmp $@ + +packet-access-igmp.md: $(PFLUA) + ../tools/dump-markdown "igmp[8] < 8" > $@.tmp && mv $@.tmp $@ + +packet-access-pim.md: $(PFLUA) + ../tools/dump-markdown "pim[8] < 8" > $@.tmp && mv $@.tmp $@ + +packet-access-igrp.md : $(PFLUA) + ../tools/dump-markdown "igrp[8] < 8" > $@.tmp && mv $@.tmp $@ + +packet-access-vrrp.md: $(PFLUA) + ../tools/dump-markdown "vrrp[8] < 8" > $@.tmp && mv $@.tmp $@ + +packet-access-sctp.md: $(PFLUA) + ../tools/dump-markdown "sctp[8] < 8" > $@.tmp && mv $@.tmp $@ diff --git a/doc/packet-access-igmp.md b/doc/packet-access-igmp.md new file mode 100644 index 0000000..1d9392f --- /dev/null +++ b/doc/packet-access-igmp.md @@ -0,0 +1,68 @@ +# igmp[8] < 8 + + +## BPF + +``` +000: A = P[12:2] +001: if (A == 2048) goto 2 else goto 10 +002: A = P[23:1] +003: if (A == 2) goto 4 else goto 10 +004: A = P[20:2] +005: if (A & 8191 != 0) goto 10 else goto 6 +006: X = (P[14:1] & 0xF) << 2 +007: A = P[X+22:1] +008: if (A >= 8) goto 10 else goto 9 +009: return 65535 +010: return 0 +``` + + +## BPF cross-compiled to Lua + +``` +return function (P, length) + local A = 0 + local X = 0 + local T = 0 + if 14 > length then return false end + A = bit.bor(bit.lshift(P[12], 8), P[12+1]) + if not (A==2048) then goto L9 end + if 24 > length then return false end + A = P[23] + if not (A==2) then goto L9 end + if 22 > length then return false end + A = bit.bor(bit.lshift(P[20], 8), P[20+1]) + if not (bit.band(A, 8191)==0) then goto L9 end + if 14 >= length then return false end + X = bit.lshift(bit.band(P[14], 15), 2) + T = bit.tobit((X+22)) + if T < 0 or T + 1 > length then return false end + A = P[T] + if (runtime_u32(A)>=8) then goto L9 end + do return true end + ::L9:: + do return false end + error("end of bpf") +end +``` + + +## Direct pflang compilation + +``` +local lshift = require("bit").lshift +local band = require("bit").band +local cast = require("ffi").cast +return function(P,length) + if length < 42 then return false end + if cast("uint16_t*", P+12)[0] ~= 8 then return false end + if P[23] ~= 2 then return false end + if band(cast("uint16_t*", P+20)[0],65311) ~= 0 then return false end + local var7 = lshift(band(P[14],15),2) + if (var7 + 23) > length then return false end + return P[(var7 + 22)] < 8 +end + +``` + diff --git a/doc/packet-access-igrp.md b/doc/packet-access-igrp.md new file mode 100644 index 0000000..679ea75 --- /dev/null +++ b/doc/packet-access-igrp.md @@ -0,0 +1,68 @@ +# igrp[8] < 8 + + +## BPF + +``` +000: A = P[12:2] +001: if (A == 2048) goto 2 else goto 10 +002: A = P[23:1] +003: if (A == 9) goto 4 else goto 10 +004: A = P[20:2] +005: if (A & 8191 != 0) goto 10 else goto 6 +006: X = (P[14:1] & 0xF) << 2 +007: A = P[X+22:1] +008: if (A >= 8) goto 10 else goto 9 +009: return 65535 +010: return 0 +``` + + +## BPF cross-compiled to Lua + +``` +return function (P, length) + local A = 0 + local X = 0 + local T = 0 + if 14 > length then return false end + A = bit.bor(bit.lshift(P[12], 8), P[12+1]) + if not (A==2048) then goto L9 end + if 24 > length then return false end + A = P[23] + if not (A==9) then goto L9 end + if 22 > length then return false end + A = bit.bor(bit.lshift(P[20], 8), P[20+1]) + if not (bit.band(A, 8191)==0) then goto L9 end + if 14 >= length then return false end + X = bit.lshift(bit.band(P[14], 15), 2) + T = bit.tobit((X+22)) + if T < 0 or T + 1 > length then return false end + A = P[T] + if (runtime_u32(A)>=8) then goto L9 end + do return true end + ::L9:: + do return false end + error("end of bpf") +end +``` + + +## Direct pflang compilation + +``` +local lshift = require("bit").lshift +local band = require("bit").band +local cast = require("ffi").cast +return function(P,length) + if length < 42 then return false end + if cast("uint16_t*", P+12)[0] ~= 8 then return false end + if P[23] ~= 9 then return false end + if band(cast("uint16_t*", P+20)[0],65311) ~= 0 then return false end + local var7 = lshift(band(P[14],15),2) + if (var7 + 23) > length then return false end + return P[(var7 + 22)] < 8 +end + +``` + diff --git a/doc/packet-access-pim.md b/doc/packet-access-pim.md new file mode 100644 index 0000000..3bbfbe7 --- /dev/null +++ b/doc/packet-access-pim.md @@ -0,0 +1,68 @@ +# pim[8] < 8 + + +## BPF + +``` +000: A = P[12:2] +001: if (A == 2048) goto 2 else goto 10 +002: A = P[23:1] +003: if (A == 103) goto 4 else goto 10 +004: A = P[20:2] +005: if (A & 8191 != 0) goto 10 else goto 6 +006: X = (P[14:1] & 0xF) << 2 +007: A = P[X+22:1] +008: if (A >= 8) goto 10 else goto 9 +009: return 65535 +010: return 0 +``` + + +## BPF cross-compiled to Lua + +``` +return function (P, length) + local A = 0 + local X = 0 + local T = 0 + if 14 > length then return false end + A = bit.bor(bit.lshift(P[12], 8), P[12+1]) + if not (A==2048) then goto L9 end + if 24 > length then return false end + A = P[23] + if not (A==103) then goto L9 end + if 22 > length then return false end + A = bit.bor(bit.lshift(P[20], 8), P[20+1]) + if not (bit.band(A, 8191)==0) then goto L9 end + if 14 >= length then return false end + X = bit.lshift(bit.band(P[14], 15), 2) + T = bit.tobit((X+22)) + if T < 0 or T + 1 > length then return false end + A = P[T] + if (runtime_u32(A)>=8) then goto L9 end + do return true end + ::L9:: + do return false end + error("end of bpf") +end +``` + + +## Direct pflang compilation + +``` +local lshift = require("bit").lshift +local band = require("bit").band +local cast = require("ffi").cast +return function(P,length) + if length < 42 then return false end + if cast("uint16_t*", P+12)[0] ~= 8 then return false end + if P[23] ~= 103 then return false end + if band(cast("uint16_t*", P+20)[0],65311) ~= 0 then return false end + local var7 = lshift(band(P[14],15),2) + if (var7 + 23) > length then return false end + return P[(var7 + 22)] < 8 +end + +``` + diff --git a/doc/packet-access-sctp.md b/doc/packet-access-sctp.md new file mode 100644 index 0000000..afe968f --- /dev/null +++ b/doc/packet-access-sctp.md @@ -0,0 +1,68 @@ +# sctp[8] < 8 + + +## BPF + +``` +000: A = P[12:2] +001: if (A == 2048) goto 2 else goto 10 +002: A = P[23:1] +003: if (A == 132) goto 4 else goto 10 +004: A = P[20:2] +005: if (A & 8191 != 0) goto 10 else goto 6 +006: X = (P[14:1] & 0xF) << 2 +007: A = P[X+22:1] +008: if (A >= 8) goto 10 else goto 9 +009: return 65535 +010: return 0 +``` + + +## BPF cross-compiled to Lua + +``` +return function (P, length) + local A = 0 + local X = 0 + local T = 0 + if 14 > length then return false end + A = bit.bor(bit.lshift(P[12], 8), P[12+1]) + if not (A==2048) then goto L9 end + if 24 > length then return false end + A = P[23] + if not (A==132) then goto L9 end + if 22 > length then return false end + A = bit.bor(bit.lshift(P[20], 8), P[20+1]) + if not (bit.band(A, 8191)==0) then goto L9 end + if 14 >= length then return false end + X = bit.lshift(bit.band(P[14], 15), 2) + T = bit.tobit((X+22)) + if T < 0 or T + 1 > length then return false end + A = P[T] + if (runtime_u32(A)>=8) then goto L9 end + do return true end + ::L9:: + do return false end + error("end of bpf") +end +``` + + +## Direct pflang compilation + +``` +local lshift = require("bit").lshift +local band = require("bit").band +local cast = require("ffi").cast +return function(P,length) + if length < 42 then return false end + if cast("uint16_t*", P+12)[0] ~= 8 then return false end + if P[23] ~= 132 then return false end + if band(cast("uint16_t*", P+20)[0],65311) ~= 0 then return false end + local var7 = lshift(band(P[14],15),2) + if (var7 + 23) > length then return false end + return P[(var7 + 22)] < 8 +end + +``` + diff --git a/doc/packet-access-vrrp.md b/doc/packet-access-vrrp.md new file mode 100644 index 0000000..726f161 --- /dev/null +++ b/doc/packet-access-vrrp.md @@ -0,0 +1,68 @@ +# vrrp[8] < 8 + + +## BPF + +``` +000: A = P[12:2] +001: if (A == 2048) goto 2 else goto 10 +002: A = P[23:1] +003: if (A == 112) goto 4 else goto 10 +004: A = P[20:2] +005: if (A & 8191 != 0) goto 10 else goto 6 +006: X = (P[14:1] & 0xF) << 2 +007: A = P[X+22:1] +008: if (A >= 8) goto 10 else goto 9 +009: return 65535 +010: return 0 +``` + + +## BPF cross-compiled to Lua + +``` +return function (P, length) + local A = 0 + local X = 0 + local T = 0 + if 14 > length then return false end + A = bit.bor(bit.lshift(P[12], 8), P[12+1]) + if not (A==2048) then goto L9 end + if 24 > length then return false end + A = P[23] + if not (A==112) then goto L9 end + if 22 > length then return false end + A = bit.bor(bit.lshift(P[20], 8), P[20+1]) + if not (bit.band(A, 8191)==0) then goto L9 end + if 14 >= length then return false end + X = bit.lshift(bit.band(P[14], 15), 2) + T = bit.tobit((X+22)) + if T < 0 or T + 1 > length then return false end + A = P[T] + if (runtime_u32(A)>=8) then goto L9 end + do return true end + ::L9:: + do return false end + error("end of bpf") +end +``` + + +## Direct pflang compilation + +``` +local lshift = require("bit").lshift +local band = require("bit").band +local cast = require("ffi").cast +return function(P,length) + if length < 42 then return false end + if cast("uint16_t*", P+12)[0] ~= 8 then return false end + if P[23] ~= 112 then return false end + if band(cast("uint16_t*", P+20)[0],65311) ~= 0 then return false end + local var7 = lshift(band(P[14],15),2) + if (var7 + 23) > length then return false end + return P[(var7 + 22)] < 8 +end + +``` +