… | |
… | |
29 | #include <sys/poll.h> |
29 | #include <sys/poll.h> |
30 | #include <sys/wait.h> |
30 | #include <sys/wait.h> |
31 | #include <errno.h> |
31 | #include <errno.h> |
32 | #include <time.h> |
32 | #include <time.h> |
33 | #include <unistd.h> |
33 | #include <unistd.h> |
|
|
34 | #include <fcntl.h> |
34 | #include <arpa/inet.h> |
35 | #include <arpa/inet.h> |
35 | #include <netinet/in.h> |
36 | #include <netinet/in.h> |
36 | #include <netinet/ip_icmp.h> |
37 | #include <netinet/ip_icmp.h> |
37 | |
38 | |
38 | #include "pidfile.h" |
39 | #include "pidfile.h" |
… | |
… | |
81 | ipv4_fd = socket (PF_INET, SOCK_RAW, ::conf.ip_proto); |
82 | ipv4_fd = socket (PF_INET, SOCK_RAW, ::conf.ip_proto); |
82 | |
83 | |
83 | if (ipv4_fd < 0) |
84 | if (ipv4_fd < 0) |
84 | return -1; |
85 | return -1; |
85 | |
86 | |
|
|
87 | fcntl (ipv4_fd, F_SETFL, O_NONBLOCK); |
|
|
88 | |
86 | #ifdef IP_MTU_DISCOVER |
89 | #ifdef IP_MTU_DISCOVER |
87 | // this I really consider a linux bug. I am neither connected |
90 | // this I really consider a linux bug. I am neither connected |
88 | // nor do I fragment myself. Linux still sets DF and doesn't |
91 | // nor do I fragment myself. Linux still sets DF and doesn't |
89 | // fragment for me sometimes. |
92 | // fragment for me sometimes. |
90 | { |
93 | { |
… | |
… | |
111 | udpv4_fd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); |
114 | udpv4_fd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); |
112 | |
115 | |
113 | if (udpv4_fd < 0) |
116 | if (udpv4_fd < 0) |
114 | return -1; |
117 | return -1; |
115 | |
118 | |
|
|
119 | fcntl (udpv4_fd, F_SETFL, O_NONBLOCK); |
|
|
120 | |
116 | // standard daemon practise... |
121 | // standard daemon practise... |
117 | { |
122 | { |
118 | int oval = 1; |
123 | int oval = 1; |
119 | setsockopt (udpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
124 | setsockopt (udpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
120 | } |
125 | } |
… | |
… | |
148 | icmpv4_fd = socket (PF_INET, SOCK_RAW, IPPROTO_ICMP); |
153 | icmpv4_fd = socket (PF_INET, SOCK_RAW, IPPROTO_ICMP); |
149 | |
154 | |
150 | if (icmpv4_fd < 0) |
155 | if (icmpv4_fd < 0) |
151 | return -1; |
156 | return -1; |
152 | |
157 | |
|
|
158 | fcntl (icmpv4_fd, F_SETFL, O_NONBLOCK); |
|
|
159 | |
153 | #ifdef ICMP_FILTER |
160 | #ifdef ICMP_FILTER |
154 | { |
161 | { |
155 | icmp_filter oval; |
162 | icmp_filter oval; |
156 | oval.data = 0xffffffff; |
163 | oval.data = 0xffffffff; |
157 | if (::conf.icmp_type < 32) |
164 | if (::conf.icmp_type < 32) |
… | |
… | |
190 | { |
197 | { |
191 | tcpv4_fd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); |
198 | tcpv4_fd = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP); |
192 | |
199 | |
193 | if (tcpv4_fd < 0) |
200 | if (tcpv4_fd < 0) |
194 | return -1; |
201 | return -1; |
|
|
202 | |
|
|
203 | fcntl (tcpv4_fd, F_SETFL, O_NONBLOCK); |
195 | |
204 | |
196 | // standard daemon practise... |
205 | // standard daemon practise... |
197 | { |
206 | { |
198 | int oval = 1; |
207 | int oval = 1; |
199 | setsockopt (tcpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
208 | setsockopt (tcpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
… | |
… | |
631 | for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) |
640 | for (conns_vector::iterator i = conns.begin (); i != conns.end (); ++i) |
632 | { |
641 | { |
633 | connection *c = *i; |
642 | connection *c = *i; |
634 | |
643 | |
635 | if (c->conf->routerprio > prio |
644 | if (c->conf->routerprio > prio |
636 | && c->connectmode == conf_node::C_ALWAYS |
645 | && c->connectmode == conf_node::C_ALWAYS // so we don't drop the connection if in use |
637 | && c->conf != THISNODE |
|
|
638 | && c->ictx && c->octx) |
646 | && c->ictx && c->octx |
|
|
647 | && c->conf != THISNODE // redundant, since ictx==octx==0 always on thisnode |
|
|
648 | && (!THISNODE->routerprio |
|
|
649 | || c->conf->routerprio <= THISNODE->routerprio)) |
639 | { |
650 | { |
640 | prio = c->conf->routerprio; |
651 | prio = c->conf->routerprio; |
641 | router = c; |
652 | router = c; |
642 | } |
653 | } |
643 | } |
654 | } |