libnl: /data/src/libnl3/src/lib/link.c Source File

libnl 3.7.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 <netlink/cli/utils.h>
14 #include <netlink/cli/link.h>
15 #include <linux/if.h>
16
17 struct rtnl_link *nl_cli_link_alloc(void)
18 {
19 struct rtnl_link *link;
20
21 link = rtnl_link_alloc();
22 if (!link)
23 nl_cli_fatal(ENOMEM, "Unable to allocate link object");
24
25 return link;
26 }
27
28 struct nl_cache *nl_cli_link_alloc_cache_family_flags(struct nl_sock *sock,
29 int family,
30 unsigned int flags)
31 {
32 struct nl_cache *cache;
33 int err;
34
35 if ((err = rtnl_link_alloc_cache_flags(sock, family, &cache, flags)) < 0)
36 nl_cli_fatal(err, "Unable to allocate link cache: %s",
37 nl_geterror(err));
38
39 nl_cache_mngt_provide(cache);
40
41 return cache;
42 }
43
44 struct nl_cache *nl_cli_link_alloc_cache_family(struct nl_sock *sock, int family)
45 {
46 return nl_cli_link_alloc_cache_family_flags(sock, family, 0);
47 }
48
49 struct nl_cache *nl_cli_link_alloc_cache(struct nl_sock *sock)
50 {
51 return nl_cli_link_alloc_cache_family(sock, AF_UNSPEC);
52 }
53
54 struct nl_cache *nl_cli_link_alloc_cache_flags(struct nl_sock *sock,
55 unsigned int flags)
56 {
57 return nl_cli_link_alloc_cache_family_flags(sock, AF_UNSPEC, flags);
58 }
59
60 void nl_cli_link_parse_family(struct rtnl_link *link, char *arg)
61 {
62 int family;
63
64 if ((family = nl_str2af(arg)) < 0)
65 nl_cli_fatal(EINVAL,
66 "Unable to translate address family \"%s\"", arg);
67
68 rtnl_link_set_family(link, family);
69 }
70
71 void nl_cli_link_parse_name(struct rtnl_link *link, char *arg)
72 {
73 rtnl_link_set_name(link, arg);
74 }
75
76 void nl_cli_link_parse_mtu(struct rtnl_link *link, char *arg)
77 {
78 uint32_t mtu = nl_cli_parse_u32(arg);
79 rtnl_link_set_mtu(link, mtu);
80 }
81
82 void nl_cli_link_parse_ifindex(struct rtnl_link *link, char *arg)
83 {
84 uint32_t index = nl_cli_parse_u32(arg);
85 rtnl_link_set_ifindex(link, index);
86 }
87
88 void nl_cli_link_parse_txqlen(struct rtnl_link *link, char *arg)
89 {
90 uint32_t qlen = nl_cli_parse_u32(arg);
91 rtnl_link_set_txqlen(link, qlen);
92 }
93
94 void nl_cli_link_parse_weight(struct rtnl_link *link, char *arg)
95 {
96 }
97
98 void nl_cli_link_parse_ifalias(struct rtnl_link *link, char *arg)
99 {
100 if (strlen(arg) > IFALIASZ)
101 nl_cli_fatal(ERANGE,
102 "Link ifalias too big, must not exceed %u in length.",
103 IFALIASZ);
104
105 rtnl_link_set_ifalias(link, arg);
106 }
107
108 /** @} */
nl_cache_mngt_provide
void nl_cache_mngt_provide(struct nl_cache *cache)
Provide a cache for global use.
Definition: cache_mngt.c:326
nl_cli_fatal
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
Definition: utils.c:71
nl_cli_parse_u32
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
Definition: utils.c:36
rtnl_link_set_mtu
void rtnl_link_set_mtu(struct rtnl_link *link, unsigned int mtu)
Set Maximum Transmission Unit of link object.
Definition: link.c:2195
rtnl_link_set_ifalias
void rtnl_link_set_ifalias(struct rtnl_link *link, const char *alias)
Set alias name of link object (SNMP IfAlias)
Definition: link.c:2437
rtnl_link_set_name
void rtnl_link_set_name(struct rtnl_link *link, const char *name)
Set name of link object.
Definition: link.c:1938
rtnl_link_alloc_cache_flags
int rtnl_link_alloc_cache_flags(struct nl_sock *sk, int family, struct nl_cache **result, unsigned int flags)
Allocate link cache and fill in all configured links.
Definition: link.c:1236
rtnl_link_set_family
void rtnl_link_set_family(struct rtnl_link *link, int family)
Set address family of link object.
Definition: link.c:2101
rtnl_link_alloc
struct rtnl_link * rtnl_link_alloc(void)
Allocate link object.
Definition: link.c:1910
rtnl_link_set_txqlen
void rtnl_link_set_txqlen(struct rtnl_link *link, unsigned int txqlen)
Set transmission queue length.
Definition: link.c:2224
rtnl_link_set_ifindex
void rtnl_link_set_ifindex(struct rtnl_link *link, int ifindex)
Set interface index of link object.
Definition: link.c:2167
rtnl_link
Link object.