Home | History | Annotate | Download | only in lib
      1 /*
      2  * src/lib/link.c     CLI Link Helpers
      3  *
      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
      7  *	of the License.
      8  *
      9  * Copyright (c) 2008-2010 Thomas Graf <tgraf (at) suug.ch>
     10  */
     11 
     12 /**
     13  * @ingroup cli
     14  * @defgroup cli_link Links
     15  *
     16  * @{
     17  */
     18 
     19 #include <netlink/cli/utils.h>
     20 #include <netlink/cli/link.h>
     21 #include <linux/if.h>
     22 
     23 struct rtnl_link *nl_cli_link_alloc(void)
     24 {
     25 	struct rtnl_link *link;
     26 
     27 	link = rtnl_link_alloc();
     28 	if (!link)
     29 		nl_cli_fatal(ENOMEM, "Unable to allocate link object");
     30 
     31 	return link;
     32 }
     33 
     34 struct nl_cache *nl_cli_link_alloc_cache_family(struct nl_sock *sock, int family)
     35 {
     36 	struct nl_cache *cache;
     37 	int err;
     38 
     39 	if ((err = rtnl_link_alloc_cache(sock, family, &cache)) < 0)
     40 		nl_cli_fatal(err, "Unable to allocate link cache: %s",
     41 			     nl_geterror(err));
     42 
     43 	nl_cache_mngt_provide(cache);
     44 
     45 	return cache;
     46 }
     47 
     48 struct nl_cache *nl_cli_link_alloc_cache(struct nl_sock *sock)
     49 {
     50 	return nl_cli_link_alloc_cache_family(sock, AF_UNSPEC);
     51 }
     52 
     53 void nl_cli_link_parse_family(struct rtnl_link *link, char *arg)
     54 {
     55 	int family;
     56 
     57 	if ((family = nl_str2af(arg)) < 0)
     58 		nl_cli_fatal(EINVAL,
     59 			     "Unable to translate address family \"%s\"", arg);
     60 
     61 	rtnl_link_set_family(link, family);
     62 }
     63 
     64 void nl_cli_link_parse_name(struct rtnl_link *link, char *arg)
     65 {
     66 	rtnl_link_set_name(link, arg);
     67 }
     68 
     69 void nl_cli_link_parse_mtu(struct rtnl_link *link, char *arg)
     70 {
     71 	uint32_t mtu = nl_cli_parse_u32(arg);
     72 	rtnl_link_set_mtu(link, mtu);
     73 }
     74 
     75 void nl_cli_link_parse_ifindex(struct rtnl_link *link, char *arg)
     76 {
     77 	uint32_t index = nl_cli_parse_u32(arg);
     78 	rtnl_link_set_ifindex(link, index);
     79 }
     80 
     81 void nl_cli_link_parse_txqlen(struct rtnl_link *link, char *arg)
     82 {
     83 	uint32_t qlen = nl_cli_parse_u32(arg);
     84 	rtnl_link_set_txqlen(link, qlen);
     85 }
     86 
     87 void nl_cli_link_parse_weight(struct rtnl_link *link, char *arg)
     88 {
     89 }
     90 
     91 void nl_cli_link_parse_ifalias(struct rtnl_link *link, char *arg)
     92 {
     93 	if (strlen(arg) > IFALIASZ)
     94 		nl_cli_fatal(ERANGE,
     95 			"Link ifalias too big, must not exceed %u in length.",
     96 			IFALIASZ);
     97 
     98 	rtnl_link_set_ifalias(link, arg);
     99 }
    100 
    101 /** @} */
    102