route: Add preferred prefix formats per protocol
* As per mailing list discussions
This commit is contained in:
@@ -40,11 +40,17 @@ enum modes {
|
|||||||
RTM_FLUSH,
|
RTM_FLUSH,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum preferredPrefixFormat {
|
||||||
|
PREFIX_PREFER_NETMASK = 0,
|
||||||
|
PREFIX_PREFER_CIDR,
|
||||||
|
};
|
||||||
|
|
||||||
struct address_family {
|
struct address_family {
|
||||||
int family;
|
int family;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* identifiers[4];
|
const char* identifiers[4];
|
||||||
int maxAddressLength;
|
int maxAddressLength;
|
||||||
|
int preferredPrefixFormat;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const address_family kFamilies[] = {
|
static const address_family kFamilies[] = {
|
||||||
@@ -53,14 +59,16 @@ static const address_family kFamilies[] = {
|
|||||||
"IPv4",
|
"IPv4",
|
||||||
{"AF_INET", "inet", "ipv4", NULL},
|
{"AF_INET", "inet", "ipv4", NULL},
|
||||||
15,
|
15,
|
||||||
|
PREFIX_PREFER_NETMASK,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
AF_INET6,
|
AF_INET6,
|
||||||
"IPv6",
|
"IPv6",
|
||||||
{"AF_INET6", "inet6", "ipv6", NULL},
|
{"AF_INET6", "inet6", "ipv6", NULL},
|
||||||
39,
|
39,
|
||||||
|
PREFIX_PREFER_CIDR,
|
||||||
},
|
},
|
||||||
{ -1, NULL, {NULL} }
|
{ -1, NULL, {NULL}, -1, -1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -193,8 +201,13 @@ list_routes(int socket, const char *interfaceName, route_entry &route)
|
|||||||
|
|
||||||
printf("%s routing table:\n", family->name);
|
printf("%s routing table:\n", family->name);
|
||||||
|
|
||||||
printf("%*s %*s Flags Interface\n", addressLength, "Destination",
|
if (family->preferredPrefixFormat == PREFIX_PREFER_NETMASK) {
|
||||||
addressLength, "Gateway");
|
printf("%*s %*s %*s Flags Interface\n", addressLength, "Destination",
|
||||||
|
addressLength, "Netmask", addressLength, "Gateway");
|
||||||
|
} else {
|
||||||
|
printf("%*s %*s Flags Interface\n", addressLength, "Destination",
|
||||||
|
addressLength, "Gateway");
|
||||||
|
}
|
||||||
|
|
||||||
while (interface < end) {
|
while (interface < end) {
|
||||||
route_entry& route = interface->ifr_route;
|
route_entry& route = interface->ifr_route;
|
||||||
@@ -206,13 +219,23 @@ list_routes(int socket, const char *interfaceName, route_entry &route)
|
|||||||
if (family != NULL) {
|
if (family != NULL) {
|
||||||
BNetworkAddress destination(*route.destination);
|
BNetworkAddress destination(*route.destination);
|
||||||
printf("%*s", addressLength, destination.ToString().String());
|
printf("%*s", addressLength, destination.ToString().String());
|
||||||
|
|
||||||
if (route.mask != NULL) {
|
if (route.mask != NULL) {
|
||||||
BNetworkAddress mask;
|
BNetworkAddress mask;
|
||||||
mask.SetTo(*route.mask);
|
mask.SetTo(*route.mask);
|
||||||
printf("/%-3zd ", mask.PrefixLength());
|
if (family->preferredPrefixFormat
|
||||||
} else
|
== PREFIX_PREFER_NETMASK) {
|
||||||
printf(" ");
|
printf(" %*s ", addressLength,
|
||||||
|
mask.ToString().String());
|
||||||
|
} else {
|
||||||
|
printf("/%-3zd ", mask.PrefixLength());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (family->preferredPrefixFormat
|
||||||
|
== PREFIX_PREFER_NETMASK) {
|
||||||
|
printf(" %*s ", addressLength, "-");
|
||||||
|
} else
|
||||||
|
printf(" ");
|
||||||
|
}
|
||||||
|
|
||||||
if ((route.flags & RTF_GATEWAY) != 0) {
|
if ((route.flags & RTF_GATEWAY) != 0) {
|
||||||
BNetworkAddress gateway;
|
BNetworkAddress gateway;
|
||||||
|
|||||||
Reference in New Issue
Block a user