Using IPv6 Addresses

Discussion to talk about software related topics only.
SeeCwriter
Posts: 372
Joined: Mon May 12, 2008 10:55 am

Using IPv6 Addresses

Post by SeeCwriter » Wed Dec 18, 2019 7:24 am

I converted one of my applications to use IPADDR for IP addresses ( was using IPADDR4), and I expected to see IPv6 addresses on the wire. But I don't. I only see IPv4 addresses.

Code: Select all

IPADDR BroadcastIP;
WORD BroadcastPort;
IPADDR ip6_multicast;

void InitMulticast()
{
   if ( !ip6_multicast.IsMultiCast() )
       ip6_multicast = IPADDR::AsciiToIp6( "224.0.100.100" );
   if ( use_multicast )
   {
       BroadcastIP = ip6_multicast;
       BroadcastPort = MULTICAST_PORT;
   }
   else
   {
       BroadcastIP.SetFromIP4( IPADDR4::GlobalBroadCast() );
       BroadcastPort = BROADCAST_PORT;
   }
}

void UdpSend( char *buf, int len, IPADDR &ip_addr, WORD port )
{
    IPADDR ip = ( ip_addr.IsNull() ) ? BroadcastIP : ip_addr;
    
    UDPPacket pkt;
    pkt.SetSourcePort(port);
    pkt.SetDestinationPort(port);
    pkt.AddData((PBYTE)buf, (WORD) len);
    pkt.Send(ip);
}
The above code works, switching between sending multicast packets and broadcast packets. But I thought the multicast packets would use IPv6 formatted IP addresses. But it just uses IPv4 packets. What has to happen for IPv6 packets to be used?

User avatar
pbreed
Posts: 842
Joined: Thu Apr 24, 2008 3:58 pm

Re: Using IPv6 Addresses

Post by pbreed » Wed Dec 18, 2019 9:54 am

224.0.100.100

Is an IPV4 address...

nd IPV6 multicast address is anythign starting with FF02.
"ff02::100:100 would be and ipv6 multicast address....

User avatar
pbreed
Posts: 842
Joined: Thu Apr 24, 2008 3:58 pm

Re: Using IPv6 Addresses

Post by pbreed » Wed Dec 18, 2019 9:56 am

224.0.100.100

Is an IPV4 address...

nd IPV6 multicast address is anything starting with FF02.
?The tools want to turn my ipv6 ADDRESS INTO UNICODE...
Remove all the spaces.

" f f 0 2 : : 1 0 : 1 0 " would be and ipv6 multicast address....

SeeCwriter
Posts: 372
Joined: Mon May 12, 2008 10:55 am

Re: Using IPv6 Addresses

Post by SeeCwriter » Wed Dec 18, 2019 10:14 am

I understand that the IP address is an IPv4 address. But I was under the impression that an IPv6 address would be created with an embedded IPv4 address per rfc2373, paragraph 2.5.4. But you're right that I didn't get the prefix right.

Code: Select all

| 80 bits                          | 16  |      32 bits        |
+----------------------------------+----------------------+
|0000..........................0000|0000| IPv4 address  |
+----------------------------------+----+-----------------+

User avatar
pbreed
Posts: 842
Joined: Thu Apr 24, 2008 3:58 pm

Re: Using IPv6 Addresses

Post by pbreed » Wed Dec 18, 2019 2:17 pm

Not how the system is setup...

We store IPV4 addresses inside an IPV6 address so you can use one type to store both address types.
The netburner code then does the right thing...

Even though you are using an IPV6 capable class to move IPv4 addresses around, the traffic on the wire will be ipv4.
This way your code, just does not care if its ipv6 or ipv4... can be treated identically everywhere...

User avatar
pbreed
Posts: 842
Joined: Thu Apr 24, 2008 3:58 pm

Re: Using IPv6 Addresses

Post by pbreed » Wed Dec 18, 2019 2:22 pm

The ffff:xxx.xxx.xxx.xxx IPv4 Map addresses are not supposed to be on the wire in ipv6 formatted packets, they are intended to be used as we are using them so that there is only one interface to the network stack, that is v4/v6 agnostic.

SeeCwriter
Posts: 372
Joined: Mon May 12, 2008 10:55 am

Re: Using IPv6 Addresses

Post by SeeCwriter » Thu Dec 19, 2019 7:59 am

Just when I think I'm starting to understand IPv6 I get a curve ball.

I don't understand. Why are numerous rfc's defining how to embed IPv4 addresses in IPv6 addressing if they are not supposed to be on the wire?

Since each device has a link-local address, what happens if another device sends UDP packet to a NB device's link-local address from its link-local address? What addresses are returned with UDPPacket::GetDestinationAddress() and UDPPacket::GetSourceAddress()?

SeeCwriter
Posts: 372
Joined: Mon May 12, 2008 10:55 am

Re: Using IPv6 Addresses

Post by SeeCwriter » Thu Dec 19, 2019 10:04 am

I added a prefix to my IPv6 multicast address, and now the full IPv6 address is put on the wire.

Code: Select all

ip6_multicast = IPADDR::AsciiToIp6( "ff12::ffff:224.0.100.100" );

User avatar
pbreed
Posts: 842
Joined: Thu Apr 24, 2008 3:58 pm

Re: Using IPv6 Addresses

Post by pbreed » Thu Dec 19, 2019 2:27 pm

?What addresses are returned with UDPPacket::GetDestinationAddress() and UDPPacket::GetSourceAddress()?

If it was an IPV6 packet it will return the IPV6 LL addresses.
It will print as an IPv6 address.

If it was an IPV4 packet it will return an address that contains the IPV4 address and the member function IIsEmbeddedIPV4()
will return true, and any attempt to print out the address will appear as an IPV4 address, because that is what is is...

If you go to the page on reserved IP Addresses...
https://en.wikipedia.org/wiki/Reserved_ ... esses#IPv6

There are two prefixes dealing with IPV4 transitions

IPV4 Mapped addresses, and IPV4 translated addresses.

IPV4 mapped addresses are a means to store an IPV4 address inside an IPV6 address object.
IPV4 mapped addresses are never meant to be seen on the wire. They are a means to say here is an IP address your supposed to treat any operations on this like its an IPv4 address. When you do IPv4 addresses on the netburner in IPV6 mode they are stored in this format.
This dual mode stack is then smart enough to "Do the right thing" talking to an IPV4 device, send IPv4 packets, talking to an IPV6 deivce using an IPV6 address send IPV6 packets.


This is different than the IPv4 translated addresses, the translated addresses are meant to enable an IPV6 host that HAS NO ipv4 stack to talk to an IPV4 device by translating the address, and expecting the router to translate the address....and packet format.


Short verison:
The NetBurner in IPV6 mode will operate identically to the Netburner in ipv4 mode
IE if all your addresses are Ipv4 then it will send recieve IPv4 packets.
with several very minor differences.

1)Internal storage of IPADDR is now 128 bits, so if you have binary formatted structures of your own design that contain IPaddresses, you need to
change their declaration to be IPADDR4 if you want them backward compatible.

2)The Netburner will do all the normal IPV6 link discovery and prefix discovery stuff in the background.

3)If someone sends you IPV6 formatted packets, Udp, Tcp etc... then the printout of the associated addresses may be larger than you expect.

4)You can choose to send IPV6 TCP and UDP to devices that have IPV6 addresses. Whether or not the address is gotten from DNS or some form of text input it will just do the right thing.

SeeCwriter
Posts: 372
Joined: Mon May 12, 2008 10:55 am

Re: Using IPv6 Addresses

Post by SeeCwriter » Fri Dec 20, 2019 9:16 am

Thank you for the explanation.

Last year I enabled dual-stack mode, and because I have structures that have
IPADDR elements, I implemented your point 1 to prevent corruption.
Now I'm trying to take the next step and actually use IPADDR. Most of it works,
but there are a couple of issues I have questions on.

First, currently the firmware is setup to enable and disable DHCP. If enabled,
the DHCP acquired address is used. If not, a static IP is used. I don't think
this is still valid in a dual-stack configuration, since all the functions are
using IPADDR4 arguments and return values and I want to pass IPADDR parameters
whether they hold IPv4 or IPv6 values.

Code: Select all

  if ( SS->use_dhcp ) 
    {
    InitializeStack();
    EnableDHCP(true); // allow stopping/restarting dhcp.(uses NB example)
    }
  else InitializeStack( SS->ip_address, SS->ip_mask, SS->ip_gateway, SS->ip_dns );

void EnableDHCP( bool enable, int wait_seconds )
{
  static int ethernet = GetFirstInterface();
  static DhcpObject *dhcp_client = new DhcpObject( ethernet );

  if ( enable ) dhcp_client->StartDHCP();
  else          dhcp_client->StopDHCP();

  if ( enable && wait_seconds )
    {
    OSSemPend( &dhcp_client->NotifySem, (WORD) (wait_seconds * TICKS_PER_SECOND) );     //lint !e534
    }
}
[/code
I believe that with IPv6, a device can have multiple IP addresses. Therefore, 
is this initialization still necessary?

Second, when a user either sets a static address or switches from DHCP to
static IP mode, I would get a pointer to the InterfaceBlock and set the network
parameters (i.e., IP, Netmask, Gateway, or DNS) to make them active immediately.
Am I correct that the Add functions in the IPv6Interface structure do the 
equivalent for IPv6? And does it matter if the parameter is an IPv4 format?


Third, how do I handle the netmask? If the module is assigned an IPv6 static 
address, what do I do about a netmask? I don't find a function such as 
AddNetmask to set a netmask or prefix length independently of setting a static
IP address. To change the netmask do I need to remove the static address then
add it back with the new prefix length?

Post Reply