xref: /aosp_15_r20/hardware/interfaces/automotive/can/1.0/default/libnl++/protocols/route/structs.h (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
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 #pragma once
18 
19 #include <libnl++/Buffer.h>
20 
21 #include <linux/rtnetlink.h>
22 #include <sys/socket.h>
23 
24 #include <sstream>
25 
26 namespace android::nl::protocols::route {
27 
28 // rtnl_link_ifmap
29 void mapToStream(std::stringstream& ss, const Buffer<nlattr> attr);
30 
31 // ifla_cacheinfo
32 void ifla_cacheinfoToStream(std::stringstream& ss, const Buffer<nlattr> attr);
33 
34 std::string familyToString(sa_family_t family);
35 
36 // rtnl_link_stats or rtnl_link_stats64
37 template <typename T>
statsToStream(std::stringstream & ss,const Buffer<nlattr> attr)38 void statsToStream(std::stringstream& ss, const Buffer<nlattr> attr) {
39     const auto& [ok, data] = attr.data<T>().getFirst();
40     if (!ok) {
41         ss << "invalid structure";
42         return;
43     }
44     ss << '{'                              //
45        << data.rx_packets << ','           //
46        << data.tx_packets << ','           //
47        << data.rx_bytes << ','             //
48        << data.tx_bytes << ','             //
49        << data.rx_errors << ','            //
50        << data.tx_errors << ','            //
51        << data.rx_dropped << ','           //
52        << data.tx_dropped << ','           //
53        << data.multicast << ','            //
54        << data.collisions << ','           //
55        << data.rx_length_errors << ','     //
56        << data.rx_over_errors << ','       //
57        << data.rx_crc_errors << ','        //
58        << data.rx_frame_errors << ','      //
59        << data.rx_fifo_errors << ','       //
60        << data.rx_missed_errors << ','     //
61        << data.tx_aborted_errors << ','    //
62        << data.tx_carrier_errors << ','    //
63        << data.tx_fifo_errors << ','       //
64        << data.tx_heartbeat_errors << ','  //
65        << data.tx_window_errors << ','     //
66        << data.rx_compressed << ','        //
67        << data.tx_compressed << '}';
68     // Not printed (due to portability): rx_nohandler, rx_otherhost_dropped
69 }
70 
71 }  // namespace android::nl::protocols::route
72