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:53 +03:00
1 parent e193732fcd
commit a2e400622b
9 files changed
+127 -9

No files matched your search

+1
View File
@@ -364,6 +364,7 @@ int checkACL(struct clientparam * param){
if(ACLmatches(acentry, param)) {
param->nolog = acentry->nolog;
param->weight = acentry->weight;
param->mark = acentry->mark;
if(acentry->action == 2) {
struct ace dup;
int res=60,i=0;
+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;
@@ -802,6 +821,7 @@ int doconnect(struct clientparam * param){
}
*SAPORT(&param->sinsl) = 0;
setopts(param->remsock, &param->srv->srvsockopts, param->srv->maxseg);
setmark(param, param->remsock);
if(extbindtodevice(param, param->remsock)) return 12;
#ifdef IP_BIND_ADDRESS_NO_PORT
+30 -9
View File
@@ -1305,15 +1305,35 @@ static int h_http(int argc, unsigned char **argv){
static int h_nolog(int argc, unsigned char **argv){
struct ace *acl = NULL;
acl = conf->acl;
if(!acl) {
fprintf(stderr, "Chaining error: last ACL entry was not \"allow/deny\" on line %d\n", linenum);
return(1);
}
while(acl->next) acl = acl->next;
if(argc == 1) acl->nolog = 1;
else acl->weight = atoi((char*)argv[1]);
return 0;
acl = conf->acl;
if(!acl) {
fprintf(stderr, "Chaining error: last ACL entry was not \"allow/deny\" on line %d\n", linenum);
return(1);
}
while(acl->next) acl = acl->next;
if(argc == 1) acl->nolog = 1;
else acl->weight = atoi((char*)argv[1]);
return 0;
}
/* mark <number>: the rule above sends with this mark, on its sockets
towards the destination and the parents, where the system has one */
static int h_mark(int argc, unsigned char **argv){
struct ace *acl = NULL;
char *end;
acl = conf->acl;
if(!acl) {
fprintf(stderr, "Chaining error: last ACL entry was not \"allow/deny\" on line %d\n", linenum);
return(1);
}
while(acl->next) acl = acl->next;
acl->mark = (int)strtol((char *)argv[1], &end, 0);
if(end == (char *)argv[1] || *end) {
fprintf(stderr, "Wrong mark, line %d\n", linenum);
return(1);
}
return 0;
}
int scanipl(unsigned char *arg, struct iplist *dst){
@@ -2172,6 +2192,7 @@ struct commands commandhandlers[]={
{NULL, "filtermaxsize", h_filtermaxsize, 2, 2},
{NULL, "nolog", h_nolog, 1, 1},
{NULL, "weight", h_nolog, 2, 2},
{NULL, "mark", h_mark, 2, 2},
{NULL, "authcache", h_authcache, 2, 4},
{NULL, "smtpp", h_proxy, 1, 0},
{NULL, "delimchar",h_delimchar, 2, 2},
+5
View File
@@ -438,6 +438,10 @@ static void * ef_ace_nolog(struct node * node){
return &((struct ace *)node->value) -> nolog;
}
static void * ef_ace_mark(struct node * node){
return &((struct ace *)node->value) -> mark;
}
static void * ef_bandlimit_next(struct node * node){
return ((struct bandlim *)node->value) -> next;
}
@@ -852,6 +856,7 @@ static struct property prop_ace[] = {
{"periods", ef_ace_period, TYPE_PERIOD, "time of the day"},
{"weight", ef_ace_weight, TYPE_INTEGER, "ace weight"},
{"nolog", ef_ace_nolog, TYPE_INTEGER, "do not log"},
{"mark", ef_ace_mark, TYPE_INTEGER, "mark the outgoing sockets with"},
{"next", ef_ace_next, TYPE_ACE, "next"}
};
+1
View File
@@ -646,6 +646,7 @@ char * printopts(char *sep);
char * printfeatures(char *sep);
void * mainreserve(int isudp, PROXYSOCKADDRTYPE *sa, const struct sockoptset *opts, int maxseg);
void maindropreserved(void *listener);
void setmark(struct clientparam *param, SOCKET sock);
#define WEBBANNERS 35
+2
View File
@@ -407,6 +407,7 @@ struct ace {
int wdays;
int weight;
int nolog;
int mark;
struct period *periods;
struct userlist *users;
struct iplist *src, *dst;
@@ -819,6 +820,7 @@ struct clientparam {
int pwtype,
weight,
nolog,
mark,
nolongdatfilter,
nosplice, /* a TLS socket of the connection is not in the kernel */
nooverwritefilter,
+1
View File
@@ -105,6 +105,7 @@ int udpbind(struct clientparam *param)
s = nssocket(param->srv, &param->srv->so, param->sostate, NS_OUT, SASOCK(&param->sinsl), SOCK_DGRAM, IPPROTO_UDP);
if (s == INVALID_SOCKET) return 11;
setmark(param, s);
#ifdef _WIN32
{ unsigned long ul = 1; ioctlsocket(s, FIONBIO, &ul); }
#else