13#include <netlink/cli/utils.h>
14#include <netlink/cli/addr.h>
16struct rtnl_addr *nl_cli_addr_alloc(
void)
18 struct rtnl_addr *addr;
20 addr = rtnl_addr_alloc();
22 nl_cli_fatal(ENOMEM,
"Unable to allocate address object");
27void nl_cli_addr_parse_family(
struct rtnl_addr *addr,
char *arg)
31 if ((family = nl_str2af(arg)) != AF_UNSPEC)
32 rtnl_addr_set_family(addr, family);
35void nl_cli_addr_parse_local(
struct rtnl_addr *addr,
char *arg)
40 a = nl_cli_addr_parse(arg, rtnl_addr_get_family(addr));
41 if ((err = rtnl_addr_set_local(addr, a)) < 0)
48void nl_cli_addr_parse_dev(
struct rtnl_addr *addr,
struct nl_cache *link_cache,
56 rtnl_addr_set_ifindex(addr, ival);
59void nl_cli_addr_parse_label(
struct rtnl_addr *addr,
char *arg)
63 if ((err = rtnl_addr_set_label(addr, arg)) < 0)
68void nl_cli_addr_parse_peer(
struct rtnl_addr *addr,
char *arg)
73 a = nl_cli_addr_parse(arg, rtnl_addr_get_family(addr));
74 if ((err = rtnl_addr_set_peer(addr, a)) < 0)
81void nl_cli_addr_parse_scope(
struct rtnl_addr *addr,
char *arg)
85 if ((ival = rtnl_str2scope(arg)) < 0)
86 nl_cli_fatal(EINVAL,
"Unknown address scope \"%s\"", arg);
88 rtnl_addr_set_scope(addr, ival);
91void nl_cli_addr_parse_broadcast(
struct rtnl_addr *addr,
char *arg)
96 a = nl_cli_addr_parse(arg, rtnl_addr_get_family(addr));
97 if ((err = rtnl_addr_set_broadcast(addr, a)) < 0)
104static uint32_t parse_lifetime(
const char *arg)
109 if (!strcasecmp(arg,
"forever"))
112 if ((err = nl_str2msec(arg, &msecs)) < 0)
113 nl_cli_fatal(err,
"Unable to parse time string \"%s\": %s",
114 arg, nl_geterror(err));
116 return (msecs / 1000);
119void nl_cli_addr_parse_preferred(
struct rtnl_addr *addr,
char *arg)
121 rtnl_addr_set_preferred_lifetime(addr, parse_lifetime(arg));
124void nl_cli_addr_parse_valid(
struct rtnl_addr *addr,
char *arg)
126 rtnl_addr_set_valid_lifetime(addr, parse_lifetime(arg));
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
int rtnl_link_name2i(struct nl_cache *cache, const char *name)
Translate link name to corresponding interface index.