mark: the rule's connections send with a mark (#846)

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.
This commit is contained in:
Vladimir Dubrovin committed 2026-11-21 16:40:51 +03:00
1 parent eec09dc4e9
commit 51cbdb2fad
9 files changed
+127 -9

No files matched your search

+20
View File
@@ -758,6 +758,25 @@ int intbindtodevice(struct clientparam *param, SOCKET sock){
#endif
}
/* The mark the matched rule gave the connection, set on its outgoing
sockets where the system has one: SO_MARK of Linux, SO_USER_COOKIE of
FreeBSD. Nowhere else it is silently nothing. */
void setmark(struct clientparam *param, SOCKET sock){
#if defined SO_MARK || defined SO_USER_COOKIE
if(param->mark)
so._setsockopt(so.state, sock, SOL_SOCKET,
#ifdef SO_MARK
SO_MARK,
#else
SO_USER_COOKIE,
#endif
(char *)&param->mark, sizeof(param->mark));
#else
(void)param;
(void)sock;
#endif
}
int doconnect(struct clientparam * param){
SASIZETYPE size;
@@ -807,6 +826,7 @@ int doconnect(struct clientparam * param){
}
*SAPORT(&param->sinsl) = 0;
setopts(param->remsock, &param->srv->srvsockopts, param->srv->maxseg);
setmark(param, param->remsock);
#ifndef _WIN32
/* not on Windows, see the accepting side in proxymain.c */