@@ -45,7 +45,8 @@ enum AclOp {
4545
4646const AclRecord IpAllow::ALL_METHOD_ACL (AclRecord::ALL_METHOD_MASK);
4747
48- int IpAllow::configid = 0 ;
48+ int IpAllow::configid = 0 ;
49+ bool IpAllow::accept_check_p = true ; // initializing global flag for fast deny
4950
5051static ConfigUpdateHandler<IpAllow> *ipAllowUpdate;
5152
@@ -108,12 +109,11 @@ IpAllow::~IpAllow()
108109}
109110
110111void
111- IpAllow::Print ( )
112+ IpAllow::PrintMap (IpMap *map )
112113{
113114 std::ostringstream s;
114- s << _map.getCount () << " ACL entries" ;
115- s << ' .' ;
116- for (IpMap::iterator spot (_map.begin ()), limit (_map.end ()); spot != limit; ++spot) {
115+ s << map->getCount () << " ACL entries." ;
116+ for (IpMap::iterator spot (map->begin ()), limit (map->end ()); spot != limit; ++spot) {
117117 char text[INET6_ADDRSTRLEN];
118118 AclRecord const *ar = static_cast <AclRecord const *>(spot->data ());
119119
@@ -156,6 +156,15 @@ IpAllow::Print()
156156 Debug (" ip-allow" , " %s" , s.str ().c_str ());
157157}
158158
159+ void
160+ IpAllow::Print ()
161+ {
162+ Debug (" ip-allow" , " Printing src map" );
163+ PrintMap (&_src_map);
164+ Debug (" ip-allow" , " Printing dest map" );
165+ PrintMap (&_dest_map);
166+ }
167+
159168int
160169IpAllow::BuildTable ()
161170{
@@ -171,7 +180,7 @@ IpAllow::BuildTable()
171180 bool alarmAlready = false ;
172181
173182 // Table should be empty
174- ink_assert (_map .getCount () == 0 );
183+ ink_assert (_src_map. getCount () == 0 && _dest_map .getCount () == 0 );
175184
176185 file_buf = readIntoBuffer (config_file_path, module_name, nullptr );
177186
@@ -190,6 +199,8 @@ IpAllow::BuildTable()
190199 }
191200
192201 if (*line != ' \0 ' && *line != ' #' ) {
202+ const matcher_tags &ip_allow_tags =
203+ strstr (line, ip_allow_dest_tags.match_ip ) != nullptr ? ip_allow_dest_tags : ip_allow_src_tags;
193204 errPtr = parseConfigLine (line, &line_info, &ip_allow_tags);
194205
195206 if (errPtr != nullptr ) {
@@ -211,6 +222,7 @@ IpAllow::BuildTable()
211222 uint32_t acl_method_mask = 0 ;
212223 AclRecord::MethodSet nonstandard_methods;
213224 bool deny_nonstandard_methods = false ;
225+ bool is_dest_ip = (strcasecmp (line_info.line [0 ][line_info.dest_entry ], " dest_ip" ) == 0 );
214226 AclOp op = ACL_OP_DENY; // "shut up", I explained to the compiler.
215227 bool op_found = false , method_found = false ;
216228 for (int i = 0 ; i < MATCHER_MAX_TOKENS; i++) {
@@ -272,10 +284,11 @@ IpAllow::BuildTable()
272284 }
273285
274286 if (method_found) {
275- _acls.push_back (AclRecord (acl_method_mask, line_num, nonstandard_methods, deny_nonstandard_methods));
276- // Color with index because at this point the address
277- // is volatile.
278- _map.fill (&addr1, &addr2, reinterpret_cast <void *>(_acls.length () - 1 ));
287+ Vec<AclRecord> &acls = is_dest_ip ? _dest_acls : _src_acls;
288+ IpMap &map = is_dest_ip ? _dest_map : _src_map;
289+ acls.push_back (AclRecord (acl_method_mask, line_num, nonstandard_methods, deny_nonstandard_methods));
290+ // Color with index in acls because at this point the address is volatile.
291+ map.fill (&addr1, &addr2, reinterpret_cast <void *>(acls.length () - 1 ));
279292 } else {
280293 snprintf (errBuf, sizeof (errBuf), " %s discarding %s entry at line %d : %s" , module_name, config_file_path, line_num,
281294 " Invalid action/method specified" ); // changed by YTS Team, yamsat bug id -59022
@@ -288,13 +301,14 @@ IpAllow::BuildTable()
288301 line = tokLine (nullptr , &tok_state);
289302 }
290303
291- if (_map .getCount () == 0 ) {
304+ if (_src_map .getCount () == 0 && _dest_map. getCount () == 0 ) { // TODO: check
292305 Warning (" %s No entries in %s. All IP Addresses will be blocked" , module_name, config_file_path);
293306 } else {
294307 // convert the coloring from indices to pointers.
295- for (IpMap::iterator spot (_map.begin ()), limit (_map.end ()); spot != limit; ++spot) {
296- spot->setData (&_acls[reinterpret_cast <size_t >(spot->data ())]);
297- }
308+ for (auto &item : _src_map)
309+ item.setData (&_src_acls[reinterpret_cast <size_t >(item.data ())]);
310+ for (auto &item : _dest_map)
311+ item.setData (&_dest_acls[reinterpret_cast <size_t >(item.data ())]);
298312 }
299313
300314 if (is_debug_tag_set (" ip-allow" )) {
0 commit comments