1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <arpa/inet.h>
4
5 #include "nm-platform.h"
6 #include "nm-linux-platform.h"
7 #include "nm-fake-platform.h"
8
9 static void
10 dump_interface (NMPlatformLink *link)
11 {
12 GArray *ip6_addresses;
13 GArray *ip4_addresses;
14 const NMPlatformIP6Address *ip6_address;
15 const NMPlatformIP4Address *ip4_address;
16 char addrstr[INET6_ADDRSTRLEN];
17 GArray *ip6_routes;
18 GArray *ip4_routes;
19 const NMPlatformIP6Route *ip6_route;
20 const NMPlatformIP4Route *ip4_route;
21 char networkstr[INET6_ADDRSTRLEN];
22 char gatewaystr[INET6_ADDRSTRLEN];
23 int vlan_id, vlan_parent;
24 const char *address;
25 size_t addrlen;
26 int i;
27
(1) Event cond_true: |
Condition "link->up", taking true branch |
(2) Event if_fallthrough: |
Falling through to end of if statement |
(3) Event if_end: |
End of if statement |
(4) Event cond_true: |
Condition "({...})", taking true branch |
(5) Event if_fallthrough: |
Falling through to end of if statement |
(6) Event if_end: |
End of if statement |
28 g_assert (link->up || !link->connected);
29
30 printf ("%d: %s: %s", link->ifindex, link->name, link->type_name);
(7) Event cond_true: |
Condition "link->up", taking true branch |
31 if (link->up)
(8) Event cond_true: |
Condition "link->connected", taking true branch |
(9) Event if_fallthrough: |
Falling through to end of if statement |
32 printf (" %s", link->connected ? "CONNECTED" : "DISCONNECTED");
33 else
(10) Event if_end: |
End of if statement |
34 printf (" DOWN");
(11) Event cond_true: |
Condition "!link->arp", taking true branch |
35 if (!link->arp)
36 printf (" noarp");
(12) Event cond_true: |
Condition "link->master", taking true branch |
37 if (link->master)
38 printf (" master %d", link->master);
(13) Event cond_true: |
Condition "link->parent", taking true branch |
39 if (link->parent)
40 printf (" parent %d", link->parent);
41 printf (" mtu %d", link->mtu);
42 printf ("\n");
(14) Event cond_true: |
Condition "link->driver", taking true branch |
43 if (link->driver)
44 printf (" driver: %s\n", link->driver);
45 printf (" UDI: %s\n", link->udi);
(15) Event check_return: |
Calling function "nm_platform_vlan_get_info(int, int *, int *)" without checking return value (as is done elsewhere 5 out of 6 times). |
(21) Event unchecked_value: |
No check of the return value of "nm_platform_vlan_get_info(link->ifindex, &vlan_parent, &vlan_id)". |
Also see events: |
[example_checked][example_checked][example_checked][example_checked][example_checked] |
46 nm_platform_vlan_get_info (link->ifindex, &vlan_parent, &vlan_id);
47 if (vlan_parent)
48 printf (" vlan parent %d id %d\n", vlan_parent, vlan_id);
49
50 if (nm_platform_link_is_software (link->ifindex))
51 printf (" class software\n");
52 if (nm_platform_link_supports_slaves (link->ifindex))
53 printf (" class supports-slaves\n");
54 if (nm_platform_link_supports_carrier_detect (link->ifindex))
55 printf (" feature carrier-detect\n");
56 if (nm_platform_link_supports_vlans (link->ifindex))
57 printf (" feature vlans\n");
58
59 address = nm_platform_link_get_address (link->ifindex, &addrlen);
60 if (address) {
61 printf (" link-address ");
62 for (i = 0; i < addrlen; i++)
63 printf ("%s%02hhx", i ? ":" : "", address[i]);
64 printf ("\n");
65 }
66
67 ip4_addresses = nm_platform_ip4_address_get_all (link->ifindex);
68 ip6_addresses = nm_platform_ip6_address_get_all (link->ifindex);
69
70 g_assert (ip4_addresses);
71 g_assert (ip6_addresses);
72
73 for (i = 0; i < ip4_addresses->len; i++) {
74 ip4_address = &g_array_index (ip4_addresses, NMPlatformIP4Address, i);
75 inet_ntop (AF_INET, &ip4_address->address, addrstr, sizeof (addrstr));
76 printf (" ip4-address %s/%d lifetime %u preferred %u\n", addrstr, ip4_address->plen, ip4_address->lifetime, ip4_address->preferred);
77 }
78
79 for (i = 0; i < ip6_addresses->len; i++) {
80 ip6_address = &g_array_index (ip6_addresses, NMPlatformIP6Address, i);
81 inet_ntop (AF_INET6, &ip6_address->address, addrstr, sizeof (addrstr));
82 printf (" ip6-address %s/%d lifetime %u preferred %u\n", addrstr, ip6_address->plen, ip6_address->lifetime, ip6_address->preferred);
83 }
84
85 g_array_unref (ip4_addresses);
86 g_array_unref (ip6_addresses);
87
88 ip4_routes = nm_platform_ip4_route_get_all (link->ifindex, TRUE);
89 ip6_routes = nm_platform_ip6_route_get_all (link->ifindex, TRUE);
90
91 g_assert (ip4_routes);
92 g_assert (ip6_routes);
93
94 for (i = 0; i < ip4_routes->len; i++) {
95 ip4_route = &g_array_index (ip4_routes, NMPlatformIP4Route, i);
96 inet_ntop (AF_INET, &ip4_route->network, networkstr, sizeof (networkstr));
97 inet_ntop (AF_INET, &ip4_route->gateway, gatewaystr, sizeof (gatewaystr));
98 printf (" ip4-route %s/%d via %s\n", networkstr, ip4_route->plen, gatewaystr);
99 }
100
101 for (i = 0; i < ip6_routes->len; i++) {
102 ip6_route = &g_array_index (ip6_routes, NMPlatformIP6Route, i);
103 inet_ntop (AF_INET6, &ip6_route->network, networkstr, sizeof (networkstr));
104 inet_ntop (AF_INET6, &ip6_route->gateway, gatewaystr, sizeof (gatewaystr));
105 printf (" ip6-route %s/%d via %s\n", networkstr, ip6_route->plen, gatewaystr);
106 }
107
108 g_array_unref (ip4_routes);
109 g_array_unref (ip6_routes);
110 }
111
112 static void
113 dump_all (void)
114 {
115 GArray *links = nm_platform_link_get_all ();
116 int i;
117
118 for (i = 0; i < links->len; i++)
119 dump_interface (&g_array_index (links, NMPlatformLink, i));
120 }
121
122 int
123 main (int argc, char **argv)
124 {
125 g_type_init ();
126
127 g_assert (argc <= 2);
128 if (argc > 1 && !g_strcmp0 (argv[1], "--fake"))
129 nm_fake_platform_setup ();
130 else
131 nm_linux_platform_setup ();
132
133 dump_all ();
134
135 return EXIT_SUCCESS;
136 }
137