… | |
… | |
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> |
… | |
… | |
530 | /* process data */ |
529 | /* process data */ |
531 | tap_packet *pkt; |
530 | tap_packet *pkt; |
532 | |
531 | |
533 | pkt = tap->recv (); |
532 | pkt = tap->recv (); |
534 | |
533 | |
|
|
534 | if (!pkt) |
|
|
535 | return; |
|
|
536 | |
|
|
537 | if (pkt->len > 14) |
|
|
538 | { |
535 | int dst = mac2id (pkt->dst); |
539 | int dst = mac2id (pkt->dst); |
536 | int src = mac2id (pkt->src); |
540 | int src = mac2id (pkt->src); |
537 | |
541 | |
538 | if (src != THISNODE->id) |
542 | if (src != THISNODE->id) |
539 | { |
|
|
540 | slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); |
|
|
541 | exit (1); |
|
|
542 | } |
|
|
543 | |
|
|
544 | if (dst == THISNODE->id) |
|
|
545 | { |
|
|
546 | slog (L_ERR, _("FATAL: tap packet destined for current node received, exiting.")); |
|
|
547 | exit (1); |
|
|
548 | } |
|
|
549 | |
|
|
550 | if (dst > conns.size ()) |
|
|
551 | slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); |
|
|
552 | else |
|
|
553 | { |
|
|
554 | if (dst) |
|
|
555 | { |
543 | { |
556 | // unicast |
544 | slog (L_ERR, _("FATAL: tap packet not originating on current node received, exiting.")); |
557 | if (dst != THISNODE->id) |
545 | exit (1); |
558 | conns[dst - 1]->inject_data_packet (pkt); |
|
|
559 | } |
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); |
560 | else |
556 | else |
561 | { |
557 | { |
|
|
558 | if (dst) |
|
|
559 | { |
|
|
560 | // unicast |
|
|
561 | if (dst != THISNODE->id) |
|
|
562 | conns[dst - 1]->inject_data_packet (pkt); |
|
|
563 | } |
|
|
564 | else |
|
|
565 | { |
562 | // broadcast, this is ugly, but due to the security policy |
566 | // broadcast, this is ugly, but due to the security policy |
563 | // we have to connect to all hosts... |
567 | // we have to connect to all hosts... |
564 | for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) |
568 | for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) |
565 | if ((*c)->conf != THISNODE) |
569 | if ((*c)->conf != THISNODE) |
566 | (*c)->inject_data_packet (pkt); |
570 | (*c)->inject_data_packet (pkt); |
|
|
571 | } |
567 | } |
572 | } |
568 | } |
573 | } |
569 | |
574 | |
570 | delete pkt; |
575 | delete pkt; |
571 | } |
576 | } |