forked from OpenSIPS/opensips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blacklists.h
122 lines (94 loc) · 3.15 KB
/
blacklists.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Copyright (C) 2007 Voice Sistem SRL
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \file
* \brief OpenSIPS Blacklist functions
*/
#ifndef _BLACKLISTS_H_
#define _BLACKLISTS_H_
#include "ip_addr.h"
#include "str.h"
#include "rw_locking.h"
#define BL_READONLY_LIST (1<<0)
#define BL_DO_EXPIRE (1<<1)
#define BL_BY_DEFAULT (1<<2)
#define BLR_APPLY_CONTRARY (1<<0)
struct bl_rule{
int flags;
struct net ip_net;
unsigned short port;
unsigned short proto;
str body;
struct bl_rule *next;
unsigned int expire_end;
};
struct bl_head{
str name;
str owner; /*!< identifier of the module that owns the set of rules */
int flags;
rw_lock_t *lock;
/* ... more fields, maybe ... */
struct bl_rule *first;
struct bl_rule *last;
};
#define BL_CORE_ID 13
int init_black_lists();
void destroy_black_lists();
struct bl_head *create_bl_head(const str *owner, int flags,
struct bl_rule *head, struct bl_rule *tail, str *name);
int add_rule_to_list(struct bl_rule **first, struct bl_rule **last,
struct net *ip_net, str *body, unsigned short port,
unsigned short proto, int flags);
int add_list_to_head(struct bl_head *elem,
struct bl_rule *first, struct bl_rule *last,
int truncate, int expire_limit);
struct bl_head *get_bl_head_by_name(str *name);
int mark_for_search(struct bl_head *list, unsigned int set);
void reset_bl_markers();
int check_against_blacklist(struct ip_addr *ip, str *text, unsigned short port,
unsigned short proto);
static inline int check_blacklists( unsigned short proto,
union sockaddr_union *to, char *body_s, int body_len)
{
str body;
struct ip_addr ip;
unsigned short port;
body.s = body_s;
body.len = body_len;
su2ip_addr(&ip, to);
port = su_getport(to);
return check_against_blacklist(&ip, &body, port, proto);
}
struct bl_net_flags {
struct net ipnet;
unsigned int flags;
};
int fixup_blacklist_proto(void** param);
int fixup_blacklist_net(void** param);
int fixup_blacklist_net_free(void** param);
int w_check_blacklist(struct sip_msg *msg, struct bl_head *head,
struct ip_addr *ip, int *port, unsigned short _proto, str *_pattern);
int w_add_blacklist_rule(struct sip_msg *msg, struct bl_head *head,
struct bl_net_flags *_nf, int *_port, unsigned short _proto,
str *_pattern, int *_exp);
int w_del_blacklist_rule(struct sip_msg *msg, struct bl_head *head,
struct bl_net_flags *_nf, int *_port, unsigned short _proto,
str *_pattern);
#endif /* _BLACKLST_H */