view return VIEW;
ip return IP;
+client_ip return CLIENT_IP;
from return FROM;
symbols return SYMBOLS;
skip_check return SKIP_CHECK;
%token LOG_LEVEL LOG_LEVEL_DEBUG LOG_LEVEL_INFO LOG_LEVEL_WARNING LOG_LEVEL_ERROR LOG_FACILITY LOG_FILENAME
%token STATFILE ALIAS PATTERN WEIGHT STATFILE_POOL_SIZE SIZE TOKENIZER CLASSIFIER
%token DELIVERY LMTP ENABLED AGENT SECTION LUACODE RAW_MODE PROFILE_FILE COUNT
-%token VIEW IP FROM SYMBOLS
+%token VIEW IP FROM SYMBOLS CLIENT_IP
%token AUTOLEARN MIN_MARK MAX_MARK
%token SETTINGS USER_SETTINGS DOMAIN_SETTINGS SYMBOL PATH SKIP_CHECK GROW_FACTOR
viewcmd:
| viewip
+ | viewclientip
| viewfrom
| viewsymbols
| viewskipcheck
}
;
+viewclientip:
+ CLIENT_IP EQSIGN QUOTEDSTRING {
+ if (cur_view == NULL) {
+ cur_view = init_view (cfg->cfg_pool);
+ }
+ if (!add_view_client_ip (cur_view, $3)) {
+ yyerror ("yyparse: invalid ip line in view definition: ip = '%s'", $3);
+ YYERROR;
+ }
+ }
+ ;
+
viewfrom:
FROM EQSIGN QUOTEDSTRING {
if (cur_view == NULL) {
GList *rcpt; /**< recipients list */
unsigned int nrcpt; /**< number of recipients */
struct in_addr from_addr; /**< client addr in numeric form */
+ struct in_addr client_addr; /**< client addr in numeric form */
char *deliver_to; /**< address to deliver */
char *user; /**< user to deliver */
char *subject; /**< subject (for non-mime) */
return FALSE;
}
+gboolean
+add_view_client_ip (struct rspamd_view * view, char *line)
+{
+ if (add_map (line, read_radix_list, fin_radix_list, (void **)&view->client_ip_tree)) {
+ return TRUE;
+ }
-struct rspamd_view *
+ return FALSE;
+}
+
+
+static struct rspamd_view *
find_view_by_ip (GList * views, struct worker_task *task)
{
GList *cur;
return NULL;
}
-struct rspamd_view *
+static struct rspamd_view *
+find_view_by_client_ip (GList * views, struct worker_task *task)
+{
+ GList *cur;
+ struct rspamd_view *v;
+
+ if (task->client_addr.s_addr == INADDR_NONE) {
+ return NULL;
+ }
+
+ cur = views;
+ while (cur) {
+ v = cur->data;
+ if (radix32tree_find (v->client_ip_tree, ntohl (task->client_addr.s_addr)) != RADIX_NO_VALUE) {
+ return v;
+ }
+ cur = g_list_next (cur);
+ }
+
+ return NULL;
+}
+
+static struct rspamd_view *
find_view_by_from (GList * views, struct worker_task *task)
{
GList *cur, *cur_re;
}
if ((selected = find_view_by_ip (views, task)) == NULL) {
- if ((selected = find_view_by_from (views, task)) == NULL) {
- /* No matching view for this task */
- task->view_checked = TRUE;
- return TRUE;
+ if ((selected = find_view_by_client_ip (views, task)) == NULL) {
+ if ((selected = find_view_by_from (views, task)) == NULL) {
+ /* No matching view for this task */
+ task->view_checked = TRUE;
+ return TRUE;
+ }
}
}
GHashTable *from_hash;
radix_tree_t *ip_tree;
+ radix_tree_t *client_ip_tree;
GHashTable *symbols_hash;
GList *symbols_re_list;
gboolean add_view_from (struct rspamd_view *view, char *line);
gboolean add_view_ip (struct rspamd_view *view, char *line);
+gboolean add_view_client_ip (struct rspamd_view *view, char *line);
gboolean add_view_symbols (struct rspamd_view *view, char *line);
gboolean check_view (GList *views, const char *symbol, struct worker_task *task);
return;
}
+
+ new_task = construct_task (worker);
+
if (ss.ss_family == AF_UNIX) {
msg_info ("accept_socket: accepted connection from unix socket");
+ new_task->client_addr.s_addr = INADDR_NONE;
}
else if (ss.ss_family == AF_INET) {
sin = (struct sockaddr_in *)&ss;
msg_info ("accept_socket: accepted connection from %s port %d", inet_ntoa (sin->sin_addr), ntohs (sin->sin_port));
+ memcpy (&new_task->client_addr, &sin->sin_addr, sizeof (struct in_addr));
}
- new_task = construct_task (worker);
-
new_task->sock = nfd;
new_task->is_mime = is_mime;
worker->srv->stat->connections_count++;