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.42 by pcg, Sun Dec 2 00:54:52 2007 UTC vs.
Revision 1.45 by pcg, Thu Dec 6 00:35:29 2007 UTC

87 snprintf (ext, 16, "_%d", (*c)->conf->id); 87 snprintf (ext, 16, "_%d", (*c)->conf->id);
88 (*c)->script_init_env (ext); 88 (*c)->script_init_env (ext);
89 } 89 }
90} 90}
91 91
92inline const char *
92const char *vpn::script_if_init () 93vpn::script_if_init ()
93{ 94{
94 script_init_env (); 95 script_init_env ();
95 96
96 return tap->if_up (); 97 return tap->if_up ();
97} 98}
98 99
100inline const char *
99const char *vpn::script_if_up () 101vpn::script_if_up ()
100{ 102{
101 script_init_env (); 103 script_init_env ();
102 104
103 char *filename; 105 char *filename;
104 asprintf (&filename, 106 asprintf (&filename,
329 exit (EXIT_FAILURE); 331 exit (EXIT_FAILURE);
330 } 332 }
331 333
332 fcntl (tap->fd, F_SETFD, FD_CLOEXEC); 334 fcntl (tap->fd, F_SETFD, FD_CLOEXEC);
333 335
336 run_script_cb cb;
337 cb.set<vpn, &vpn::script_if_init> (this);
338
334 if (tap->if_up () && 339 if (tap->if_up () &&
335 !run_script (run_script_cb (this, &vpn::script_if_init), true)) 340 !run_script (cb, true))
336 { 341 {
337 slog (L_ERR, _("interface initialization command '%s' failed, exiting."), 342 slog (L_ERR, _("interface initialization command '%s' failed, exiting."),
338 tap->if_up ()); 343 tap->if_up ());
339 exit (EXIT_FAILURE); 344 exit (EXIT_FAILURE);
340 } 345 }
341 346
342 if (!run_script (run_script_cb (this, &vpn::script_if_up), true)) 347 cb.set<vpn, &vpn::script_if_up> (this);
348 if (!run_script (cb, true))
343 { 349 {
344 slog (L_ERR, _("if-up command execution failed, exiting.")); 350 slog (L_ERR, _("if-up command execution failed, exiting."));
345 exit (EXIT_FAILURE); 351 exit (EXIT_FAILURE);
346 } 352 }
347 353
497 } 503 }
498 504
499 return false; 505 return false;
500} 506}
501 507
502void 508inline void
503vpn::ipv4_ev (ev::io &w, int revents) 509vpn::ipv4_ev (ev::io &w, int revents)
504{ 510{
505 if (revents & EV_READ) 511 if (revents & EV_READ)
506 { 512 {
507 vpn_packet *pkt = new vpn_packet; 513 vpn_packet *pkt = new vpn_packet;
538 exit (EXIT_FAILURE); 544 exit (EXIT_FAILURE);
539 } 545 }
540} 546}
541 547
542#if ENABLE_ICMP 548#if ENABLE_ICMP
543void 549inline void
544vpn::icmpv4_ev (ev::io &w, int revents) 550vpn::icmpv4_ev (ev::io &w, int revents)
545{ 551{
546 if (revents & EV_READ) 552 if (revents & EV_READ)
547 { 553 {
548 vpn_packet *pkt = new vpn_packet; 554 vpn_packet *pkt = new vpn_packet;
586 exit (EXIT_FAILURE); 592 exit (EXIT_FAILURE);
587 } 593 }
588} 594}
589#endif 595#endif
590 596
591void 597inline void
592vpn::udpv4_ev (ev::io &w, int revents) 598vpn::udpv4_ev (ev::io &w, int revents)
593{ 599{
594 if (revents & EV_READ) 600 if (revents & EV_READ)
595 { 601 {
596 vpn_packet *pkt = new vpn_packet; 602 vpn_packet *pkt = new vpn_packet;
623 revents); 629 revents);
624 exit (EXIT_FAILURE); 630 exit (EXIT_FAILURE);
625 } 631 }
626} 632}
627 633
628void 634inline void
629vpn::tap_ev (ev::io &w, int revents) 635vpn::tap_ev (ev::io &w, int revents)
630{ 636{
631 if (revents & EV_READ) 637 if (revents & EV_READ)
632 { 638 {
633 /* process data */ 639 /* process data */
665 } 671 }
666 else 672 else
667 abort (); 673 abort ();
668} 674}
669 675
670void 676inline void
671vpn::event_cb (ev::timer &w, int) 677vpn::event_cb (ev::timer &w, int)
672{ 678{
673 if (events) 679 if (events)
674 { 680 {
675 if (events & EVENT_SHUTDOWN) 681 if (events & EVENT_SHUTDOWN)
776 782
777 slog (L_NOTICE, _("END status dump")); 783 slog (L_NOTICE, _("END status dump"));
778} 784}
779 785
780vpn::vpn (void) 786vpn::vpn (void)
787{
781: event (this, &vpn::event_cb) 788 event .set<vpn, &vpn::event_cb > (this);
782, udpv4_ev_watcher (this, &vpn::udpv4_ev) 789 udpv4_ev_watcher .set<vpn, &vpn::udpv4_ev > (this);
783, ipv4_ev_watcher (this, &vpn::ipv4_ev) 790 ipv4_ev_watcher .set<vpn, &vpn::ipv4_ev > (this);
784#if ENABLE_TCP 791#if ENABLE_TCP
785, tcpv4_ev_watcher (this, &vpn::tcpv4_ev) 792 tcpv4_ev_watcher .set<vpn, &vpn::tcpv4_ev > (this);
786#endif 793#endif
787#if ENABLE_ICMP 794#if ENABLE_ICMP
788, icmpv4_ev_watcher(this, &vpn::icmpv4_ev) 795 icmpv4_ev_watcher.set<vpn, &vpn::icmpv4_ev> (this);
789#endif 796#endif
790#if ENABLE_DNS 797#if ENABLE_DNS
791, dnsv4_ev_watcher (this, &vpn::dnsv4_ev) 798 dnsv4_ev_watcher .set<vpn, &vpn::dnsv4_ev > (this);
792#endif 799#endif
793, tap_ev_watcher (this, &vpn::tap_ev) 800 tap_ev_watcher .set<vpn, &vpn::tap_ev > (this);
794{
795} 801}
796 802
797vpn::~vpn () 803vpn::~vpn ()
798{ 804{
799} 805}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines