diff options
author | Andrew Cady <d@jerkface.net> | 2020-08-21 08:03:58 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-08-21 08:03:58 -0400 |
commit | 472f2f06be419bdf6bfbe794db9db0a53955fd85 (patch) | |
tree | 0d3113a071e4ca1d30d9623643cb759b84f94198 | |
parent | 1c8ef41b1b7c42bcfe5625f6996d02a0e3dae5d0 (diff) |
Allow wildcards in rules
The hostname "*" is treated as a wildcard.
Port 0 is treated as a wildcard.
Closes https://github.com/gjedeer/tuntox/issues/56
-rw-r--r-- | main.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -108,14 +108,13 @@ int allowed_toxid_cmp(allowed_toxid *a, allowed_toxid *b) | |||
108 | return memcmp(a->toxid, b->toxid, TOX_PUBLIC_KEY_SIZE); | 108 | return memcmp(a->toxid, b->toxid, TOX_PUBLIC_KEY_SIZE); |
109 | } | 109 | } |
110 | 110 | ||
111 | /* Comparison function for rule objects */ | 111 | /* Match rule r against candidate host, port. Returns 0 for match. */ |
112 | int rule_match(rule *a, rule *b) | 112 | int rule_match(rule *r, rule *candidate) |
113 | { | 113 | { |
114 | //log_printf(L_INFO, "Comparison result: %d %d\n", strcmp(a->host, b->host), (a->port == b->port)); | 114 | bool host_match = !strcmp(r->host, "*") || !strcmp(r->host, candidate->host); |
115 | if ((strcmp(a->host, b->host)==0) && (a->port == b->port)) | 115 | bool port_match = r->port == 0 || r->port == candidate->port; |
116 | return 0; | 116 | |
117 | else | 117 | return port_match && host_match ? 0 : -1; |
118 | return -1; | ||
119 | } | 118 | } |
120 | 119 | ||
121 | void update_select_nfds(int fd) | 120 | void update_select_nfds(int fd) |