34#include <netlink-private/netlink.h>
35#include <netlink/netlink.h>
36#include <netlink/utils.h>
37#include <netlink/route/rtnl.h>
38#include <netlink/route/route.h>
45static NL_LIST_HEAD(table_names);
47static int add_routing_table_name(
long id,
const char *name)
49 return __trans_list_add(
id, name, &table_names);
52static void __init init_routing_table_names(
void)
54 add_routing_table_name(RT_TABLE_UNSPEC,
"unspec");
55 add_routing_table_name(RT_TABLE_COMPAT,
"compat");
56 add_routing_table_name(RT_TABLE_DEFAULT,
"default");
57 add_routing_table_name(RT_TABLE_MAIN,
"main");
58 add_routing_table_name(RT_TABLE_LOCAL,
"local");
61static void __exit release_routing_table_names(
void)
63 __trans_list_clear(&table_names);
66int rtnl_route_read_table_names(
const char *path)
68 __trans_list_clear(&table_names);
70 return __nl_read_num_str_file(path, &add_routing_table_name);
73char *rtnl_route_table2str(
int table,
char *buf,
size_t size)
75 return __list_type2str(table, buf, size, &table_names);
78int rtnl_route_str2table(
const char *name)
80 return __list_str2type(name, &table_names);
91static NL_LIST_HEAD(proto_names);
93static int add_proto_name(
long id,
const char *name)
95 return __trans_list_add(
id, name, &proto_names);
98static void __init init_proto_names(
void)
100 add_proto_name(RTPROT_UNSPEC,
"unspec");
101 add_proto_name(RTPROT_REDIRECT,
"redirect");
102 add_proto_name(RTPROT_KERNEL,
"kernel");
103 add_proto_name(RTPROT_BOOT,
"boot");
104 add_proto_name(RTPROT_STATIC,
"static");
107static void __exit release_proto_names(
void)
109 __trans_list_clear(&proto_names);
112int rtnl_route_read_protocol_names(
const char *path)
114 __trans_list_clear(&proto_names);
116 return __nl_read_num_str_file(path, &add_proto_name);
119char *rtnl_route_proto2str(
int proto,
char *buf,
size_t size)
121 return __list_type2str(proto, buf, size, &proto_names);
124int rtnl_route_str2proto(
const char *name)
126 return __list_str2type(name, &proto_names);
136static const struct trans_tbl route_metrices[] = {
137 __ADD(RTAX_UNSPEC, unspec),
138 __ADD(RTAX_LOCK, lock),
139 __ADD(RTAX_MTU, mtu),
140 __ADD(RTAX_WINDOW, window),
141 __ADD(RTAX_RTT, rtt),
142 __ADD(RTAX_RTTVAR, rttvar),
143 __ADD(RTAX_SSTHRESH, ssthresh),
144 __ADD(RTAX_CWND, cwnd),
145 __ADD(RTAX_ADVMSS, advmss),
146 __ADD(RTAX_REORDERING, reordering),
147 __ADD(RTAX_HOPLIMIT, hoplimit),
148 __ADD(RTAX_INITCWND, initcwnd),
149 __ADD(RTAX_FEATURES, features),
152char *rtnl_route_metric2str(
int metric,
char *buf,
size_t size)
154 return __type2str(metric, buf, size, route_metrices,
155 ARRAY_SIZE(route_metrices));
158int rtnl_route_str2metric(
const char *name)
160 return __str2type(name, route_metrices, ARRAY_SIZE(route_metrices));