123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include <netlink-private/netlink.h>
- #include <netlink/netlink.h>
- #include <netlink/utils.h>
- #include <netlink/route/rtnl.h>
- int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
- {
- int err;
- struct rtgenmsg gmsg = {
- .rtgen_family = family,
- };
- err = nl_send_simple(sk, type, flags, &gmsg, sizeof(gmsg));
- return err >= 0 ? 0 : err;
- }
- static const struct trans_tbl rtntypes[] = {
- __ADD(RTN_UNSPEC,unspec)
- __ADD(RTN_UNICAST,unicast)
- __ADD(RTN_LOCAL,local)
- __ADD(RTN_BROADCAST,broadcast)
- __ADD(RTN_ANYCAST,anycast)
- __ADD(RTN_MULTICAST,multicast)
- __ADD(RTN_BLACKHOLE,blackhole)
- __ADD(RTN_UNREACHABLE,unreachable)
- __ADD(RTN_PROHIBIT,prohibit)
- __ADD(RTN_THROW,throw)
- __ADD(RTN_NAT,nat)
- __ADD(RTN_XRESOLVE,xresolve)
- };
- char *nl_rtntype2str(int type, char *buf, size_t size)
- {
- return __type2str(type, buf, size, rtntypes, ARRAY_SIZE(rtntypes));
- }
- int nl_str2rtntype(const char *name)
- {
- return __str2type(name, rtntypes, ARRAY_SIZE(rtntypes));
- }
- static const struct trans_tbl scopes[] = {
- __ADD(255,nowhere)
- __ADD(254,host)
- __ADD(253,link)
- __ADD(200,site)
- __ADD(0,global)
- };
- char *rtnl_scope2str(int scope, char *buf, size_t size)
- {
- return __type2str(scope, buf, size, scopes, ARRAY_SIZE(scopes));
- }
- int rtnl_str2scope(const char *name)
- {
- return __str2type(name, scopes, ARRAY_SIZE(scopes));
- }
- char * rtnl_realms2str(uint32_t realms, char *buf, size_t len)
- {
- int from = RTNL_REALM_FROM(realms);
- int to = RTNL_REALM_TO(realms);
- snprintf(buf, len, "%d/%d", from, to);
- return buf;
- }
|