1 | /* |
1 | /* |
2 | vpn.C -- handle the protocol, encryption, handshaking etc. |
2 | vpn.C -- handle the protocol, encryption, handshaking etc. |
|
|
3 | Copyright (C) 2003 Marc Lehmann <pcg@goof.com> |
3 | |
4 | |
4 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
335 | |
336 | |
336 | return true; |
337 | return true; |
337 | } |
338 | } |
338 | |
339 | |
339 | void |
340 | void |
|
|
341 | vpn::inject_data_packet (tap_packet *pkt, int dst) |
|
|
342 | { |
|
|
343 | if (dst) |
|
|
344 | { |
|
|
345 | // unicast |
|
|
346 | if (dst != THISNODE->id) |
|
|
347 | conns[dst - 1]->inject_data_packet (pkt); |
|
|
348 | } |
|
|
349 | else |
|
|
350 | { |
|
|
351 | // broadcast, this is ugly, but due to the security policy |
|
|
352 | // we have to connect to all hosts... |
|
|
353 | for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) |
|
|
354 | if ((*c)->conf != THISNODE) |
|
|
355 | (*c)->inject_data_packet (pkt, true); |
|
|
356 | } |
|
|
357 | } |
|
|
358 | |
|
|
359 | void |
340 | vpn::recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi) |
360 | vpn::recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi) |
341 | { |
361 | { |
342 | unsigned int src = pkt->src (); |
362 | unsigned int src = pkt->src (); |
343 | unsigned int dst = pkt->dst (); |
363 | unsigned int dst = pkt->dst (); |
344 | |
364 | |
… | |
… | |
358 | connection *c = conns[src - 1]; |
378 | connection *c = conns[src - 1]; |
359 | |
379 | |
360 | if (dst == 0) |
380 | if (dst == 0) |
361 | slog (L_WARN, _("%s(%s): received broadcast (protocol violation)"), |
381 | slog (L_WARN, _("%s(%s): received broadcast (protocol violation)"), |
362 | c->conf->nodename, (const char *)rsi); |
382 | c->conf->nodename, (const char *)rsi); |
363 | else if (dst != 0 && dst != THISNODE->id) |
383 | else if (dst != THISNODE->id) |
364 | { |
384 | { |
365 | if (THISNODE->routerprio) |
385 | if (THISNODE->routerprio) |
366 | // the tos setting gets lost here. who cares. |
386 | // the tos setting gets lost here. who cares. |
367 | conns[dst - 1]->inject_vpn_packet (pkt); |
387 | conns[dst - 1]->inject_vpn_packet (pkt); |
368 | else |
388 | else |
… | |
… | |
552 | } |
572 | } |
553 | |
573 | |
554 | if (dst > conns.size ()) |
574 | if (dst > conns.size ()) |
555 | slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); |
575 | slog (L_ERR, _("tap packet for unknown node %d received, ignoring."), dst); |
556 | else |
576 | else |
557 | { |
|
|
558 | if (dst) |
|
|
559 | { |
|
|
560 | // unicast |
|
|
561 | if (dst != THISNODE->id) |
|
|
562 | conns[dst - 1]->inject_data_packet (pkt); |
|
|
563 | } |
|
|
564 | else |
|
|
565 | { |
|
|
566 | // broadcast, this is ugly, but due to the security policy |
|
|
567 | // we have to connect to all hosts... |
|
|
568 | for (conns_vector::iterator c = conns.begin (); c != conns.end (); ++c) |
|
|
569 | if ((*c)->conf != THISNODE) |
|
|
570 | (*c)->inject_data_packet (pkt); |
577 | inject_data_packet (pkt, dst); |
571 | } |
|
|
572 | } |
|
|
573 | } |
578 | } |
574 | |
579 | |
575 | delete pkt; |
580 | delete pkt; |
576 | } |
581 | } |
577 | else if (revents & (POLLHUP | POLLERR)) |
582 | else if (revents & (POLLHUP | POLLERR)) |