chiark / gitweb /
networkd: introduce ipip tunnel
[elogind.git] / src / network / networkd.c
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 "sd-event.h"
23 #include "sd-daemon.h"
24
25 #include "networkd.h"
26
27 int main(int argc, char *argv[]) {
28         _cleanup_manager_free_ Manager *m = NULL;
29         int r;
30
31         log_set_target(LOG_TARGET_AUTO);
32         log_parse_environment();
33         log_open();
34
35         umask(0022);
36
37         if (argc != 1) {
38                 log_error("This program takes no arguments.");
39                 r = -EINVAL;
40                 goto out;
41         }
42
43         /* Always create the directories people can create inotify
44          * watches in. */
45         r = mkdir_label("/run/systemd/network", 0755);
46         if (r < 0)
47                 log_error("Could not create runtime directory: %s",
48                           strerror(-r));
49
50         r = mkdir_label("/run/systemd/network/links", 0755);
51         if (r < 0)
52                 log_error("Could not create runtime directory 'links': %s",
53                           strerror(-r));
54
55         r = mkdir_label("/run/systemd/network/leases", 0755);
56         if (r < 0)
57                 log_error("Could not create runtime directory 'leases': %s",
58                           strerror(-r));
59
60         r = manager_new(&m);
61         if (r < 0) {
62                 log_error("Could not create manager: %s", strerror(-r));
63                 goto out;
64         }
65
66         r = manager_udev_listen(m);
67         if (r < 0) {
68                 log_error("Could not connect to udev: %s", strerror(-r));
69                 goto out;
70         }
71
72         r = manager_rtnl_listen(m);
73         if (r < 0) {
74                 log_error("Could not connect to rtnl: %s", strerror(-r));
75                 goto out;
76         }
77
78         r = manager_bus_listen(m);
79         if (r < 0) {
80                 log_error("Could not connect to system bus: %s", strerror(-r));
81                 goto out;
82         }
83
84         r = manager_load_config(m);
85         if (r < 0) {
86                 log_error("Could not load configuration files: %s", strerror(-r));
87                 goto out;
88         }
89
90         r = manager_init_kmod_ctx(m);
91         if (r < 0) {
92                 log_error("Could not init kmod context: %s", strerror(-r));
93                 goto out;
94         }
95
96         r = manager_rtnl_enumerate_links(m);
97         if (r < 0) {
98                 log_error("Could not enumerate links: %s", strerror(-r));
99                 goto out;
100         }
101
102         /* write out empty resolv.conf to avoid a
103          * dangling symlink */
104         r = manager_update_resolv_conf(m);
105         if (r < 0) {
106                 log_error("Could not create resolv.conf: %s", strerror(-r));
107                 goto out;
108         }
109
110         sd_notify(false,
111                   "READY=1\n"
112                   "STATUS=Processing requests...");
113
114         r = sd_event_loop(m->event);
115         if (r < 0) {
116                 log_error("Event loop failed: %s", strerror(-r));
117                 goto out;
118         }
119
120 out:
121         sd_notify(false,
122                   "STATUS=Shutting down...");
123
124         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
125 }