]>
Commit | Line | Data |
---|---|---|
a98c2da5 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
a98c2da5 | 3 | * |
bbc27441 AJ |
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. | |
a98c2da5 AJ |
7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 89 EUI-64 Handling */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
a98c2da5 AJ |
12 | |
13 | #if USE_SQUID_EUI | |
14 | ||
27bc2077 | 15 | #include "compat/eui64_aton.h" |
a98c2da5 AJ |
16 | #include "Debug.h" |
17 | #include "eui/Eui64.h" | |
18 | #include "globals.h" | |
96d89ea0 | 19 | #include "ip/Address.h" |
a98c2da5 | 20 | |
a98c2da5 AJ |
21 | bool |
22 | Eui::Eui64::decode(const char *asc) | |
23 | { | |
68e47c3e | 24 | if (eui64_aton(asc, (struct eui64 *)eui) != 0) { |
e2849af8 A |
25 | debugs(28, 4, "id=" << (void*)this << " decode fail on " << asc); |
26 | return false; | |
68e47c3e | 27 | } |
a98c2da5 | 28 | |
68e47c3e | 29 | debugs(28, 4, "id=" << (void*)this << " ATON decoded " << asc); |
a98c2da5 AJ |
30 | return true; |
31 | } | |
32 | ||
33 | bool | |
736a7789 | 34 | Eui::Eui64::encode(char *buf, const int len) const |
a98c2da5 AJ |
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]); | |
68e47c3e | 41 | debugs(28, 4, "id=" << (void*)this << " encoded " << buf); |
a98c2da5 AJ |
42 | return true; |
43 | } | |
44 | ||
45 | // return binary representation of the EUI | |
46 | bool | |
00406b24 | 47 | Eui::Eui64::lookup(const Ip::Address &c) |
a98c2da5 AJ |
48 | { |
49 | /* try to short-circuit slow OS lookups by using SLAAC data */ | |
68e47c3e AJ |
50 | if (lookupSlaac(c)) |
51 | return true; | |
a98c2da5 AJ |
52 | |
53 | // find EUI-64 some other way. NDP table lookup? | |
54 | return lookupNdp(c); | |
55 | } | |
56 | ||
57 | bool | |
00406b24 | 58 | Eui::Eui64::lookupSlaac(const Ip::Address &c) |
a98c2da5 | 59 | { |
a98c2da5 | 60 | /* RFC 4291 Link-Local unicast addresses which contain SLAAC - usually trustable. */ |
68e47c3e | 61 | if (c.isSiteLocal6() && c.isSiteLocalAuto()) { |
a98c2da5 AJ |
62 | |
63 | // strip the final 64 bits of the address... | |
64 | struct in6_addr tmp; | |
4dd643d5 | 65 | c.getInAddr(tmp); |
a98c2da5 | 66 | memcpy(eui, &(tmp.s6_addr[8]), SZ_EUI64_BUF); |
68e47c3e | 67 | debugs(28, 4, "id=" << (void*)this << " SLAAC decoded " << c); |
a98c2da5 AJ |
68 | return true; |
69 | } | |
68e47c3e AJ |
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')); | |
a98c2da5 AJ |
73 | return false; |
74 | } | |
75 | ||
76 | // return binary representation of the EUI | |
77 | bool | |
ced8def3 | 78 | Eui::Eui64::lookupNdp(const Ip::Address &/*c*/) |
a98c2da5 | 79 | { |
812652e4 | 80 | #if 0 /* no actual lookup coded yet */ |
a98c2da5 | 81 | |
812652e4 | 82 | /* no OS yet supported for NDP protocol lookup */ |
fa84c01d | 83 | debugs(28, DBG_CRITICAL, "ERROR: ARP / MAC / EUI-* operations not supported on this operating system."); |
a98c2da5 AJ |
84 | |
85 | /* | |
86 | * Address was not found on any interface | |
87 | */ | |
68e47c3e | 88 | debugs(28, 3, "id=" << (void*)this << ' ' << c << " NOT found"); |
812652e4 | 89 | #endif /* 0 */ |
a98c2da5 AJ |
90 | |
91 | clear(); | |
92 | return false; | |
93 | } | |
94 | ||
95 | #endif /* USE_SQUID_EUI */ | |
f53969cc | 96 |