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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors