array_ensure_capacity_delta(array, 1); \
(array).data[(array).len++] = (obj); \
} while (0)
-#define array_append(array, objs, len) \
+#define array_append(array, objs, Len) \
do { \
- const typeof((array).len) __len = (len); \
+ const typeof((array).len) __len = (Len); \
array_ensure_capacity_delta(array, __len); \
memcpy((array).data + (array).len, objs, \
__len * sizeof(*(array).data)); \
array_ensure_can_edit(array); \
p_shrink(&(array).data, (array).len, &(array).size); \
} while (0)
-#define array_elt(array, n) (array).data[(n)]
-#define array_ptr(array, n) (array).data + (n)
+#define array_elt(array, n) ((array).data[(n)])
+#define array_ptr(array, n) ((array).data + (n))
#define foreach(var, array) \
for (uint32_t __Ai = 0 ; __Ai < (array).len ; ++__Ai) { \
typedef struct rbl_filter_t {
PA(rbldb_t) rbls;
A(int) weights;
+ A(char) hosts;
+ A(int) host_offsets;
+ A(int) host_weights;
int32_t hard_threshold;
int32_t soft_threshold;
if (*rbl) {
array_deep_wipe((*rbl)->rbls, rbldb_delete);
array_wipe((*rbl)->weights);
+ array_wipe((*rbl)->hosts);
+ array_wipe((*rbl)->host_offsets);
+ array_wipe((*rbl)->host_weights);
p_delete(rbl);
}
}
}
} break;
+ /* host parameter.
+ * weight:hostname.
+ * define a RBL to use through DNS resolution.
+ */
+ case ATK_HOST: {
+ int weight = 0;
+ const char *current = param->value;
+ const char *p = m_strchrnul(param->value, ':');
+ char *next = NULL;
+ for (int i = 0 ; i < 2 ; ++i) {
+ PARSE_CHECK(i == 1 || *p,
+ "host parameter must contains a weight option");
+ switch (i) {
+ case 0:
+ weight = strtol(current, &next, 10);
+ PARSE_CHECK(next == p && weight >= 0 && weight <= 1024,
+ "illegal weight value %.*s",
+ (p - current), current);
+ break;
+
+ case 1:
+ array_add(data->host_offsets, array_len(data->hosts));
+ array_append(data->hosts, current, strlen(current) + 1);
+ array_add(data->host_weights, weight);
+ break;
+ }
+ if (i != 1) {
+ current = p + 1;
+ p = m_strchrnul(current, ':');
+ }
+ }
+ } break;
+
/* hard_threshold parameter is an integer.
* If the matching score is greater or equal than this threshold,
* the hook "hard_match" is called.
int weight = array_elt(data->weights, i);
if (rbldb_ipv4_lookup(rbl, ip)) {
sum += weight;
+ if (sum >= data->hard_threshold) {
+ return HTK_HARD_MATCH;
+ }
}
}
if (sum >= data->hard_threshold) {
/* Parameters.
*/
(void)filter_param_register(type, "file");
+ (void)filter_param_register(type, "host");
(void)filter_param_register(type, "hard_threshold");
(void)filter_param_register(type, "soft_threshold");
return 0;