Eui64.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 28 Access Control */
10 
11 #include "squid.h"
12 
13 #if USE_SQUID_EUI
14 
15 #include "acl/Eui64.h"
16 #include "acl/FilledChecklist.h"
17 #include "Debug.h"
18 #include "eui/Eui64.h"
19 #include "globals.h"
20 #include "ip/Address.h"
21 
22 ACL *
24 {
25  return new ACLEui64(*this);
26 }
27 
28 ACLEui64::ACLEui64 (char const *theClass) : class_ (theClass)
29 {}
30 
31 ACLEui64::ACLEui64 (ACLEui64 const & old) : eui64Data(old.eui64Data), class_ (old.class_)
32 {
33 }
34 
35 char const *
37 {
38  return class_;
39 }
40 
41 bool
43 {
44  return eui64Data.empty();
45 }
46 
47 Eui::Eui64 *
48 aclParseEuiData(const char *t)
49 {
50  char buf[256];
51  Eui::Eui64 *q = new Eui::Eui64;
52  debugs(28, 5, "aclParseEuiData: " << t);
53 
54  if (sscanf(t, "%[0-9a-fA-F:]", buf) != 1) {
55  debugs(28, DBG_CRITICAL, "aclParseEuiData: Bad EUI-64 address: '" << t << "'");
56  delete q;
57  return NULL;
58  }
59 
60  if (!q->decode(buf)) {
61  debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
62  debugs(28, DBG_CRITICAL, "aclParseEuiData: Ignoring invalid EUI-64 acl entry: can't parse '" << buf << "'");
63  delete q;
64  return NULL;
65  }
66 
67  return q;
68 }
69 
70 /*******************/
71 /* aclParseEuiList */
72 /*******************/
73 void
75 {
76  while (const char * t = ConfigParser::strtokFile()) {
77  if (Eui::Eui64 * q = aclParseEuiData(t)) {
78  eui64Data.insert(*q);
79  delete q;
80  }
81  }
82 }
83 
84 int
86 {
87  ACLFilledChecklist *checklist = Filled(cl);
88 
89  /* IPv4 does not do EUI-64 (yet) */
90  if (!checklist->src_addr.isIPv6()) {
91  debugs(14, 3, "ACLEui64::match: IPv6 Required for EUI-64 Lookups. Skipping " << checklist->src_addr );
92  return 0;
93  }
94 
95  Eui::Eui64 lookingFor;
96  if (lookingFor.lookup(checklist->src_addr)) {
97  bool found = (eui64Data.find(lookingFor) != eui64Data.end());
98  debugs(28, 3, checklist->src_addr << "' " << (found ? "found" : "NOT found"));
99  return found;
100  }
101 
102  debugs(28, 3, checklist->src_addr << " NOT found");
103  return 0;
104 }
105 
106 SBufList
108 {
109  SBufList sl;
110  for (auto i = eui64Data.begin(); i != eui64Data.end(); ++i) {
111  static char buf[48];
112  i->encode(buf,48);
113  sl.push_back(SBuf(buf));
114  }
115  return sl;
116 }
117 
118 #endif /* USE_SQUID_EUI */
119 
virtual bool empty() const
Definition: Eui64.cc:42
Definition: SBuf.h:87
Eui::Eui64 * aclParseEuiData(const char *t)
Definition: Eui64.cc:48
Ip::Address src_addr
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
int i
Definition: membanger.c:49
Definition: Acl.h:39
virtual void parse()
parses node represenation in squid.conf; dies on failures
Definition: Eui64.cc:74
virtual char const * typeString() const
Definition: Eui64.cc:36
#define DBG_CRITICAL
Definition: Debug.h:44
Eui64Data_t eui64Data
Definition: Eui64.h:40
bool isIPv6() const
Definition: Address.cc:157
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
int config_lineno
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
Definition: Eui64.cc:85
const char * cfg_filename
ACLEui64(char const *)
Definition: Eui64.cc:28
Definition: Eui64.h:21
virtual ACL * clone() const
Definition: Eui64.cc:23
std::list< SBuf > SBufList
Definition: forward.h:26
void const char * buf
Definition: stub_helper.cc:16
char const * class_
Definition: Eui64.h:41
bool decode(const char *asc)
Definition: Eui64.cc:22
char config_input_line[BUFSIZ]
static char * strtokFile()
Definition: ConfigParser.cc:82
virtual SBufList dump() const
Definition: Eui64.cc:107
bool lookup(const Ip::Address &c)
Definition: Eui64.cc:47
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors