]> git.ipfire.org Git - thirdparty/squid.git/blob - src/eui/Eui64.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / eui / Eui64.cc
1 /*
2 * Copyright (C) 1996-2023 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 89 EUI-64 Handling */
10
11 #include "squid.h"
12
13 #if USE_SQUID_EUI
14
15 #include "compat/eui64_aton.h"
16 #include "debug/Stream.h"
17 #include "eui/Eui64.h"
18 #include "globals.h"
19 #include "ip/Address.h"
20
21 bool
22 Eui::Eui64::decode(const char *asc)
23 {
24 if (eui64_aton(asc, (struct eui64 *)eui) != 0) {
25 debugs(28, 4, "id=" << (void*)this << " decode fail on " << asc);
26 return false;
27 }
28
29 debugs(28, 4, "id=" << (void*)this << " ATON decoded " << asc);
30 return true;
31 }
32
33 bool
34 Eui::Eui64::encode(char *buf, const int len) const
35 {
36 if (len < SZ_EUI64_BUF) return false;
37
38 snprintf(buf, len, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
39 eui[0], eui[1], eui[2], eui[3],
40 eui[4], eui[5], eui[6], eui[7]);
41 debugs(28, 4, "id=" << (void*)this << " encoded " << buf);
42 return true;
43 }
44
45 // return binary representation of the EUI
46 bool
47 Eui::Eui64::lookup(const Ip::Address &c)
48 {
49 /* try to short-circuit slow OS lookups by using SLAAC data */
50 if (lookupSlaac(c))
51 return true;
52
53 // find EUI-64 some other way. NDP table lookup?
54 return lookupNdp(c);
55 }
56
57 bool
58 Eui::Eui64::lookupSlaac(const Ip::Address &c)
59 {
60 /* RFC 4291 Link-Local unicast addresses which contain SLAAC - usually trustable. */
61 if (c.isSiteLocal6() && c.isSiteLocalAuto()) {
62
63 // strip the final 64 bits of the address...
64 struct in6_addr tmp;
65 c.getInAddr(tmp);
66 memcpy(eui, &(tmp.s6_addr[8]), SZ_EUI64_BUF);
67 debugs(28, 4, "id=" << (void*)this << " SLAAC decoded " << c);
68 return true;
69 }
70
71 debugs(28, 4, "id=" << (void*)this << " SLAAC fail on " << c << " SL-6="
72 << (c.isSiteLocal6()?'T':'F') << " AAC-6=" << (c.isSiteLocalAuto()?'T':'F'));
73 return false;
74 }
75
76 // return binary representation of the EUI
77 bool
78 Eui::Eui64::lookupNdp(const Ip::Address &/*c*/)
79 {
80 #if 0 /* no actual lookup coded yet */
81
82 /* no OS yet supported for NDP protocol lookup */
83 debugs(28, DBG_CRITICAL, "ERROR: ARP / MAC / EUI-* operations not supported on this operating system.");
84
85 /*
86 * Address was not found on any interface
87 */
88 debugs(28, 3, "id=" << (void*)this << ' ' << c << " NOT found");
89 #endif /* 0 */
90
91 clear();
92 return false;
93 }
94
95 #endif /* USE_SQUID_EUI */
96