… | |
… | |
35 | #include "slog.h" |
35 | #include "slog.h" |
36 | #include "device.h" |
36 | #include "device.h" |
37 | #include "vpn.h" |
37 | #include "vpn.h" |
38 | #include "connection.h" |
38 | #include "connection.h" |
39 | |
39 | |
40 | #include <sys/socket.h> |
40 | #include "netcompat.h" |
41 | #ifdef HAVE_NETINET_IN_H |
|
|
42 | # include <netinet/in.h> |
|
|
43 | #endif |
|
|
44 | #include <arpa/inet.h> |
|
|
45 | #include <net/if.h> |
|
|
46 | #ifdef HAVE_NETINET_IN_SYSTM_H |
|
|
47 | # include <netinet/in_systm.h> |
|
|
48 | #endif |
|
|
49 | #ifdef HAVE_NETINET_IP_H |
|
|
50 | # include <netinet/ip.h> |
|
|
51 | #endif |
|
|
52 | |
|
|
53 | #ifndef IPTOS_TOS_MASK |
|
|
54 | # define IPTOS_TOS_MASK (IPTOS_LOWDELAY | IPTOS_THROUGHPUT | IPTOS_RELIABILITY | IPTOS_MINCOST) |
|
|
55 | #endif |
|
|
56 | |
41 | |
57 | #if !HAVE_RAND_PSEUDO_BYTES |
42 | #if !HAVE_RAND_PSEUDO_BYTES |
58 | # define RAND_pseudo_bytes RAND_bytes |
43 | # define RAND_pseudo_bytes RAND_bytes |
59 | #endif |
44 | #endif |
60 | |
45 | |
… | |
… | |
815 | reset_connection (); |
800 | reset_connection (); |
816 | establish_connection (); |
801 | establish_connection (); |
817 | } |
802 | } |
818 | |
803 | |
819 | void |
804 | void |
820 | connection::send_data_packet (tap_packet *pkt, bool broadcast) |
805 | connection::send_data_packet (tap_packet *pkt) |
821 | { |
806 | { |
822 | vpndata_packet *p = new vpndata_packet; |
807 | vpndata_packet *p = new vpndata_packet; |
823 | int tos = 0; |
808 | int tos = 0; |
824 | |
809 | |
825 | // I am not hilarious about peeking into packets, but so be it. |
810 | // I am not hilarious about peeking into packets, but so be it. |
826 | if (conf->inherit_tos |
811 | if (conf->inherit_tos && pkt->is_ipv4 ()) |
827 | && (*pkt)[12] == 0x08 && (*pkt)[13] == 0x00 // IP |
|
|
828 | && ((*pkt)[14] & 0xf0) == 0x40) // IPv4 |
|
|
829 | tos = (*pkt)[15] & IPTOS_TOS_MASK; |
812 | tos = (*pkt)[15] & IPTOS_TOS_MASK; |
830 | |
813 | |
831 | p->setup (this, broadcast ? 0 : conf->id, &((*pkt)[6 + 6]), pkt->len - 6 - 6, ++oseqno); // skip 2 macs |
814 | p->setup (this, conf->id, &((*pkt)[6 + 6]), pkt->len - 6 - 6, ++oseqno); // skip 2 macs |
832 | send_vpn_packet (p, si, tos); |
815 | send_vpn_packet (p, si, tos); |
833 | |
816 | |
834 | delete p; |
817 | delete p; |
835 | |
818 | |
836 | if (oseqno > MAX_SEQNO) |
819 | if (oseqno > MAX_SEQNO) |
837 | rekey (); |
820 | rekey (); |
838 | } |
821 | } |
839 | |
822 | |
840 | void |
823 | void |
841 | connection::inject_data_packet (tap_packet *pkt, bool broadcast) |
824 | connection::inject_data_packet (tap_packet *pkt, bool broadcast/*TODO DDD*/) |
842 | { |
825 | { |
843 | if (ictx && octx) |
826 | if (ictx && octx) |
844 | send_data_packet (pkt, broadcast); |
827 | send_data_packet (pkt); |
845 | else |
828 | else |
846 | { |
829 | { |
847 | if (!broadcast)//DDDD |
830 | if (!broadcast)//DDDD |
848 | data_queue.put (new tap_packet (*pkt)); |
831 | data_queue.put (new tap_packet (*pkt)); |
849 | |
832 | |
… | |
… | |
1052 | |
1035 | |
1053 | if (iseqno.recv_ok (seqno)) |
1036 | if (iseqno.recv_ok (seqno)) |
1054 | { |
1037 | { |
1055 | vpn->tap->send (d); |
1038 | vpn->tap->send (d); |
1056 | |
1039 | |
1057 | if (p->dst () == 0) // re-broadcast |
|
|
1058 | for (vpn::conns_vector::iterator i = vpn->conns.begin (); i != vpn->conns.end (); ++i) |
|
|
1059 | { |
|
|
1060 | connection *c = *i; |
|
|
1061 | |
|
|
1062 | if (c->conf != THISNODE && c->conf != conf) |
|
|
1063 | c->inject_data_packet (d); |
|
|
1064 | } |
|
|
1065 | |
|
|
1066 | if (si != rsi) |
1040 | if (si != rsi) |
1067 | { |
1041 | { |
1068 | // fast re-sync on connection changes, useful especially for tcp/ip |
1042 | // fast re-sync on connection changes, useful especially for tcp/ip |
1069 | si = rsi; |
1043 | si = rsi; |
1070 | |
1044 | |