mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
mark <number> extends the allow or deny rule above it, as nolog and weight do: a connection the rule lets through carries the mark on its outgoing sockets, towards the destination and towards the parents, so policy routing and firewall rules can tell its packets apart (SO_MARK of Linux, SO_USER_COOKIE of FreeBSD; on a system with no mark the command sets it to nothing). The UDP sockets of a session towards a destination are marked the same, the SOCKS UDP ASSOCIATE relays among them, for the rule that let the session through is looked up for each destination. A mark with no rule above it, or not a number, is refused.
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
"""The mark command: a rule's connections carry a mark.
|
|
|
|
mark <number> extends the rule above it like nolog and weight; the
|
|
connection it lets through sends with the mark on its sockets towards
|
|
the destination. Where the system has no mark (Linux SO_MARK, FreeBSD
|
|
SO_USER_COOKIE) the command changes nothing, and what is checked here
|
|
is the flow: a rule with a mark serves as one without.
|
|
"""
|
|
|
|
|
|
def run(t):
|
|
if not t.skip_unless("httpsrv"):
|
|
return
|
|
|
|
origin = t.free_port()
|
|
t.start("mark_origin", f"""
|
|
log
|
|
auth iponly
|
|
allow *
|
|
http data * /data**
|
|
httpsrv -p{origin}
|
|
""", ports=[origin])
|
|
|
|
# a rule with a mark serves the connections it lets through
|
|
prox = t.free_port()
|
|
t.start("mark_rule", f"""
|
|
log
|
|
auth iponly
|
|
allow * * 192.168.0.0/16
|
|
allow * * 127.0.0.0/8
|
|
mark 20
|
|
proxy -p{prox}
|
|
""", ports=[prox])
|
|
|
|
t.eq(200, t.http(f"http://127.0.0.1:{origin}/data",
|
|
proxy=f"127.0.0.1:{prox}").status,
|
|
"a request matched by a rule with a mark is served")
|
|
|
|
# a mark of the rule above only: a rule of its own is refused
|
|
out = t.run_config("mark_alone", "log\nmark 20\nnot_a_command\n")
|
|
t.contains(out, "'mark' failed",
|
|
"a mark with no rule above it is refused")
|
|
t.not_contains(out, "'not_a_command'",
|
|
"and the file stops at the refused line")
|
|
|
|
# and so is a mark that is not a number
|
|
out = t.run_config("mark_word", "log\nallow *\nmark twenty\nnot_a_command\n")
|
|
t.contains(out, "Wrong mark",
|
|
"a mark that is not a number is refused")
|