ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/vpn.C
(Generate patch)

Comparing gvpe/src/vpn.C (file contents):
Revision 1.68 by root, Wed Jul 15 23:04:06 2015 UTC vs.
Revision 1.70 by root, Thu Oct 6 03:03:09 2022 UTC

59 59
60vpn network; // THE vpn (bad design...) 60vpn network; // THE vpn (bad design...)
61 61
62///////////////////////////////////////////////////////////////////////////// 62/////////////////////////////////////////////////////////////////////////////
63 63
64// hopefully temporary workaround for rare buffer full conditions
65// if it happens, usually instantly retrying or retrying ~5ms later
66// is good enough with current network technologies/kernels
67
68static ssize_t
69xsendto (int fd, const void *buf, size_t len, int flags,
70 const struct sockaddr *sa, socklen_t salen)
71{
72 ssize_t res;
73
74 for (int retry = 0; retry <= 13; ++retry) // ~100ms
75 {
76 res = sendto (fd, buf, len, flags, sa, salen);
77
78 if (res >= 0 || errno != ENOBUFS)
79 break;
80
81 struct timespec ts = { 0, 1000 * retry };
82 nanosleep (&ts, 0);
83 }
84
85 return res;
86}
87
88/////////////////////////////////////////////////////////////////////////////
89
64static void inline 90static void inline
65set_tos (int fd, int &tos_prev, int tos) 91set_tos (int fd, int &tos_prev, int tos)
66{ 92{
67#if defined(SOL_IP) && defined(IP_TOS) 93#if defined(SOL_IP) && defined(IP_TOS)
68 if (tos_prev == tos) 94 if (tos_prev == tos)
232 return -1; 258 return -1;
233 259
234#ifdef ICMP_FILTER 260#ifdef ICMP_FILTER
235 { 261 {
236 icmp_filter oval; 262 icmp_filter oval;
237 oval.data = 0xffffffff; 263 oval.data = 0;
238 if (::conf.icmp_type < 32) 264 if (::conf.icmp_type < 32)
239 oval.data &= ~(1 << ::conf.icmp_type); 265 oval.data |= 1 << ::conf.icmp_type;
266 oval.data = ~oval.data;
240 267
241 setsockopt (icmpv4_fd, SOL_RAW, ICMP_FILTER, &oval, sizeof oval); 268 setsockopt (icmpv4_fd, SOL_RAW, ICMP_FILTER, &oval, sizeof oval);
242 } 269 }
243#endif 270#endif
244 271
460 487
461bool 488bool
462vpn::send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) 489vpn::send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos)
463{ 490{
464 set_tos (ipv4_fd, ipv4_tos, tos); 491 set_tos (ipv4_fd, ipv4_tos, tos);
465 sendto (ipv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ()); 492 xsendto (ipv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ());
466 493
467 return true; 494 return true;
468} 495}
469 496
470static u16 497static u16
501 hdr->code = 255; 528 hdr->code = 255;
502 hdr->checksum = 0; 529 hdr->checksum = 0;
503 hdr->checksum = ipv4_checksum ((u16 *)hdr, pkt->len); 530 hdr->checksum = ipv4_checksum ((u16 *)hdr, pkt->len);
504 531
505 set_tos (icmpv4_fd, icmpv4_tos, tos); 532 set_tos (icmpv4_fd, icmpv4_tos, tos);
506 sendto (icmpv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ()); 533 xsendto (icmpv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ());
507 534
508 return true; 535 return true;
509} 536}
510#endif 537#endif
511 538
512bool 539bool
513vpn::send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) 540vpn::send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos)
514{ 541{
515 set_tos (udpv4_fd, udpv4_tos, tos); 542 set_tos (udpv4_fd, udpv4_tos, tos);
516 sendto (udpv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ()); 543 xsendto (udpv4_fd, &((*pkt)[0]), pkt->len, 0, si.sav4 (), si.salenv4 ());
517 544
518 return true; 545 return true;
519} 546}
520 547
521void 548void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines