Netdev List
 help / color / mirror / Atom feed
From: Gerrit Renker <gerrit@erg.abdn.ac.uk>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Gerrit Renker <gerrit@erg.abdn.ac.uk>
Subject: [PATCH 2/4] inet6: Consolidate common code for IPv6 Hop Limit / Traffic Class
Date: Sun, 19 Jul 2009 20:23:37 +0200	[thread overview]
Message-ID: <1248027819-23959-3-git-send-email-gerrit@erg.abdn.ac.uk> (raw)
In-Reply-To: <1248027819-23959-2-git-send-email-gerrit@erg.abdn.ac.uk>

The RFC 3542 definitions for Hop Limit (6.3) and Traffic Class (6.5) cmsg
values differ only in the names of the cmsg type. So does the code.
The patch combines these commonalities.

Further changes:
----------------
Replaced other use of temporary 'int' variable with 'val' variable.

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
---
 net/ipv6/datagram.c |   34 ++++++++++++----------------------
 1 files changed, 12 insertions(+), 22 deletions(-)

--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -504,10 +504,10 @@ int datagram_send_ctl(struct net *net,
 	struct cmsghdr *cmsg;
 	struct ipv6_rt_hdr *rthdr;
 	struct ipv6_opt_hdr *hdr;
+	int val;
 	int len;
 
 	for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
-		int addr_type;
 
 		if (!CMSG_OK(msg, cmsg))
 			return -EINVAL;
@@ -532,17 +532,17 @@ int datagram_send_ctl(struct net *net,
 				fl->oif = src_info->ipi6_ifindex;
 			}
 
-			addr_type = __ipv6_addr_type(&src_info->ipi6_addr);
+			val = __ipv6_addr_type(&src_info->ipi6_addr);
 
 			if (fl->oif) {
 				dev = dev_get_by_index(net, fl->oif);
 				if (!dev)
 					return -ENODEV;
-			} else if (addr_type & IPV6_ADDR_LINKLOCAL)
+			} else if (val & IPV6_ADDR_LINKLOCAL)
 				return -EINVAL;
 
-			if (addr_type != IPV6_ADDR_ANY) {
-				int strict = __ipv6_addr_src_scope(addr_type) <= IPV6_ADDR_SCOPE_LINKLOCAL;
+			if (val != IPV6_ADDR_ANY) {
+				int strict = __ipv6_addr_src_scope(val) <= IPV6_ADDR_SCOPE_LINKLOCAL;
 				if (!ipv6_chk_addr(net, &src_info->ipi6_addr, strict ? dev : NULL, 0))
 					return -EINVAL;
 				ipv6_addr_copy(&fl->fl6_src, &src_info->ipi6_addr);
@@ -666,30 +666,20 @@ int datagram_send_ctl(struct net *net,
 
 		case IPV6_2292HOPLIMIT:
 		case IPV6_HOPLIMIT:
-			if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
-				return -EINVAL;
-
-			*hlimit = *(int *)CMSG_DATA(cmsg);
-			if (*hlimit < -1 || *hlimit > 0xff)
-				return -EINVAL;
-
-			break;
-
 		case IPV6_TCLASS:
-		    {
-			int tc;
-
 			if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
 				return -EINVAL;
 
-			tc = *(int *)CMSG_DATA(cmsg);
-			if (tc < -1 || tc > 0xff)
+			val = *(int *)CMSG_DATA(cmsg);
+			if (val < -1 || val > 0xff)
 				return -EINVAL;
 
-			*tclass = tc;
-
+			if (cmsg->cmsg_type == IPV6_TCLASS)
+				*tclass = val;
+			else
+				*hlimit = val;
 			break;
-		    }
+
 		default:
 			LIMIT_NETDEBUG(KERN_DEBUG "invalid cmsg type: %d\n",
 				       cmsg->cmsg_type);

  reply	other threads:[~2009-07-19 18:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <inet6_minor_cleanups>
2009-07-19 18:23 ` [PATCH 0/4] inet6: minor cleanups Gerrit Renker
2009-07-19 18:23   ` [PATCH 1/4] inet6: Return convention in datagram_send_ctl Gerrit Renker
2009-07-19 18:23     ` Gerrit Renker [this message]
2009-07-19 18:23       ` [PATCH 3/4] inet6: Conversion from u8 to int Gerrit Renker
2009-07-19 18:23         ` [PATCH 4/4] inet: in_route.h redefined macro Gerrit Renker
2009-07-21 19:57   ` [PATCH 0/4] inet6: minor cleanups David Miller
2009-07-22 20:17     ` Question: AF-Independence of ECN (was [PATCH 0/4] inet6: minor cleanups) Gerrit Renker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1248027819-23959-3-git-send-email-gerrit@erg.abdn.ac.uk \
    --to=gerrit@erg.abdn.ac.uk \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox