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