TUNInterface_ipv6_withroute_root_test.c 2.0 KB

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