libnl 3.10.0
link.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2008-2010 Thomas Graf <tgraf@suug.ch>
4 */
5
6/**
7 * @ingroup cli
8 * @defgroup cli_link Links
9 *
10 * @{
11 */
12
13#include "nl-default.h"
14
15#include <linux/if.h>
16
17#include <netlink/cli/utils.h>
18#include <netlink/cli/link.h>
19
20struct rtnl_link *nl_cli_link_alloc(void)
21{
22 struct rtnl_link *link;
23
24 link = rtnl_link_alloc();
25 if (!link)
26 nl_cli_fatal(ENOMEM, "Unable to allocate link object");
27
28 return link;
29}
30
31struct nl_cache *nl_cli_link_alloc_cache_family_flags(struct nl_sock *sock,
32 int family,
33 unsigned int flags)
34{
35 struct nl_cache *cache;
36 int err;
37
38 if ((err = rtnl_link_alloc_cache_flags(sock, family, &cache, flags)) < 0)
39 nl_cli_fatal(err, "Unable to allocate link cache: %s",
40 nl_geterror(err));
41
43
44 return cache;
45}
46
47struct nl_cache *nl_cli_link_alloc_cache_family(struct nl_sock *sock, int family)
48{
49 return nl_cli_link_alloc_cache_family_flags(sock, family, 0);
50}
51
52struct nl_cache *nl_cli_link_alloc_cache(struct nl_sock *sock)
53{
54 return nl_cli_link_alloc_cache_family(sock, AF_UNSPEC);
55}
56
57struct nl_cache *nl_cli_link_alloc_cache_flags(struct nl_sock *sock,
58 unsigned int flags)
59{
60 return nl_cli_link_alloc_cache_family_flags(sock, AF_UNSPEC, flags);
61}
62
63void nl_cli_link_parse_family(struct rtnl_link *link, char *arg)
64{
65 int family;
66
67 if ((family = nl_str2af(arg)) < 0)
68 nl_cli_fatal(EINVAL,
69 "Unable to translate address family \"%s\"", arg);
70
71 rtnl_link_set_family(link, family);
72}
73
74void nl_cli_link_parse_name(struct rtnl_link *link, char *arg)
75{
76 rtnl_link_set_name(link, arg);
77}
78
79void nl_cli_link_parse_mtu(struct rtnl_link *link, char *arg)
80{
81 uint32_t mtu = nl_cli_parse_u32(arg);
82 rtnl_link_set_mtu(link, mtu);
83}
84
85void nl_cli_link_parse_ifindex(struct rtnl_link *link, char *arg)
86{
87 uint32_t index = nl_cli_parse_u32(arg);
88 rtnl_link_set_ifindex(link, index);
89}
90
91void nl_cli_link_parse_txqlen(struct rtnl_link *link, char *arg)
92{
93 uint32_t qlen = nl_cli_parse_u32(arg);
94 rtnl_link_set_txqlen(link, qlen);
95}
96
97void nl_cli_link_parse_weight(struct rtnl_link *link, char *arg)
98{
99}
100
101void nl_cli_link_parse_ifalias(struct rtnl_link *link, char *arg)
102{
103 if (strlen(arg) > IFALIASZ)
104 nl_cli_fatal(ERANGE,
105 "Link ifalias too big, must not exceed %u in length.",
106 IFALIASZ);
107
108 rtnl_link_set_ifalias(link, arg);
109}
110
111/** @} */
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
Definition cache_mngt.c:332
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition utils.c:71
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
Definition utils.c:36