TAPWrapper_root_test.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "interface/tuntap/TUNInterface.h"
  16. #include "memory/Allocator.h"
  17. #include "util/log/Log.h"
  18. #include "util/log/FileWriterLog.h"
  19. #include "util/platform/netdev/NetDev.h"
  20. #include "test/RootTest.h"
  21. #include "interface/tuntap/test/TUNTools.h"
  22. #include "interface/tuntap/TAPWrapper.h"
  23. #include "interface/tuntap/NDPServer.h"
  24. #include "interface/tuntap/ARPServer.h"
  25. int main(int argc, char** argv)
  26. {
  27. struct Allocator* alloc = Allocator_new(1<<20);
  28. struct EventBase* base = EventBase_new(alloc);
  29. struct Log* log = FileWriterLog_new(stdout, alloc);
  30. struct Sockaddr* addrA = Sockaddr_fromBytes(TUNTools_testIP6AddrA, Sockaddr_AF_INET6, alloc);
  31. struct Sockaddr* addrB = Sockaddr_fromBytes(TUNTools_testIP6AddrB, Sockaddr_AF_INET6, alloc);
  32. char assignedIfName[TUNInterface_IFNAMSIZ];
  33. struct Iface* tap = Er_assert(TUNInterface_new(NULL, assignedIfName, 1, base, log, alloc));
  34. struct TAPWrapper* tapWrapper = TAPWrapper_new(tap, log, alloc);
  35. // Now setup the NDP server so the tun will work correctly.
  36. struct NDPServer* ndp = NDPServer_new(&tapWrapper->internal, log, TAPWrapper_LOCAL_MAC, alloc);
  37. struct ARPServer* arp = ARPServer_new(&ndp->internal, log, TAPWrapper_LOCAL_MAC, alloc);
  38. addrA->flags |= Sockaddr_flags_PREFIX;
  39. addrA->prefix = 126;
  40. Er_assert(NetDev_addAddress(assignedIfName, addrA, log, alloc));
  41. TUNTools_echoTest(addrA, addrB, TUNTools_genericIP6Echo, &arp->internal, base, log, alloc);
  42. Allocator_free(alloc);
  43. return 0;
  44. }