rule.c revision 8808743839b0f459394ecd00cb0f7c1896c0ab7a
1b1928704201034c785a26296a49f69355eb56a05Nick Lewycky/* 2b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * src/lib/rule.c CLI Routing Rule Helpers 3b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * 4b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * This library is free software; you can redistribute it and/or 5b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * modify it under the terms of the GNU Lesser General Public 6b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * License as published by the Free Software Foundation version 2.1 7b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * of the License. 8b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * 9b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * Copyright (c) 2008-2009 Thomas Graf <tgraf@suug.ch> 10b1928704201034c785a26296a49f69355eb56a05Nick Lewycky */ 11b1928704201034c785a26296a49f69355eb56a05Nick Lewycky 12b1928704201034c785a26296a49f69355eb56a05Nick Lewycky/** 13b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * @ingroup cli 14b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * @defgroup cli_rule Routing Rules 15b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * 16b1928704201034c785a26296a49f69355eb56a05Nick Lewycky * @{ 17b1928704201034c785a26296a49f69355eb56a05Nick Lewycky */ 18b1928704201034c785a26296a49f69355eb56a05Nick Lewycky 19b1928704201034c785a26296a49f69355eb56a05Nick Lewycky#include <netlink/cli/utils.h> 20d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include <netlink/cli/rule.h> 21b1928704201034c785a26296a49f69355eb56a05Nick Lewycky 22b1928704201034c785a26296a49f69355eb56a05Nick Lewyckystruct rtnl_rule *nl_cli_rule_alloc(void) 2306cb8ed00696eb14d1b831921452e50ec0568ea2Chandler Carruth{ 24b1928704201034c785a26296a49f69355eb56a05Nick Lewycky struct rtnl_rule *rule; 25b1928704201034c785a26296a49f69355eb56a05Nick Lewycky 26b1928704201034c785a26296a49f69355eb56a05Nick Lewycky rule = rtnl_rule_alloc(); 27d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth if (!rule) 280b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth nl_cli_fatal(ENOMEM, "Unable to allocate rule object"); 290b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth 300b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth return rule; 31d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth} 32a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky 3306cb8ed00696eb14d1b831921452e50ec0568ea2Chandler Carruthstruct nl_cache *nl_cli_rule_alloc_cache(struct nl_sock *sk) 3406cb8ed00696eb14d1b831921452e50ec0568ea2Chandler Carruth{ 3539c41c3c93e0d223792acb093adce21a714b01c6Bill Wendling struct nl_cache *cache; 3606cb8ed00696eb14d1b831921452e50ec0568ea2Chandler Carruth int err; 3706cb8ed00696eb14d1b831921452e50ec0568ea2Chandler Carruth 3806cb8ed00696eb14d1b831921452e50ec0568ea2Chandler Carruth if ((err = rtnl_rule_alloc_cache(sk, AF_UNSPEC, &cache)) < 0) 3906cb8ed00696eb14d1b831921452e50ec0568ea2Chandler Carruth nl_cli_fatal(err, "Unable to allocate routing rule cache: %s\n", 40b1928704201034c785a26296a49f69355eb56a05Nick Lewycky nl_geterror(err)); 41b1928704201034c785a26296a49f69355eb56a05Nick Lewycky 42b1928704201034c785a26296a49f69355eb56a05Nick Lewycky nl_cache_mngt_provide(cache); 43b1928704201034c785a26296a49f69355eb56a05Nick Lewycky 44a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky return cache; 45a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky} 46a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky 47a204ef3168c8804808c716115ba915c89d8849b9Nick Lewyckyvoid nl_cli_rule_parse_family(struct rtnl_rule *rule, char *arg) 48a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky{ 49a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky int family; 50a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky 51a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky if ((family = nl_str2af(arg)) != AF_UNSPEC) 52a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky rtnl_rule_set_family(rule, family); 53a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky} 54a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky 55a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky/** @} */ 56a204ef3168c8804808c716115ba915c89d8849b9Nick Lewycky