2
* lib/route/rtnl.c Routing Netlink
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation version 2.1
9
* Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
13
* @defgroup rtnl Routing Family
17
#include <netlink-local.h>
18
#include <netlink/netlink.h>
19
#include <netlink/utils.h>
20
#include <netlink/route/rtnl.h>
28
* Send routing netlink request message
29
* @arg sk Netlink socket.
30
* @arg type Netlink message type.
31
* @arg family Address family.
32
* @arg flags Additional netlink message flags.
34
* Fills out a routing netlink request message and sends it out
35
* using nl_send_simple().
37
* @return 0 on success or a negative error code.
39
int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
41
struct rtgenmsg gmsg = {
42
.rtgen_family = family,
45
return nl_send_simple(sk, type, flags, &gmsg, sizeof(gmsg));
51
* @name Routing Type Translations
55
static const struct trans_tbl rtntypes[] = {
56
__ADD(RTN_UNSPEC,unspec)
57
__ADD(RTN_UNICAST,unicast)
58
__ADD(RTN_LOCAL,local)
59
__ADD(RTN_BROADCAST,broadcast)
60
__ADD(RTN_ANYCAST,anycast)
61
__ADD(RTN_MULTICAST,multicast)
62
__ADD(RTN_BLACKHOLE,blackhole)
63
__ADD(RTN_UNREACHABLE,unreachable)
64
__ADD(RTN_PROHIBIT,prohibit)
65
__ADD(RTN_THROW,throw)
67
__ADD(RTN_XRESOLVE,xresolve)
70
char *nl_rtntype2str(int type, char *buf, size_t size)
72
return __type2str(type, buf, size, rtntypes, ARRAY_SIZE(rtntypes));
75
int nl_str2rtntype(const char *name)
77
return __str2type(name, rtntypes, ARRAY_SIZE(rtntypes));
83
* @name Scope Translations
87
static const struct trans_tbl scopes[] = {
95
char *rtnl_scope2str(int scope, char *buf, size_t size)
97
return __type2str(scope, buf, size, scopes, ARRAY_SIZE(scopes));
100
int rtnl_str2scope(const char *name)
102
return __str2type(name, scopes, ARRAY_SIZE(scopes));
108
* @name Realms Translations
112
char * rtnl_realms2str(uint32_t realms, char *buf, size_t len)
114
int from = RTNL_REALM_FROM(realms);
115
int to = RTNL_REALM_TO(realms);
117
snprintf(buf, len, "%d/%d", from, to);