… | |
… | |
108 | |
108 | |
109 | if (ipv4_fd < 0) |
109 | if (ipv4_fd < 0) |
110 | return -1; |
110 | return -1; |
111 | |
111 | |
112 | fcntl (ipv4_fd, F_SETFL, O_NONBLOCK); |
112 | fcntl (ipv4_fd, F_SETFL, O_NONBLOCK); |
|
|
113 | fcntl (ipv4_fd, F_SETFD, FD_CLOEXEC); |
113 | |
114 | |
114 | #if defined(SOL_IP) && defined(IP_MTU_DISCOVER) |
115 | #if defined(SOL_IP) && defined(IP_MTU_DISCOVER) |
115 | // this I really consider a linux bug. I am neither connected |
116 | // this I really consider a linux bug. I am neither connected |
116 | // nor do I fragment myself. Linux still sets DF and doesn't |
117 | // nor do I fragment myself. Linux still sets DF and doesn't |
117 | // fragment for me sometimes. |
118 | // fragment for me sometimes. |
… | |
… | |
140 | |
141 | |
141 | if (udpv4_fd < 0) |
142 | if (udpv4_fd < 0) |
142 | return -1; |
143 | return -1; |
143 | |
144 | |
144 | fcntl (udpv4_fd, F_SETFL, O_NONBLOCK); |
145 | fcntl (udpv4_fd, F_SETFL, O_NONBLOCK); |
|
|
146 | fcntl (udpv4_fd, F_SETFD, FD_CLOEXEC); |
145 | |
147 | |
146 | // standard daemon practise... |
148 | // standard daemon practise... |
147 | { |
149 | { |
148 | int oval = 1; |
150 | int oval = 1; |
149 | setsockopt (udpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
151 | setsockopt (udpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
… | |
… | |
179 | |
181 | |
180 | if (icmpv4_fd < 0) |
182 | if (icmpv4_fd < 0) |
181 | return -1; |
183 | return -1; |
182 | |
184 | |
183 | fcntl (icmpv4_fd, F_SETFL, O_NONBLOCK); |
185 | fcntl (icmpv4_fd, F_SETFL, O_NONBLOCK); |
|
|
186 | fcntl (icmpv4_fd, F_SETFD, FD_CLOEXEC); |
184 | |
187 | |
185 | #ifdef ICMP_FILTER |
188 | #ifdef ICMP_FILTER |
186 | { |
189 | { |
187 | icmp_filter oval; |
190 | icmp_filter oval; |
188 | oval.data = 0xffffffff; |
191 | oval.data = 0xffffffff; |
… | |
… | |
224 | |
227 | |
225 | if (tcpv4_fd < 0) |
228 | if (tcpv4_fd < 0) |
226 | return -1; |
229 | return -1; |
227 | |
230 | |
228 | fcntl (tcpv4_fd, F_SETFL, O_NONBLOCK); |
231 | fcntl (tcpv4_fd, F_SETFL, O_NONBLOCK); |
|
|
232 | fcntl (tcpv4_fd, F_SETFD, FD_CLOEXEC); |
229 | |
233 | |
230 | // standard daemon practise... |
234 | // standard daemon practise... |
231 | { |
235 | { |
232 | int oval = 1; |
236 | int oval = 1; |
233 | setsockopt (tcpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
237 | setsockopt (tcpv4_fd, SOL_SOCKET, SO_REUSEADDR, &oval, sizeof oval); |
… | |
… | |
258 | |
262 | |
259 | dnsv4_fd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); |
263 | dnsv4_fd = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); |
260 | |
264 | |
261 | if (dnsv4_fd < 0) |
265 | if (dnsv4_fd < 0) |
262 | return -1; |
266 | return -1; |
|
|
267 | |
|
|
268 | fcntl (dnsv4_fd, F_SETFL, O_NONBLOCK); |
|
|
269 | fcntl (dnsv4_fd, F_SETFD, FD_CLOEXEC); |
263 | |
270 | |
264 | # if defined(SOL_IP) && defined(IP_MTU_DISCOVER) |
271 | # if defined(SOL_IP) && defined(IP_MTU_DISCOVER) |
265 | // this I really consider a linux bug. I am neither connected |
272 | // this I really consider a linux bug. I am neither connected |
266 | // nor do I fragment myself. Linux still sets DF and doesn't |
273 | // nor do I fragment myself. Linux still sets DF and doesn't |
267 | // fragment for me sometimes. |
274 | // fragment for me sometimes. |
… | |
… | |
302 | { |
309 | { |
303 | slog (L_ERR, _("cannot create network interface '%s'"), conf.ifname); |
310 | slog (L_ERR, _("cannot create network interface '%s'"), conf.ifname); |
304 | exit (EXIT_FAILURE); |
311 | exit (EXIT_FAILURE); |
305 | } |
312 | } |
306 | |
313 | |
|
|
314 | fcntl (tap->fd, F_SETFD, FD_CLOEXEC); |
|
|
315 | |
307 | if (tap->if_up () && |
316 | if (tap->if_up () && |
308 | !run_script (run_script_cb (this, &vpn::script_if_init), true)) |
317 | !run_script (run_script_cb (this, &vpn::script_if_init), true)) |
309 | { |
318 | { |
310 | slog (L_ERR, _("interface initialization command '%s' failed, exiting."), |
319 | slog (L_ERR, _("interface initialization command '%s' failed, exiting."), |
311 | tap->if_up ()); |
320 | tap->if_up ()); |