Eui64.cc
Go to the documentation of this file.
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
21bool
22Eui::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
33bool
34Eui::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
46bool
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
57bool
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
77bool
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
unsigned char eui[SZ_EUI64_BUF]
Definition: Eui64.h:85
bool lookupNdp(const Ip::Address &c)
Definition: Eui64.cc:78
bool lookupSlaac(const Ip::Address &c)
Definition: Eui64.cc:58
bool decode(const char *asc)
Definition: Eui64.cc:22
bool lookup(const Ip::Address &c)
Definition: Eui64.cc:47
bool encode(char *buf, const int len) const
Definition: Eui64.cc:34
bool isSiteLocal6() const
Definition: Address.cc:267
bool isSiteLocalAuto() const
Definition: Address.cc:277
bool getInAddr(struct in_addr &) const
Definition: Address.cc:1020
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
int eui64_aton(const char *a, struct eui64 *e)
Definition: eui64_aton.c:94
#define SZ_EUI64_BUF
Definition: Eui64.h:31

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors