Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use metric and IPv6 dst prefix length when finding best route for ipv6 dst #639

Merged
merged 4 commits into from
Jan 19, 2021

Conversation

ArnoStiefvater
Copy link
Member

What:

Previously the first matching route for a given destination was taken for getting the interface to use.
Now the metric and the length of the IPv6 "mask" is also taken into account for determining the best matching route.

Already fixed for ipv4 in #610

Why:

Sometimes a less optimal route was chosen which resulted in getting the wrong interface.

How:

Add different routes with something like sudo ip -6 addr add 2001:db8:0:f104::/64 dev enp0s3 and test via the following code which can be put in the pcap_tests.c file. This code was not committed into the tests because its working is dependent on the local /proc/net/ipv6_route file.

Ensure (pcap, v6_routethrough)
{
  struct in6_addr dest;
  struct in6_addr dst2;
  struct in6_addr src;
  char *interface;
  char addr1[INET6_ADDRSTRLEN];

  // example dst addr. You need to add your own ipv6 here depending on what you want to test.
  const uint8_t one1_in[16] = {0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0xF1, 0x04,
                               0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
  memcpy (dest.s6_addr, one1_in, sizeof one1_in);
  // example dst2 addr.  You need to add your own ipv6 here depending on what you want to test.
  const uint8_t two1_in[16] = {0x20, 0x01, 0x0D, 0xB8, 0x00, 0x00, 0xF1, 0x04,
                               0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01};
  memcpy (dst2.s6_addr, two1_in, sizeof two1_in);

  interface = v6_routethrough (&dest, &src);
  g_warning ("Interface: %s", interface);
  g_warning ("src: %s", inet_ntop (AF_INET6, &src, addr1, sizeof (addr1)));

  interface = v6_routethrough (&dst2, &src);
  g_warning ("Interface: %s", interface);
  g_warning ("src: %s", inet_ntop (AF_INET6, &src, addr1, sizeof (addr1)));

  assert_that (0, is_true); // debug info will be printed. Use correct asserts as needed instead.
}

Checklist:

This function is used for v6_routethrough() only.
routethrough() uses its own, similar logic for
getting the ipv4 routes.
Consider metric and IPv6 prefix length when finding
best matching route.
@ArnoStiefvater ArnoStiefvater merged commit 023042f into greenbone:openvas-20.08 Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants