Bug 228068 - tclass is not used when sending to IPv4 mapped address via IPv6 socket
Summary: tclass is not used when sending to IPv4 mapped address via IPv6 socket
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 11.1-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-net (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-08 13:40 UTC by Paul Reynolds
Modified: 2018-05-22 14:57 UTC (History)
0 users

See Also:


Attachments
Patch to set tos interval value when tclass is set (1.44 KB, patch)
2018-05-22 14:57 UTC, Paul Reynolds
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Reynolds 2018-05-08 13:40:57 UTC
When sending a udp packet from an IPv6 socket to an IPv4 mapped address, I would expect the setting for IPV6_TCLASS to be used in the TOS IP header field. It does not appear to be. A similar mapping for TTL should be present, though I did not check for that.

Can be seen with a simple c program and wireshark:

#include <stdio.h>
#include <string.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int main() {

     int s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
     if (s < 0) {
         perror("socket");
         return -1;
     }

     int value = (40 << 2) & 0xFC;
     int ret = setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &value, sizeof(value));
     if (ret < 0) {
         perror("setsockopt");
         return -2;
     }

     struct addrinfo hints;
     memset(&hints, 0, sizeof(hints));
     struct addrinfo *res = NULL;
     ret = getaddrinfo("::ffff:10.10.10.10", "1234", &hints, &res);
     if (ret != 0) {
         perror("getaddrinfo");
         return -3;
     }

     const char *msg = "hello world";
     ssize_t n = sendto(s, msg, strlen(msg), 0, res->ai_addr, res->ai_addrlen);
     if (n < 0) {
         freeaddrinfo(res);
         perror("sendto");
         return -4;
     }

     freeaddrinfo(res);
     return 0;
}
Comment 1 Paul Reynolds 2018-05-22 14:57:01 UTC
Created attachment 193614 [details]
Patch to set tos interval value when tclass is set

This patch seems to fix the issue for me. I'm not sure if this is the right way to fix this though.