libnl 1.1.4

Routing Utility Functions. More...

Routing Metrices Translations

char * rtnl_route_metric2str (int metric, char *buf, size_t size)
 
int rtnl_route_str2metric (const char *name)
 

Nexthop Flags Translations

char * rtnl_route_nh_flags2str (int flags, char *buf, size_t len)
 
int rtnl_route_nh_str2flags (const char *name)
 

Routing Table Identifier Translations

int rtnl_route_read_table_names (const char *path)
 
char * rtnl_route_table2str (int table, char *buf, size_t size)
 
int rtnl_route_str2table (const char *name)
 

Routing Protocol Translations

int rtnl_route_read_protocol_names (const char *path)
 
char * rtnl_route_proto2str (int proto, char *buf, size_t size)
 
int rtnl_route_str2proto (const char *name)
 

Detailed Description

1) Translating Routing Table Names
// libnl is only aware of the de facto standard routing table names.
// Additional name <-> identifier associations have to be read in via
// a configuration file, f.e. /etc/iproute2/rt_tables
err = rtnl_route_read_table_names("/etc/iproute2/rt_tables");
// Translating a table name to its idenfier
int table = rtnl_route_str2table("main");
// ... and the other way around.
char buf[32];
printf("Name: %s\n",
rtnl_route_table2str(table, buf, sizeof(buf)));

Function Documentation

◆ rtnl_route_read_table_names()

int rtnl_route_read_table_names ( const char *  path)

Definition at line 71 of file route_utils.c.

72{
73 __trans_list_clear(&table_names);
74
75 return __nl_read_num_str_file(path, &add_routing_table_name);
76}

◆ rtnl_route_table2str()

char * rtnl_route_table2str ( int  table,
char *  buf,
size_t  size 
)

Definition at line 78 of file route_utils.c.

79{
80 return __list_type2str(table, buf, size, &table_names);
81}

◆ rtnl_route_str2table()

int rtnl_route_str2table ( const char *  name)

Definition at line 83 of file route_utils.c.

84{
85 return __list_str2type(name, &table_names);
86}

◆ rtnl_route_read_protocol_names()

int rtnl_route_read_protocol_names ( const char *  path)

Definition at line 117 of file route_utils.c.

118{
119 __trans_list_clear(&proto_names);
120
121 return __nl_read_num_str_file(path, &add_proto_name);
122}

◆ rtnl_route_proto2str()

char * rtnl_route_proto2str ( int  proto,
char *  buf,
size_t  size 
)

Definition at line 124 of file route_utils.c.

125{
126 return __list_type2str(proto, buf, size, &proto_names);
127}

◆ rtnl_route_str2proto()

int rtnl_route_str2proto ( const char *  name)

Definition at line 129 of file route_utils.c.

130{
131 return __list_str2type(name, &proto_names);
132}

◆ rtnl_route_metric2str()

char * rtnl_route_metric2str ( int  metric,
char *  buf,
size_t  size 
)

Definition at line 157 of file route_utils.c.

158{
159 return __type2str(metric, buf, size, route_metrices,
160 ARRAY_SIZE(route_metrices));
161}

◆ rtnl_route_str2metric()

int rtnl_route_str2metric ( const char *  name)

Definition at line 163 of file route_utils.c.

164{
165 return __str2type(name, route_metrices, ARRAY_SIZE(route_metrices));
166}

◆ rtnl_route_nh_flags2str()

char * rtnl_route_nh_flags2str ( int  flags,
char *  buf,
size_t  len 
)

Definition at line 181 of file route_utils.c.

182{
183 return __flags2str(flags, buf, len, nh_flags, ARRAY_SIZE(nh_flags));
184}

◆ rtnl_route_nh_str2flags()

int rtnl_route_nh_str2flags ( const char *  name)

Definition at line 186 of file route_utils.c.

187{
188 return __str2flags(name, nh_flags, ARRAY_SIZE(nh_flags));
189}