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(Route *route, Link *link,
58 sd_rtnl_message_handler_t callback) {
59 _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
63 assert(link->manager);
64 assert(link->manager->rtnl);
65 assert(link->ifindex > 0);
66 assert(route->family == AF_INET || route->family == AF_INET6);
68 r = sd_rtnl_message_route_new(RTM_NEWROUTE, route->family, 0, 0, 0,
69 RT_TABLE_MAIN, RT_SCOPE_UNIVERSE, RTPROT_BOOT,
70 RTN_UNICAST, 0, &req);
72 log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
76 r = sd_rtnl_message_append(req, RTA_GATEWAY, &route->in_addr);
78 log_error("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
82 r = sd_rtnl_message_append(req, RTA_OIF, &link->ifindex);
84 log_error("Could not append RTA_OIF attribute: %s", strerror(-r));
88 r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
90 log_error("Could not send rtnetlink message: %s", strerror(-r));
94 link->rtnl_messages ++;
99 int config_parse_gateway(const char *unit,
100 const char *filename,
108 _cleanup_route_free_ Route *n = NULL;
109 _cleanup_free_ char *route = NULL;
117 r = route_new(userdata, &n);
121 r = net_parse_inaddr(rvalue, &n->family, &n->in_addr);
123 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
124 "Route is invalid, ignoring assignment: %s", route);