00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <netlink-local.h>
00041 #include <netlink/netlink.h>
00042 #include <netlink/utils.h>
00043 #include <netlink/route/rtnl.h>
00044 #include <netlink/route/route.h>
00045
00046
00047
00048
00049
00050
00051 static NL_LIST_HEAD(table_names);
00052
00053 static int add_routing_table_name(long id, const char *name)
00054 {
00055 return __trans_list_add(id, name, &table_names);
00056 }
00057
00058 static void __init init_routing_table_names(void)
00059 {
00060 add_routing_table_name(RT_TABLE_UNSPEC, "unspec");
00061 add_routing_table_name(RT_TABLE_DEFAULT, "default");
00062 add_routing_table_name(RT_TABLE_MAIN, "main");
00063 add_routing_table_name(RT_TABLE_LOCAL, "local");
00064 };
00065
00066 int rtnl_route_read_table_names(const char *path)
00067 {
00068 __trans_list_clear(&table_names);
00069
00070 return __nl_read_num_str_file(path, &add_routing_table_name);
00071 }
00072
00073 char *rtnl_route_table2str(int table, char *buf, size_t size)
00074 {
00075 return __list_type2str(table, buf, size, &table_names);
00076 }
00077
00078 int rtnl_route_str2table(const char *name)
00079 {
00080 return __list_str2type(name, &table_names);
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 static NL_LIST_HEAD(proto_names);
00092
00093 static int add_proto_name(long id, const char *name)
00094 {
00095 return __trans_list_add(id, name, &proto_names);
00096 }
00097
00098 static void __init init_proto_names(void)
00099 {
00100 add_proto_name(RTPROT_UNSPEC, "unspec");
00101 add_proto_name(RTPROT_REDIRECT, "redirect");
00102 add_proto_name(RTPROT_KERNEL, "kernel");
00103 add_proto_name(RTPROT_BOOT, "boot");
00104 add_proto_name(RTPROT_STATIC, "static");
00105 };
00106
00107 int rtnl_route_read_protocol_names(const char *path)
00108 {
00109 __trans_list_clear(&proto_names);
00110
00111 return __nl_read_num_str_file(path, &add_proto_name);
00112 }
00113
00114 char *rtnl_route_proto2str(int proto, char *buf, size_t size)
00115 {
00116 return __list_type2str(proto, buf, size, &proto_names);
00117 }
00118
00119 int rtnl_route_str2proto(const char *name)
00120 {
00121 return __list_str2type(name, &proto_names);
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131 static struct trans_tbl route_metrices[] = {
00132 __ADD(RTAX_UNSPEC, unspec)
00133 __ADD(RTAX_LOCK, lock)
00134 __ADD(RTAX_MTU, mtu)
00135 __ADD(RTAX_WINDOW, window)
00136 __ADD(RTAX_RTT, rtt)
00137 __ADD(RTAX_RTTVAR, rttvar)
00138 __ADD(RTAX_SSTHRESH, ssthresh)
00139 __ADD(RTAX_CWND, cwnd)
00140 __ADD(RTAX_ADVMSS, advmss)
00141 __ADD(RTAX_REORDERING, reordering)
00142 __ADD(RTAX_HOPLIMIT, hoplimit)
00143 __ADD(RTAX_INITCWND, initcwnd)
00144 __ADD(RTAX_FEATURES, features)
00145 };
00146
00147 char *rtnl_route_metric2str(int metric, char *buf, size_t size)
00148 {
00149 return __type2str(metric, buf, size, route_metrices,
00150 ARRAY_SIZE(route_metrices));
00151 }
00152
00153 int rtnl_route_str2metric(const char *name)
00154 {
00155 return __str2type(name, route_metrices, ARRAY_SIZE(route_metrices));
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165 static struct trans_tbl nh_flags[] = {
00166 __ADD(RTNH_F_DEAD, dead)
00167 __ADD(RTNH_F_PERVASIVE, pervasive)
00168 __ADD(RTNH_F_ONLINK, onlink)
00169 };
00170
00171 char * rtnl_route_nh_flags2str(int flags, char *buf, size_t len)
00172 {
00173 return __flags2str(flags, buf, len, nh_flags, ARRAY_SIZE(nh_flags));
00174 }
00175
00176 int rtnl_route_nh_str2flags(const char *name)
00177 {
00178 return __str2flags(name, nh_flags, ARRAY_SIZE(nh_flags));
00179 }
00180
00181
00182
00183