samples: bpf: Convert route table network order fields into readable format
authorGokul Sivakumar <gokulkumar792@gmail.com>
Sun, 19 Sep 2021 08:03:04 +0000 (13:33 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 21 Sep 2021 20:27:54 +0000 (13:27 -0700)
commitf5c4e4191b542c8ceb4e945342fda8ea2e9a9193
treecabf05f899926a78adcca6cf6317d90356d2fb28
parent97c140d94e2e5f050d5f418317cc34f83da3d0f5
samples: bpf: Convert route table network order fields into readable format

The route table that is dumped when the xdp_router_ipv4 process is launched
has the "Gateway" field in non-readable network byte order format, also the
alignment is off when printing the table.

Destination             Gateway         Genmask         Metric          Iface
  0.0.0.0               196a8c0         0               0               enp7s0
  0.0.0.0               196a8c0         0               0               wlp6s0
169.254.0.0             196a8c0         16              0               enp7s0
172.17.0.0                0             16              0               docker0
192.168.150.0             0             24              0               enp7s0
192.168.150.0             0             24              0               wlp6s0

Fix this by converting the "Gateway" field from network byte order Hex into
dotted decimal notation IPv4 format and "Genmask" from CIDR notation into
dotted decimal notation IPv4 format. Also fix the aligntment of the fields
in the route table.

Destination     Gateway         Genmask         Metric Iface
0.0.0.0         192.168.150.1   0.0.0.0         0      enp7s0
0.0.0.0         192.168.150.1   0.0.0.0         0      wlp6s0
169.254.0.0     192.168.150.1   255.255.0.0     0      enp7s0
172.17.0.0      0.0.0.0         255.255.0.0     0      docker0
192.168.150.0   0.0.0.0         255.255.255.0   0      enp7s0
192.168.150.0   0.0.0.0         255.255.255.0   0      wlp6s0

Signed-off-by: Gokul Sivakumar <gokulkumar792@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210919080305.173588-1-gokulkumar792@gmail.com
samples/bpf/xdp_router_ipv4_user.c