• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 "structs.h"
18 
19 namespace android::nl::protocols::route {
20 
mapToStream(std::stringstream & ss,const Buffer<nlattr> attr)21 void mapToStream(std::stringstream& ss, const Buffer<nlattr> attr) {
22     const auto& [ok, data] = attr.data<rtnl_link_ifmap>().getFirst();
23     if (!ok) {
24         ss << "invalid structure";
25         return;
26     }
27     ss << '{'                        //
28        << data.mem_start << ','      //
29        << data.mem_end << ','        //
30        << data.base_addr << ','      //
31        << data.irq << ','            //
32        << unsigned(data.dma) << ','  //
33        << unsigned(data.port) << '}';
34 }
35 
ifla_cacheinfoToStream(std::stringstream & ss,const Buffer<nlattr> attr)36 void ifla_cacheinfoToStream(std::stringstream& ss, const Buffer<nlattr> attr) {
37     const auto& [ok, data] = attr.data<ifla_cacheinfo>().getFirst();
38     if (!ok) {
39         ss << "invalid structure";
40         return;
41     }
42     ss << '{'                         //
43        << data.max_reasm_len << ','   //
44        << data.tstamp << ','          //
45        << data.reachable_time << ','  //
46        << data.retrans_time << '}';
47 }
48 
49 // clang-format off
familyToString(sa_family_t family)50 std::string familyToString(sa_family_t family) {
51     switch (family) {
52         case AF_UNSPEC: return "UNSPEC";
53         case AF_UNIX: return "UNIX";
54         case AF_INET: return "INET";
55         case AF_AX25: return "AX25";
56         case AF_IPX: return "IPX";
57         case AF_APPLETALK: return "APPLETALK";
58         case AF_NETROM: return "NETROM";
59         case AF_BRIDGE: return "BRIDGE";
60         case AF_ATMPVC: return "ATMPVC";
61         case AF_X25: return "X25";
62         case AF_INET6: return "INET6";
63         case AF_ROSE: return "ROSE";
64         case AF_DECnet: return "DECnet";
65         case AF_NETBEUI: return "NETBEUI";
66         case AF_SECURITY: return "SECURITY";
67         case AF_KEY: return "KEY";
68         case AF_NETLINK: return "NETLINK";
69         case AF_PACKET: return "PACKET";
70         case AF_ASH: return "ASH";
71         case AF_ECONET: return "ECONET";
72         case AF_ATMSVC: return "ATMSVC";
73         case AF_RDS: return "RDS";
74         case AF_SNA: return "SNA";
75         case AF_IRDA: return "IRDA";
76         case AF_PPPOX: return "PPPOX";
77         case AF_WANPIPE: return "WANPIPE";
78         case AF_LLC: return "LLC";
79         case 27 /*AF_IB*/: return "IB";
80         case 28 /*AF_MPLS*/: return "MPLS";
81         case AF_CAN: return "CAN";
82         case AF_TIPC: return "TIPC";
83         case AF_BLUETOOTH: return "BLUETOOTH";
84         case AF_IUCV: return "IUCV";
85         case AF_RXRPC: return "RXRPC";
86         case AF_ISDN: return "ISDN";
87         case AF_PHONET: return "PHONET";
88         case AF_IEEE802154: return "IEEE802154";
89         case AF_CAIF: return "CAIF";
90         case AF_ALG: return "ALG";
91         case AF_NFC: return "NFC";
92         case AF_VSOCK: return "VSOCK";
93         case AF_KCM: return "KCM";
94         case AF_QIPCRTR: return "QIPCRTR";
95         case 43 /*AF_SMC*/: return "SMC";
96         case 44 /*AF_XDP*/: return "XDP";
97         default:
98             return std::to_string(family);
99     }
100 }
101 // clang-format on
102 
103 }  // namespace android::nl::protocols::route
104