1 /*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "Addr.h"
18
19 #include "../structs.h"
20 #include "attributes.h"
21 #include "structs.h"
22
23 // should be in linux/if_addr.h
24 #define IFA_F_MANAGETEMPADDR 0x100
25 #define IFA_F_NOPREFIXROUTE 0x200
26 #define IFA_F_MCAUTOJOIN 0x400
27 #define IFA_F_STABLE_PRIVACY 0x800
28
29 namespace android::nl::protocols::route {
30
31 using DataType = AttributeDefinition::DataType;
32
33 // clang-format off
Addr()34 Addr::Addr() : MessageDefinition<ifaddrmsg>("addr", {
35 {RTM_NEWADDR, {"NEWADDR", MessageGenre::New}},
36 {RTM_DELADDR, {"DELADDR", MessageGenre::Delete}},
37 {RTM_GETADDR, {"GETADDR", MessageGenre::Get}},
38 }, gAttributes) {}
39
40 static const FlagsMap ifaFlagsMap {
41 {IFA_F_SECONDARY, "SECONDARY"},
42 {IFA_F_NODAD, "NODAD"},
43 {IFA_F_OPTIMISTIC, "OPTIMISTIC"},
44 {IFA_F_DADFAILED, "DADFAILED"},
45 {IFA_F_HOMEADDRESS, "HOMEADDRESS"},
46 {IFA_F_DEPRECATED, "DEPRECATED"},
47 {IFA_F_TENTATIVE, "TENTATIVE"},
48 {IFA_F_PERMANENT, "PERMANENT"},
49 {IFA_F_MANAGETEMPADDR, "MANAGETEMPADDR"},
50 {IFA_F_NOPREFIXROUTE, "NOPREFIXROUTE"},
51 {IFA_F_MCAUTOJOIN, "MCAUTOJOIN"},
52 {IFA_F_STABLE_PRIVACY, "STABLE_PRIVACY"},
53 };
54 // clang-format on
55
toStream(std::stringstream & ss,const ifaddrmsg & data) const56 void Addr::toStream(std::stringstream& ss, const ifaddrmsg& data) const {
57 ss << "ifaddrmsg{"
58 << "family=" << familyToString(data.ifa_family)
59 << ", prefixlen=" << unsigned(data.ifa_prefixlen) << ", flags=";
60 flagsToStream(ss, ifaFlagsMap, data.ifa_flags);
61 ss << ", scope=" << unsigned(data.ifa_scope) << ", index=" << data.ifa_index << "}";
62 }
63
64 } // namespace android::nl::protocols::route
65