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