]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-route.c
device: fix typo
[thirdparty/systemd.git] / src / network / networkd-route.c
CommitLineData
f579559b
TG
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
7
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.
12
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.
17
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/>.
20***/
21
22#include <net/if.h>
23
24#include "networkd.h"
25
26#include "utf8.h"
27#include "util.h"
28#include "conf-parser.h"
29#include "net-util.h"
30
31int route_new(Network *network, Route **ret) {
32 _cleanup_route_free_ Route *route = NULL;
33
34 route = new0(Route, 1);
35 if (!route)
36 return -ENOMEM;
37
38 route->network = network;
39
40 LIST_PREPEND(routes, network->routes, route);
41
42 *ret = route;
43 route = NULL;
44
45 return 0;
46}
47
48void route_free(Route *route) {
49 if (!route)
50 return;
51
52 LIST_REMOVE(routes, route->network->routes, route);
53
54 free(route);
55}
56
f882c247
TG
57int route_configure(Route *route, Link *link,
58 sd_rtnl_message_handler_t callback) {
f579559b
TG
59 _cleanup_sd_rtnl_message_unref_ sd_rtnl_message *req = NULL;
60 int r;
61
f579559b 62 assert(link);
f882c247
TG
63 assert(link->manager);
64 assert(link->manager->rtnl);
f579559b
TG
65 assert(link->ifindex > 0);
66 assert(route->family == AF_INET || route->family == AF_INET6);
67
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);
71 if (r < 0) {
72 log_error("Could not create RTM_NEWROUTE message: %s", strerror(-r));
73 return r;
74 }
75
76 r = sd_rtnl_message_append(req, RTA_GATEWAY, &route->in_addr);
77 if (r < 0) {
78 log_error("Could not append RTA_GATEWAY attribute: %s", strerror(-r));
79 return r;
80 }
81
82 r = sd_rtnl_message_append(req, RTA_OIF, &link->ifindex);
83 if (r < 0) {
84 log_error("Could not append RTA_OIF attribute: %s", strerror(-r));
85 return r;
86 }
87
f882c247 88 r = sd_rtnl_call_async(link->manager->rtnl, req, callback, link, 0, NULL);
f579559b 89 if (r < 0) {
f882c247 90 log_error("Could not send rtnetlink message: %s", strerror(-r));
f579559b
TG
91 return r;
92 }
93
f882c247 94 link->rtnl_messages ++;
f579559b
TG
95
96 return 0;
97}
98
99int config_parse_gateway(const char *unit,
100 const char *filename,
101 unsigned line,
102 const char *section,
103 const char *lvalue,
104 int ltype,
105 const char *rvalue,
106 void *data,
107 void *userdata) {
108 _cleanup_route_free_ Route *n = NULL;
109 _cleanup_free_ char *route = NULL;
110 int r;
111
112 assert(filename);
113 assert(lvalue);
114 assert(rvalue);
115 assert(data);
116
117 r = route_new(userdata, &n);
118 if (r < 0)
119 return r;
120
121 r = net_parse_inaddr(rvalue, &n->family, &n->in_addr);
122 if (r < 0) {
123 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
124 "Route is invalid, ignoring assignment: %s", route);
125 return 0;
126 }
127
128 n = NULL;
129
130 return 0;
131}