diff --git a/include/netinet/in.h b/include/netinet/in.h index ba920b870c1..c240634d200 100644 --- a/include/netinet/in.h +++ b/include/netinet/in.h @@ -129,6 +129,8 @@ * the incoming packet */ #define IPV6_RECVPKTINFO (__SO_PROTOCOL + 9) /* It functions just same as * IPV6_PKTINFO for now */ +#define IPV6_TCLASS (__SO_PROTOCOL + 10) /* Access the Traffic Class + * field */ /* Values used with SIOCSIFMCFILTER and SIOCGIFMCFILTER ioctl's */ diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h index 1eb599e02fe..8f72e6ce92c 100644 --- a/include/nuttx/net/ip.h +++ b/include/nuttx/net/ip.h @@ -77,6 +77,26 @@ #define IP_PROTO_UDP 17 #define IP_PROTO_ICMP6 58 +/* Values for the TOS field */ + +#define IPTOS_TOS_MASK 0x1e +#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_RELIABILITY 0x04 +#define IPTOS_MINCOST 0x02 + +#define IPTOS_PREC_MASK 0xe0 +#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 + /* Flag bits in 16-bit flags + fragment offset IPv4 header field */ #define IP_FLAG_RESERVED 0x8000 diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 504a927d556..51c73352db8 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -222,6 +222,11 @@ struct socket_conn_s uint8_t s_flags; /* See _SF_* definitions */ + /* Definitions of IPv4 TOS and IPv6 Traffic Class */ + + uint8_t s_tos; /* IPv4 Type of Service */ +#define s_tclass s_tos /* IPv6 traffic class defination */ + /* Connection-specific content may follow */ }; diff --git a/net/icmp/icmp_reply.c b/net/icmp/icmp_reply.c index ad9aed29638..a19f556497b 100644 --- a/net/icmp/icmp_reply.c +++ b/net/icmp/icmp_reply.c @@ -183,7 +183,7 @@ void icmp_reply(FAR struct net_driver_s *dev, int type, int code) ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_ICMP, &dev->d_ipaddr, (FAR in_addr_t *)ipv4->srcipaddr, - IP_TTL_DEFAULT, NULL); + IP_TTL_DEFAULT, 0, NULL); /* Initialize the ICMP header */ diff --git a/net/icmp/icmp_sendmsg.c b/net/icmp/icmp_sendmsg.c index d6db44b95ce..9a0a846d1f5 100644 --- a/net/icmp/icmp_sendmsg.c +++ b/net/icmp/icmp_sendmsg.c @@ -119,7 +119,7 @@ static void sendto_request(FAR struct net_driver_s *dev, ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_ICMP, &dev->d_ipaddr, &pstate->snd_toaddr, - IP_TTL_DEFAULT, NULL); + IP_TTL_DEFAULT, 0, NULL); /* Copy the ICMP header and payload into place after the IPv4 header */ diff --git a/net/icmpv6/icmpv6_advertise.c b/net/icmpv6/icmpv6_advertise.c index decce33189c..0bc2c4c5f96 100644 --- a/net/icmpv6/icmpv6_advertise.c +++ b/net/icmpv6/icmpv6_advertise.c @@ -77,7 +77,7 @@ void icmpv6_advertise(FAR struct net_driver_s *dev, l3size = SIZEOF_ICMPV6_NEIGHBOR_ADVERTISE_S(lladdrsize); ipv6_build_header(IPv6BUF, l3size, IP_PROTO_ICMP6, - dev->d_ipv6addr, destipaddr, 255); + dev->d_ipv6addr, destipaddr, 255, 0); /* Set up the ICMPv6 Neighbor Advertise response */ diff --git a/net/icmpv6/icmpv6_radvertise.c b/net/icmpv6/icmpv6_radvertise.c index 0281472687d..f6a226ea2a9 100644 --- a/net/icmpv6/icmpv6_radvertise.c +++ b/net/icmpv6/icmpv6_radvertise.c @@ -137,7 +137,7 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev) icmpv6_linkipaddr(dev, srcv6addr); ipv6_build_header(IPv6BUF, l3size, IP_PROTO_ICMP6, - srcv6addr, g_ipv6_allnodes, 255); + srcv6addr, g_ipv6_allnodes, 255, 0); /* Set up the ICMPv6 Router Advertise response */ diff --git a/net/icmpv6/icmpv6_reply.c b/net/icmpv6/icmpv6_reply.c index e67f303c724..4f20d3b2632 100644 --- a/net/icmpv6/icmpv6_reply.c +++ b/net/icmpv6/icmpv6_reply.c @@ -171,7 +171,7 @@ void icmpv6_reply(FAR struct net_driver_s *dev, int type, int code, int data) dev->d_len = ipicmplen + datalen; ipv6_build_header(IPv6BUF, dev->d_len - IPv6_HDRLEN, IP_PROTO_ICMP6, - dev->d_ipv6addr, ipv6->srcipaddr, 255); + dev->d_ipv6addr, ipv6->srcipaddr, 255, 0); /* Initialize the ICMPv6 header */ diff --git a/net/icmpv6/icmpv6_rsolicit.c b/net/icmpv6/icmpv6_rsolicit.c index 117ebbd02e4..efce18ef200 100644 --- a/net/icmpv6/icmpv6_rsolicit.c +++ b/net/icmpv6/icmpv6_rsolicit.c @@ -76,7 +76,7 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev) l3size = SIZEOF_ICMPV6_ROUTER_SOLICIT_S(lladdrsize); ipv6_build_header(IPv6BUF, l3size, IP_PROTO_ICMP6, - dev->d_ipv6addr, g_ipv6_allrouters, 255); + dev->d_ipv6addr, g_ipv6_allrouters, 255, 0); /* Set up the ICMPv6 Router Solicitation message */ diff --git a/net/icmpv6/icmpv6_sendmsg.c b/net/icmpv6/icmpv6_sendmsg.c index 1fdc6d2ebb5..43ac77781b6 100644 --- a/net/icmpv6/icmpv6_sendmsg.c +++ b/net/icmpv6/icmpv6_sendmsg.c @@ -115,7 +115,7 @@ static void sendto_request(FAR struct net_driver_s *dev, dev->d_len = IPv6_HDRLEN + pstate->snd_buflen; ipv6_build_header(IPv6BUF, pstate->snd_buflen, IP_PROTO_ICMP6, - dev->d_ipv6addr, pstate->snd_toaddr.s6_addr16, 255); + dev->d_ipv6addr, pstate->snd_toaddr.s6_addr16, 255, 0); /* Copy the ICMPv6 request and payload into place after the IPv6 header */ diff --git a/net/icmpv6/icmpv6_solicit.c b/net/icmpv6/icmpv6_solicit.c index 3fd2b7a4632..07421c9cba1 100644 --- a/net/icmpv6/icmpv6_solicit.c +++ b/net/icmpv6/icmpv6_solicit.c @@ -95,7 +95,7 @@ void icmpv6_solicit(FAR struct net_driver_s *dev, dstaddr[7] = ipaddr[7]; ipv6_build_header(IPv6BUF, l3size, IP_PROTO_ICMP6, - dev->d_ipv6addr, dstaddr, 255); + dev->d_ipv6addr, dstaddr, 255, 0); /* Set up the ICMPv6 Neighbor Solicitation message */ diff --git a/net/igmp/igmp_send.c b/net/igmp/igmp_send.c index d60a49a21fc..9f770909c20 100644 --- a/net/igmp/igmp_send.c +++ b/net/igmp/igmp_send.c @@ -142,7 +142,7 @@ void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group, opt.len = sizeof(uint32_t); ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_IGMP, - &dev->d_ipaddr, destipaddr, IGMP_TTL, &opt); + &dev->d_ipaddr, destipaddr, IGMP_TTL, 0, &opt); /* Set up the IGMP message */ diff --git a/net/inet/Make.defs b/net/inet/Make.defs index 498d15e679e..5f49ae2bcc4 100644 --- a/net/inet/Make.defs +++ b/net/inet/Make.defs @@ -35,7 +35,7 @@ SOCK_CSRCS += ipv4_setsockopt.c ipv4_getsockopt.c ipv4_getsockname.c ipv4_getpee endif ifeq ($(CONFIG_NET_IPv6),y) -SOCK_CSRCS += ipv6_setsockopt.c ipv6_getsockname.c ipv6_getpeername.c ipv6_build_header.c +SOCK_CSRCS += ipv6_setsockopt.c ipv6_getsockname.c ipv6_getpeername.c ipv6_build_header.c ipv6_getsockopt.c endif # Include inet build support diff --git a/net/inet/inet.h b/net/inet/inet.h index 6dc2fdf4a6e..3c685a84757 100644 --- a/net/inet/inet.h +++ b/net/inet/inet.h @@ -192,6 +192,10 @@ int ipv6_setsockopt(FAR struct socket *psock, int option, int ipv4_getsockopt(FAR struct socket *psock, int option, FAR void *value, FAR socklen_t *value_len); #endif +#ifdef CONFIG_NET_IPv6 +int ipv6_getsockopt(FAR struct socket *psock, int option, + FAR void *value, FAR socklen_t *value_len); +#endif /**************************************************************************** * Name: ipv4_getsockname and ipv6_sockname @@ -300,6 +304,7 @@ int inet_txdrain(FAR struct socket *psock, unsigned int timeout); * src_ip Source IPv4 address * dst_ip Destination IPv4 address * ttl Time to live(IPv4) + * tos Type of Service(IPv4) * opt IPv4 options * * Returned Value: @@ -311,7 +316,7 @@ int inet_txdrain(FAR struct socket *psock, unsigned int timeout); uint16_t ipv4_build_header(FAR struct ipv4_hdr_s *ipv4, uint16_t total_len, uint16_t prot, FAR const in_addr_t *src_ip, FAR const in_addr_t *dst_ip, uint8_t ttl, - FAR struct ipv4_opt_s *opt); + uint8_t tos, FAR struct ipv4_opt_s *opt); #endif /**************************************************************************** @@ -327,6 +332,7 @@ uint16_t ipv4_build_header(FAR struct ipv4_hdr_s *ipv4, uint16_t total_len, * src_ip Source IPv6 address * dst_ip Destination IPv6 address * ttl hop limit(IPv6) + * tclass traffic class(IPv6) * * Returned Value: * length of IPv6 header @@ -336,7 +342,8 @@ uint16_t ipv4_build_header(FAR struct ipv4_hdr_s *ipv4, uint16_t total_len, #ifdef CONFIG_NET_IPv6 uint16_t ipv6_build_header(FAR struct ipv6_hdr_s *ipv6, uint16_t payload_len, uint16_t prot, const net_ipv6addr_t src_ip, - const net_ipv6addr_t dst_ip, uint8_t ttl); + const net_ipv6addr_t dst_ip, uint8_t ttl, + uint8_t tclass); #endif #undef EXTERN diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c index 7c2b30cfcbd..8a71c93f710 100644 --- a/net/inet/inet_sockif.c +++ b/net/inet/inet_sockif.c @@ -750,10 +750,15 @@ static int inet_getsockopt(FAR struct socket *psock, int level, int option, #endif #ifdef CONFIG_NET_IPv4 - case IPPROTO_IP: + case IPPROTO_IP:/* IPv4 protocol socket options (see include/netinet/in.h) */ return ipv4_getsockopt(psock, option, value, value_len); #endif +#ifdef CONFIG_NET_IPv6 + case IPPROTO_IPV6:/* IPv6 protocol socket options (see include/netinet/in.h) */ + return ipv6_getsockopt(psock, option, value, value_len); +#endif + default: return -ENOPROTOOPT; } @@ -1018,12 +1023,12 @@ static int inet_setsockopt(FAR struct socket *psock, int level, int option, #endif #ifdef CONFIG_NET_IPv4 - case IPPROTO_IP:/* TCP protocol socket options (see include/netinet/in.h) */ + case IPPROTO_IP:/* IPv4 protocol socket options (see include/netinet/in.h) */ return ipv4_setsockopt(psock, option, value, value_len); #endif #ifdef CONFIG_NET_IPv6 - case IPPROTO_IPV6:/* TCP protocol socket options (see include/netinet/in.h) */ + case IPPROTO_IPV6:/* IPv6 protocol socket options (see include/netinet/in.h) */ return ipv6_setsockopt(psock, option, value, value_len); #endif default: diff --git a/net/inet/ipv4_build_header.c b/net/inet/ipv4_build_header.c index 61b1cd979a3..001cba22bff 100644 --- a/net/inet/ipv4_build_header.c +++ b/net/inet/ipv4_build_header.c @@ -67,12 +67,12 @@ static uint16_t g_ipid; uint16_t ipv4_build_header(FAR struct ipv4_hdr_s *ipv4, uint16_t total_len, uint16_t prot, FAR const in_addr_t *src_ip, FAR const in_addr_t *dst_ip, uint8_t ttl, - FAR struct ipv4_opt_s *opt) + uint8_t tos, FAR struct ipv4_opt_s *opt) { /* Initialize the IP header. */ ipv4->vhl = 0x45; /* orginal initial value like this */ - ipv4->tos = 0; + ipv4->tos = tos; ipv4->len[0] = (total_len >> 8); ipv4->len[1] = (total_len & 0xff); ++g_ipid; diff --git a/net/inet/ipv4_getsockopt.c b/net/inet/ipv4_getsockopt.c index 36ef1f07087..97bb5d83950 100644 --- a/net/inet/ipv4_getsockopt.c +++ b/net/inet/ipv4_getsockopt.c @@ -84,6 +84,17 @@ int ipv4_getsockopt(FAR struct socket *psock, int option, break; #endif + case IP_TOS: + { + FAR struct socket_conn_s *conn = + (FAR struct socket_conn_s *)psock->s_conn; + + *(FAR uint8_t *)value = conn->s_tos; + *value_len = 1; + ret = OK; + } + break; + default: nerr("ERROR: Unrecognized IPv4 option: %d\n", option); ret = -ENOPROTOOPT; diff --git a/net/inet/ipv4_setsockopt.c b/net/inet/ipv4_setsockopt.c index 2e97fbec5a8..55cda380f2f 100644 --- a/net/inet/ipv4_setsockopt.c +++ b/net/inet/ipv4_setsockopt.c @@ -261,6 +261,26 @@ int ipv4_setsockopt(FAR struct socket *psock, int option, } break; #endif + case IP_TOS: + { + FAR struct socket_conn_s *conn = + (FAR struct socket_conn_s *)psock->s_conn; + int tos; + + tos = (value_len >= sizeof(int)) ? + *(FAR int *)value : (int)*(FAR unsigned char *)value; + if (tos < 0 || tos > 0xff) + { + nerr("ERROR: invalid tos:%d\n", tos); + ret = -EINVAL; + } + else + { + conn->s_tos = tos; + ret = OK; + } + } + break; #ifdef CONFIG_NET_IPTABLES case IPT_SO_SET_REPLACE: diff --git a/net/inet/ipv6_build_header.c b/net/inet/ipv6_build_header.c index bf049dc30e9..aa96e0b896a 100644 --- a/net/inet/ipv6_build_header.c +++ b/net/inet/ipv6_build_header.c @@ -48,6 +48,7 @@ * src_ip Source IPv6 address * dst_ip Destination IPv6 address * ttl Time to live(IPv4) hop limit(IPv6) + * tclass traffic class(IPv6) * * Returned Value: * length of IPv6 header @@ -56,12 +57,13 @@ uint16_t ipv6_build_header(FAR struct ipv6_hdr_s *ipv6, uint16_t payload_len, uint16_t prot, const net_ipv6addr_t src_ip, - const net_ipv6addr_t dst_ip, uint8_t ttl) + const net_ipv6addr_t dst_ip, uint8_t ttl, + uint8_t tclass) { /* Set up the IPv6 header */ ipv6->vtc = 0x60; /* Version/traffic class (MS) */ - ipv6->tcf = 0; /* Traffic class(LS)/Flow label(MS) */ + ipv6->tcf = tclass; /* Traffic class(LS)/Flow label(MS) */ ipv6->flow = 0; /* Flow label (LS) */ ipv6->len[0] = (payload_len >> 8); /* Length excludes the IPv6 header */ ipv6->len[1] = (payload_len & 0xff); diff --git a/net/inet/ipv6_getsockopt.c b/net/inet/ipv6_getsockopt.c new file mode 100644 index 00000000000..610bae1d428 --- /dev/null +++ b/net/inet/ipv6_getsockopt.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * net/inet/ipv6_getsockopt.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +#include + +#include + +#include "mld/mld.h" +#include "inet/inet.h" +#include "udp/udp.h" + +#ifdef CONFIG_NET_IPv6 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: ipv6_getsockopt + * + * Description: + * ipv6_getsockopt() sets the IPv6-protocol socket option specified by the + * 'option' argument to the value pointed to by the 'value' argument for + * the socket specified by the 'psock' argument. + * + * See for the a complete list of values of IPv6 protocol + * socket options. + * + * Input Parameters: + * psock Socket structure of socket to operate on + * option identifies the option to set + * value Points to the argument value + * value_len The length of the argument value + * + * Returned Value: + * Returns zero (OK) on success. On failure, it returns a negated errno + * value to indicate the nature of the error. + * + ****************************************************************************/ + +int ipv6_getsockopt(FAR struct socket *psock, int option, + FAR void *value, FAR socklen_t *value_len) +{ + int ret; + + ninfo("option: %d\n", option); + + net_lock(); + switch (option) + { + case IPV6_TCLASS: + { + FAR struct socket_conn_s *conn = + (FAR struct socket_conn_s *)psock->s_conn; + + *(FAR uint8_t *)value = conn->s_tclass; + *value_len = 1; + ret = OK; + } + break; + + default: + nerr("ERROR: Unrecognized IPv6 option: %d\n", option); + ret = -ENOPROTOOPT; + break; + } + + net_unlock(); + return ret; +} + +#endif /* CONFIG_NET_IPv6 */ diff --git a/net/inet/ipv6_setsockopt.c b/net/inet/ipv6_setsockopt.c index 5f581a6ba83..56c39134419 100644 --- a/net/inet/ipv6_setsockopt.c +++ b/net/inet/ipv6_setsockopt.c @@ -69,16 +69,17 @@ int ipv6_setsockopt(FAR struct socket *psock, int option, FAR const void *value, socklen_t value_len) { -#ifdef CONFIG_NET_MLD int ret; ninfo("option: %d\n", option); - /* Handle MLD-related socket options */ - net_lock(); switch (option) { +#ifdef CONFIG_NET_MLD + + /* Handle MLD-related socket options */ + case IPV6_JOIN_GROUP: /* Join a multicast group */ { FAR const struct ipv6_mreq *mrec ; @@ -111,6 +112,21 @@ int ipv6_setsockopt(FAR struct socket *psock, int option, } break; + /* The following IPv6 socket options are defined, but not implemented */ + + case IPV6_MULTICAST_HOPS: /* Multicast hop limit */ + case IPV6_MULTICAST_IF: /* Interface to use for outgoing multicast + * packets */ + case IPV6_MULTICAST_LOOP: /* Multicast packets are delivered back to + * the local application */ +#endif + case IPV6_UNICAST_HOPS: /* Unicast hop limit */ + case IPV6_V6ONLY: /* Restrict AF_INET6 socket to IPv6 + * communications only */ + nwarn("WARNING: Unimplemented IPv6 option: %d\n", option); + ret = -ENOSYS; + break; + #if defined(CONFIG_NET_UDP) && !defined(CONFIG_NET_UDP_NO_STACK) case IPV6_PKTINFO: case IPV6_RECVPKTINFO: @@ -142,18 +158,41 @@ int ipv6_setsockopt(FAR struct socket *psock, int option, break; #endif - /* The following IPv6 socket options are defined, but not implemented */ + case IPV6_TCLASS: + { + FAR struct socket_conn_s *conn = + (FAR struct socket_conn_s *)psock->s_conn; + int tclass; - case IPV6_MULTICAST_HOPS: /* Multicast hop limit */ - case IPV6_MULTICAST_IF: /* Interface to use for outgoing multicast - * packets */ - case IPV6_MULTICAST_LOOP: /* Multicast packets are delivered back to - * the local application */ - case IPV6_UNICAST_HOPS: /* Unicast hop limit */ - case IPV6_V6ONLY: /* Restrict AF_INET6 socket to IPv6 - * communications only */ - nwarn("WARNING: Unimplemented IPv6 option: %d\n", option); - ret = -ENOSYS; + tclass = (value_len >= sizeof(int)) ? + *(FAR int *)value : (int)*(FAR unsigned char *)value; + + /* According to RFC3542 6.5, the interpretation of the integer + * traffic class value is: + * x < -1: return an error of EINVAL + * x == -1: use kernel default + * 0 <= x <= 255: use x + * x >= 256: return an error of EINVAL + */ + + if (tclass < -1 || tclass > 0xff) + { + nerr("ERROR: invalid tclass:%d\n", tclass); + ret = -EINVAL; + } + else + { + if (tclass == -1) + { + /* Default value is 0 */ + + tclass = 0; + } + + conn->s_tclass = tclass; + ret = OK; + } + } break; default: @@ -164,9 +203,6 @@ int ipv6_setsockopt(FAR struct socket *psock, int option, net_unlock(); return ret; -#else - return -ENOPROTOOPT; -#endif } #endif /* CONFIG_NET_IPv6 */ diff --git a/net/mld/mld_send.c b/net/mld/mld_send.c index 8364808f7c6..09d676f0750 100644 --- a/net/mld/mld_send.c +++ b/net/mld/mld_send.c @@ -210,7 +210,7 @@ void mld_send(FAR struct net_driver_s *dev, FAR struct mld_group_s *group, destipaddr[4], destipaddr[5], destipaddr[6], destipaddr[7]); ipv6_build_header(IPv6BUF, dev->d_sndlen, NEXT_HOPBYBOT_EH, - dev->d_ipv6addr, destipaddr, MLD_TTL); + dev->d_ipv6addr, destipaddr, MLD_TTL, 0); /* Add the router alert IP header option. * diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 999b001ea2e..846fa663c20 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -1108,6 +1108,7 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile, * * Input Parameters: * dev - The device driver structure to use in the send operation + * conn - The TCP connection structure holding connection information * * Returned Value: * None @@ -1117,7 +1118,7 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile, * ****************************************************************************/ -void tcp_reset(FAR struct net_driver_s *dev); +void tcp_reset(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn); /**************************************************************************** * Name: tcp_rx_mss diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index 001dea54d66..b398cd74f6a 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -829,7 +829,7 @@ reset: #ifdef CONFIG_NET_STATISTICS g_netstats.tcp.synrst++; #endif - tcp_reset(dev); + tcp_reset(dev, conn); return; found: @@ -1283,7 +1283,7 @@ found: goto drop; } - tcp_reset(dev); + tcp_reset(dev, conn); return; case TCP_ESTABLISHED: diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 0c57c32e8e5..ae231b161ef 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -182,7 +182,7 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev, ninfo("do IPv6 IP header build!\n"); ipv6_build_header(IPv6BUF, dev->d_len - IPv6_HDRLEN, IP_PROTO_TCP, dev->d_ipv6addr, conn->u.ipv6.raddr, - IP_TTL_DEFAULT); + IP_TTL_DEFAULT, conn->sconn.s_tclass); /* Calculate TCP checksum. */ @@ -202,7 +202,7 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev, ninfo("do IPv4 IP header build!\n"); ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_TCP, &dev->d_ipaddr, &conn->u.ipv4.raddr, - IP_TTL_DEFAULT, NULL); + IP_TTL_DEFAULT, conn->sconn.s_tos, NULL); /* Calculate TCP checksum. */ @@ -360,7 +360,7 @@ void tcp_send(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, * ****************************************************************************/ -void tcp_reset(FAR struct net_driver_s *dev) +void tcp_reset(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn) { FAR struct tcp_hdr_s *tcp; uint32_t ackno; @@ -477,7 +477,7 @@ void tcp_reset(FAR struct net_driver_s *dev) ipv6_build_header(ipv6, dev->d_len - IPv6_HDRLEN, IP_PROTO_TCP, dev->d_ipv6addr, ipv6->srcipaddr, - IP_TTL_DEFAULT); + IP_TTL_DEFAULT, conn->sconn.s_tclass); tcp->tcpchksum = 0; tcp->tcpchksum = ~tcp_ipv6_chksum(dev); @@ -493,7 +493,7 @@ void tcp_reset(FAR struct net_driver_s *dev) ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_TCP, &dev->d_ipaddr, (FAR in_addr_t *)ipv4->srcipaddr, - IP_TTL_DEFAULT, NULL); + IP_TTL_DEFAULT, conn->sconn.s_tos, NULL); tcp->tcpchksum = 0; tcp->tcpchksum = ~tcp_ipv4_chksum(dev); diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index 7b85e0a1438..fa01e04849c 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -124,7 +124,7 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) ipv4_build_header(IPv4BUF, dev->d_len, IP_PROTO_UDP, &dev->d_ipaddr, &raddr, IP_TTL_DEFAULT, - NULL); + conn->sconn.s_tos, NULL); #ifdef CONFIG_NET_STATISTICS g_netstats.ipv4.sent++; @@ -149,7 +149,8 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) dev->d_len = dev->d_sndlen + UDP_HDRLEN; ipv6_build_header(IPv6BUF, dev->d_len, IP_PROTO_UDP, - dev->d_ipv6addr, conn->u.ipv6.raddr, conn->ttl); + dev->d_ipv6addr, conn->u.ipv6.raddr, conn->ttl, + conn->sconn.s_tclass); /* The total length to send is the size of the application data * plus the IPv6 and UDP headers (and, eventually, the link layer