Home | History | Annotate | Download | only in lib
      1 /*
      2  * src/lib/neigh.c     CLI Neighbour 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-2009 Thomas Graf <tgraf (at) suug.ch>
     10  */
     11 
     12 /**
     13  * @ingroup cli
     14  * @defgroup cli_neigh Neighbour
     15  *
     16  * @{
     17  */
     18 
     19 #include <netlink/cli/utils.h>
     20 #include <netlink/cli/neigh.h>
     21 
     22 struct rtnl_neigh *nl_cli_neigh_alloc(void)
     23 {
     24 	struct rtnl_neigh *neigh;
     25 
     26 	neigh = rtnl_neigh_alloc();
     27 	if (!neigh)
     28 		nl_cli_fatal(ENOMEM, "Unable to allocate neighbour object");
     29 
     30 	return neigh;
     31 }
     32 
     33 void nl_cli_neigh_parse_dst(struct rtnl_neigh *neigh, char *arg)
     34 {
     35 	struct nl_addr *a;
     36 	int err;
     37 
     38 	a = nl_cli_addr_parse(arg, rtnl_neigh_get_family(neigh));
     39 	if ((err = rtnl_neigh_set_dst(neigh, a)) < 0)
     40 		nl_cli_fatal(err, "Unable to set local address: %s",
     41 			nl_geterror(err));
     42 
     43 	nl_addr_put(a);
     44 }
     45 
     46 void nl_cli_neigh_parse_lladdr(struct rtnl_neigh *neigh, char *arg)
     47 {
     48 	struct nl_addr *a;
     49 
     50 	a = nl_cli_addr_parse(arg, AF_UNSPEC);
     51 	rtnl_neigh_set_lladdr(neigh, a);
     52 	nl_addr_put(a);
     53 }
     54 
     55 void nl_cli_neigh_parse_dev(struct rtnl_neigh *neigh,
     56 			    struct nl_cache *link_cache, char *arg)
     57 {
     58 	int ival;
     59 
     60 	if (!(ival = rtnl_link_name2i(link_cache, arg)))
     61 		nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg);
     62 
     63 	rtnl_neigh_set_ifindex(neigh, ival);
     64 }
     65 
     66 void nl_cli_neigh_parse_family(struct rtnl_neigh *neigh, char *arg)
     67 {
     68 	int family;
     69 
     70 	if ((family = nl_str2af(arg)) == AF_UNSPEC)
     71 		nl_cli_fatal(EINVAL,
     72 			     "Unable to translate address family \"%s\"", arg);
     73 
     74 	rtnl_neigh_set_family(neigh, family);
     75 }
     76 
     77 void nl_cli_neigh_parse_state(struct rtnl_neigh *neigh, char *arg)
     78 {
     79 	int state;
     80 
     81 	if ((state = rtnl_neigh_str2state(arg)) < 0)
     82 		nl_cli_fatal(state, "Unable to translate state \"%s\": %s",
     83 			arg, state);
     84 
     85 	rtnl_neigh_set_state(neigh, state);
     86 }
     87 
     88 /** @} */
     89