1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include "conf-parser.h"
31 int route_new(Network *network, Route **ret) {
32 _cleanup_route_free_ Route *route = NULL;
34 route = new0(Route, 1);
38 route->network = network;
40 LIST_PREPEND(routes, network->routes, route);
48 void route_free(Route *route) {
52 LIST_REMOVE(routes, route->network->routes, route);
57 int route_configure(Manager *manager, Route *route, Link *link) {
58 _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
63 assert(link->ifindex > 0);
64 assert(route->family == AF_INET || route->family == AF_INET6);
66 r = sd_rtnl_message_route_new(RTM_NEWROUTE, route->family, 0, 0, 0,
67 RT_TABLE_MAIN, RT_SCOPE_UNIVERSE, RTPROT_BOOT,
68 RTN_UNICAST, 0, &req);
70 log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
74 r = sd_rtnl_message_append(req, RTA_GATEWAY, &route->in_addr);
76 log_error("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
80 r = sd_rtnl_message_append(req, RTA_OIF, &link->ifindex);
82 log_error("Could not append RTA_OIF attribute: %s", strerror(-r));
86 r = sd_rtnl_call(manager->rtnl, req, 0, NULL);
88 log_error("Could not configure route: %s", strerror(-r));
92 log_info("Configured route");
97 int config_parse_gateway(const char *unit,
106 _cleanup_route_free_ Route *n = NULL;
107 _cleanup_free_ char *route = NULL;
115 r = route_new(userdata, &n);
119 r = net_parse_inaddr(rvalue, &n->family, &n->in_addr);
121 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
122 "Route is invalid, ignoring assignment: %s", route);