… | |
… | |
34 | #include "conf.h" |
34 | #include "conf.h" |
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 | |
|
|
40 | #include "netcompat.h" |
39 | |
41 | |
40 | #if !HAVE_RAND_PSEUDO_BYTES |
42 | #if !HAVE_RAND_PSEUDO_BYTES |
41 | # define RAND_pseudo_bytes RAND_bytes |
43 | # define RAND_pseudo_bytes RAND_bytes |
42 | #endif |
44 | #endif |
43 | |
45 | |
… | |
… | |
798 | reset_connection (); |
800 | reset_connection (); |
799 | establish_connection (); |
801 | establish_connection (); |
800 | } |
802 | } |
801 | |
803 | |
802 | void |
804 | void |
803 | connection::send_data_packet (tap_packet *pkt, bool broadcast) |
805 | connection::send_data_packet (tap_packet *pkt) |
804 | { |
806 | { |
805 | vpndata_packet *p = new vpndata_packet; |
807 | vpndata_packet *p = new vpndata_packet; |
806 | int tos = 0; |
808 | int tos = 0; |
807 | |
809 | |
808 | // 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. |
809 | if (conf->inherit_tos |
811 | if (conf->inherit_tos && pkt->is_ipv4 ()) |
810 | && (*pkt)[12] == 0x08 && (*pkt)[13] == 0x00 // IP |
|
|
811 | && ((*pkt)[14] & 0xf0) == 0x40) // IPv4 |
|
|
812 | tos = (*pkt)[15] & IPTOS_TOS_MASK; |
812 | tos = (*pkt)[15] & IPTOS_TOS_MASK; |
813 | |
813 | |
814 | 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 |
815 | send_vpn_packet (p, si, tos); |
815 | send_vpn_packet (p, si, tos); |
816 | |
816 | |
817 | delete p; |
817 | delete p; |
818 | |
818 | |
819 | if (oseqno > MAX_SEQNO) |
819 | if (oseqno > MAX_SEQNO) |
820 | rekey (); |
820 | rekey (); |
821 | } |
821 | } |
822 | |
822 | |
823 | void |
823 | void |
824 | connection::inject_data_packet (tap_packet *pkt, bool broadcast) |
824 | connection::inject_data_packet (tap_packet *pkt, bool broadcast/*TODO DDD*/) |
825 | { |
825 | { |
826 | if (ictx && octx) |
826 | if (ictx && octx) |
827 | send_data_packet (pkt, broadcast); |
827 | send_data_packet (pkt); |
828 | else |
828 | else |
829 | { |
829 | { |
830 | if (!broadcast)//DDDD |
830 | if (!broadcast)//DDDD |
831 | data_queue.put (new tap_packet (*pkt)); |
831 | data_queue.put (new tap_packet (*pkt)); |
832 | |
832 | |
… | |
… | |
1035 | |
1035 | |
1036 | if (iseqno.recv_ok (seqno)) |
1036 | if (iseqno.recv_ok (seqno)) |
1037 | { |
1037 | { |
1038 | vpn->tap->send (d); |
1038 | vpn->tap->send (d); |
1039 | |
1039 | |
1040 | if (p->dst () == 0) // re-broadcast |
|
|
1041 | for (vpn::conns_vector::iterator i = vpn->conns.begin (); i != vpn->conns.end (); ++i) |
|
|
1042 | { |
|
|
1043 | connection *c = *i; |
|
|
1044 | |
|
|
1045 | if (c->conf != THISNODE && c->conf != conf) |
|
|
1046 | c->inject_data_packet (d); |
|
|
1047 | } |
|
|
1048 | |
|
|
1049 | if (si != rsi) |
1040 | if (si != rsi) |
1050 | { |
1041 | { |
1051 | // fast re-sync on connection changes, useful especially for tcp/ip |
1042 | // fast re-sync on connection changes, useful especially for tcp/ip |
1052 | si = rsi; |
1043 | si = rsi; |
1053 | |
1044 | |