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 "attributes.h"
18 
19 #include "../structs.h"
20 #include "structs.h"
21 
22 #include <linux/rtnetlink.h>
23 #include <net/if.h>
24 
25 namespace android::nl::protocols::route {
26 
27 using DataType = AttributeDefinition::DataType;
28 using Flags = AttributeDefinition::Flags;
29 
30 // clang-format off
31 AttributeMap gAttributes = {
32     {IFLA_ADDRESS, {"ADDRESS"}},
33     {IFLA_BROADCAST, {"BROADCAST"}},
34     {IFLA_IFNAME, {"IFNAME", DataType::StringNul}},
35     {IFLA_MTU, {"MTU", DataType::Uint}},
36     {IFLA_LINK, {"LINK", DataType::Uint}},
37     {IFLA_QDISC, {"QDISC", DataType::Raw, AttributeMap{}, Flags::Verbose}},  // should be DataType::String, but looks like binary blob
38     {IFLA_STATS, {"STATS", DataType::Struct, statsToStream<rtnl_link_stats>}},
39     {IFLA_COST, {"COST", DataType::Uint}},
40     {IFLA_PRIORITY, {"PRIORITY"}},
41     {IFLA_MASTER, {"MASTER", DataType::Uint}},
42     {IFLA_WIRELESS, {"WIRELESS"}},
43     {IFLA_PROTINFO, {"PROTINFO"}},
44     {IFLA_TXQLEN, {"TXQLEN", DataType::Uint}},
45     {IFLA_MAP, {"MAP", DataType::Struct, mapToStream}},
46     {IFLA_WEIGHT, {"WEIGHT", DataType::Uint}},
47     {IFLA_OPERSTATE, {"OPERSTATE", DataType::Uint}},
48     {IFLA_LINKMODE, {"LINKMODE", DataType::Uint}},
49     {IFLA_LINKINFO, {"LINKINFO", DataType::Nested, AttributeMap{
50         {IFLA_INFO_KIND, {"INFO_KIND", DataType::String}},
51         {IFLA_INFO_DATA, {"INFO_DATA", DataType::Nested}},
52         {IFLA_INFO_XSTATS, {"INFO_XSTATS"}},
53         {IFLA_INFO_SLAVE_KIND, {"INFO_SLAVE_KIND", DataType::String}},
54         {IFLA_INFO_SLAVE_DATA, {"INFO_SLAVE_DATA"}},
55     }}},
56     {IFLA_NET_NS_PID, {"NET_NS_PID", DataType::Uint}},
57     {IFLA_IFALIAS, {"IFALIAS", DataType::String}},
58     {IFLA_NUM_VF, {"NUM_VF", DataType::Uint}},
59     {IFLA_VFINFO_LIST, {"VFINFO_LIST"}},
60     {IFLA_STATS64, {"STATS64", DataType::Struct, statsToStream<rtnl_link_stats64>}},
61     {IFLA_VF_PORTS, {"VF_PORTS"}},
62     {IFLA_PORT_SELF, {"PORT_SELF"}},
63     {IFLA_AF_SPEC, {"AF_SPEC", DataType::Nested, AttributeMap{
64         {AF_INET, {"AF_INET", DataType::Nested, AttributeMap{
65             {IFLA_INET_CONF, {"INET_CONF", DataType::Struct, arrayToStream<int32_t>}},
66         }}},
67         {AF_INET6, {"AF_INET6", DataType::Nested, AttributeMap{
68             {IFLA_INET6_FLAGS, {"INET6_FLAGS", DataType::Uint}},
69             {IFLA_INET6_CONF, {"INET6_CONF", DataType::Struct, arrayToStream<int32_t>}},
70             {IFLA_INET6_STATS, {"INET6_STATS", DataType::Struct, arrayToStream<uint64_t>}},
71             {IFLA_INET6_MCAST, {"INET6_MCAST"}},
72             {IFLA_INET6_CACHEINFO, {"INET6_CACHEINFO", DataType::Struct, ifla_cacheinfoToStream}},
73             {IFLA_INET6_ICMP6STATS, {"INET6_ICMP6STATS", DataType::Struct, arrayToStream<uint64_t>}},
74             {IFLA_INET6_TOKEN, {"INET6_TOKEN"}},
75             {IFLA_INET6_ADDR_GEN_MODE, {"INET6_ADDR_GEN_MODE", DataType::Uint}},
76         }}},
77     }}},
78     {IFLA_GROUP, {"GROUP", DataType::Uint}},
79     {IFLA_NET_NS_FD, {"NET_NS_FD", DataType::Uint}},
80     {IFLA_EXT_MASK, {"EXT_MASK", DataType::Uint}},
81     {IFLA_PROMISCUITY, {"PROMISCUITY", DataType::Uint}},
82     {IFLA_NUM_TX_QUEUES, {"NUM_TX_QUEUES", DataType::Uint}},
83     {IFLA_NUM_RX_QUEUES, {"NUM_RX_QUEUES", DataType::Uint}},
84     {IFLA_CARRIER, {"CARRIER", DataType::Uint}},
85     {IFLA_PHYS_PORT_ID, {"PHYS_PORT_ID"}},
86     {IFLA_CARRIER_CHANGES, {"CARRIER_CHANGES", DataType::Uint}},
87     {IFLA_PHYS_SWITCH_ID, {"PHYS_SWITCH_ID"}},
88     {IFLA_LINK_NETNSID, {"LINK_NETNSID"}},  // NLA_S32
89     {IFLA_PHYS_PORT_NAME, {"PHYS_PORT_NAME", DataType::String}},
90     {IFLA_PROTO_DOWN, {"PROTO_DOWN", DataType::Uint}},
91     {IFLA_GSO_MAX_SEGS, {"GSO_MAX_SEGS", DataType::Uint}},
92     {IFLA_GSO_MAX_SIZE, {"GSO_MAX_SIZE", DataType::Uint}},
93     {IFLA_PAD, {"PAD"}},
94     {IFLA_XDP, {"XDP"}},
95     {IFLA_EVENT, {"EVENT", DataType::Uint}},
96     {IFLA_NEW_NETNSID, {"NEW_NETNSID"}},  // NLA_S32
97     {IFLA_TARGET_NETNSID, {"TARGET_NETNSID"}},  // NLA_S32
98     {IFLA_CARRIER_UP_COUNT, {"CARRIER_UP_COUNT", DataType::Uint}},
99     {IFLA_CARRIER_DOWN_COUNT, {"CARRIER_DOWN_COUNT", DataType::Uint}},
100     {IFLA_NEW_IFINDEX, {"NEW_IFINDEX"}},  // NLA_S32
101     {IFLA_MIN_MTU, {"MIN_MTU", DataType::Uint}},
102     {IFLA_MAX_MTU, {"MAX_MTU", DataType::Uint}},
103     {IFLA_PROP_LIST, {"PROP_LIST"}},
104     {IFLA_ALT_IFNAME, {"ALT_IFNAME", DataType::String}},
105     {IFLA_PERM_ADDRESS, {"PERM_ADDRESS"}},
106 };
107 // clang-format on
108 
109 }  // namespace android::nl::protocols::route
110