TUNInterface_ipv6_withroute_root_test.c 2.0 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 "interface/tuntap/TUNMessageType.h"
  17. #include "memory/Allocator.h"
  18. #include "memory/MallocAllocator.h"
  19. #include "util/Assert.h"
  20. #include "util/log/Log.h"
  21. #include "util/log/FileWriterLog.h"
  22. #include "util/events/Timeout.h"
  23. #include "wire/Ethernet.h"
  24. #include "wire/Headers.h"
  25. #include "util/platform/netdev/NetDev.h"
  26. #include "test/RootTest.h"
  27. #include "interface/tuntap/test/TUNTools.h"
  28. int main(int argc, char** argv)
  29. {
  30. struct Allocator* alloc = MallocAllocator_new(1<<20);
  31. struct EventBase* base = EventBase_new(alloc);
  32. struct Log* logger = FileWriterLog_new(stdout, alloc);
  33. struct Sockaddr* addrA = Sockaddr_fromBytes(TUNTools_testIP6AddrA, Sockaddr_AF_INET6, alloc);
  34. struct Sockaddr* addrC = Sockaddr_fromBytes(TUNTools_testIP6AddrC, Sockaddr_AF_INET6, alloc);
  35. char assignedIfName[TUNInterface_IFNAMSIZ];
  36. struct Iface* tun = Er_assert(TUNInterface_new(NULL, assignedIfName, 0, base, logger, alloc));
  37. addrA->flags |= Sockaddr_flags_PREFIX;
  38. addrA->prefix = 126;
  39. Er_assert(NetDev_addAddress(assignedIfName, addrA, logger, alloc));
  40. addrC->flags |= Sockaddr_flags_PREFIX;
  41. addrC->prefix = 125;
  42. Er_assert(NetDev_setRoutes(assignedIfName, ((struct Sockaddr*[]) { addrC }), 1, logger, alloc));
  43. TUNTools_echoTest(addrA, addrC, TUNTools_genericIP6Echo, tun, base, logger, alloc);
  44. Allocator_free(alloc);
  45. return 0;
  46. }