00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <netlink-local.h>
00018 #include <netlink/netlink.h>
00019 #include <netlink/utils.h>
00020 #include <netlink/route/rtnl.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
00040 {
00041 struct rtgenmsg gmsg = {
00042 .rtgen_family = family,
00043 };
00044
00045 return nl_send_simple(sk, type, flags, &gmsg, sizeof(gmsg));
00046 }
00047
00048
00049
00050
00051
00052
00053
00054
00055 static const struct trans_tbl rtntypes[] = {
00056 __ADD(RTN_UNSPEC,unspec)
00057 __ADD(RTN_UNICAST,unicast)
00058 __ADD(RTN_LOCAL,local)
00059 __ADD(RTN_BROADCAST,broadcast)
00060 __ADD(RTN_ANYCAST,anycast)
00061 __ADD(RTN_MULTICAST,multicast)
00062 __ADD(RTN_BLACKHOLE,blackhole)
00063 __ADD(RTN_UNREACHABLE,unreachable)
00064 __ADD(RTN_PROHIBIT,prohibit)
00065 __ADD(RTN_THROW,throw)
00066 __ADD(RTN_NAT,nat)
00067 __ADD(RTN_XRESOLVE,xresolve)
00068 };
00069
00070 char *nl_rtntype2str(int type, char *buf, size_t size)
00071 {
00072 return __type2str(type, buf, size, rtntypes, ARRAY_SIZE(rtntypes));
00073 }
00074
00075 int nl_str2rtntype(const char *name)
00076 {
00077 return __str2type(name, rtntypes, ARRAY_SIZE(rtntypes));
00078 }
00079
00080
00081
00082
00083
00084
00085
00086
00087 static const struct trans_tbl scopes[] = {
00088 __ADD(255,nowhere)
00089 __ADD(254,host)
00090 __ADD(253,link)
00091 __ADD(200,site)
00092 __ADD(0,universe)
00093 };
00094
00095 char *rtnl_scope2str(int scope, char *buf, size_t size)
00096 {
00097 return __type2str(scope, buf, size, scopes, ARRAY_SIZE(scopes));
00098 }
00099
00100 int rtnl_str2scope(const char *name)
00101 {
00102 return __str2type(name, scopes, ARRAY_SIZE(scopes));
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112 char * rtnl_realms2str(uint32_t realms, char *buf, size_t len)
00113 {
00114 int from = RTNL_REALM_FROM(realms);
00115 int to = RTNL_REALM_TO(realms);
00116
00117 snprintf(buf, len, "%d/%d", from, to);
00118
00119 return buf;
00120 }
00121
00122
00123
00124