File: link.c

package info (click to toggle)
libnl3 3.4.0-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,120 kB
  • sloc: ansic: 57,494; sh: 4,447; python: 3,702; makefile: 888; yacc: 478; cpp: 454; lex: 210
file content (114 lines) | stat: -rw-r--r-- 2,560 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * src/lib/link.c     CLI Link Helpers
 *
 *	This library is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation version 2.1
 *	of the License.
 *
 * Copyright (c) 2008-2010 Thomas Graf <tgraf@suug.ch>
 */

/**
 * @ingroup cli
 * @defgroup cli_link Links
 *
 * @{
 */

#include <netlink/cli/utils.h>
#include <netlink/cli/link.h>
#include <linux/if.h>

struct rtnl_link *nl_cli_link_alloc(void)
{
	struct rtnl_link *link;

	link = rtnl_link_alloc();
	if (!link)
		nl_cli_fatal(ENOMEM, "Unable to allocate link object");

	return link;
}

struct nl_cache *nl_cli_link_alloc_cache_family_flags(struct nl_sock *sock,
						      int family,
						      unsigned int flags)
{
	struct nl_cache *cache;
	int err;

	if ((err = rtnl_link_alloc_cache_flags(sock, family, &cache, flags)) < 0)
		nl_cli_fatal(err, "Unable to allocate link cache: %s",
			     nl_geterror(err));

	nl_cache_mngt_provide(cache);

	return cache;
}

struct nl_cache *nl_cli_link_alloc_cache_family(struct nl_sock *sock, int family)
{
	return nl_cli_link_alloc_cache_family_flags(sock, family, 0);
}

struct nl_cache *nl_cli_link_alloc_cache(struct nl_sock *sock)
{
	return nl_cli_link_alloc_cache_family(sock, AF_UNSPEC);
}

struct nl_cache *nl_cli_link_alloc_cache_flags(struct nl_sock *sock,
						unsigned int flags)
{
	return nl_cli_link_alloc_cache_family_flags(sock, AF_UNSPEC, flags);
}

void nl_cli_link_parse_family(struct rtnl_link *link, char *arg)
{
	int family;

	if ((family = nl_str2af(arg)) < 0)
		nl_cli_fatal(EINVAL,
			     "Unable to translate address family \"%s\"", arg);

	rtnl_link_set_family(link, family);
}

void nl_cli_link_parse_name(struct rtnl_link *link, char *arg)
{
	rtnl_link_set_name(link, arg);
}

void nl_cli_link_parse_mtu(struct rtnl_link *link, char *arg)
{
	uint32_t mtu = nl_cli_parse_u32(arg);
	rtnl_link_set_mtu(link, mtu);
}

void nl_cli_link_parse_ifindex(struct rtnl_link *link, char *arg)
{
	uint32_t index = nl_cli_parse_u32(arg);
	rtnl_link_set_ifindex(link, index);
}

void nl_cli_link_parse_txqlen(struct rtnl_link *link, char *arg)
{
	uint32_t qlen = nl_cli_parse_u32(arg);
	rtnl_link_set_txqlen(link, qlen);
}

void nl_cli_link_parse_weight(struct rtnl_link *link, char *arg)
{
}

void nl_cli_link_parse_ifalias(struct rtnl_link *link, char *arg)
{
	if (strlen(arg) > IFALIASZ)
		nl_cli_fatal(ERANGE,
			"Link ifalias too big, must not exceed %u in length.",
			IFALIASZ);

	rtnl_link_set_ifalias(link, arg);
}

/** @} */