libnl
3.2.3
|
00001 /* 00002 * src/lib/neigh.c CLI Neighbour Helpers 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation version 2.1 00007 * of the License. 00008 * 00009 * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 /** 00013 * @ingroup cli 00014 * @defgroup cli_neigh Neighbour 00015 * 00016 * @{ 00017 */ 00018 00019 #include <netlink/cli/utils.h> 00020 #include <netlink/cli/neigh.h> 00021 00022 struct rtnl_neigh *nl_cli_neigh_alloc(void) 00023 { 00024 struct rtnl_neigh *neigh; 00025 00026 neigh = rtnl_neigh_alloc(); 00027 if (!neigh) 00028 nl_cli_fatal(ENOMEM, "Unable to allocate neighbout object"); 00029 00030 return neigh; 00031 } 00032 00033 void nl_cli_neigh_parse_dst(struct rtnl_neigh *neigh, char *arg) 00034 { 00035 struct nl_addr *a; 00036 int err; 00037 00038 a = nl_cli_addr_parse(arg, rtnl_neigh_get_family(neigh)); 00039 if ((err = rtnl_neigh_set_dst(neigh, a)) < 0) 00040 nl_cli_fatal(err, "Unable to set local address: %s", 00041 nl_geterror(err)); 00042 00043 nl_addr_put(a); 00044 } 00045 00046 void nl_cli_neigh_parse_lladdr(struct rtnl_neigh *neigh, char *arg) 00047 { 00048 struct nl_addr *a; 00049 00050 a = nl_cli_addr_parse(arg, AF_UNSPEC); 00051 rtnl_neigh_set_lladdr(neigh, a); 00052 nl_addr_put(a); 00053 } 00054 00055 void nl_cli_neigh_parse_dev(struct rtnl_neigh *neigh, 00056 struct nl_cache *link_cache, char *arg) 00057 { 00058 int ival; 00059 00060 if (!(ival = rtnl_link_name2i(link_cache, arg))) 00061 nl_cli_fatal(ENOENT, "Link \"%s\" does not exist", arg); 00062 00063 rtnl_neigh_set_ifindex(neigh, ival); 00064 } 00065 00066 void nl_cli_neigh_parse_family(struct rtnl_neigh *neigh, char *arg) 00067 { 00068 int family; 00069 00070 if ((family = nl_str2af(arg)) == AF_UNSPEC) 00071 nl_cli_fatal(EINVAL, 00072 "Unable to translate address family \"%s\"", arg); 00073 00074 rtnl_neigh_set_family(neigh, family); 00075 } 00076 00077 void nl_cli_neigh_parse_state(struct rtnl_neigh *neigh, char *arg) 00078 { 00079 int state; 00080 00081 if ((state = rtnl_neigh_str2state(arg)) < 0) 00082 nl_cli_fatal(state, "Unable to translate state \"%s\": %s", 00083 arg, state); 00084 00085 rtnl_neigh_set_state(neigh, state); 00086 } 00087 00088 /** @} */