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

IP_ADDRESS_PREFIX size seems wrong #405

Closed
iquiw opened this issue Jun 2, 2023 · 0 comments
Closed

IP_ADDRESS_PREFIX size seems wrong #405

iquiw opened this issue Jun 2, 2023 · 0 comments

Comments

@iquiw
Copy link

iquiw commented Jun 2, 2023

Describe the bug and how to reproduce

Run the following program.
(Please change InterfaceIndex to proper value below)

        static void Main(string[] args)
        {
            InitializeIpForwardEntry(out var route);

            route.InterfaceIndex = 6;

            route.DestinationPrefix.Prefix.Ipv6.sin6_family = Ws2_32.ADDRESS_FAMILY.AF_INET6;
            route.DestinationPrefix.Prefix.Ipv6.sin6_addr = new Ws2_32.IN6_ADDR(IPAddress.Parse("2404:6800:4004:801::2003").GetAddressBytes());
            route.DestinationPrefix.PrefixLength = 128;

            route.NextHop.Ipv6.sin6_family = Ws2_32.ADDRESS_FAMILY.AF_INET6;
            route.NextHop.Ipv6.sin6_addr = new Ws2_32.IN6_ADDR(IPAddress.Parse("fe80::1").GetAddressBytes());
            route.SitePrefixLength = 128;
            route.Metric = 0;
            route.Protocol = IpHlpApi.MIB_IPFORWARD_PROTO.MIB_IPPROTO_NETMGMT;
            route.Loopback = false;
            route.AutoconfigureAddress = false;
            route.Publish = false;
            route.Immortal = false;

            CreateIpForwardEntry2(ref route);
        }

Then NextHop and RouteMetric of the route are wrong values.

> Get-NetRoute -DestinationPrefix 2404:6800:4004:801::2003/128

ifIndex DestinationPrefix                              NextHop                                  RouteMetric ifMetric PolicyStore
------- -----------------                              -------                                  ----------- -------- -----------
6       2404:6800:4004:801::2003/128                   ::                                                 3 45       ActiveStore

What code is involved

I suppose structure size (= 30) of IP_ADDRESS_PREFIX is wrong.

[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct IP_ADDRESS_PREFIX : IEquatable<IP_ADDRESS_PREFIX>

The value 32 seems correct according to C++ sizeof() output.

		[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 32)]
		public struct IP_ADDRESS_PREFIX : IEquatable<IP_ADDRESS_PREFIX>

Expected behavior

With Size = 32, NextHop and Mertic will be the correct values.

> Get-NetRoute -DestinationPrefix 2404:6800:4004:801::2003/128

ifIndex DestinationPrefix                              NextHop                                  RouteMetric ifMetric PolicyStore
------- -----------------                              -------                                  ----------- -------- -----------
6       2404:6800:4004:801::2003/128                   fe80::1                                            0 45       ActiveStore
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

No branches or pull requests

2 participants