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.14 by pcg, Tue Oct 14 03:22:09 2003 UTC vs.
Revision 1.17 by pcg, Wed Oct 15 06:06:41 2003 UTC

24#include <cstring> 24#include <cstring>
25#include <cstdio> 25#include <cstdio>
26 26
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/socket.h> 28#include <sys/socket.h>
29#include <sys/poll.h>
30#include <sys/wait.h> 29#include <sys/wait.h>
31#include <errno.h> 30#include <errno.h>
32#include <time.h> 31#include <time.h>
33#include <unistd.h> 32#include <unistd.h>
34#include <fcntl.h> 33#include <fcntl.h>
35#include <sys/socket.h> 34#include <sys/socket.h>
36#include <netinet/in.h> 35
37#include <arpa/inet.h> 36#include "netcompat.h"
38#include <net/if.h>
39#ifdef HAVE_NETINET_IN_SYSTM_H
40# include <netinet/in_systm.h>
41#endif
42#ifdef HAVE_NETINET_IP_H
43# include <netinet/ip.h>
44#endif
45#ifdef HAVE_NETINET_TCP_H
46# include <netinet/tcp.h>
47#endif
48#if ENABLE_ICMP
49# include <netinet/ip_icmp.h>
50#endif
51 37
52#include "pidfile.h" 38#include "pidfile.h"
53 39
54#include "connection.h" 40#include "connection.h"
55#include "util.h" 41#include "util.h"
56#include "vpn.h" 42#include "vpn.h"
57
58#if !defined(SOL_IP) && defined(IPPROTO_IP)
59# define SOL_IP IPPROTO_IP
60#endif
61 43
62///////////////////////////////////////////////////////////////////////////// 44/////////////////////////////////////////////////////////////////////////////
63 45
64const char *vpn::script_if_up () 46const char *vpn::script_if_up ()
65{ 47{
320 302
321 return ~sum; 303 return ~sum;
322} 304}
323 305
324#if ENABLE_ICMP 306#if ENABLE_ICMP
325struct icmp_header {
326 u8 type;
327 u8 code;
328 u16 checksum;
329 union {
330 struct {
331 u16 id;
332 u16 sequence;
333 } echo;
334 u32 gateway;
335 struct {
336 u16 unused;
337 u16 mtu;
338 } frag;
339 } un;
340};
341
342bool 307bool
343vpn::send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos) 308vpn::send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos)
344{ 309{
345#if defined(SOL_IP) && defined(IP_TOS) 310#if defined(SOL_IP) && defined(IP_TOS)
346 setsockopt (icmpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos); 311 setsockopt (icmpv4_fd, SOL_IP, IP_TOS, &tos, sizeof tos);
564 /* process data */ 529 /* process data */
565 tap_packet *pkt; 530 tap_packet *pkt;
566 531
567 pkt = tap->recv (); 532 pkt = tap->recv ();
568 533
534 if (!pkt)
535 return;
536
537 if (pkt->len > 14)
538 {
569 int dst = mac2id (pkt->dst); 539 int dst = mac2id (pkt->dst);
570 int src = mac2id (pkt->src); 540 int src = mac2id (pkt->src);
571 541
572 if (src != THISNODE->id) 542 if (src != THISNODE->id)
573 {
574 slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting."));
575 exit (1);
576 }
577
578 if (dst == THISNODE->id)
579 {
580 slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting."));
581 exit (1);
582 }
583
584 if (dst > conns.size ())
585 slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst);
586 else
587 {
588 if (dst)
589 { 543 {
590 // unicast 544 slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting."));
591 if (dst != THISNODE->id) 545 exit (1);
592 conns[dst - 1]->inject_data_packet (pkt);
593 } 546 }
547
548 if (dst == THISNODE->id)
549 {
550 slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting."));
551 exit (1);
552 }
553
554 if (dst > conns.size ())
555 slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst);
594 else 556 else
595 { 557 {
558 if (dst)
559 {
560 // unicast
561 if (dst != THISNODE->id)
562 conns[dst - 1]->inject_data_packet (pkt);
563 }
564 else
565 {
596 // broadcast, this is ugly, but due to the security policy 566 // broadcast, this is ugly, but due to the security policy
597 // we have to connect to all hosts... 567 // we have to connect to all hosts...
598 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) 568 for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c)
599 if ((*c)->conf != THISNODE) 569 if ((*c)->conf != THISNODE)
600 (*c)->inject_data_packet (pkt); 570 (*c)->inject_data_packet (pkt);
571 }
601 } 572 }
602 } 573 }
603 574
604 delete pkt; 575 delete pkt;
605 } 576 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines