40 #include <netlink-local.h>
41 #include <netlink/netlink.h>
42 #include <netlink/utils.h>
43 #include <netlink/route/rtnl.h>
44 #include <netlink/route/route.h>
51 static NL_LIST_HEAD(table_names);
53 static int add_routing_table_name(
long id,
const char *name)
55 return __trans_list_add(
id, name, &table_names);
58 static void __init init_routing_table_names(
void)
60 add_routing_table_name(RT_TABLE_UNSPEC,
"unspec");
61 add_routing_table_name(RT_TABLE_DEFAULT,
"default");
62 add_routing_table_name(RT_TABLE_MAIN,
"main");
63 add_routing_table_name(RT_TABLE_LOCAL,
"local");
66 int 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);
73 char *rtnl_route_table2str(
int table,
char *buf,
size_t size)
75 return __list_type2str(table, buf, size, &table_names);
78 int rtnl_route_str2table(
const char *name)
80 return __list_str2type(name, &table_names);
91 static NL_LIST_HEAD(proto_names);
93 static int add_proto_name(
long id,
const char *name)
95 return __trans_list_add(
id, name, &proto_names);
98 static 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");
107 int rtnl_route_read_protocol_names(
const char *path)
109 __trans_list_clear(&proto_names);
111 return __nl_read_num_str_file(path, &add_proto_name);
114 char *rtnl_route_proto2str(
int proto,
char *buf,
size_t size)
116 return __list_type2str(proto, buf, size, &proto_names);
119 int rtnl_route_str2proto(
const char *name)
121 return __list_str2type(name, &proto_names);
131 static struct trans_tbl route_metrices[] = {
132 __ADD(RTAX_UNSPEC, unspec)
133 __ADD(RTAX_LOCK, lock)
135 __ADD(RTAX_WINDOW, window)
137 __ADD(RTAX_RTTVAR, rttvar)
138 __ADD(RTAX_SSTHRESH, ssthresh)
139 __ADD(RTAX_CWND, cwnd)
140 __ADD(RTAX_ADVMSS, advmss)
141 __ADD(RTAX_REORDERING, reordering)
142 __ADD(RTAX_HOPLIMIT, hoplimit)
143 __ADD(RTAX_INITCWND, initcwnd)
144 __ADD(RTAX_FEATURES, features)
147 char *rtnl_route_metric2str(
int metric,
char *buf,
size_t size)
149 return __type2str(metric, buf, size, route_metrices,
150 ARRAY_SIZE(route_metrices));
153 int rtnl_route_str2metric(
const char *name)
155 return __str2type(name, route_metrices, ARRAY_SIZE(route_metrices));
165 static struct trans_tbl nh_flags[] = {
166 __ADD(RTNH_F_DEAD, dead)
167 __ADD(RTNH_F_PERVASIVE, pervasive)
168 __ADD(RTNH_F_ONLINK, onlink)
171 char * rtnl_route_nh_flags2str(
int flags,
char *buf,
size_t len)
173 return __flags2str(flags, buf, len, nh_flags, ARRAY_SIZE(nh_flags));
176 int rtnl_route_nh_str2flags(
const char *name)
178 return __str2flags(name, nh_flags, ARRAY_SIZE(nh_flags));