Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=befffe901649e2cc421d0d150c4379d01658cf6b
Commit:     befffe901649e2cc421d0d150c4379d01658cf6b
Parent:     832e3ca62d6ee1893db05f5202c24ae5331e19ba
Author:     Brian Haley <[EMAIL PROTECTED]>
AuthorDate: Tue Dec 12 17:09:49 2006 -0800
Committer:  David S. Miller <[EMAIL PROTECTED]>
CommitDate: Wed Dec 13 16:48:25 2006 -0800

    [IPV6]: Fix IPV6_UNICAST_HOPS getsockopt().
    
    > Relevant standard (RFC 3493) notes:
    >
    >    The IPV6_UNICAST_HOPS option may be used with getsockopt() to
    >    determine the hop limit value that the system will use for subsequent
    >    unicast packets sent via that socket.
    >
    > I don't reckon -1 could be the hop limit value.
    
    -1 means un-initialized.
    
    > IMHO, the value from
    > case 1 (if socket is connected to some destination), otherwise case 2
    > (if bound to a scope interface) or ultimately the default hop limit
    > ought to be returned instead, as it will be most often correct, while
    > the current behavior is always wrong, unless setsockopt() has been used
    > first. I don't if some people may think doing a route lookup in
    > getsockopt might be overly expensive, but at least the two other cases
    > should be ok, particularly the last one.
    
    The following patch seems to work for me, but this code has behaved this
    way for a while, so don't know if it will break any existing apps.
    
    Signed-off-by: Brian Haley <[EMAIL PROTECTED]>
    Signed-off-by: David S. Miller <[EMAIL PROTECTED]>
---
 net/ipv6/ipv6_sockglue.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
index 1eafcfc..352690e 100644
--- a/net/ipv6/ipv6_sockglue.c
+++ b/net/ipv6/ipv6_sockglue.c
@@ -978,12 +978,27 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, 
int optname,
                break;
 
        case IPV6_UNICAST_HOPS:
-               val = np->hop_limit;
-               break;
-
        case IPV6_MULTICAST_HOPS:
-               val = np->mcast_hops;
+       {
+               struct dst_entry *dst;
+
+               if (optname == IPV6_UNICAST_HOPS)
+                       val = np->hop_limit;
+               else
+                       val = np->mcast_hops;
+
+               dst = sk_dst_get(sk);
+               if (dst) {
+                       if (val < 0)
+                               val = dst_metric(dst, RTAX_HOPLIMIT);
+                       if (val < 0)
+                               val = ipv6_get_hoplimit(dst->dev);
+                       dst_release(dst);
+               }
+               if (val < 0)
+                       val = ipv6_devconf.hop_limit;
                break;
+       }
 
        case IPV6_MULTICAST_LOOP:
                val = np->mc_loop;
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to