]> git.ipfire.org Git - thirdparty/squid.git/blame - src/eui/Eui64.cc
SourceLayout: Add Ip namespace for internal libip
[thirdparty/squid.git] / src / eui / Eui64.cc
CommitLineData
a98c2da5
AJ
1/*
2 * DEBUG: section ?? EUI-64 Handling
3 * AUTHOR: Amos Jeffries
4 *
5 * Copyright (c) 2009, Amos Jeffries <squid3@treenet.co.nz>
6 */
7
8#include "config.h"
9
10#if USE_SQUID_EUI
11
27bc2077 12#include "compat/eui64_aton.h"
a98c2da5
AJ
13#include "Debug.h"
14#include "eui/Eui64.h"
15#include "globals.h"
16#include "ip/IpAddress.h"
17
a98c2da5
AJ
18bool
19Eui::Eui64::decode(const char *asc)
20{
21 if (eui64_aton(asc, (struct eui64 *)eui) != 0) return false;
22
23 return true;
24}
25
26bool
27Eui::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
38bool
b7ac5457 39Eui::Eui64::lookup(Ip::Address &c)
a98c2da5
AJ
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
48bool
b7ac5457 49Eui::Eui64::lookupSlaac(Ip::Address &c)
a98c2da5
AJ
50{
51#if USE_IPV6
52 /* RFC 4291 Link-Local unicast addresses which contain SLAAC - usually trustable. */
53 if (c.IsSiteLocal6() && c.IsSlaac() ) {
54
55 // strip the final 64 bits of the address...
56 struct in6_addr tmp;
57 c.GetInAddr(tmp);
58 memcpy(eui, &(tmp.s6_addr[8]), SZ_EUI64_BUF);
59
60 return true;
61 }
62#endif
63 return false;
64}
65
66// return binary representation of the EUI
67bool
b7ac5457 68Eui::Eui64::lookupNdp(Ip::Address &c)
a98c2da5
AJ
69{
70#if USE_IPV6
71
72#if 0 /* no OS yet supported for NDP protocol lookup */
73
74#else
75 debugs(28, 0, "ERROR: ARP / MAC / EUI-* operations not supported on this operating system.");
76#endif
77
78 /*
79 * Address was not found on any interface
80 */
81 debugs(28, 3, HERE << c << " NOT found");
82#else
83 debugs(28, 0, "ERROR: IPv6 EUI-64 operations not supported on this operating system.");
84#endif
85
86 clear();
87 return false;
88}
89
90#endif /* USE_SQUID_EUI */