~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/IPAllow.h

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
/*****************************************************************************
 
25
 *
 
26
 *  IPAllow.h - Interface to IP Access Control systtem
 
27
 *
 
28
 *
 
29
 ****************************************************************************/
 
30
 
 
31
#ifndef _IP_ALLOW_H_
 
32
#define _IP_ALLOW_H_
 
33
 
 
34
#include "IpLookup.h"
 
35
#include "Main.h"
 
36
 
 
37
void initIPAllow();
 
38
void reloadIPAllow();
 
39
 
 
40
//
 
41
// Timeout the IpAllowTable * this amount of time after the
 
42
//    a reconfig event happens that the old table gets thrown
 
43
//    away
 
44
//
 
45
#define IP_ALLOW_TIMEOUT            (HRTIME_HOUR*1)
 
46
 
 
47
// INKqa05845
 
48
#define IP_ALLOW 1
 
49
#define IP_DENY -1
 
50
class IpAllowRecord
 
51
{
 
52
public:
 
53
  int access;
 
54
  int line_num;
 
55
};
 
56
 
 
57
class IpAllow:public IpLookup
 
58
{
 
59
public:
 
60
  IpAllow(const char *config_var, const char *name, const char *action_val);
 
61
   ~IpAllow();
 
62
  int BuildTable();
 
63
  void Print();
 
64
  bool match(ip_addr_t ip);
 
65
private:
 
66
  const char *config_file_var;
 
67
  char config_file_path[PATH_NAME_MAX];
 
68
  const char *module_name;
 
69
  const char *action;
 
70
  bool err_allow_all;
 
71
};
 
72
 
 
73
extern IpAllow *ip_allow_table;
 
74
 
 
75
// INKqa05845
 
76
inline bool
 
77
IpAllow::match(ip_addr_t ip)
 
78
{
 
79
  if (err_allow_all == true) {
 
80
    return true;
 
81
  } else {
 
82
    IpAllowRecord *cur = NULL, *result = NULL;
 
83
    IpLookupState s;
 
84
    bool found;
 
85
    found = IpLookup::MatchFirst(ip, &s, (void **) &cur);
 
86
    result = cur;
 
87
    while (found) {
 
88
      if (cur->line_num < result->line_num) {
 
89
        result = cur;
 
90
      }
 
91
      found = IpLookup::MatchNext(&s, (void **) &cur);
 
92
    }
 
93
    return ((result != NULL) && (result->access == IP_ALLOW));
 
94
  }
 
95
}
 
96
 
 
97
#endif