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_COMPAT, "compat");
00062 add_routing_table_name(RT_TABLE_DEFAULT, "default");
00063 add_routing_table_name(RT_TABLE_MAIN, "main");
00064 add_routing_table_name(RT_TABLE_LOCAL, "local");
00065 };
00066
00067 static void __exit release_routing_table_names(void)
00068 {
00069 __trans_list_clear(&table_names);
00070 }
00071
00072 int rtnl_route_read_table_names(const char *path)
00073 {
00074 __trans_list_clear(&table_names);
00075
00076 return __nl_read_num_str_file(path, &add_routing_table_name);
00077 }
00078
00079 char *rtnl_route_table2str(int table, char *buf, size_t size)
00080 {
00081 return __list_type2str(table, buf, size, &table_names);
00082 }
00083
00084 int rtnl_route_str2table(const char *name)
00085 {
00086 return __list_str2type(name, &table_names);
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 static NL_LIST_HEAD(proto_names);
00098
00099 static int add_proto_name(long id, const char *name)
00100 {
00101 return __trans_list_add(id, name, &proto_names);
00102 }
00103
00104 static void __init init_proto_names(void)
00105 {
00106 add_proto_name(RTPROT_UNSPEC, "unspec");
00107 add_proto_name(RTPROT_REDIRECT, "redirect");
00108 add_proto_name(RTPROT_KERNEL, "kernel");
00109 add_proto_name(RTPROT_BOOT, "boot");
00110 add_proto_name(RTPROT_STATIC, "static");
00111 };
00112
00113 static void __exit release_proto_names(void)
00114 {
00115 __trans_list_clear(&proto_names);
00116 }
00117
00118 int rtnl_route_read_protocol_names(const char *path)
00119 {
00120 __trans_list_clear(&proto_names);
00121
00122 return __nl_read_num_str_file(path, &add_proto_name);
00123 }
00124
00125 char *rtnl_route_proto2str(int proto, char *buf, size_t size)
00126 {
00127 return __list_type2str(proto, buf, size, &proto_names);
00128 }
00129
00130 int rtnl_route_str2proto(const char *name)
00131 {
00132 return __list_str2type(name, &proto_names);
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142 static const struct trans_tbl route_metrices[] = {
00143 __ADD(RTAX_UNSPEC, unspec)
00144 __ADD(RTAX_LOCK, lock)
00145 __ADD(RTAX_MTU, mtu)
00146 __ADD(RTAX_WINDOW, window)
00147 __ADD(RTAX_RTT, rtt)
00148 __ADD(RTAX_RTTVAR, rttvar)
00149 __ADD(RTAX_SSTHRESH, ssthresh)
00150 __ADD(RTAX_CWND, cwnd)
00151 __ADD(RTAX_ADVMSS, advmss)
00152 __ADD(RTAX_REORDERING, reordering)
00153 __ADD(RTAX_HOPLIMIT, hoplimit)
00154 __ADD(RTAX_INITCWND, initcwnd)
00155 __ADD(RTAX_FEATURES, features)
00156 };
00157
00158 char *rtnl_route_metric2str(int metric, char *buf, size_t size)
00159 {
00160 return __type2str(metric, buf, size, route_metrices,
00161 ARRAY_SIZE(route_metrices));
00162 }
00163
00164 int rtnl_route_str2metric(const char *name)
00165 {
00166 return __str2type(name, route_metrices, ARRAY_SIZE(route_metrices));
00167 }
00168
00169
00170
00171