TAPWrapper_root_test.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "memory/MallocAllocator.h"
  18. #include "util/log/Log.h"
  19. #include "util/log/FileWriterLog.h"
  20. #include "util/platform/netdev/NetDev.h"
  21. #include "test/RootTest.h"
  22. #include "interface/tuntap/test/TUNTools.h"
  23. #include "interface/tuntap/TAPWrapper.h"
  24. #include "interface/tuntap/NDPServer.h"
  25. #include "interface/tuntap/ARPServer.h"
  26. int main(int argc, char** argv)
  27. {
  28. struct Allocator* alloc = MallocAllocator_new(1<<20);
  29. struct EventBase* base = EventBase_new(alloc);
  30. struct Log* log = FileWriterLog_new(stdout, alloc);
  31. struct Sockaddr* addrA = Sockaddr_fromBytes(TUNTools_testIP6AddrA, Sockaddr_AF_INET6, alloc);
  32. struct Sockaddr* addrB = Sockaddr_fromBytes(TUNTools_testIP6AddrB, Sockaddr_AF_INET6, alloc);
  33. char assignedIfName[TUNInterface_IFNAMSIZ];
  34. struct Iface* tap = Er_assert(TUNInterface_new(NULL, assignedIfName, 1, base, log, alloc));
  35. struct TAPWrapper* tapWrapper = TAPWrapper_new(tap, log, alloc);
  36. // Now setup the NDP server so the tun will work correctly.
  37. struct NDPServer* ndp = NDPServer_new(&tapWrapper->internal, log, TAPWrapper_LOCAL_MAC, alloc);
  38. struct ARPServer* arp = ARPServer_new(&ndp->internal, log, TAPWrapper_LOCAL_MAC, alloc);
  39. addrA->flags |= Sockaddr_flags_PREFIX;
  40. addrA->prefix = 126;
  41. Er_assert(NetDev_addAddress(assignedIfName, addrA, log, alloc));
  42. TUNTools_echoTest(addrA, addrB, TUNTools_genericIP6Echo, &arp->internal, base, log, alloc);
  43. Allocator_free(alloc);
  44. return 0;
  45. }