]> git.ipfire.org Git - thirdparty/squid.git/blob - src/eui/Eui64.cc
Renamed squid.h to squid-old.h and config.h to squid.h
[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) return false;
22
23 return true;
24 }
25
26 bool
27 Eui::Eui64::encode(char *buf, const int len)
28 {
29 if (len < SZ_EUI64_BUF) return false;
30
31 snprintf(buf, len, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
32 eui[0], eui[1], eui[2], eui[3],
33 eui[4], eui[5], eui[6], eui[7]);
34 return true;
35 }
36
37 // return binary representation of the EUI
38 bool
39 Eui::Eui64::lookup(const Ip::Address &c)
40 {
41 /* try to short-circuit slow OS lookups by using SLAAC data */
42 if (lookupSlaac(c)) return true;
43
44 // find EUI-64 some other way. NDP table lookup?
45 return lookupNdp(c);
46 }
47
48 bool
49 Eui::Eui64::lookupSlaac(const Ip::Address &c)
50 {
51 /* RFC 4291 Link-Local unicast addresses which contain SLAAC - usually trustable. */
52 if (c.IsSiteLocal6() && c.IsSlaac() ) {
53
54 // strip the final 64 bits of the address...
55 struct in6_addr tmp;
56 c.GetInAddr(tmp);
57 memcpy(eui, &(tmp.s6_addr[8]), SZ_EUI64_BUF);
58
59 return true;
60 }
61 return false;
62 }
63
64 // return binary representation of the EUI
65 bool
66 Eui::Eui64::lookupNdp(const Ip::Address &c)
67 {
68 #if 0 /* no actual lookup coded yet */
69
70 /* no OS yet supported for NDP protocol lookup */
71 debugs(28, 0, "ERROR: ARP / MAC / EUI-* operations not supported on this operating system.");
72
73 /*
74 * Address was not found on any interface
75 */
76 debugs(28, 3, HERE << c << " NOT found");
77 #endif /* 0 */
78
79 clear();
80 return false;
81 }
82
83 #endif /* USE_SQUID_EUI */