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 namespace android::nl::protocols::route {
24
25 using DataType = AttributeDefinition::DataType;
26
27 // clang-format off
Addr()28 Addr::Addr() : MessageDefinition<ifaddrmsg>("addr", {
29 {RTM_NEWADDR, {"NEWADDR", MessageGenre::New}},
30 {RTM_DELADDR, {"DELADDR", MessageGenre::Delete}},
31 {RTM_GETADDR, {"GETADDR", MessageGenre::Get}},
32 }, gAttributes) {}
33
34 static const FlagsMap ifaFlagsMap {
35 {IFA_F_SECONDARY, "SECONDARY"},
36 {IFA_F_NODAD, "NODAD"},
37 {IFA_F_OPTIMISTIC, "OPTIMISTIC"},
38 {IFA_F_DADFAILED, "DADFAILED"},
39 {IFA_F_HOMEADDRESS, "HOMEADDRESS"},
40 {IFA_F_DEPRECATED, "DEPRECATED"},
41 {IFA_F_TENTATIVE, "TENTATIVE"},
42 {IFA_F_PERMANENT, "PERMANENT"},
43 {IFA_F_MANAGETEMPADDR, "MANAGETEMPADDR"},
44 {IFA_F_NOPREFIXROUTE, "NOPREFIXROUTE"},
45 {IFA_F_MCAUTOJOIN, "MCAUTOJOIN"},
46 {IFA_F_STABLE_PRIVACY, "STABLE_PRIVACY"},
47 };
48 // clang-format on
49
toStream(std::stringstream & ss,const ifaddrmsg & data) const50 void Addr::toStream(std::stringstream& ss, const ifaddrmsg& data) const {
51 ss << "ifaddrmsg{"
52 << "family=" << familyToString(data.ifa_family)
53 << ", prefixlen=" << unsigned(data.ifa_prefixlen) << ", flags=";
54 flagsToStream(ss, ifaFlagsMap, data.ifa_flags);
55 ss << ", scope=" << unsigned(data.ifa_scope) << ", index=" << data.ifa_index << "}";
56 }
57
58 } // namespace android::nl::protocols::route
59