… | |
… | |
19 | |
19 | |
20 | #include "config.h" |
20 | #include "config.h" |
21 | |
21 | |
22 | #include <list> |
22 | #include <list> |
23 | |
23 | |
|
|
24 | #include <cstdio> |
|
|
25 | #include <cstring> |
24 | #include <cstdlib> |
26 | #include <cstdlib> |
25 | #include <cstring> |
|
|
26 | #include <cstdio> |
|
|
27 | |
27 | |
28 | #include <sys/types.h> |
28 | #include <sys/types.h> |
29 | #include <sys/socket.h> |
29 | #include <sys/socket.h> |
30 | #include <sys/wait.h> |
30 | #include <sys/wait.h> |
31 | #include <errno.h> |
31 | #include <errno.h> |
… | |
… | |
98 | sockinfo si (THISNODE, PROT_IPv4); |
98 | sockinfo si (THISNODE, PROT_IPv4); |
99 | |
99 | |
100 | if (bind (ipv4_fd, si.sav4 (), si.salenv4 ())) |
100 | if (bind (ipv4_fd, si.sav4 (), si.salenv4 ())) |
101 | { |
101 | { |
102 | slog (L_ERR, _("can't bind ipv4 socket on %s: %s"), (const char *)si, strerror (errno)); |
102 | slog (L_ERR, _("can't bind ipv4 socket on %s: %s"), (const char *)si, strerror (errno)); |
103 | exit (1); |
103 | exit (EXIT_FAILURE); |
104 | } |
104 | } |
105 | |
105 | |
106 | ipv4_ev_watcher.start (ipv4_fd, EVENT_READ); |
106 | ipv4_ev_watcher.start (ipv4_fd, EVENT_READ); |
107 | } |
107 | } |
108 | |
108 | |
… | |
… | |
136 | sockinfo si (THISNODE, PROT_UDPv4); |
136 | sockinfo si (THISNODE, PROT_UDPv4); |
137 | |
137 | |
138 | if (bind (udpv4_fd, si.sav4 (), si.salenv4 ())) |
138 | if (bind (udpv4_fd, si.sav4 (), si.salenv4 ())) |
139 | { |
139 | { |
140 | slog (L_ERR, _("can't bind udpv4 on %s: %s"), (const char *)si, strerror (errno)); |
140 | slog (L_ERR, _("can't bind udpv4 on %s: %s"), (const char *)si, strerror (errno)); |
141 | exit (1); |
141 | exit (EXIT_FAILURE); |
142 | } |
142 | } |
143 | |
143 | |
144 | udpv4_ev_watcher.start (udpv4_fd, EVENT_READ); |
144 | udpv4_ev_watcher.start (udpv4_fd, EVENT_READ); |
145 | } |
145 | } |
146 | |
146 | |
… | |
… | |
180 | sockinfo si (THISNODE, PROT_ICMPv4); |
180 | sockinfo si (THISNODE, PROT_ICMPv4); |
181 | |
181 | |
182 | if (bind (icmpv4_fd, si.sav4 (), si.salenv4 ())) |
182 | if (bind (icmpv4_fd, si.sav4 (), si.salenv4 ())) |
183 | { |
183 | { |
184 | slog (L_ERR, _("can't bind icmpv4 on %s: %s"), (const char *)si, strerror (errno)); |
184 | slog (L_ERR, _("can't bind icmpv4 on %s: %s"), (const char *)si, strerror (errno)); |
185 | exit (1); |
185 | exit (EXIT_FAILURE); |
186 | } |
186 | } |
187 | |
187 | |
188 | icmpv4_ev_watcher.start (icmpv4_fd, EVENT_READ); |
188 | icmpv4_ev_watcher.start (icmpv4_fd, EVENT_READ); |
189 | } |
189 | } |
190 | #endif |
190 | #endif |
… | |
… | |
210 | sockinfo si (THISNODE, PROT_TCPv4); |
210 | sockinfo si (THISNODE, PROT_TCPv4); |
211 | |
211 | |
212 | if (bind (tcpv4_fd, si.sav4 (), si.salenv4 ())) |
212 | if (bind (tcpv4_fd, si.sav4 (), si.salenv4 ())) |
213 | { |
213 | { |
214 | slog (L_ERR, _("can't bind tcpv4 on %s: %s"), (const char *)si, strerror (errno)); |
214 | slog (L_ERR, _("can't bind tcpv4 on %s: %s"), (const char *)si, strerror (errno)); |
215 | exit (1); |
215 | exit (EXIT_FAILURE); |
216 | } |
216 | } |
217 | |
217 | |
218 | if (listen (tcpv4_fd, 5)) |
218 | if (listen (tcpv4_fd, 5)) |
219 | { |
219 | { |
220 | slog (L_ERR, _("can't listen tcpv4 on %s: %s"), (const char *)si, strerror (errno)); |
220 | slog (L_ERR, _("can't listen tcpv4 on %s: %s"), (const char *)si, strerror (errno)); |
221 | exit (1); |
221 | exit (EXIT_FAILURE); |
222 | } |
222 | } |
223 | |
223 | |
224 | tcpv4_ev_watcher.start (tcpv4_fd, EVENT_READ); |
224 | tcpv4_ev_watcher.start (tcpv4_fd, EVENT_READ); |
225 | } |
225 | } |
226 | #endif |
226 | #endif |
227 | |
227 | |
228 | tap = new tap_device (); |
228 | tap = new tap_device (); |
229 | if (!tap) //D this, of course, never catches |
229 | if (!tap) //D this, of course, never catches |
230 | { |
230 | { |
231 | slog (L_ERR, _("cannot create network interface '%s'"), conf.ifname); |
231 | slog (L_ERR, _("cannot create network interface '%s'"), conf.ifname); |
232 | exit (1); |
232 | exit (EXIT_FAILURE); |
233 | } |
233 | } |
234 | |
234 | |
235 | run_script (run_script_cb (this, &vpn::script_if_up), true); |
235 | run_script (run_script_cb (this, &vpn::script_if_up), true); |
236 | |
236 | |
237 | tap_ev_watcher.start (tap->fd, EVENT_READ); |
237 | tap_ev_watcher.start (tap->fd, EVENT_READ); |
… | |
… | |
430 | else |
430 | else |
431 | { |
431 | { |
432 | slog (L_ERR, |
432 | slog (L_ERR, |
433 | _("FATAL: unknown revents %08x in socket, terminating\n"), |
433 | _("FATAL: unknown revents %08x in socket, terminating\n"), |
434 | revents); |
434 | revents); |
435 | exit (1); |
435 | exit (EXIT_FAILURE); |
436 | } |
436 | } |
437 | } |
437 | } |
438 | |
438 | |
439 | #if ENABLE_ICMP |
439 | #if ENABLE_ICMP |
440 | void |
440 | void |
… | |
… | |
478 | else |
478 | else |
479 | { |
479 | { |
480 | slog (L_ERR, |
480 | slog (L_ERR, |
481 | _("FATAL: unknown revents %08x in socket, terminating\n"), |
481 | _("FATAL: unknown revents %08x in socket, terminating\n"), |
482 | revents); |
482 | revents); |
483 | exit (1); |
483 | exit (EXIT_FAILURE); |
484 | } |
484 | } |
485 | } |
485 | } |
486 | #endif |
486 | #endif |
487 | |
487 | |
488 | void |
488 | void |
… | |
… | |
516 | else |
516 | else |
517 | { |
517 | { |
518 | slog (L_ERR, |
518 | slog (L_ERR, |
519 | _("FATAL: unknown revents %08x in socket, terminating\n"), |
519 | _("FATAL: unknown revents %08x in socket, terminating\n"), |
520 | revents); |
520 | revents); |
521 | exit (1); |
521 | exit (EXIT_FAILURE); |
522 | } |
522 | } |
523 | } |
523 | } |
524 | |
524 | |
525 | void |
525 | void |
526 | vpn::tap_ev (io_watcher &w, short revents) |
526 | vpn::tap_ev (io_watcher &w, short revents) |
… | |
… | |
541 | int src = mac2id (pkt->src); |
541 | int src = mac2id (pkt->src); |
542 | |
542 | |
543 | if (src != THISNODE->id) |
543 | if (src != THISNODE->id) |
544 | { |
544 | { |
545 | slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); |
545 | slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); |
546 | exit (1); |
546 | exit (EXIT_FAILURE); |
547 | } |
547 | } |
548 | |
548 | |
549 | if (dst == THISNODE->id) |
549 | if (dst == THISNODE->id) |
550 | { |
550 | { |
551 | slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting.")); |
551 | slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting.")); |
552 | exit (1); |
552 | exit (EXIT_FAILURE); |
553 | } |
553 | } |
554 | |
554 | |
555 | if (dst > conns.size ()) |
555 | if (dst > conns.size ()) |
556 | slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); |
556 | slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); |
557 | else |
557 | else |
… | |
… | |
574 | slog (L_INFO, _("preparing shutdown...")); |
574 | slog (L_INFO, _("preparing shutdown...")); |
575 | |
575 | |
576 | shutdown_all (); |
576 | shutdown_all (); |
577 | remove_pid (pidfilename); |
577 | remove_pid (pidfilename); |
578 | slog (L_INFO, _("terminating")); |
578 | slog (L_INFO, _("terminating")); |
579 | exit (0); |
579 | exit (EXIT_SUCCESS); |
580 | } |
580 | } |
581 | |
581 | |
582 | if (events & EVENT_RECONNECT) |
582 | if (events & EVENT_RECONNECT) |
583 | { |
583 | { |
584 | slog (L_INFO, _("forced reconnect")); |
584 | slog (L_INFO, _("forced reconnect")); |